Ticket #2226: mythtv-diseqc-multiswitch.patch
| File mythtv-diseqc-multiswitch.patch, 9.0 KB (added by , 19 years ago) |
|---|
-
libs/libmythtv/diseqc.cpp
450 450 ApplyVoltage(settings, tuning); 451 451 452 452 // turn off tone burst first if commands need to be sent 453 if (m_root->IsCommandNeeded(settings ))453 if (m_root->IsCommandNeeded(settings, tuning)) 454 454 { 455 455 SetTone(false); 456 456 usleep(DISEQC_SHORT_WAIT); … … 969 969 if (pos < 0) 970 970 return false; 971 971 972 // determine if switch command needs to be sent based on last pos973 if ((m_last_pos == (uint)pos) && m_children[pos])974 return m_children[pos]->Execute(settings, tuning);975 976 972 // perform switching 977 switch (m_type)973 if (ShouldSwitch(settings, tuning)) 978 974 { 979 case kTypeTone: 980 success = ExecuteTone(settings, tuning, pos); 981 break; 982 case kTypeDiSEqCCommitted: 983 case kTypeDiSEqCUncommitted: 984 success = ExecuteDiseqc(settings, tuning, pos); 985 break; 986 case kTypeLegacySW21: 987 case kTypeLegacySW42: 988 case kTypeLegacySW64: 989 success = ExecuteLegacy(settings, tuning, pos); 990 break; 991 default: 992 success = false; 993 VERBOSE(VB_IMPORTANT, LOC_ERR + 994 QString("Unknown switch type (%1)") 995 .arg((uint)m_type)); 996 break; 997 } 975 switch (m_type) 976 { 977 case kTypeTone: 978 success = ExecuteTone(settings, tuning, pos); 979 break; 980 case kTypeDiSEqCCommitted: 981 case kTypeDiSEqCUncommitted: 982 success = ExecuteDiseqc(settings, tuning, pos); 983 break; 984 case kTypeLegacySW21: 985 case kTypeLegacySW42: 986 case kTypeLegacySW64: 987 success = ExecuteLegacy(settings, tuning, pos); 988 break; 989 default: 990 success = false; 991 VERBOSE(VB_IMPORTANT, LOC_ERR + 992 QString("Unknown switch type (%1)") 993 .arg((uint)m_type)); 994 break; 995 } 998 996 999 // if a child device will be sending a diseqc command, wait 100ms 1000 if (m_children[pos]->IsCommandNeeded(settings)) 1001 { 1002 VERBOSE(VB_CHANNEL, LOC + "Waiting for switch"); 1003 usleep(DISEQC_LONG_WAIT); 997 // if a child device will be sending a diseqc command, wait 100ms 998 if (m_children[pos]->IsCommandNeeded(settings, tuning)) 999 { 1000 VERBOSE(VB_CHANNEL, LOC + "Waiting for switch"); 1001 usleep(DISEQC_LONG_WAIT); 1002 } 1003 1004 m_last_pos = pos; 1004 1005 } 1005 1006 1006 m_last_pos = pos;1007 1008 1007 // chain to child if the switch was successful 1009 1008 if (success) 1010 1009 success = m_children[pos]->Execute(settings, tuning); … … 1015 1014 void DiSEqCDevSwitch::Reset(void) 1016 1015 { 1017 1016 m_last_pos = (uint) -1; 1017 m_last_high_band = (uint) -1; 1018 m_last_horizontal = (uint) -1; 1018 1019 dvbdev_vec_t::iterator it = m_children.begin(); 1019 1020 for (; it != m_children.end(); ++it) 1020 1021 { … … 1023 1024 } 1024 1025 } 1025 1026 1026 bool DiSEqCDevSwitch::IsCommandNeeded(const DiSEqCDevSettings &settings) const 1027 bool DiSEqCDevSwitch::IsCommandNeeded(const DiSEqCDevSettings &settings, 1028 const DVBTuning &tuning) const 1027 1029 { 1028 // sanity check switch position1029 1030 int pos = GetPosition(settings); 1030 1031 if (pos < 0) 1031 1032 return false; 1032 1033 1033 // if position is changing, a command is definitely needed 1034 if ((uint)pos != m_last_pos) 1035 return true; 1036 1037 // otherwise, the child that will be selected may need a command 1038 return m_children[pos]->IsCommandNeeded(settings); 1034 return (ShouldSwitch(settings, tuning) || 1035 m_children[pos]->IsCommandNeeded(settings, tuning)); 1039 1036 } 1040 1037 1041 1038 DiSEqCDevDevice *DiSEqCDevSwitch::GetSelectedChild(const DiSEqCDevSettings &settings) const … … 1348 1345 return false; 1349 1346 } 1350 1347 1348 bool DiSEqCDevSwitch::ShouldSwitch(const DiSEqCDevSettings &settings, 1349 const DVBTuning &tuning) const 1350 { 1351 int pos = GetPosition(settings); 1352 if (pos < 0) 1353 return false; 1354 1355 // committed switch should change for band and polarity as well 1356 if (kTypeDiSEqCCommitted == m_type) 1357 { 1358 // retrieve LNB info 1359 bool high_band = false; 1360 bool horizontal = false; 1361 DiSEqCDevLNB *lnb = m_tree.FindLNB(settings); 1362 if (lnb) 1363 { 1364 high_band = lnb->IsHighBand(tuning); 1365 horizontal = lnb->IsHorizontal(tuning); 1366 } 1367 1368 if(high_band != m_last_high_band || 1369 horizontal != m_last_horizontal) 1370 return true; 1371 } 1372 1373 return m_last_pos != (uint)pos; 1374 } 1375 1351 1376 bool DiSEqCDevSwitch::ExecuteDiseqc(const DiSEqCDevSettings &settings, 1352 1377 const DVBTuning &tuning, 1353 1378 uint pos) … … 1385 1410 VERBOSE(VB_CHANNEL, LOC + "Changing to DiSEqC switch port " + 1386 1411 QString("%1/%2").arg(pos + 1).arg(m_num_ports)); 1387 1412 1388 return m_tree.SendCommand(DISEQC_ADR_SW_ALL, cmd, m_repeat, 1, &data); 1413 bool ret = m_tree.SendCommand(DISEQC_ADR_SW_ALL, cmd, m_repeat, 1, &data); 1414 if(ret) 1415 { 1416 m_last_high_band = high_band; 1417 m_last_horizontal = horizontal; 1418 } 1419 return ret; 1389 1420 } 1390 1421 1391 1422 int DiSEqCDevSwitch::GetPosition(const DiSEqCDevSettings &settings) const … … 1490 1521 m_child->Reset(); 1491 1522 } 1492 1523 1493 bool DiSEqCDevRotor::IsCommandNeeded(const DiSEqCDevSettings &settings) const 1524 bool DiSEqCDevRotor::IsCommandNeeded(const DiSEqCDevSettings &settings, 1525 const DVBTuning &tuning) const 1494 1526 { 1495 1527 double position = settings.GetValue(GetDeviceID()); 1496 1528 … … 1498 1530 return true; 1499 1531 1500 1532 if (m_child) 1501 return m_child->IsCommandNeeded(settings );1533 return m_child->IsCommandNeeded(settings, tuning); 1502 1534 1503 1535 return false; 1504 1536 } … … 1528 1560 return true; 1529 1561 } 1530 1562 1531 uint DiSEqCDevRotor::GetVoltage(const DiSEqCDevSettings &settings, 1532 const DVBTuning &tuning) const 1563 bool DiSEqCDevRotor::IsMoving(const DiSEqCDevSettings &settings) const 1533 1564 { 1534 1565 double position = settings.GetValue(GetDeviceID()); 1535 1566 double completed = GetProgress(); 1536 1567 bool moving = (completed < 1.0) || (position != m_last_position); 1537 1568 1569 return (m_last_pos_known && moving); 1570 } 1571 1572 uint DiSEqCDevRotor::GetVoltage(const DiSEqCDevSettings &settings, 1573 const DVBTuning &tuning) const 1574 { 1538 1575 // override voltage if the last position is known and the rotor is moving 1539 if ( m_last_pos_known && moving)1576 if (IsMoving(settings)) 1540 1577 { 1541 1578 VERBOSE(VB_CHANNEL, LOC + 1542 1579 "Overriding voltage to 18V for faster rotor movement"); -
libs/libmythtv/diseqc.h
159 159 QString GetDescription(void) const { return m_desc; } 160 160 virtual uint GetChildCount(void) const { return 0; } 161 161 virtual bool IsCommandNeeded( 162 const DiSEqCDevSettings&) const { return false; } 162 const DiSEqCDevSettings&, const DVBTuning&) 163 const { return false; } 163 164 virtual uint GetVoltage( 164 165 const DiSEqCDevSettings&, const DVBTuning&) const = 0; 165 166 … … 230 231 // Gets 231 232 dvbdev_switch_t GetType(void) const { return m_type; } 232 233 uint GetNumPorts(void) const { return m_num_ports; } 234 bool ShouldSwitch(const DiSEqCDevSettings &settings, 235 const DVBTuning &tuning) const; 233 236 virtual uint GetChildCount(void) const; 234 virtual bool IsCommandNeeded(const DiSEqCDevSettings&) const; 237 virtual bool IsCommandNeeded(const DiSEqCDevSettings&, 238 const DVBTuning&) const; 235 239 virtual uint GetVoltage(const DiSEqCDevSettings&, 236 240 const DVBTuning&) const; 237 241 … … 257 261 dvbdev_switch_t m_type; 258 262 uint m_num_ports; 259 263 uint m_last_pos; 264 uint m_last_high_band; 265 uint m_last_horizontal; 260 266 dvbdev_vec_t m_children; 261 267 262 268 static const TypeTable SwitchTypeTable[7]; … … 291 297 double GetProgress(void) const; 292 298 bool IsPositionKnown(void) const; 293 299 virtual uint GetChildCount(void) const { return 1; } 294 virtual bool IsCommandNeeded(const DiSEqCDevSettings&) const; 300 virtual bool IsCommandNeeded(const DiSEqCDevSettings&, 301 const DVBTuning&) const; 302 bool IsMoving(const DiSEqCDevSettings&) const; 295 303 virtual uint GetVoltage(const DiSEqCDevSettings&, 296 304 const DVBTuning&) const; 297 305
