00001
00002
00003
00004
00005
00006
00007
00008 #include <cmath>
00009
00010
00011 #include "mythdbcon.h"
00012 #include "mythlogging.h"
00013 #include "diseqcsettings.h"
00014
00015
00016
00017 static GlobalLineEdit *DiSEqCLatitude(void)
00018 {
00019 GlobalLineEdit *gc = new GlobalLineEdit("latitude");
00020 gc->setLabel("Latitude");
00021 gc->setHelpText(
00022 DeviceTree::tr("The Cartesian latitude for your location. "
00023 "Use negative numbers for southern "
00024 "and western coordinates."));
00025 return gc;
00026 }
00027
00028 static GlobalLineEdit *DiSEqCLongitude(void)
00029 {
00030 GlobalLineEdit *gc = new GlobalLineEdit("longitude");
00031 gc->setLabel("Longitude");
00032 gc->setHelpText(
00033 DeviceTree::tr("The Cartesian longitude for your location. "
00034 "Use negative numbers for southern "
00035 "and western coordinates."));
00036 return gc;
00037 }
00038
00040
00041 class DeviceTypeSetting : public ComboBoxSetting, public Storage
00042 {
00043 public:
00044 DeviceTypeSetting(DiSEqCDevDevice &device) :
00045 ComboBoxSetting(this), m_device(device)
00046 {
00047 setLabel(DeviceTree::tr("Device Type"));
00048 addSelection(DeviceTree::tr("Switch"),
00049 QString::number((uint) DiSEqCDevDevice::kTypeSwitch));
00050 addSelection(DeviceTree::tr("Rotor"),
00051 QString::number((uint) DiSEqCDevDevice::kTypeRotor));
00052 addSelection(DeviceTree::tr("LNB"),
00053 QString::number((uint) DiSEqCDevDevice::kTypeLNB));
00054 }
00055
00056 virtual void Load(void)
00057 {
00058 QString tmp = QString::number((uint) m_device.GetDeviceType());
00059 setValue(getValueIndex(tmp));
00060 }
00061
00062 virtual void Save(void)
00063 {
00064 m_device.SetDeviceType(
00065 (DiSEqCDevDevice::dvbdev_t) getValue().toUInt());
00066 }
00067
00068 virtual void Save(QString ) { }
00069
00070 private:
00071 DiSEqCDevDevice &m_device;
00072 };
00073
00075
00076 class DeviceDescrSetting : public LineEditSetting, public Storage
00077 {
00078 public:
00079 DeviceDescrSetting(DiSEqCDevDevice &device) :
00080 LineEditSetting(this), m_device(device)
00081 {
00082 setLabel(DeviceTree::tr("Description"));
00083 QString help = DeviceTree::tr(
00084 "Optional descriptive name for this device, to "
00085 "make it easier to configure settings later.");
00086 setHelpText(help);
00087 }
00088
00089 virtual void Load(void)
00090 {
00091 setValue(m_device.GetDescription());
00092 }
00093
00094 virtual void Save(void)
00095 {
00096 m_device.SetDescription(getValue());
00097 }
00098
00099 virtual void Save(QString ) { }
00100
00101 private:
00102 DiSEqCDevDevice &m_device;
00103 };
00104
00105
00107
00108 class DeviceRepeatSetting : public SpinBoxSetting, public Storage
00109 {
00110 public:
00111 DeviceRepeatSetting(DiSEqCDevDevice &device) :
00112 SpinBoxSetting(this, 0, 5, 1), m_device(device)
00113 {
00114 setLabel(DeviceTree::tr("Repeat Count"));
00115 QString help = DeviceTree::tr(
00116 "Number of times to repeat DiSEqC commands sent to this device. "
00117 "Larger values may help with less reliable devices.");
00118 setHelpText(help);
00119 }
00120
00121 virtual void Load(void)
00122 {
00123 setValue(m_device.GetRepeatCount());
00124 }
00125
00126 virtual void Save(void)
00127 {
00128 m_device.SetRepeatCount(getValue().toUInt());
00129 }
00130
00131 virtual void Save(QString ) { }
00132
00133 private:
00134 DiSEqCDevDevice &m_device;
00135 };
00136
00138
00139 class SwitchTypeSetting : public ComboBoxSetting, public Storage
00140 {
00141 public:
00142 SwitchTypeSetting(DiSEqCDevSwitch &switch_dev) :
00143 ComboBoxSetting(this), m_switch(switch_dev)
00144 {
00145 setLabel(DeviceTree::tr("Switch Type"));
00146 setHelpText(DeviceTree::tr("Select the type of switch from the list."));
00147
00148 addSelection(DeviceTree::tr("Tone"),
00149 QString::number((uint) DiSEqCDevSwitch::kTypeTone));
00150 addSelection(DeviceTree::tr("Voltage"),
00151 QString::number((uint) DiSEqCDevSwitch::kTypeVoltage));
00152 addSelection(DeviceTree::tr("Mini DiSEqC"),
00153 QString::number((uint) DiSEqCDevSwitch::kTypeMiniDiSEqC));
00154 addSelection(DeviceTree::tr("DiSEqC"),
00155 QString::number((uint)
00156 DiSEqCDevSwitch::kTypeDiSEqCCommitted));
00157 addSelection(DeviceTree::tr("DiSEqC (Uncommitted)"),
00158 QString::number((uint)
00159 DiSEqCDevSwitch::kTypeDiSEqCUncommitted));
00160 addSelection(DeviceTree::tr("Legacy SW21"),
00161 QString::number((uint) DiSEqCDevSwitch::kTypeLegacySW21));
00162 addSelection(DeviceTree::tr("Legacy SW42"),
00163 QString::number((uint) DiSEqCDevSwitch::kTypeLegacySW42));
00164 addSelection(DeviceTree::tr("Legacy SW64"),
00165 QString::number((uint) DiSEqCDevSwitch::kTypeLegacySW64));
00166 }
00167
00168 virtual void Load(void)
00169 {
00170 setValue(getValueIndex(QString::number((uint) m_switch.GetType())));
00171 }
00172
00173 virtual void Save(void)
00174 {
00175 m_switch.SetType((DiSEqCDevSwitch::dvbdev_switch_t)
00176 getValue().toUInt());
00177 }
00178
00179 virtual void Save(QString ) { }
00180
00181 private:
00182 DiSEqCDevSwitch &m_switch;
00183 };
00184
00186
00187 class SwitchAddressSetting : public LineEditSetting, public Storage
00188 {
00189 public:
00190 SwitchAddressSetting(DiSEqCDevSwitch &switch_dev) :
00191 LineEditSetting(this), m_switch(switch_dev)
00192 {
00193 setLabel(DeviceTree::tr("Address of switch"));
00194 setHelpText(DeviceTree::tr("The DiSEqC address of the switch."));
00195 }
00196
00197 virtual void Load(void)
00198 {
00199 setValue(QString("0x%1").arg(m_switch.GetAddress(), 0, 16));
00200 }
00201
00202 virtual void Save(void)
00203 {
00204 m_switch.SetAddress(getValue().toUInt(0, 16));
00205 }
00206 virtual void Save(QString ) { Save(); }
00207
00208 private:
00209 DiSEqCDevSwitch &m_switch;
00210 };
00211
00213
00214 class SwitchPortsSetting : public LineEditSetting, public Storage
00215 {
00216 public:
00217 SwitchPortsSetting(DiSEqCDevSwitch &switch_dev) :
00218 LineEditSetting(this), m_switch(switch_dev)
00219 {
00220 setLabel(DeviceTree::tr("Number of ports"));
00221 setHelpText(DeviceTree::tr("The number of ports this switch has."));
00222 }
00223
00224 virtual void Load(void)
00225 {
00226 setValue(QString::number(m_switch.GetNumPorts()));
00227 }
00228
00229 virtual void Save(void)
00230 {
00231 m_switch.SetNumPorts(getValue().toUInt());
00232 }
00233
00234 virtual void Save(QString ) { }
00235
00236 private:
00237 DiSEqCDevSwitch &m_switch;
00238 };
00239
00241
00242 SwitchConfig::SwitchConfig(DiSEqCDevSwitch &switch_dev)
00243 {
00244 ConfigurationGroup *group =
00245 new VerticalConfigurationGroup(false, false);
00246 group->setLabel(DeviceTree::tr("Switch Configuration"));
00247
00248 group->addChild(new DeviceDescrSetting(switch_dev));
00249 group->addChild(new DeviceRepeatSetting(switch_dev));
00250 m_type = new SwitchTypeSetting(switch_dev);
00251 group->addChild(m_type);
00252 m_address = new SwitchAddressSetting(switch_dev);
00253 group->addChild(m_address);
00254 m_ports = new SwitchPortsSetting(switch_dev);
00255 group->addChild(m_ports);
00256
00257 connect(m_type, SIGNAL(valueChanged(const QString&)),
00258 this, SLOT( update(void)));
00259
00260 addChild(group);
00261 }
00262
00263 void SwitchConfig::update(void)
00264 {
00265 switch ((DiSEqCDevSwitch::dvbdev_switch_t) m_type->getValue().toUInt())
00266 {
00267 case DiSEqCDevSwitch::kTypeTone:
00268 case DiSEqCDevSwitch::kTypeVoltage:
00269 case DiSEqCDevSwitch::kTypeMiniDiSEqC:
00270 case DiSEqCDevSwitch::kTypeLegacySW21:
00271 case DiSEqCDevSwitch::kTypeLegacySW42:
00272 m_address->setValue(QString("0x10"));
00273 m_address->setEnabled(false);
00274 m_ports->setValue("2");
00275 m_ports->setEnabled(false);
00276 break;
00277 case DiSEqCDevSwitch::kTypeLegacySW64:
00278 m_address->setValue(QString("0x10"));
00279 m_address->setEnabled(false);
00280 m_ports->setValue("3");
00281 m_ports->setEnabled(false);
00282 break;
00283 case DiSEqCDevSwitch::kTypeDiSEqCCommitted:
00284 case DiSEqCDevSwitch::kTypeDiSEqCUncommitted:
00285 m_address->setEnabled(true);
00286 m_ports->setEnabled(true);
00287 break;
00288 }
00289 }
00290
00292
00293 class RotorTypeSetting : public ComboBoxSetting, public Storage
00294 {
00295 public:
00296 RotorTypeSetting(DiSEqCDevRotor &rotor) :
00297 ComboBoxSetting(this), m_rotor(rotor)
00298 {
00299 setLabel(DeviceTree::tr("Rotor Type"));
00300 setHelpText(DeviceTree::tr("Select the type of rotor from the list."));
00301 addSelection(DeviceTree::tr("DiSEqC 1.2"),
00302 QString::number((uint) DiSEqCDevRotor::kTypeDiSEqC_1_2));
00303 addSelection(DeviceTree::tr("DiSEqC 1.3 (GotoX/USALS)"),
00304 QString::number((uint) DiSEqCDevRotor::kTypeDiSEqC_1_3));
00305 }
00306
00307 virtual void Load(void)
00308 {
00309 setValue(getValueIndex(QString::number((uint)m_rotor.GetType())));
00310 }
00311
00312 virtual void Save(void)
00313 {
00314 m_rotor.SetType((DiSEqCDevRotor::dvbdev_rotor_t)getValue().toUInt());
00315 }
00316
00317 virtual void Save(QString ) { }
00318
00319 private:
00320 DiSEqCDevRotor &m_rotor;
00321 };
00322
00324
00325 class RotorLoSpeedSetting : public LineEditSetting, public Storage
00326 {
00327 public:
00328 RotorLoSpeedSetting(DiSEqCDevRotor &rotor) :
00329 LineEditSetting(this), m_rotor(rotor)
00330 {
00331 setLabel(DeviceTree::tr("Rotor Low Speed (deg/sec)"));
00332 QString help = DeviceTree::tr(
00333 "To allow the approximate monitoring of rotor movement, enter "
00334 "the rated angular speed of the rotor when powered at 13V.");
00335 setHelpText(help);
00336 }
00337
00338 virtual void Load(void)
00339 {
00340 setValue(QString::number(m_rotor.GetLoSpeed()));
00341 }
00342
00343 virtual void Save(void)
00344 {
00345 m_rotor.SetLoSpeed(getValue().toDouble());
00346 }
00347
00348 virtual void Save(QString ) { }
00349
00350 private:
00351 DiSEqCDevRotor &m_rotor;
00352 };
00353
00355
00356 class RotorHiSpeedSetting : public LineEditSetting, public Storage
00357 {
00358 public:
00359 RotorHiSpeedSetting(DiSEqCDevRotor &rotor) :
00360 LineEditSetting(this), m_rotor(rotor)
00361 {
00362 setLabel(DeviceTree::tr("Rotor High Speed (deg/sec)"));
00363 QString help = DeviceTree::tr(
00364 "To allow the approximate monitoring of rotor movement, enter "
00365 "the rated angular speed of the rotor when powered at 18V.");
00366 setHelpText(help);
00367 }
00368
00369 virtual void Load(void)
00370 {
00371 setValue(QString::number(m_rotor.GetHiSpeed()));
00372 }
00373
00374 virtual void Save(void)
00375 {
00376 m_rotor.SetHiSpeed(getValue().toDouble());
00377 }
00378
00379 virtual void Save(QString ) { }
00380
00381 private:
00382 DiSEqCDevRotor &m_rotor;
00383 };
00384
00386
00387 static QString AngleToString(double angle)
00388 {
00389 QString str = QString::null;
00390 if (angle >= 0.0)
00391 str = QString::number(angle) +
00392 DeviceTree::tr("E", "Eastern Hemisphere");
00393 else
00394 str = QString::number(-angle) +
00395 DeviceTree::tr("W", "Western Hemisphere");
00396 return str;
00397 }
00398
00399 static double AngleToEdit(double angle, QString &hemi)
00400 {
00401 if (angle > 0.0)
00402 {
00403 hemi = "E";
00404 return angle;
00405 }
00406
00407 hemi = "W";
00408 return -angle;
00409 }
00410
00411 static double AngleToFloat(const QString &angle, bool translated = true)
00412 {
00413 if (angle.length() < 2)
00414 return 0.0;
00415
00416 double pos;
00417 QChar postfix = angle.at(angle.length() - 1);
00418 if (postfix.isLetter())
00419 {
00420 pos = angle.left(angle.length() - 1).toDouble();
00421 if ((translated &&
00422 (postfix.toUpper() ==
00423 DeviceTree::tr("W", "Western Hemisphere")[0])) ||
00424 (!translated && (postfix.toUpper() == 'W')))
00425 {
00426 pos = -pos;
00427 }
00428 }
00429 else
00430 pos = angle.toDouble();
00431
00432 return pos;
00433 }
00434
00435 RotorPosMap::RotorPosMap(DiSEqCDevRotor &rotor) :
00436 ListBoxSetting(this), m_rotor(rotor)
00437 {
00438 connect(this, SIGNAL(editButtonPressed(int)), SLOT(edit(void)));
00439 connect(this, SIGNAL(deleteButtonPressed(int)), SLOT(del(void)));
00440 connect(this, SIGNAL(accepted(int)), SLOT(edit(void)));
00441 }
00442
00443 void RotorPosMap::Load(void)
00444 {
00445 m_posmap = m_rotor.GetPosMap();
00446 PopulateList();
00447 }
00448
00449 void RotorPosMap::Save(void)
00450 {
00451 m_rotor.SetPosMap(m_posmap);
00452 }
00453
00454 void RotorPosMap::edit(void)
00455 {
00456 uint id = getValue().toUInt();
00457
00458 QString angle;
00459 if (MythPopupBox::showGetTextPopup(
00460 GetMythMainWindow(),
00461 DeviceTree::tr("Position Index %1").arg(id),
00462 DeviceTree::tr("Orbital Position"), angle))
00463 {
00464 m_posmap[id] = AngleToFloat(angle);
00465 PopulateList();
00466 }
00467 }
00468
00469 void RotorPosMap::del(void)
00470 {
00471 uint id = getValue().toUInt();
00472 m_posmap.erase(m_posmap.find(id));
00473 PopulateList();
00474 }
00475
00476 void RotorPosMap::PopulateList(void)
00477 {
00478 int old_sel = getValueIndex(getValue());
00479 clearSelections();
00480 uint num_pos = 64;
00481 for (uint pos = 1; pos < num_pos; pos++)
00482 {
00483 uint_to_dbl_t::const_iterator it = m_posmap.find(pos);
00484 QString posval = DeviceTree::tr("None");
00485 if (it != m_posmap.end())
00486 posval = AngleToString(*it);
00487
00488 addSelection(DeviceTree::tr("Position #%1 (%2)").arg(pos).arg(posval),
00489 QString::number(pos));
00490 }
00491 setCurrentItem(old_sel);
00492 }
00493
00495
00496 class RotorPosConfig : public ConfigurationDialog
00497 {
00498 public:
00499 RotorPosConfig(DiSEqCDevRotor &rotor)
00500 {
00501 setLabel(DeviceTree::tr("Rotor Position Map"));
00502 addChild(new RotorPosMap(rotor));
00503 }
00504
00505 virtual DialogCode exec(void)
00506 {
00507 while (ConfigurationDialog::exec() == kDialogCodeAccepted);
00508 return kDialogCodeRejected;
00509 }
00510 virtual DialogCode exec(bool , bool )
00511 { return exec(); }
00512 };
00513
00515
00516 RotorConfig::RotorConfig(DiSEqCDevRotor &rotor) : m_rotor(rotor)
00517 {
00518 ConfigurationGroup *group =
00519 new VerticalConfigurationGroup(false, false);
00520 group->setLabel(DeviceTree::tr("Rotor Configuration"));
00521
00522 group->addChild(new DeviceDescrSetting(rotor));
00523 group->addChild(new DeviceRepeatSetting(rotor));
00524
00525 ConfigurationGroup *tgroup =
00526 new HorizontalConfigurationGroup(false, false, true, true);
00527
00528 RotorTypeSetting *rtype = new RotorTypeSetting(rotor);
00529 connect(rtype, SIGNAL(valueChanged(const QString&)),
00530 this, SLOT( SetType( const QString&)));
00531 tgroup->addChild(rtype);
00532
00533 m_pos = new TransButtonSetting();
00534 m_pos->setLabel(DeviceTree::tr("Positions"));
00535 m_pos->setHelpText(DeviceTree::tr("Rotor position setup."));
00536 m_pos->setEnabled(rotor.GetType() == DiSEqCDevRotor::kTypeDiSEqC_1_2);
00537 connect(m_pos, SIGNAL(pressed(void)),
00538 this, SLOT( RunRotorPositionsDialog(void)));
00539 tgroup->addChild(m_pos);
00540
00541 group->addChild(tgroup);
00542 group->addChild(new RotorLoSpeedSetting(rotor));
00543 group->addChild(new RotorHiSpeedSetting(rotor));
00544 group->addChild(DiSEqCLatitude());
00545 group->addChild(DiSEqCLongitude());
00546
00547 addChild(group);
00548 }
00549
00550 void RotorConfig::SetType(const QString &type)
00551 {
00552 DiSEqCDevRotor::dvbdev_rotor_t rtype;
00553 rtype = (DiSEqCDevRotor::dvbdev_rotor_t) type.toUInt();
00554 m_pos->setEnabled(rtype == DiSEqCDevRotor::kTypeDiSEqC_1_2);
00555 }
00556
00557 void RotorConfig::RunRotorPositionsDialog(void)
00558 {
00559 RotorPosConfig config(m_rotor);
00560 config.exec();
00561 config.Save();
00562 }
00563
00565
00566 class lnb_preset
00567 {
00568 public:
00569 lnb_preset(const QString &_name, DiSEqCDevLNB::dvbdev_lnb_t _type,
00570 uint _lof_sw = 0, uint _lof_lo = 0,
00571 uint _lof_hi = 0, bool _pol_inv = false) :
00572 name(_name), type(_type),
00573 lof_sw(_lof_sw), lof_lo(_lof_lo),
00574 lof_hi(_lof_hi), pol_inv(_pol_inv) {}
00575
00576 public:
00577 QString name;
00578 DiSEqCDevLNB::dvbdev_lnb_t type;
00579 uint lof_sw;
00580 uint lof_lo;
00581 uint lof_hi;
00582 bool pol_inv;
00583 };
00584
00585 static lnb_preset lnb_presets[] =
00586 {
00587
00588 lnb_preset(DeviceTree::tr("Universal (Europe)"),
00589 DiSEqCDevLNB::kTypeVoltageAndToneControl,
00590 11700000, 9750000, 10600000),
00591 lnb_preset(DeviceTree::tr("Single (Europe)"),
00592 DiSEqCDevLNB::kTypeVoltageControl, 0, 9750000),
00593 lnb_preset(DeviceTree::tr("Circular (N. America)"),
00594 DiSEqCDevLNB::kTypeVoltageControl, 0, 11250000),
00595 lnb_preset(DeviceTree::tr("Linear (N. America)"),
00596 DiSEqCDevLNB::kTypeVoltageControl, 0, 10750000),
00597 lnb_preset(DeviceTree::tr("C Band"),
00598 DiSEqCDevLNB::kTypeVoltageControl, 0, 5150000),
00599 lnb_preset(DeviceTree::tr("DishPro Bandstacked"),
00600 DiSEqCDevLNB::kTypeBandstacked, 0, 11250000, 14350000),
00601 lnb_preset(QString::null, DiSEqCDevLNB::kTypeVoltageControl),
00602 };
00603
00604 static uint FindPreset(const DiSEqCDevLNB &lnb)
00605 {
00606 uint i;
00607 for (i = 0; !lnb_presets[i].name.isEmpty(); i++)
00608 {
00609 if (lnb_presets[i].type == lnb.GetType() &&
00610 lnb_presets[i].lof_sw == lnb.GetLOFSwitch() &&
00611 lnb_presets[i].lof_lo == lnb.GetLOFLow() &&
00612 lnb_presets[i].lof_hi == lnb.GetLOFHigh() &&
00613 lnb_presets[i].pol_inv== lnb.IsPolarityInverted())
00614 {
00615 break;
00616 }
00617 }
00618 return i;
00619 }
00620
00621 class LNBPresetSetting : public ComboBoxSetting, public Storage
00622 {
00623 public:
00624 LNBPresetSetting(DiSEqCDevLNB &lnb) : ComboBoxSetting(this), m_lnb(lnb)
00625 {
00626 setLabel(DeviceTree::tr("LNB Preset"));
00627 QString help = DeviceTree::tr(
00628 "Select the LNB preset from the list, or choose "
00629 "'Custom' and set the advanced settings below.");
00630 setHelpText(help);
00631
00632 uint i = 0;
00633 for (; !lnb_presets[i].name.isEmpty(); i++)
00634 addSelection(lnb_presets[i].name, QString::number(i));
00635 addSelection(DeviceTree::tr("Custom"), QString::number(i));
00636 }
00637
00638 virtual void Load(void)
00639 {
00640 setValue(FindPreset(m_lnb));
00641 }
00642
00643 virtual void Save(void)
00644 {
00645 }
00646
00647 virtual void Save(QString )
00648 {
00649 }
00650
00651 private:
00652 DiSEqCDevLNB &m_lnb;
00653 };
00654
00656
00657 class LNBTypeSetting : public ComboBoxSetting, public Storage
00658 {
00659 public:
00660 LNBTypeSetting(DiSEqCDevLNB &lnb) : ComboBoxSetting(this), m_lnb(lnb)
00661 {
00662 setLabel(DeviceTree::tr("LNB Type"));
00663 setHelpText(DeviceTree::tr("Select the type of LNB from the list."));
00664 addSelection(DeviceTree::tr("Legacy (Fixed)"),
00665 QString::number((uint) DiSEqCDevLNB::kTypeFixed));
00666 addSelection(DeviceTree::tr("Standard (Voltage)"),
00667 QString::number((uint) DiSEqCDevLNB::
00668 kTypeVoltageControl));
00669 addSelection(DeviceTree::tr("Universal (Voltage & Tone)"),
00670 QString::number((uint) DiSEqCDevLNB::
00671 kTypeVoltageAndToneControl));
00672 addSelection(DeviceTree::tr("Bandstacked"),
00673 QString::number((uint) DiSEqCDevLNB::kTypeBandstacked));
00674 }
00675
00676 virtual void Load(void)
00677 {
00678 setValue(getValueIndex(QString::number((uint) m_lnb.GetType())));
00679 }
00680
00681 virtual void Save(void)
00682 {
00683 m_lnb.SetType((DiSEqCDevLNB::dvbdev_lnb_t) getValue().toUInt());
00684 }
00685
00686 virtual void Save(QString ) { }
00687
00688 private:
00689 DiSEqCDevLNB &m_lnb;
00690 };
00691
00693
00694 class LNBLOFSwitchSetting : public LineEditSetting, public Storage
00695 {
00696 public:
00697 LNBLOFSwitchSetting(DiSEqCDevLNB &lnb) : LineEditSetting(this), m_lnb(lnb)
00698 {
00699 setLabel(DeviceTree::tr("LNB LOF Switch (MHz)"));
00700 QString help = DeviceTree::tr(
00701 "This defines at what frequency the LNB will do a "
00702 "switch from high to low setting, and vice versa.");
00703 setHelpText(help);
00704 }
00705
00706 virtual void Load(void)
00707 {
00708 setValue(QString::number(m_lnb.GetLOFSwitch() / 1000));
00709 }
00710
00711 virtual void Save(void)
00712 {
00713 m_lnb.SetLOFSwitch(getValue().toUInt() * 1000);
00714 }
00715
00716 virtual void Save(QString ) { }
00717
00718 private:
00719 DiSEqCDevLNB &m_lnb;
00720 };
00721
00723
00724 class LNBLOFLowSetting : public LineEditSetting, public Storage
00725 {
00726 public:
00727 LNBLOFLowSetting(DiSEqCDevLNB &lnb) : LineEditSetting(this), m_lnb(lnb)
00728 {
00729 setLabel(DeviceTree::tr("LNB LOF Low (MHz)"));
00730 QString help = DeviceTree::tr(
00731 "This defines the offset the frequency coming "
00732 "from the LNB will be in low setting. For bandstacked "
00733 "LNBs this is the vertical/right polarization band.");
00734 setHelpText(help);
00735 }
00736
00737 virtual void Load(void)
00738 {
00739 setValue(QString::number(m_lnb.GetLOFLow() / 1000));
00740 }
00741
00742 virtual void Save(void)
00743 {
00744 m_lnb.SetLOFLow(getValue().toUInt() * 1000);
00745 }
00746
00747 virtual void Save(QString ) { }
00748
00749 private:
00750 DiSEqCDevLNB &m_lnb;
00751 };
00752
00754
00755 class LNBLOFHighSetting : public LineEditSetting, public Storage
00756 {
00757 public:
00758 LNBLOFHighSetting(DiSEqCDevLNB &lnb) : LineEditSetting(this), m_lnb(lnb)
00759 {
00760 setLabel(DeviceTree::tr("LNB LOF High (MHz)"));
00761 QString help = DeviceTree::tr(
00762 "This defines the offset the frequency coming from "
00763 "the LNB will be in high setting. For bandstacked "
00764 "LNBs this is the horizontal/left polarization band.");
00765 setHelpText(help);
00766 }
00767
00768 virtual void Load(void)
00769 {
00770 setValue(QString::number(m_lnb.GetLOFHigh() / 1000));
00771 }
00772
00773 virtual void Save(void)
00774 {
00775 m_lnb.SetLOFHigh(getValue().toUInt() * 1000);
00776 }
00777
00778 virtual void Save(QString ) { }
00779
00780 private:
00781 DiSEqCDevLNB &m_lnb;
00782 };
00783
00784 class LNBPolarityInvertedSetting : public CheckBoxSetting, public Storage
00785 {
00786 public:
00787 LNBPolarityInvertedSetting(DiSEqCDevLNB &lnb) :
00788 CheckBoxSetting(this), m_lnb(lnb)
00789 {
00790 setLabel(DeviceTree::tr("LNB Reversed"));
00791 QString help = DeviceTree::tr(
00792 "This defines whether the signal reaching the LNB "
00793 "is reversed from normal polarization. This happens "
00794 "to circular signals bouncing twice on a toroidal "
00795 "dish.");
00796 setHelpText(help);
00797 }
00798
00799 virtual void Load(void)
00800 {
00801 setValue(m_lnb.IsPolarityInverted());
00802 }
00803
00804 virtual void Save(void)
00805 {
00806 m_lnb.SetPolarityInverted(boolValue());
00807 }
00808
00809 virtual void Save(QString ) { }
00810
00811 private:
00812 DiSEqCDevLNB &m_lnb;
00813 };
00814
00816
00817 LNBConfig::LNBConfig(DiSEqCDevLNB &lnb)
00818 {
00819 ConfigurationGroup *group =
00820 new VerticalConfigurationGroup(false, false);
00821 group->setLabel(DeviceTree::tr("LNB Configuration"));
00822
00823 group->addChild(new DeviceDescrSetting(lnb));
00824 LNBPresetSetting *preset = new LNBPresetSetting(lnb);
00825 group->addChild(preset);
00826 m_type = new LNBTypeSetting(lnb);
00827 group->addChild(m_type);
00828 m_lof_switch = new LNBLOFSwitchSetting(lnb);
00829 group->addChild(m_lof_switch);
00830 m_lof_lo = new LNBLOFLowSetting(lnb);
00831 group->addChild(m_lof_lo);
00832 m_lof_hi = new LNBLOFHighSetting(lnb);
00833 group->addChild(m_lof_hi);
00834 m_pol_inv = new LNBPolarityInvertedSetting(lnb);
00835 group->addChild(m_pol_inv);
00836 connect(m_type, SIGNAL(valueChanged(const QString&)),
00837 this, SLOT( UpdateType( void)));
00838 connect(preset, SIGNAL(valueChanged(const QString&)),
00839 this, SLOT( SetPreset( const QString&)));
00840 addChild(group);
00841 }
00842
00843 void LNBConfig::SetPreset(const QString &value)
00844 {
00845 uint index = value.toUInt();
00846 if (index >= (sizeof(lnb_presets) / sizeof(lnb_preset)))
00847 return;
00848
00849 lnb_preset &preset = lnb_presets[index];
00850 if (preset.name.isEmpty())
00851 {
00852 m_type->setEnabled(true);
00853 UpdateType();
00854 }
00855 else
00856 {
00857 m_type->setValue(m_type->getValueIndex(
00858 QString::number((uint)preset.type)));
00859 m_lof_switch->setValue(QString::number(preset.lof_sw / 1000));
00860 m_lof_lo->setValue(QString::number(preset.lof_lo / 1000));
00861 m_lof_hi->setValue(QString::number(preset.lof_hi / 1000));
00862 m_pol_inv->setValue(preset.pol_inv);
00863 m_type->setEnabled(false);
00864 m_lof_switch->setEnabled(false);
00865 m_lof_hi->setEnabled(false);
00866 m_lof_lo->setEnabled(false);
00867 m_pol_inv->setEnabled(false);
00868 }
00869 }
00870
00871 void LNBConfig::UpdateType(void)
00872 {
00873 if (!m_type->isEnabled())
00874 return;
00875
00876 switch ((DiSEqCDevLNB::dvbdev_lnb_t) m_type->getValue().toUInt())
00877 {
00878 case DiSEqCDevLNB::kTypeFixed:
00879 case DiSEqCDevLNB::kTypeVoltageControl:
00880 m_lof_switch->setEnabled(false);
00881 m_lof_hi->setEnabled(false);
00882 m_lof_lo->setEnabled(true);
00883 m_pol_inv->setEnabled(true);
00884 break;
00885 case DiSEqCDevLNB::kTypeVoltageAndToneControl:
00886 m_lof_switch->setEnabled(true);
00887 m_lof_hi->setEnabled(true);
00888 m_lof_lo->setEnabled(true);
00889 m_pol_inv->setEnabled(true);
00890 break;
00891 case DiSEqCDevLNB::kTypeBandstacked:
00892 m_lof_switch->setEnabled(false);
00893 m_lof_hi->setEnabled(true);
00894 m_lof_lo->setEnabled(true);
00895 m_pol_inv->setEnabled(true);
00896 break;
00897 }
00898 }
00899
00901
00902 DeviceTree::DeviceTree(DiSEqCDevTree &tree) :
00903 ListBoxSetting(this), m_tree(tree)
00904 {
00905 connect(this, SIGNAL(editButtonPressed(int)), SLOT(edit(void)));
00906 connect(this, SIGNAL(deleteButtonPressed(int)), SLOT(del(void)));
00907 connect(this, SIGNAL(accepted(int)), SLOT(edit(void)));
00908 }
00909
00910 void DeviceTree::Load(void)
00911 {
00912 PopulateTree();
00913 }
00914
00915 void DeviceTree::Save(void)
00916 {
00917 }
00918
00919 bool DeviceTree::EditNodeDialog(uint nodeid)
00920 {
00921 DiSEqCDevDevice *dev = m_tree.FindDevice(nodeid);
00922 if (!dev)
00923 {
00924 LOG(VB_GENERAL, LOG_ERR, QString("DeviceTree::EditNodeDialog(%1) "
00925 "-- device not found").arg(nodeid));
00926 return false;
00927 }
00928
00929 bool changed = false;
00930 switch (dev->GetDeviceType())
00931 {
00932 case DiSEqCDevDevice::kTypeSwitch:
00933 {
00934 DiSEqCDevSwitch *sw = dynamic_cast<DiSEqCDevSwitch*>(dev);
00935 if (sw)
00936 {
00937 SwitchConfig config(*sw);
00938 changed = (config.exec() == MythDialog::Accepted);
00939 }
00940 }
00941 break;
00942
00943 case DiSEqCDevDevice::kTypeRotor:
00944 {
00945 DiSEqCDevRotor *rotor = dynamic_cast<DiSEqCDevRotor*>(dev);
00946 if (rotor)
00947 {
00948 RotorConfig config(*rotor);
00949 changed = (config.exec() == MythDialog::Accepted);
00950 }
00951 }
00952 break;
00953
00954 case DiSEqCDevDevice::kTypeLNB:
00955 {
00956 DiSEqCDevLNB *lnb = dynamic_cast<DiSEqCDevLNB*>(dev);
00957 if (lnb)
00958 {
00959 LNBConfig config(*lnb);
00960 changed = (config.exec() == MythDialog::Accepted);
00961 }
00962 }
00963 break;
00964
00965 default:
00966 break;
00967 }
00968
00969 if (changed)
00970 PopulateTree();
00971
00972 return changed;
00973 }
00974
00975 bool DeviceTree::RunTypeDialog(DiSEqCDevDevice::dvbdev_t &type)
00976 {
00977 MythPopupBox *popup = new MythPopupBox(GetMythMainWindow(), "");
00978 popup->addLabel(tr("Select Type of Device"));
00979
00980 MythListBox *list = new MythListBox(popup);
00981 list->insertItem(tr("Switch"));
00982 list->insertItem(tr("Rotor"));
00983 list->insertItem(tr("LNB"));
00984 list->setCurrentRow(0, QItemSelectionModel::Select);
00985
00986 popup->addWidget(list);
00987 connect(list, SIGNAL(accepted(int)),
00988 popup, SLOT( AcceptItem(int)));
00989 list->setFocus();
00990
00991 DialogCode res = popup->ExecPopup();
00992 type = (DiSEqCDevDevice::dvbdev_t)(list->currentRow());
00993
00994 popup->hide();
00995 popup->deleteLater();
00996
00997 return kDialogCodeRejected != res;
00998 }
00999
01000 void DeviceTree::CreateRootNodeDialog(void)
01001 {
01002 DiSEqCDevDevice::dvbdev_t type;
01003 if (!RunTypeDialog(type))
01004 return;
01005
01006 DiSEqCDevDevice *dev = DiSEqCDevDevice::CreateByType(m_tree, type);
01007 if (dev)
01008 {
01009 m_tree.SetRoot(dev);
01010
01011 if (!EditNodeDialog(dev->GetDeviceID()))
01012 m_tree.SetRoot(NULL);
01013
01014 PopulateTree();
01015 }
01016 }
01017
01018 void DeviceTree::CreateNewNodeDialog(uint parentid, uint child_num)
01019 {
01020 DiSEqCDevDevice *parent = m_tree.FindDevice(parentid);
01021 if (!parent)
01022 return;
01023
01024 DiSEqCDevDevice::dvbdev_t type;
01025 if (RunTypeDialog(type))
01026 {
01027 DiSEqCDevDevice *dev = DiSEqCDevDevice::CreateByType(m_tree, type);
01028 if (!dev)
01029 return;
01030
01031 if (parent->SetChild(child_num, dev))
01032 {
01033 if (!EditNodeDialog(dev->GetDeviceID()))
01034 parent->SetChild(child_num, NULL);
01035 PopulateTree();
01036 }
01037 else
01038 {
01039 delete dev;
01040 }
01041 }
01042 }
01043
01044 void DeviceTree::edit(void)
01045 {
01046 QString id = getValue();
01047 if (id.indexOf(':') == -1)
01048 {
01049 EditNodeDialog(id.toUInt());
01050 }
01051 else
01052 {
01053 QStringList vals = id.split(':');
01054 if (vals[0].isEmpty())
01055 CreateRootNodeDialog();
01056 else
01057 CreateNewNodeDialog(vals[0].toUInt(), vals[1].toUInt());
01058 }
01059 setFocus();
01060 }
01061
01062 void DeviceTree::del(void)
01063 {
01064 QString id = getValue();
01065
01066 if (id.indexOf(':') == -1)
01067 {
01068 uint nodeid = id.toUInt();
01069 DiSEqCDevDevice *dev = m_tree.FindDevice(nodeid);
01070 if (dev)
01071 {
01072 DiSEqCDevDevice *parent = dev->GetParent();
01073 if (parent)
01074 parent->SetChild(dev->GetOrdinal(), NULL);
01075 else
01076 m_tree.SetRoot(NULL);
01077
01078 PopulateTree();
01079 }
01080 }
01081
01082 setFocus();
01083 }
01084
01085 void DeviceTree::PopulateTree(void)
01086 {
01087 int old_sel = getValueIndex(getValue());
01088 clearSelections();
01089 PopulateTree(m_tree.Root());
01090 setCurrentItem(old_sel);
01091 }
01092
01093 void DeviceTree::PopulateTree(DiSEqCDevDevice *node,
01094 DiSEqCDevDevice *parent,
01095 uint childnum,
01096 uint depth)
01097 {
01098 QString indent;
01099 indent.fill(' ', 8 * depth);
01100
01101 if (node)
01102 {
01103 QString id = QString::number(node->GetDeviceID());
01104 addSelection(indent + node->GetDescription(), id);
01105 uint num_ch = node->GetChildCount();
01106 for (uint ch = 0; ch < num_ch; ch++)
01107 PopulateTree(node->GetChild(ch), node, ch, depth+1);
01108 }
01109 else
01110 {
01111 QString id;
01112 if (parent)
01113 id = QString::number(parent->GetDeviceID());
01114 id += ":" + QString::number(childnum);
01115
01116 addSelection(indent + "(Unconnected)", id);
01117 }
01118 }
01119
01121
01122 DTVDeviceTreeWizard::DTVDeviceTreeWizard(DiSEqCDevTree &tree)
01123 {
01124 setLabel(DeviceTree::tr("DiSEqC Device Tree"));
01125 addChild(new DeviceTree(tree));
01126 }
01127
01128 DialogCode DTVDeviceTreeWizard::exec(void)
01129 {
01130 while (ConfigurationDialog::exec() == kDialogCodeAccepted);
01131 return kDialogCodeRejected;
01132 }
01133
01135
01136 class SwitchSetting : public ComboBoxSetting, public Storage
01137 {
01138 public:
01139 SwitchSetting(DiSEqCDevDevice &node, DiSEqCDevSettings &settings)
01140 : ComboBoxSetting(this), m_node(node), m_settings(settings)
01141 {
01142 setLabel(node.GetDescription());
01143 setHelpText(DeviceTree::tr("Choose a port to use for this switch."));
01144
01145 uint num_children = node.GetChildCount();
01146 for (uint ch = 0; ch < num_children; ch++)
01147 {
01148 QString val = QString("%1").arg(ch);
01149 QString descr = DeviceTree::tr("Port %1").arg(ch+1);
01150 DiSEqCDevDevice *child = node.GetChild(ch);
01151 if (child)
01152 descr += QString(" (%2)").arg(child->GetDescription());
01153 addSelection(descr, val);
01154 }
01155 }
01156
01157 virtual void Load(void)
01158 {
01159 double value = m_settings.GetValue(m_node.GetDeviceID());
01160 setValue((uint)value);
01161 }
01162
01163 virtual void Save(void)
01164 {
01165 m_settings.SetValue(m_node.GetDeviceID(), getValue().toDouble());
01166 }
01167
01168 virtual void Save(QString ) {}
01169
01170 private:
01171 DiSEqCDevDevice &m_node;
01172 DiSEqCDevSettings &m_settings;
01173 };
01174
01176
01177 class RotorSetting : public ComboBoxSetting, public Storage
01178 {
01179 public:
01180 RotorSetting(DiSEqCDevDevice &node, DiSEqCDevSettings &settings)
01181 : ComboBoxSetting(this), m_node(node), m_settings(settings)
01182 {
01183 setLabel(node.GetDescription());
01184 setHelpText(DeviceTree::tr("Choose a satellite position."));
01185
01186 DiSEqCDevRotor *rotor = dynamic_cast<DiSEqCDevRotor*>(&m_node);
01187 if (rotor)
01188 m_posmap = rotor->GetPosMap();
01189 }
01190
01191 virtual void Load(void)
01192 {
01193 clearSelections();
01194
01195 uint_to_dbl_t::const_iterator it;
01196 for (it = m_posmap.begin(); it != m_posmap.end(); ++it)
01197 addSelection(AngleToString(*it), QString::number(*it));
01198
01199 double angle = m_settings.GetValue(m_node.GetDeviceID());
01200 setValue(getValueIndex(QString::number(angle)));
01201 }
01202
01203 virtual void Save(void)
01204 {
01205 m_settings.SetValue(m_node.GetDeviceID(), getValue().toDouble());
01206 }
01207
01208 virtual void Save(QString ) { }
01209
01210 private:
01211 DiSEqCDevDevice &m_node;
01212 DiSEqCDevSettings &m_settings;
01213 uint_to_dbl_t m_posmap;
01214 };
01215
01217
01218 class USALSRotorSetting : public HorizontalConfigurationGroup
01219 {
01220 public:
01221 USALSRotorSetting(DiSEqCDevDevice &node, DiSEqCDevSettings &settings) :
01222 HorizontalConfigurationGroup(false, false, true, true),
01223 numeric(new TransLineEditSetting()),
01224 hemisphere(new TransComboBoxSetting(false)),
01225 m_node(node), m_settings(settings)
01226 {
01227 QString help =
01228 DeviceTree::tr(
01229 "Locates the satellite you wish to point to "
01230 "with the longitude along the Clarke Belt of "
01231 "the satellite [-180..180] and its hemisphere.");
01232
01233 numeric->setLabel(DeviceTree::tr("Longitude (degrees)"));
01234 numeric->setHelpText(help);
01235 hemisphere->setLabel(DeviceTree::tr("Hemisphere"));
01236 hemisphere->addSelection(DeviceTree::tr("Eastern"), "E", false);
01237 hemisphere->addSelection(DeviceTree::tr("Western"), "W", true);
01238 hemisphere->setHelpText(help);
01239
01240 addChild(numeric);
01241 addChild(hemisphere);
01242 }
01243
01244 virtual void Load(void)
01245 {
01246 double val = m_settings.GetValue(m_node.GetDeviceID());
01247 QString hemi = QString::null;
01248 double eval = AngleToEdit(val, hemi);
01249 numeric->setValue(QString::number(eval));
01250 hemisphere->setValue(hemisphere->getValueIndex(hemi));
01251 }
01252
01253 virtual void Save(void)
01254 {
01255 QString val = QString::number(numeric->getValue().toDouble());
01256 val += hemisphere->getValue();
01257 m_settings.SetValue(m_node.GetDeviceID(), AngleToFloat(val, false));
01258 }
01259
01260 virtual void Save(QString ) { }
01261
01262 private:
01263 TransLineEditSetting *numeric;
01264 TransComboBoxSetting *hemisphere;
01265 DiSEqCDevDevice &m_node;
01266 DiSEqCDevSettings &m_settings;
01267 };
01268
01270
01271 DTVDeviceConfigGroup::DTVDeviceConfigGroup(
01272 DiSEqCDevSettings &settings, uint cardid, bool switches_enabled) :
01273 VerticalConfigurationGroup(false, false, true, true),
01274 m_settings(settings), m_switches_enabled(switches_enabled)
01275 {
01276 setLabel(DeviceTree::tr("DTV Device Configuration"));
01277
01278
01279 m_tree.Load(cardid);
01280
01281
01282 AddNodes(this, QString::null, m_tree.Root());
01283 }
01284
01285 DTVDeviceConfigGroup::~DTVDeviceConfigGroup(void)
01286 {
01287 }
01288
01289 void DTVDeviceConfigGroup::AddNodes(
01290 ConfigurationGroup *group, const QString &trigger, DiSEqCDevDevice *node)
01291 {
01292 if (!node)
01293 return;
01294
01295 Setting *setting = NULL;
01296 switch (node->GetDeviceType())
01297 {
01298 case DiSEqCDevDevice::kTypeSwitch:
01299 setting = new SwitchSetting(*node, m_settings);
01300 setting->setEnabled(m_switches_enabled);
01301 break;
01302 case DiSEqCDevDevice::kTypeRotor:
01303 {
01304 DiSEqCDevRotor *rotor = dynamic_cast<DiSEqCDevRotor*>(node);
01305 if (rotor && (rotor->GetType() == DiSEqCDevRotor::kTypeDiSEqC_1_2))
01306 setting = new RotorSetting(*node, m_settings);
01307 else
01308 setting = new USALSRotorSetting(*node, m_settings);
01309 break;
01310 }
01311 default:
01312 break;
01313 }
01314
01315 if (!setting)
01316 {
01317 AddChild(group, trigger, new TransLabelSetting());
01318 return;
01319 }
01320
01321 m_devs[node->GetDeviceID()] = setting;
01322
01323 uint num_ch = node->GetChildCount();
01324 if (DiSEqCDevDevice::kTypeSwitch == node->GetDeviceType())
01325 {
01326 bool useframe = (node != m_tree.Root());
01327 bool zerospace = !useframe;
01328 TriggeredConfigurationGroup *cgrp = new TriggeredConfigurationGroup(
01329 false, useframe, true, true, false, false, true, zerospace);
01330
01331 cgrp->addChild(setting);
01332 cgrp->setTrigger(setting);
01333
01334 for (uint i = 0; i < num_ch; i++)
01335 AddNodes(cgrp, QString::number(i), node->GetChild(i));
01336
01337 AddChild(group, trigger, cgrp);
01338 return;
01339 }
01340
01341 if (!num_ch)
01342 {
01343 AddChild(group, trigger, setting);
01344 return;
01345 }
01346
01347 VerticalConfigurationGroup *cgrp =
01348 new VerticalConfigurationGroup(false, false, true, true);
01349
01350 AddChild(cgrp, QString::null, setting);
01351 for (uint i = 0; i < num_ch; i++)
01352 AddNodes(cgrp, QString::null, node->GetChild(i));
01353
01354 AddChild(group, trigger, cgrp);
01355 }
01356
01357 void DTVDeviceConfigGroup::AddChild(
01358 ConfigurationGroup *group, const QString &trigger, Setting *setting)
01359 {
01360 TriggeredConfigurationGroup *grp =
01361 dynamic_cast<TriggeredConfigurationGroup*>(group);
01362
01363 if (grp && !trigger.isEmpty())
01364 grp->addTarget(trigger, setting);
01365 else
01366 group->addChild(setting);
01367 }
01368
01370
01371 enum OLD_DISEQC_TYPES
01372 {
01373 DISEQC_SINGLE = 0,
01374 DISEQC_MINI_2 = 1,
01375 DISEQC_SWITCH_2_1_0 = 2,
01376 DISEQC_SWITCH_2_1_1 = 3,
01377 DISEQC_SWITCH_4_1_0 = 4,
01378 DISEQC_SWITCH_4_1_1 = 5,
01379 DISEQC_POSITIONER_1_2 = 6,
01380 DISEQC_POSITIONER_X = 7,
01381 DISEQC_POSITIONER_1_2_SWITCH_2 = 8,
01382 DISEQC_POSITIONER_X_SWITCH_2 = 9,
01383 DISEQC_SW21 = 10,
01384 DISEQC_SW64 = 11,
01385 };
01386
01387
01388 bool convert_diseqc_db(void)
01389 {
01390 MSqlQuery cquery(MSqlQuery::InitCon());
01391 cquery.prepare(
01392 "SELECT cardid, dvb_diseqc_type "
01393 "FROM capturecard"
01394 "WHERE dvb_diseqc_type IS NOT NULL AND "
01395 " diseqcid IS NULL");
01396
01397
01398 if (!cquery.exec())
01399 return false;
01400
01401 MSqlQuery iquery(MSqlQuery::InitCon());
01402 iquery.prepare(
01403 "SELECT cardinputid, diseqc_port, diseqc_pos, "
01404 " lnb_lof_switch, lnb_lof_hi, lnb_lof_lo "
01405 "FROM cardinput "
01406 "WHERE cardinput.cardid = :CARDID");
01407
01408 while (cquery.next())
01409 {
01410 uint cardid = cquery.value(0).toUInt();
01411 OLD_DISEQC_TYPES type = (OLD_DISEQC_TYPES) cquery.value(1).toUInt();
01412
01413 DiSEqCDevTree tree;
01414 DiSEqCDevDevice *root = NULL;
01415 uint add_lnbs = 0;
01416 DiSEqCDevLNB::dvbdev_lnb_t lnb_type =
01417 DiSEqCDevLNB::kTypeVoltageAndToneControl;
01418
01419
01420 switch (type)
01421 {
01422 case DISEQC_SINGLE:
01423 {
01424
01425 root = DiSEqCDevDevice::CreateByType(
01426 tree, DiSEqCDevDevice::kTypeLNB);
01427 break;
01428 }
01429
01430 case DISEQC_MINI_2:
01431 {
01432
01433 root = DiSEqCDevDevice::CreateByType(
01434 tree, DiSEqCDevDevice::kTypeSwitch);
01435 DiSEqCDevSwitch *sw = dynamic_cast<DiSEqCDevSwitch*>(root);
01436 if (sw)
01437 {
01438 sw->SetType(DiSEqCDevSwitch::kTypeTone);
01439 sw->SetNumPorts(2);
01440 add_lnbs = 2;
01441 }
01442 break;
01443 }
01444
01445 case DISEQC_SWITCH_2_1_0:
01446 case DISEQC_SWITCH_2_1_1:
01447 {
01448
01449 root = DiSEqCDevDevice::CreateByType(
01450 tree, DiSEqCDevDevice::kTypeSwitch);
01451 DiSEqCDevSwitch *sw = dynamic_cast<DiSEqCDevSwitch*>(root);
01452 if (sw)
01453 {
01454 sw->SetType(DiSEqCDevSwitch::kTypeDiSEqCCommitted);
01455 sw->SetAddress(0x10);
01456 sw->SetNumPorts(2);
01457 add_lnbs = 2;
01458 }
01459 break;
01460 }
01461
01462 case DISEQC_SWITCH_4_1_0:
01463 case DISEQC_SWITCH_4_1_1:
01464 {
01465
01466 root = DiSEqCDevDevice::CreateByType(
01467 tree, DiSEqCDevDevice::kTypeSwitch);
01468 DiSEqCDevSwitch *sw = dynamic_cast<DiSEqCDevSwitch*>(root);
01469 if (sw)
01470 {
01471 sw->SetType(DiSEqCDevSwitch::kTypeDiSEqCCommitted);
01472 sw->SetAddress(0x10);
01473 sw->SetNumPorts(4);
01474 add_lnbs = 4;
01475 }
01476 break;
01477 }
01478
01479 case DISEQC_POSITIONER_1_2:
01480 {
01481
01482 root = DiSEqCDevDevice::CreateByType(
01483 tree, DiSEqCDevDevice::kTypeRotor);
01484 DiSEqCDevRotor *rotor = dynamic_cast<DiSEqCDevRotor*>(root);
01485 if (rotor)
01486 {
01487 rotor->SetType(DiSEqCDevRotor::kTypeDiSEqC_1_2);
01488 add_lnbs = 1;
01489 }
01490 break;
01491 }
01492
01493 case DISEQC_POSITIONER_X:
01494 {
01495
01496 root = DiSEqCDevDevice::CreateByType(
01497 tree, DiSEqCDevDevice::kTypeRotor);
01498 DiSEqCDevRotor *rotor = dynamic_cast<DiSEqCDevRotor*>(root);
01499 if (rotor)
01500 {
01501 rotor->SetType(DiSEqCDevRotor::kTypeDiSEqC_1_3);
01502 add_lnbs = 1;
01503 }
01504 break;
01505 }
01506
01507 case DISEQC_POSITIONER_1_2_SWITCH_2:
01508 {
01509
01510 root = DiSEqCDevDevice::CreateByType(
01511 tree, DiSEqCDevDevice::kTypeSwitch);
01512 DiSEqCDevSwitch *sw = dynamic_cast<DiSEqCDevSwitch*>(root);
01513 if (sw)
01514 {
01515 sw->SetType(DiSEqCDevSwitch::kTypeDiSEqCUncommitted);
01516 sw->SetNumPorts(10);
01517 add_lnbs = 10;
01518 }
01519 break;
01520 }
01521
01522 case DISEQC_SW21:
01523 {
01524
01525 root = DiSEqCDevDevice::CreateByType(
01526 tree, DiSEqCDevDevice::kTypeSwitch);
01527 DiSEqCDevSwitch *sw = dynamic_cast<DiSEqCDevSwitch*>(root);
01528 if (sw)
01529 {
01530 sw->SetType(DiSEqCDevSwitch::kTypeLegacySW21);
01531 sw->SetNumPorts(2);
01532 add_lnbs = 2;
01533 lnb_type = DiSEqCDevLNB::kTypeFixed;
01534 }
01535 break;
01536 }
01537
01538 case DISEQC_SW64:
01539 {
01540
01541 root = DiSEqCDevDevice::CreateByType(
01542 tree, DiSEqCDevDevice::kTypeSwitch);
01543 DiSEqCDevSwitch *sw = dynamic_cast<DiSEqCDevSwitch*>(root);
01544 if (sw)
01545 {
01546 sw->SetType(DiSEqCDevSwitch::kTypeLegacySW64);
01547 sw->SetNumPorts(3);
01548 add_lnbs = 3;
01549 lnb_type = DiSEqCDevLNB::kTypeFixed;
01550 }
01551 break;
01552 }
01553
01554 default:
01555 {
01556 LOG(VB_GENERAL, LOG_ERR, "Unknown DiSEqC device type " +
01557 QString("%1 ignoring card %2").arg(type).arg(cardid));
01558 break;
01559 }
01560 }
01561
01562 if (!root)
01563 continue;
01564
01565 tree.SetRoot(root);
01566
01567
01568 for (uint i = 0; i < add_lnbs; i++)
01569 {
01570 DiSEqCDevLNB *lnb = dynamic_cast<DiSEqCDevLNB*>
01571 (DiSEqCDevDevice::CreateByType(
01572 tree, DiSEqCDevDevice::kTypeLNB));
01573 if (lnb)
01574 {
01575 lnb->SetType(lnb_type);
01576 lnb->SetDescription(QString("LNB #%1").arg(i+1));
01577 if (!root->SetChild(i, lnb))
01578 delete lnb;
01579 }
01580 }
01581
01582
01583 tree.Store(cardid);
01584
01585
01586 DiSEqCDevSettings set;
01587 iquery.bindValue(":CARDID", cardid);
01588
01589 if (!iquery.exec())
01590 return false;
01591
01592 while (iquery.next())
01593 {
01594 uint inputid = iquery.value(0).toUInt();
01595 uint port = iquery.value(1).toUInt();
01596 double pos = iquery.value(2).toDouble();
01597 DiSEqCDevLNB *lnb = NULL;
01598
01599
01600 switch (type)
01601 {
01602 case DISEQC_SINGLE:
01603 lnb = dynamic_cast<DiSEqCDevLNB*>(root);
01604 break;
01605
01606 case DISEQC_MINI_2:
01607 case DISEQC_SWITCH_2_1_0:
01608 case DISEQC_SWITCH_2_1_1:
01609 case DISEQC_SWITCH_4_1_0:
01610 case DISEQC_SWITCH_4_1_1:
01611 case DISEQC_SW21:
01612 case DISEQC_SW64:
01613 case DISEQC_POSITIONER_1_2_SWITCH_2:
01614 lnb = dynamic_cast<DiSEqCDevLNB*>(root->GetChild(port));
01615 set.SetValue(root->GetDeviceID(), port);
01616 break;
01617
01618 case DISEQC_POSITIONER_1_2:
01619 case DISEQC_POSITIONER_X:
01620 lnb = dynamic_cast<DiSEqCDevLNB*>(root->GetChild(0));
01621 set.SetValue(root->GetDeviceID(), pos);
01622 break;
01623
01624 default:
01625 break;
01626 }
01627
01628
01629 if (lnb)
01630 {
01631 lnb->SetLOFSwitch(iquery.value(3).toUInt());
01632 lnb->SetLOFHigh(iquery.value(4).toUInt());
01633 lnb->SetLOFLow(iquery.value(5).toUInt());
01634 }
01635
01636
01637 set.Store(inputid);
01638 }
01639
01640
01641 tree.Store(cardid);
01642
01643
01644 DiSEqCDev trees;
01645 trees.InvalidateTrees();
01646 }
01647
01648 return true;
01649 }