MythTV master
diseqcsettings.cpp
Go to the documentation of this file.
1/*
2 * \file diseqcsettings.cpp
3 * \brief DVB-S Device Tree Configuration Classes.
4 * \author Copyright (C) 2006, Yeasah Pell
5 */
6
7// Std C headers
8#include <array>
9#include <cmath>
10#include <utility>
11
12// MythTV headers
14#include "diseqcsettings.h"
15
16/* Lat/Long items relocated from videosource.cpp */
17
19{
20 auto *gc = new GlobalTextEditSetting("latitude");
21 gc->setLabel("Latitude");
22 gc->setHelpText(
23 DeviceTree::tr("The Cartesian latitude for your location. "
24 "Use negative numbers for southern coordinates."));
25 return gc;
26}
27
29{
30 auto *gc = new GlobalTextEditSetting("longitude");
31 gc->setLabel("Longitude");
32 gc->setHelpText(
33 DeviceTree::tr("The Cartesian longitude for your location. "
34 "Use negative numbers for western coordinates."));
35 return gc;
36}
37
39
41{
42 public:
44 {
45 setLabel(DeviceTree::tr("Device Type"));
46 addSelection(DeviceTree::tr("Unconnected"),
47 QString::number((uint) 0xFFFF));
48 addSelection(DeviceTree::tr("Switch"),
49 QString::number((uint) DiSEqCDevDevice::kTypeSwitch));
50 addSelection(DeviceTree::tr("Rotor"),
51 QString::number((uint) DiSEqCDevDevice::kTypeRotor));
52 addSelection(DeviceTree::tr("Unicable"),
53 QString::number((uint) DiSEqCDevDevice::kTypeSCR));
54 addSelection(DeviceTree::tr("LNB"),
55 QString::number((uint) DiSEqCDevDevice::kTypeLNB));
56 }
57
58 void Load(void) override // StandardSetting
59 {
60 if (m_device)
61 {
62 QString tmp = QString::number((uint) m_device->GetDeviceType());
64 }
65 setChanged(false);
66 }
67
69 {
70 m_device = dev;
71 }
72
74 {
75 SetDevice(nullptr);
77 }
78
80 {
81 return m_device;
82 }
83
84 private:
86};
87
89
91{
92 public:
94 m_device(device)
95 {
96 setLabel(DeviceTree::tr("Description"));
97 QString help = DeviceTree::tr(
98 "Optional descriptive name for this device, to "
99 "make it easier to configure settings later.");
101 }
102
103 void Load(void) override // StandardSetting
104 {
106 setChanged(false);
107 }
108
109 void Save(void) override // StandardSetting
110 {
112 }
113
114 private:
116};
117
118
120
122{
123 public:
125 TransMythUISpinBoxSetting(0, 15, 1), m_device(device)
126 {
127 setLabel(DeviceTree::tr("Repeat Count"));
128 QString help = DeviceTree::tr(
129 "Number of repeat (command with repeat flag ON) or resend (the same command) DiSEqC commands. "
130 "If value is higher than 10, command will be resend N-10 times. "
131 "If value is lower than 10, command will be repeated N times. "
132 "Repeat useful for unreliable DiSEqC equipment; resend useful when unreliable DiSEqC equipment has broken/unsupported repeat flag support.");
134 }
135
136 void Load(void) override // StandardSetting
137 {
139 setChanged(false);
140 }
141
142 void Save(void) override // StandardSetting
143 {
144 m_device.SetRepeatCount(getValue().toUInt());
145 }
146
147 private:
149};
150
152
154{
155 public:
156 explicit SwitchTypeSetting(DiSEqCDevSwitch &switch_dev) :
157 m_switch(switch_dev)
158 {
159 setLabel(DeviceTree::tr("Switch Type"));
160 setHelpText(DeviceTree::tr("Select the type of switch from the list."));
161
162 addSelection(DeviceTree::tr("Tone"),
163 QString::number((uint) DiSEqCDevSwitch::kTypeTone));
164 addSelection(DeviceTree::tr("Voltage"),
165 QString::number((uint) DiSEqCDevSwitch::kTypeVoltage));
166 addSelection(DeviceTree::tr("Mini DiSEqC"),
167 QString::number((uint) DiSEqCDevSwitch::kTypeMiniDiSEqC));
168 addSelection(DeviceTree::tr("DiSEqC"),
169 QString::number((uint)
171 addSelection(DeviceTree::tr("DiSEqC (Uncommitted)"),
172 QString::number((uint)
174 addSelection(DeviceTree::tr("Legacy SW21"),
175 QString::number((uint) DiSEqCDevSwitch::kTypeLegacySW21));
176 addSelection(DeviceTree::tr("Legacy SW42"),
177 QString::number((uint) DiSEqCDevSwitch::kTypeLegacySW42));
178 addSelection(DeviceTree::tr("Legacy SW64"),
179 QString::number((uint) DiSEqCDevSwitch::kTypeLegacySW64));
180 }
181
182 void Load(void) override // StandardSetting
183 {
184 setValue(getValueIndex(QString::number((uint) m_switch.GetType())));
185 setChanged(false);
186 }
187
188 void Save(void) override // StandardSetting
189 {
191 getValue().toUInt());
192 }
193
194 private:
196};
197
199
201{
202 public:
203 explicit SwitchAddressSetting(DiSEqCDevSwitch &switch_dev) :
204 m_switch(switch_dev)
205 {
206 setLabel(DeviceTree::tr("Address of switch"));
207 setHelpText(DeviceTree::tr("The DiSEqC address of the switch."));
208 }
209
210 void Load(void) override // StandardSetting
211 {
212 setValue(QString("0x%1").arg(m_switch.GetAddress(), 0, 16));
213 setChanged(false);
214 }
215
216 void Save(void) override // StandardSetting
217 {
218 m_switch.SetAddress(getValue().toUInt(nullptr, 16));
219 }
220
221 private:
223};
224
226
228{
229 public:
230 explicit SwitchPortsSetting(DiSEqCDevSwitch &switch_dev) :
231 m_switch(switch_dev)
232 {
233 setLabel(DeviceTree::tr("Number of ports"));
234 setHelpText(DeviceTree::tr("The number of ports this switch has."));
235 }
236
237 void Load(void) override // StandardSetting
238 {
239 setValue(QString::number(m_switch.GetNumPorts()));
240 setChanged(false);
241 }
242
243 void Save(void) override // StandardSetting
244 {
245 m_switch.SetNumPorts(getValue().toUInt());
246 }
247
248 private:
250};
251
253
255 : m_deviceDescr(new DeviceDescrSetting(switch_dev)),
256 m_type(new SwitchTypeSetting(switch_dev)),
257 m_ports(new SwitchPortsSetting(switch_dev)),
258 m_address(new SwitchAddressSetting(switch_dev))
259{
260 setLabel(DeviceTree::tr("Switch Configuration"));
261
262 parent = this;
263 parent->addChild(m_deviceDescr);
264 parent->addChild(new DeviceRepeatSetting(switch_dev));
265 parent->addChild(m_type);
266 parent->addChild(m_address);
267 parent->addChild(m_ports);
268
269 connect(m_type, qOverload<const QString&>(&StandardSetting::valueChanged),
270 this, qOverload<const QString&>(&SwitchConfig::update));
271 connect(m_deviceDescr, qOverload<const QString&>(&StandardSetting::valueChanged),
272 this, qOverload<const QString&>(&StandardSetting::setValue));
273}
274
276{
279 update();
280 setChanged(false);
281}
282
284{
286 {
292 m_address->setValue(QString("0x10"));
293 m_address->setEnabled(false);
294 m_ports->setValue("2");
295 m_ports->setEnabled(false);
296 break;
298 m_address->setValue(QString("0x10"));
299 m_address->setEnabled(false);
300 m_ports->setValue("3");
301 m_ports->setEnabled(false);
302 break;
305 m_address->setEnabled(true);
306 m_ports->setEnabled(true);
307 break;
308 }
309}
310
311void SwitchConfig::update(const QString &/*value*/)
312{
313 update();
314}
315
317{
318 QStringList actions;
319 if (GetMythMainWindow()->TranslateKeyPress("Global", e, actions))
320 return true;
321
322 auto isdelete = [](const QString & action) { return action == "DELETE"; };
323 if (std::any_of(actions.cbegin(), actions.cend(), isdelete))
324 {
325 emit DeleteClicked();
326 return true;
327 }
328
329 return false;
330}
331
333
335{
336 public:
338 m_rotor(rotor)
339 {
340 setLabel(DeviceTree::tr("Rotor Type"));
341 setHelpText(DeviceTree::tr("Select the type of rotor from the list."));
342 addSelection(DeviceTree::tr("DiSEqC 1.2"),
343 QString::number((uint) DiSEqCDevRotor::kTypeDiSEqC_1_2));
344 addSelection(DeviceTree::tr("DiSEqC 1.3 (GotoX/USALS)"),
345 QString::number((uint) DiSEqCDevRotor::kTypeDiSEqC_1_3));
346 }
347
348 void Load(void) override // StandardSetting
349 {
350 setValue(getValueIndex(QString::number((uint)m_rotor.GetType())));
351 setChanged(false);
352 }
353
354 void Save(void) override // StandardSetting
355 {
357 }
358
359 private:
361};
362
364
366{
367 public:
369 m_rotor(rotor)
370 {
371 setLabel(DeviceTree::tr("Rotor Low Speed (deg/sec)"));
372 QString help = DeviceTree::tr(
373 "To allow the approximate monitoring of rotor movement, enter "
374 "the rated angular speed of the rotor when powered at 13V.");
376 }
377
378 void Load(void) override // StandardSetting
379 {
380 setValue(QString::number(m_rotor.GetLoSpeed()));
381 setChanged(false);
382 }
383
384 void Save(void) override // StandardSetting
385 {
386 m_rotor.SetLoSpeed(getValue().toDouble());
387 }
388
389 private:
391};
392
394
396{
397 public:
399 m_rotor(rotor)
400 {
401 setLabel(DeviceTree::tr("Rotor High Speed (deg/sec)"));
402 QString help = DeviceTree::tr(
403 "To allow the approximate monitoring of rotor movement, enter "
404 "the rated angular speed of the rotor when powered at 18V.");
406 }
407
408 void Load(void) override // StandardSetting
409 {
410 setValue(QString::number(m_rotor.GetHiSpeed()));
411 setChanged(false);
412 }
413
414 void Save(void) override // StandardSetting
415 {
416 m_rotor.SetHiSpeed(getValue().toDouble());
417 }
418
419 private:
421};
422
424
425static QString AngleToString(double angle)
426{
427 QString str;
428 if (angle >= 0.0)
429 {
430 str = QString::number(angle) +
431 DeviceTree::tr("E", "Eastern Hemisphere");
432 }
433 else /* if (angle < 0.0) */
434 {
435 str = QString::number(-angle) +
436 DeviceTree::tr("W", "Western Hemisphere");
437 }
438 return str;
439}
440
441static double AngleToEdit(double angle, QString &hemi)
442{
443 if (angle > 0.0)
444 {
445 hemi = "E";
446 return angle;
447 }
448
449 hemi = "W";
450 return -angle;
451}
452
453static double AngleToFloat(const QString &angle, bool translated = true)
454{
455 if (angle.length() < 2)
456 return 0.0;
457
458 double pos = __builtin_nan("");
459 QChar postfix = angle.at(angle.length() - 1);
460 if (postfix.isLetter())
461 {
462 pos = angle.left(angle.length() - 1).toDouble();
463 if ((translated &&
464 (postfix.toUpper() ==
465 DeviceTree::tr("W", "Western Hemisphere").at(0))) ||
466 (!translated && (postfix.toUpper() == 'W')))
467 {
468 pos = -pos;
469 }
470 }
471 else
472 {
473 pos = angle.toDouble();
474 }
475
476 return pos;
477}
478
480{
482 PopulateList();
483}
484
486{
488}
489
491{
492public:
493 RotorPosTextEdit(const QString &label, uint id, const QString &value) :
494 m_id(id)
495 {
496 setLabel(label);
497 setValue(value);
498 }
499
500 void updateButton(MythUIButtonListItem *item) override // MythUITextEditSetting
501 {
503 if (getValue().isEmpty())
504 item->SetText(DeviceTree::tr("None"), "value");
505 }
506
508};
509
511{
512 auto *posEdit = dynamic_cast<RotorPosTextEdit*>(setting);
513 if (posEdit == nullptr)
514 return;
515 QString value = posEdit->getValue();
516 if (value.isEmpty())
517 m_posmap.erase(m_posmap.find(posEdit->m_id));
518 else
519 m_posmap[posEdit->m_id] = AngleToFloat(posEdit->getValue());
520}
521
523{
524 uint num_pos = 64;
525 for (uint pos = 1; pos < num_pos; pos++)
526 {
527 uint_to_dbl_t::const_iterator it = m_posmap.constFind(pos);
528 QString posval;
529 if (it != m_posmap.constEnd())
530 posval = AngleToString(*it);
531
532 auto *posEdit =
533 new RotorPosTextEdit(DeviceTree::tr("Position #%1").arg(pos),
534 pos,
535 posval);
536 connect(posEdit, qOverload<StandardSetting*>(&StandardSetting::valueChanged),
537 this, &RotorPosMap::newValue);
538 addChild(posEdit);
539 }
540}
541
543
545 : m_rotor(rotor),
546 m_pos(new RotorPosMap(rotor))
547{
548 setLabel(DeviceTree::tr("Rotor Configuration"));
549 setValue(rotor.GetDescription());
550
551 parent = this;
552 parent->addChild(new DeviceDescrSetting(rotor));
553 parent->addChild(new DeviceRepeatSetting(rotor));
554
555 auto *rtype = new RotorTypeSetting(rotor);
556 connect(rtype, qOverload<const QString&>(&StandardSetting::valueChanged),
557 this, &RotorConfig::SetType);
558 parent->addChild(rtype);
559
560 m_pos->setLabel(DeviceTree::tr("Positions"));
561 m_pos->setHelpText(DeviceTree::tr("Rotor position setup."));
562 parent->addChild(m_pos);
563
564 parent->addChild(new RotorLoSpeedSetting(rotor));
565 parent->addChild(new RotorHiSpeedSetting(rotor));
566 parent->addChild(DiSEqCLatitude());
567 parent->addChild(DiSEqCLongitude());
568}
569
571{
574}
575
576void RotorConfig::SetType(const QString &type)
577{
578 auto rtype = (DiSEqCDevRotor::dvbdev_rotor_t) type.toUInt();
580}
581
583
585{
586 public:
588 TransMythUISpinBoxSetting(0, 7, 1), m_scr(scr)
589 {
590 setLabel(DeviceTree::tr("Userband"));
591 setHelpText(DeviceTree::tr(
592 "Unicable userband ID (0-7). The Unicable userband channels "
593 "are often numbered starting at 1 but MythTV starts at 0."));
594 }
595
596 void Load(void) override // StandardSetting
597 {
599 setChanged(false);
600 }
601
602 void Save(void) override // StandardSetting
603 {
605 }
606
607 private:
609};
610
612
614{
615 public:
617 {
618 setLabel(DeviceTree::tr("Frequency (MHz)"));
619 setHelpText(DeviceTree::tr("Unicable userband frequency (usually 1210, 1420, 1680 and 2040 MHz)"));
620 }
621
622 void Load(void) override // StandardSetting
623 {
624 setValue(QString::number(m_scr.GetFrequency()));
625 setChanged(false);
626 }
627
628 void Save(void) override // StandardSetting
629 {
630 m_scr.SetFrequency(getValue().toUInt());
631 }
632
633 private:
635};
636
638
640{
641 public:
642 explicit SCRPINSetting(DiSEqCDevSCR &scr) : m_scr(scr)
643 {
644 setLabel(DeviceTree::tr("PIN code"));
645 setHelpText(DeviceTree::tr("Unicable PIN code (-1 disabled, 0 - 255)"));
646 }
647
648 void Load(void) override // StandardSetting
649 {
650 setValue(QString::number(m_scr.GetPIN()));
651 setChanged(false);
652 }
653
654 void Save(void) override // StandardSetting
655 {
656 m_scr.SetPIN(getValue().toInt());
657 }
658
659 private:
661};
662
664
666{
667 setLabel(DeviceTree::tr("Unicable Configuration"));
668
669 parent = this;
670 parent->addChild(new SCRUserBandSetting(scr));
671 parent->addChild(new SCRFrequencySetting(scr));
672 parent->addChild(new SCRPINSetting(scr));
673 parent->addChild(new DeviceRepeatSetting(scr));
674}
675
677
679{
680 public:
682 uint _lof_sw = 0, uint _lof_lo = 0,
683 uint _lof_hi = 0, bool _pol_inv = false) :
684 m_name(std::move(_name)), m_type(_type),
685 m_lofSw(_lof_sw), m_lofLo(_lof_lo),
686 m_lofHi(_lof_hi), m_polInv(_pol_inv) {}
687
688 public:
689 QString m_name;
695};
696
697static const std::array<const lnb_preset,7> lnb_presets
698{
699
700 /* description, type, LOF switch, LOF low, LOF high, inverted polarity */
701 lnb_preset(QT_TRANSLATE_NOOP("DeviceTree", "Universal (Europe)"),
703 11700000, 9750000, 10600000),
704 lnb_preset(QT_TRANSLATE_NOOP("DeviceTree", "Single (Europe)"),
706 lnb_preset(QT_TRANSLATE_NOOP("DeviceTree", "Circular (N. America)"),
708 lnb_preset(QT_TRANSLATE_NOOP("DeviceTree", "Linear (N. America)"),
710 lnb_preset(QT_TRANSLATE_NOOP("DeviceTree", "C Band"),
712 lnb_preset(QT_TRANSLATE_NOOP("DeviceTree", "DishPro Bandstacked"),
713 DiSEqCDevLNB::kTypeBandstacked, 0, 11250000, 14350000),
715};
716
717static uint FindPreset(const DiSEqCDevLNB &lnb)
718{
719 uint i = 0;
720 for ( ; !lnb_presets[i].m_name.isEmpty(); i++)
721 {
722 if (lnb_presets[i].m_type == lnb.GetType() &&
723 lnb_presets[i].m_lofSw == lnb.GetLOFSwitch() &&
724 lnb_presets[i].m_lofLo == lnb.GetLOFLow() &&
725 lnb_presets[i].m_lofHi == lnb.GetLOFHigh() &&
726 lnb_presets[i].m_polInv== lnb.IsPolarityInverted())
727 {
728 break;
729 }
730 }
731 return i;
732}
733
735{
736 public:
737 explicit LNBPresetSetting(DiSEqCDevLNB &lnb) : m_lnb(lnb)
738 {
739 setLabel(DeviceTree::tr("LNB Preset"));
740 QString help = DeviceTree::tr(
741 "Select the LNB preset from the list, or choose "
742 "'Custom' and set the advanced settings below.");
744
745 uint i = 0;
746 for (; !lnb_presets[i].m_name.isEmpty(); i++)
747 addSelection(DeviceTree::tr( lnb_presets[i].m_name.toUtf8() ),
748 QString::number(i));
749 addSelection(DeviceTree::tr("Custom"), QString::number(i));
750 }
751
752 void Load(void) override // StandardSetting
753 {
755 setChanged(false);
756 }
757
758 void Save(void) override // StandardSetting
759 {
760 }
761
762 private:
764};
765
767
769{
770 public:
771 explicit LNBTypeSetting(DiSEqCDevLNB &lnb) : m_lnb(lnb)
772 {
773 setLabel(DeviceTree::tr("LNB Type"));
774 setHelpText(DeviceTree::tr("Select the type of LNB from the list."));
775 addSelection(DeviceTree::tr("Legacy (Fixed)"),
776 QString::number((uint) DiSEqCDevLNB::kTypeFixed));
777 addSelection(DeviceTree::tr("Standard (Voltage)"),
778 QString::number((uint) DiSEqCDevLNB::
779 kTypeVoltageControl));
780 addSelection(DeviceTree::tr("Universal (Voltage & Tone)"),
781 QString::number((uint) DiSEqCDevLNB::
782 kTypeVoltageAndToneControl));
783 addSelection(DeviceTree::tr("Bandstacked"),
784 QString::number((uint) DiSEqCDevLNB::kTypeBandstacked));
785 }
786
787 void Load(void) override // StandardSetting
788 {
789 setValue(getValueIndex(QString::number((uint) m_lnb.GetType())));
790 setChanged(false);
791 }
792
793 void Save(void) override // StandardSetting
794 {
796 }
797
798 private:
800};
801
803
805{
806 public:
808 {
809 setLabel(DeviceTree::tr("LNB LOF Switch (MHz)"));
810 QString help = DeviceTree::tr(
811 "This defines at what frequency the LNB will do a "
812 "switch from high to low setting, and vice versa.");
814 }
815
816 void Load(void) override // StandardSetting
817 {
818 setValue(QString::number(m_lnb.GetLOFSwitch() / 1000));
819 setChanged(false);
820 }
821
822 void Save(void) override // StandardSetting
823 {
824 m_lnb.SetLOFSwitch(getValue().toUInt() * 1000);
825 }
826
827 private:
829};
830
832
834{
835 public:
836 explicit LNBLOFLowSetting(DiSEqCDevLNB &lnb) : m_lnb(lnb)
837 {
838 setLabel(DeviceTree::tr("LNB LOF Low (MHz)"));
839 QString help = DeviceTree::tr(
840 "This defines the offset the frequency coming "
841 "from the LNB will be in low setting. For bandstacked "
842 "LNBs this is the vertical/right polarization band.");
844 }
845
846 void Load(void) override // StandardSetting
847 {
848 setValue(QString::number(m_lnb.GetLOFLow() / 1000));
849 setChanged(false);
850 }
851
852 void Save(void) override // StandardSetting
853 {
854 m_lnb.SetLOFLow(getValue().toUInt() * 1000);
855 }
856
857 private:
859};
860
862
864{
865 public:
867 {
868 setLabel(DeviceTree::tr("LNB LOF High (MHz)"));
869 QString help = DeviceTree::tr(
870 "This defines the offset the frequency coming from "
871 "the LNB will be in high setting. For bandstacked "
872 "LNBs this is the horizontal/left polarization band.");
874 }
875
876 void Load(void) override // StandardSetting
877 {
878 setValue(QString::number(m_lnb.GetLOFHigh() / 1000));
879 setChanged(false);
880 }
881
882 void Save(void) override // StandardSetting
883 {
884 m_lnb.SetLOFHigh(getValue().toUInt() * 1000);
885 }
886
887 private:
889};
890
892{
893 public:
895 m_lnb(lnb)
896 {
897 setLabel(DeviceTree::tr("LNB Reversed"));
898 QString help = DeviceTree::tr(
899 "This defines whether the signal reaching the LNB "
900 "is reversed from normal polarization. This happens "
901 "to circular signals bouncing twice on a toroidal "
902 "dish.");
904 }
905
906 void Load(void) override // StandardSetting
907 {
909 setChanged(false);
910 }
911
912 void Save(void) override // StandardSetting
913 {
915 }
916
917 private:
919};
920
922
924 : m_preset(new LNBPresetSetting(lnb)),
925 m_type(new LNBTypeSetting(lnb)),
926 m_lofSwitch(new LNBLOFSwitchSetting(lnb)),
927 m_lofLo(new LNBLOFLowSetting(lnb)),
928 m_lofHi(new LNBLOFHighSetting(lnb)),
929 m_polInv(new LNBPolarityInvertedSetting(lnb))
930{
931 setLabel(DeviceTree::tr("LNB Configuration"));
933
934 parent = this;
935 auto *deviceDescr = new DeviceDescrSetting(lnb);
936 parent->addChild(deviceDescr);
937 parent->addChild(m_preset);
938 parent->addChild(m_type);
939 parent->addChild(m_lofSwitch);
940 parent->addChild(m_lofLo);
941 parent->addChild(m_lofHi);
942 parent->addChild(m_polInv);
943 connect(m_type, qOverload<const QString&>(&StandardSetting::valueChanged),
944 this, qOverload<const QString&>(&LNBConfig::UpdateType));
945 connect(m_preset, qOverload<const QString&>(&StandardSetting::valueChanged),
946 this, &LNBConfig::SetPreset);
947 connect(deviceDescr, qOverload<const QString&>(&StandardSetting::valueChanged),
948 this, qOverload<const QString&>(&StandardSetting::setValue));
949}
950
952{
955}
956
957void LNBConfig::SetPreset(const QString &value)
958{
959 uint index = value.toUInt();
960 if (index >= (sizeof(lnb_presets) / sizeof(lnb_preset)))
961 return;
962
963 const lnb_preset &preset = lnb_presets[index];
964 if (preset.m_name.isEmpty())
965 {
966 m_type->setEnabled(true);
967 UpdateType();
968 }
969 else
970 {
972 QString::number((uint)preset.m_type)));
973 m_lofSwitch->setValue(QString::number(preset.m_lofSw / 1000));
974 m_lofLo->setValue(QString::number(preset.m_lofLo / 1000));
975 m_lofHi->setValue(QString::number(preset.m_lofHi / 1000));
976 m_polInv->setValue(preset.m_polInv);
977 m_type->setEnabled(false);
978 m_lofSwitch->setEnabled(false);
979 m_lofHi->setEnabled(false);
980 m_lofLo->setEnabled(false);
981 m_polInv->setEnabled(false);
982 }
983}
984
986{
987 if (!m_type->isEnabled())
988 return;
989
990 switch ((DiSEqCDevLNB::dvbdev_lnb_t) m_type->getValue().toUInt())
991 {
994 m_lofSwitch->setEnabled(false);
995 m_lofHi->setEnabled(false);
996 m_lofLo->setEnabled(true);
997 m_polInv->setEnabled(true);
998 break;
1000 m_lofSwitch->setEnabled(true);
1001 m_lofHi->setEnabled(true);
1002 m_lofLo->setEnabled(true);
1003 m_polInv->setEnabled(true);
1004 break;
1006 m_lofSwitch->setEnabled(false);
1007 m_lofHi->setEnabled(true);
1008 m_lofLo->setEnabled(true);
1009 m_polInv->setEnabled(true);
1010 break;
1011 }
1012}
1013
1014void LNBConfig::UpdateType(const QString &/*value*/)
1015{
1016 UpdateType();
1017}
1019
1021{
1022 PopulateTree();
1024}
1025
1027{
1028 DiSEqCDevDevice *dev = devtype->GetDevice();
1029 if (dev)
1030 {
1031 DiSEqCDevDevice *parent = dev->GetParent();
1032 if (parent)
1033 parent->SetChild(dev->GetOrdinal(), nullptr);
1034 else
1035 m_tree.SetRoot(nullptr);
1036 }
1037
1038 devtype->DeleteDevice();
1039}
1040
1042{
1043 clearSettings();
1045}
1046
1048 StandardSetting *parent)
1049{
1050 DiseqcConfigBase *setting = nullptr;
1051 switch (dev->GetDeviceType())
1052 {
1054 {
1055 auto *sw = dynamic_cast<DiSEqCDevSwitch*>(dev);
1056 if (sw)
1057 setting = new SwitchConfig(*sw, parent);
1058 }
1059 break;
1060
1062 {
1063 auto *rotor = dynamic_cast<DiSEqCDevRotor*>(dev);
1064 if (rotor)
1065 setting = new RotorConfig(*rotor, parent);
1066 }
1067 break;
1068
1070 {
1071 auto *scr = dynamic_cast<DiSEqCDevSCR*>(dev);
1072 if (scr)
1073 setting = new SCRConfig(*scr, parent);
1074 }
1075 break;
1076
1078 {
1079 auto *lnb = dynamic_cast<DiSEqCDevLNB*>(dev);
1080 if (lnb)
1081 setting = new LNBConfig(*lnb, parent);
1082 }
1083 break;
1084
1085 default:
1086 break;
1087 }
1088
1089 return setting;
1090}
1091
1093 DiSEqCDevDevice *parent,
1094 uint childnum,
1095 GroupSetting *parentSetting)
1096{
1097 if (node)
1098 {
1099 auto *devtype = new DeviceTypeSetting();
1100 devtype->SetDevice(node);
1101 devtype->Load();
1103 devtype);
1104
1105 if (setting)
1106 {
1107 setting->Load();
1108 devtype->addChild(setting);
1109 PopulateChildren(node, setting);
1110
1111 AddDeviceTypeSetting(devtype, parent, childnum, parentSetting);
1112 }
1113 else
1114 {
1115 delete devtype;
1116 }
1117 }
1118 else
1119 {
1120 auto *devtype = new DeviceTypeSetting();
1121 AddDeviceTypeSetting(devtype, parent, childnum, parentSetting);
1122 }
1123}
1124
1126 DiSEqCDevDevice *parent,
1127 uint childnum,
1128 GroupSetting *parentSetting)
1129{
1130 if (parentSetting)
1131 parentSetting->addChild(devtype);
1132 else // Root node
1133 addChild(devtype);
1134
1135 ConnectToValueChanged(devtype, parent, childnum);
1136}
1137
1139 DiSEqCDevDevice *parent,
1140 uint childnum)
1141{
1142 auto slot = [devtype, parent, childnum, this](const QString &value)
1143 {
1144 ValueChanged(value, devtype, parent, childnum);
1145 };
1146
1147 connect(devtype,
1148 static_cast<void (StandardSetting::*)(const QString&)>(
1150 this,
1151 slot);
1152}
1153
1155 GroupSetting *parentSetting)
1156{
1157 uint num_ch = node->GetChildCount();
1158 for (uint ch = 0; ch < num_ch; ch++)
1159 {
1160 PopulateTree(node->GetChild(ch), node, ch, parentSetting);
1161 }
1162}
1163
1164void DeviceTree::ValueChanged(const QString &value,
1165 DeviceTypeSetting *devtype,
1166 DiSEqCDevDevice *parent,
1167 uint childnum)
1168{
1169 // Remove old setting from m_tree
1170 DeleteDevice(devtype);
1171
1172 const auto type = static_cast<DiSEqCDevDevice::dvbdev_t>(value.toUInt());
1173
1175 if (dev)
1176 {
1177 if (!parent)
1178 {
1179 m_tree.SetRoot(dev);
1180 PopulateTree();
1181 }
1182 else if (parent->SetChild(childnum, dev))
1183 {
1184 DiseqcConfigBase *newConfig =
1185 DiseqcConfigBase::CreateByType(dev, devtype);
1186 newConfig->Load();
1187
1188 PopulateChildren(dev, newConfig);
1189
1190 devtype->addChild(newConfig);
1191 devtype->SetDevice(dev);
1192 }
1193 else
1194 {
1195 delete dev;
1196 }
1197 }
1198
1199 emit settingsChanged(this);
1200}
1201
1203
1205{
1206 public:
1208 : m_node(node), m_settings(settings)
1209 {
1210 setLabel(node.GetDescription());
1211 setHelpText(DeviceTree::tr("Choose a port to use for this switch."));
1212
1213 uint num_children = node.GetChildCount();
1214 for (uint ch = 0; ch < num_children; ch++)
1215 {
1216 QString val = QString("%1").arg(ch);
1217 QString descr = DeviceTree::tr("Port %1").arg(ch+1);
1218 DiSEqCDevDevice *child = node.GetChild(ch);
1219 if (child)
1220 descr += QString(" (%2)").arg(child->GetDescription());
1221 addSelection(descr, val);
1222 }
1223 }
1224
1225 void Load(void) override // StandardSetting
1226 {
1227 double value = m_settings.GetValue(m_node.GetDeviceID());
1228 setValue((uint)value);
1229 setChanged(false);
1230 }
1231
1232 void Save(void) override // StandardSetting
1233 {
1235 }
1236
1237 private:
1240};
1241
1243
1245{
1246 public:
1248 : m_node(node), m_settings(settings)
1249 {
1250 setLabel(node.GetDescription());
1251 setHelpText(DeviceTree::tr("Choose a satellite position."));
1252
1253 auto *rotor = dynamic_cast<DiSEqCDevRotor*>(&m_node);
1254 if (rotor)
1255 m_posmap = rotor->GetPosMap();
1256 }
1257
1258 void Load(void) override // StandardSetting
1259 {
1261
1262 for (double d : std::as_const(m_posmap))
1263 addSelection(AngleToString(d), QString::number(d));
1264
1265 double angle = m_settings.GetValue(m_node.GetDeviceID());
1266 setValue(getValueIndex(QString::number(angle)));
1267 setChanged(false);
1268 }
1269
1270 void Save(void) override // StandardSetting
1271 {
1273 }
1274
1275 private:
1279};
1280
1282
1284{
1285 public:
1289 m_node(node), m_settings(settings)
1290 {
1291 QString help =
1292 DeviceTree::tr(
1293 "Locates the satellite you wish to point to "
1294 "with the longitude along the Clarke Belt of "
1295 "the satellite [-180..180] and its hemisphere.");
1296
1297 m_numeric->setLabel(DeviceTree::tr("Longitude (degrees)"));
1299 m_hemisphere->setLabel(DeviceTree::tr("Hemisphere"));
1300 m_hemisphere->addSelection(DeviceTree::tr("Eastern"), "E", false);
1301 m_hemisphere->addSelection(DeviceTree::tr("Western"), "W", true);
1303
1306
1307 addChild(new RotorConfig(dynamic_cast<DiSEqCDevRotor&>(m_node), this));
1308 }
1309
1310 void Load(void) override // StandardSetting
1311 {
1312 double val = m_settings.GetValue(m_node.GetDeviceID());
1313 QString hemi;
1314 double eval = AngleToEdit(val, hemi);
1315 m_numeric->setValue(QString::number(eval));
1318 }
1319
1320 void Save(void) override // StandardSetting
1321 {
1322 QString val = QString::number(m_numeric->getValue().toDouble());
1323 val += m_hemisphere->getValue();
1325 }
1326
1327 private:
1332};
1333
1335
1337{
1338 public:
1340 : m_node(node), m_settings(settings)
1341 {
1342 setLabel("Position");
1343 setHelpText(DeviceTree::tr("Unicable satellite position (A/B)"));
1345 QString::number((uint)DiSEqCDevSCR::kTypeScrPosA), true);
1347 QString::number((uint)DiSEqCDevSCR::kTypeScrPosB), false);
1348 }
1349
1350 void Load(void) override // StandardSetting
1351 {
1352 double value = m_settings.GetValue(m_node.GetDeviceID());
1353 setValue(getValueIndex(QString::number((uint)value)));
1354 setChanged(false);
1355 }
1356
1357 void Save(void) override // StandardSetting
1358 {
1360 }
1361
1362 private:
1365};
1366
1368
1370 DiSEqCDevSettings &settings, uint cardid, bool switches_enabled) :
1371 m_settings(settings), m_switchesEnabled(switches_enabled)
1372{
1373 setLabel(DeviceTree::tr("DTV Device Configuration"));
1374
1375 // load
1376 m_tree.Load(cardid);
1377
1378 // initial UI setup
1379 AddNodes(this, QString(), m_tree.Root());
1380}
1381
1383 StandardSetting *group, const QString &trigger, DiSEqCDevDevice *node)
1384{
1385 if (!node)
1386 return;
1387
1388 StandardSetting *setting = nullptr;
1389 switch (node->GetDeviceType())
1390 {
1392 setting = new SwitchSetting(*node, m_settings);
1393 setting->setEnabled(m_switchesEnabled);
1394 break;
1396 {
1397 auto *rotor = dynamic_cast<DiSEqCDevRotor*>(node);
1398 if (rotor && (rotor->GetType() == DiSEqCDevRotor::kTypeDiSEqC_1_2))
1399 setting = new RotorSetting(*node, m_settings);
1400 else
1401 setting = new USALSRotorSetting(*node, m_settings);
1402 break;
1403 }
1405 {
1406 setting = new SCRPositionSetting(*node, m_settings);
1407 break;
1408 }
1409 default:
1410 break;
1411 }
1412
1413 if (!setting)
1414 return;
1415
1416 m_devs[node->GetDeviceID()] = setting;
1417
1418 uint num_ch = node->GetChildCount();
1420 {
1421 for (uint i = 0; i < num_ch; i++)
1422 AddNodes(setting, QString::number(i), node->GetChild(i));
1423
1424 AddChild(group, trigger, setting);
1425 return;
1426 }
1427
1428 if (!num_ch)
1429 {
1430 AddChild(group, trigger, setting);
1431 return;
1432 }
1433
1434 AddChild(group, trigger, setting);
1435 for (uint i = 0; i < num_ch; i++)
1436 AddNodes(group, trigger, node->GetChild(i));
1437}
1438
1440 StandardSetting *group, const QString &trigger, StandardSetting *setting)
1441{
1442 if (!trigger.isEmpty())
1443 group->addTargetedChild(trigger, setting);
1444 else
1445 group->addChild(setting);
1446}
DiSEqCDevTree m_tree
devid_to_setting_t m_devs
DTVDeviceConfigGroup(DiSEqCDevSettings &settings, uint cardid, bool switches_enabled)
static void AddChild(StandardSetting *group, const QString &trigger, StandardSetting *setting)
void AddNodes(StandardSetting *group, const QString &trigger, DiSEqCDevDevice *node)
DiSEqCDevSettings & m_settings
void Save(void) override
DiSEqCDevDevice & m_device
void Load(void) override
DeviceDescrSetting(DiSEqCDevDevice &device)
void Load(void) override
DiSEqCDevDevice & m_device
void Save(void) override
DeviceRepeatSetting(DiSEqCDevDevice &device)
DiSEqCDevTree & m_tree
void ValueChanged(const QString &value, DeviceTypeSetting *devtype, DiSEqCDevDevice *parent, uint childnum)
void DeleteDevice(DeviceTypeSetting *devtype)
void Load(void) override
void AddDeviceTypeSetting(DeviceTypeSetting *devtype, DiSEqCDevDevice *parent, uint childnum, GroupSetting *parentSetting)
void PopulateTree(void)
void PopulateChildren(DiSEqCDevDevice *node, GroupSetting *parentSetting)
void ConnectToValueChanged(DeviceTypeSetting *devtype, DiSEqCDevDevice *parent, uint childnum)
void Load(void) override
void SetDevice(DiSEqCDevDevice *dev)
DiSEqCDevDevice * m_device
DiSEqCDevDevice * GetDevice()
Represents a node in a DVB-S device network.
Definition: diseqc.h:140
uint GetDeviceID(void) const
Definition: diseqc.h:170
void SetRepeatCount(uint repeat)
Definition: diseqc.h:164
virtual uint GetChildCount(void) const
Retrieves the proper number of children for this node.
Definition: diseqc.h:177
virtual DiSEqCDevDevice * GetChild(uint)
Retrieves the nth child of this node.
Definition: diseqc.h:188
uint GetOrdinal(void) const
Definition: diseqc.h:174
QString GetDescription(void) const
Definition: diseqc.h:175
void SetDescription(const QString &desc)
Definition: diseqc.h:163
uint GetRepeatCount(void) const
Definition: diseqc.h:176
static DiSEqCDevDevice * CreateByType(DiSEqCDevTree &tree, dvbdev_t type, uint dev_id=0)
Definition: diseqc.cpp:935
virtual bool SetChild(uint, DiSEqCDevDevice *)
Changes the nth child of this node.
Definition: diseqc.h:165
dvbdev_t GetDeviceType(void) const
Definition: diseqc.h:169
DiSEqCDevDevice * GetParent(void) const
Definition: diseqc.h:173
LNB Class.
Definition: diseqc.h:447
dvbdev_lnb_t GetType(void) const
Definition: diseqc.h:472
bool IsPolarityInverted(void) const
Definition: diseqc.h:476
uint GetLOFHigh(void) const
Definition: diseqc.h:474
uint GetLOFSwitch(void) const
Definition: diseqc.h:473
void SetLOFLow(uint lof_lo)
Definition: diseqc.h:468
void SetType(dvbdev_lnb_t type)
Definition: diseqc.h:465
void SetPolarityInverted(bool inv)
Definition: diseqc.h:469
@ kTypeFixed
Definition: diseqc.h:460
@ kTypeVoltageAndToneControl
Definition: diseqc.h:462
@ kTypeBandstacked
Definition: diseqc.h:463
@ kTypeVoltageControl
Definition: diseqc.h:461
uint GetLOFLow(void) const
Definition: diseqc.h:475
void SetLOFSwitch(uint lof_switch)
Definition: diseqc.h:466
void SetLOFHigh(uint lof_hi)
Definition: diseqc.h:467
Rotor class.
Definition: diseqc.h:303
double GetLoSpeed(void) const
Definition: diseqc.h:326
double GetHiSpeed(void) const
Definition: diseqc.h:327
@ kTypeDiSEqC_1_3
Definition: diseqc.h:316
@ kTypeDiSEqC_1_2
Definition: diseqc.h:316
void SetHiSpeed(double speed)
Definition: diseqc.h:319
uint_to_dbl_t GetPosMap(void) const
Definition: diseqc.cpp:1974
void SetType(dvbdev_rotor_t type)
Definition: diseqc.h:317
void SetPosMap(const uint_to_dbl_t &posmap)
Definition: diseqc.cpp:1984
dvbdev_rotor_t GetType(void) const
Definition: diseqc.h:325
void SetLoSpeed(double speed)
Definition: diseqc.h:318
Unicable / SCR Class.
Definition: diseqc.h:383
int GetPIN(void) const
Definition: diseqc.h:410
uint GetFrequency(void) const
Definition: diseqc.h:409
void SetPIN(int pin)
Definition: diseqc.h:404
static QString SCRPositionToString(dvbdev_pos_t pos)
Definition: diseqc.h:427
void SetFrequency(uint freq)
Definition: diseqc.h:403
@ kTypeScrPosB
Definition: diseqc.h:400
@ kTypeScrPosA
Definition: diseqc.h:399
uint GetUserBand(void) const
Definition: diseqc.h:408
void SetUserBand(uint userband)
Definition: diseqc.h:402
DVB-S device settings class.
Definition: diseqc.h:37
double GetValue(uint devid) const
Retrieves a value from this configuration chain by device id.
Definition: diseqc.cpp:204
void SetValue(uint devid, double value)
Sets a value for this configuration chain by device id.
Definition: diseqc.cpp:219
Switch class, including tone, legacy and DiSEqC switches.
Definition: diseqc.h:224
void SetAddress(uint address)
Definition: diseqc.h:249
void SetType(dvbdev_switch_t type)
Definition: diseqc.h:248
dvbdev_switch_t GetType(void) const
Definition: diseqc.h:254
uint GetAddress(void) const
Definition: diseqc.h:255
@ kTypeDiSEqCUncommitted
Definition: diseqc.h:241
@ kTypeDiSEqCCommitted
Definition: diseqc.h:240
void SetNumPorts(uint num_ports)
Definition: diseqc.cpp:1339
uint GetNumPorts(void) const
Definition: diseqc.h:256
bool Load(const QString &device)
Loads the device tree from the database.
Definition: diseqc.cpp:311
void SetRoot(DiSEqCDevDevice *root)
Changes the root node of the tree.
Definition: diseqc.cpp:632
DiSEqCDevDevice * Root(void)
Retrieves the root node in the tree.
Definition: diseqc.h:93
static DiseqcConfigBase * CreateByType(DiSEqCDevDevice *dev, StandardSetting *parent)
void DeleteClicked(void)
bool keyPressEvent(QKeyEvent *event) override
void UpdateType(void)
void SetPreset(const QString &value)
LNBPolarityInvertedSetting * m_polInv
LNBPresetSetting * m_preset
LNBTypeSetting * m_type
void Load(void) override
LNBLOFSwitchSetting * m_lofSwitch
LNBConfig(DiSEqCDevLNB &lnb, StandardSetting *parent)
LNBLOFLowSetting * m_lofLo
LNBLOFHighSetting * m_lofHi
DiSEqCDevLNB & m_lnb
LNBLOFHighSetting(DiSEqCDevLNB &lnb)
void Load(void) override
void Save(void) override
void Save(void) override
LNBLOFLowSetting(DiSEqCDevLNB &lnb)
DiSEqCDevLNB & m_lnb
void Load(void) override
void Load(void) override
DiSEqCDevLNB & m_lnb
LNBLOFSwitchSetting(DiSEqCDevLNB &lnb)
void Save(void) override
LNBPolarityInvertedSetting(DiSEqCDevLNB &lnb)
void Save(void) override
void Load(void) override
LNBPresetSetting(DiSEqCDevLNB &lnb)
void Save(void) override
DiSEqCDevLNB & m_lnb
void Load(void) override
void Load(void) override
LNBTypeSetting(DiSEqCDevLNB &lnb)
DiSEqCDevLNB & m_lnb
void Save(void) override
void setValue(const QString &newValue) override
void addSelection(const QString &label, QString value=QString(), bool select=false)
void setValue(int value) override
int getValueIndex(const QString &value) const
void updateButton(MythUIButtonListItem *item) override
This method is called whenever the UI need to reflect a change Reimplement this If you widget need a ...
RotorPosMap * m_pos
void Load() override
RotorConfig(DiSEqCDevRotor &rotor, StandardSetting *parent)
void SetType(const QString &type)
DiSEqCDevRotor & m_rotor
RotorHiSpeedSetting(DiSEqCDevRotor &rotor)
void Save(void) override
void Load(void) override
DiSEqCDevRotor & m_rotor
void Save(void) override
void Load(void) override
DiSEqCDevRotor & m_rotor
RotorLoSpeedSetting(DiSEqCDevRotor &rotor)
void PopulateList(void)
void Save(void) override
void newValue(StandardSetting *setting)
void Load(void) override
DiSEqCDevRotor & m_rotor
uint_to_dbl_t m_posmap
RotorPosTextEdit(const QString &label, uint id, const QString &value)
void updateButton(MythUIButtonListItem *item) override
This method is called whenever the UI need to reflect a change Reimplement this If you widget need a ...
uint_to_dbl_t m_posmap
DiSEqCDevDevice & m_node
DiSEqCDevSettings & m_settings
RotorSetting(DiSEqCDevDevice &node, DiSEqCDevSettings &settings)
void Load(void) override
void Save(void) override
void Load(void) override
DiSEqCDevRotor & m_rotor
void Save(void) override
RotorTypeSetting(DiSEqCDevRotor &rotor)
SCRConfig(DiSEqCDevSCR &scr, StandardSetting *parent)
void Save(void) override
DiSEqCDevSCR & m_scr
SCRFrequencySetting(DiSEqCDevSCR &scr)
void Load(void) override
void Load(void) override
void Save(void) override
SCRPINSetting(DiSEqCDevSCR &scr)
DiSEqCDevSCR & m_scr
DiSEqCDevSettings & m_settings
DiSEqCDevDevice & m_node
SCRPositionSetting(DiSEqCDevDevice &node, DiSEqCDevSettings &settings)
void Save(void) override
void Load(void) override
void Save(void) override
void Load(void) override
SCRUserBandSetting(DiSEqCDevSCR &scr)
DiSEqCDevSCR & m_scr
virtual void addChild(StandardSetting *child)
virtual void Load(void)
bool isEnabled() const
void addTargetedChild(const QString &value, StandardSetting *setting)
virtual void clearSettings()
void settingsChanged(StandardSetting *selectedSetting=nullptr)
virtual void setHelpText(const QString &str)
virtual void setValue(const QString &newValue)
void valueChanged(const QString &newValue)
virtual QString getValue(void) const
virtual void setEnabled(bool enabled)
virtual void setLabel(QString str)
void setChanged(bool changed)
SwitchAddressSetting(DiSEqCDevSwitch &switch_dev)
DiSEqCDevSwitch & m_switch
void Load(void) override
void Save(void) override
DeviceDescrSetting * m_deviceDescr
SwitchConfig(DiSEqCDevSwitch &switch_dev, StandardSetting *parent)
SwitchAddressSetting * m_address
void Load(void) override
void update(void)
SwitchPortsSetting * m_ports
SwitchTypeSetting * m_type
SwitchPortsSetting(DiSEqCDevSwitch &switch_dev)
void Save(void) override
DiSEqCDevSwitch & m_switch
void Load(void) override
SwitchSetting(DiSEqCDevDevice &node, DiSEqCDevSettings &settings)
DiSEqCDevDevice & m_node
void Save(void) override
void Load(void) override
DiSEqCDevSettings & m_settings
void Load(void) override
void Save(void) override
SwitchTypeSetting(DiSEqCDevSwitch &switch_dev)
DiSEqCDevSwitch & m_switch
DiSEqCDevDevice & m_node
void Save(void) override
TransTextEditSetting * m_numeric
void Load(void) override
USALSRotorSetting(DiSEqCDevDevice &node, DiSEqCDevSettings &settings)
DiSEqCDevSettings & m_settings
TransMythUIComboBoxSetting * m_hemisphere
lnb_preset(QString _name, DiSEqCDevLNB::dvbdev_lnb_t _type, uint _lof_sw=0, uint _lof_lo=0, uint _lof_hi=0, bool _pol_inv=false)
DiSEqCDevLNB::dvbdev_lnb_t m_type
QMap< uint, double > uint_to_dbl_t
Definition: diseqc.h:30
static const std::array< const lnb_preset, 7 > lnb_presets
static QString AngleToString(double angle)
static uint FindPreset(const DiSEqCDevLNB &lnb)
static double AngleToEdit(double angle, QString &hemi)
static double AngleToFloat(const QString &angle, bool translated=true)
static GlobalTextEditSetting * DiSEqCLongitude(void)
static GlobalTextEditSetting * DiSEqCLatitude(void)
unsigned int uint
Definition: freesurround.h:24
static guint32 * tmp
Definition: goom_core.cpp:26
static const iso6937table * d
MythMainWindow * GetMythMainWindow(void)
STL namespace.