2 using System.Windows.Forms;
4 namespace CecConfigGui.actions
6 class ConnectToDevice : UpdateProcess
8 public ConnectToDevice(ref LibCecSharp lib, LibCECConfiguration config)
14 public override void Process()
16 SendEvent(UpdateEventType.StatusText, "Opening connection...");
17 SendEvent(UpdateEventType.ProgressBar, 10);
19 //TODO read the com port setting from the configuration
20 CecAdapter[] adapters = Lib.FindAdapters(string.Empty);
21 if (adapters.Length == 0)
23 DialogResult result = MessageBox.Show("Could not detect to any CEC adapter. Please check your configuration. Do you want to try again?", "Pulse-Eight USB-CEC Adapter", MessageBoxButtons.YesNo);
24 if (result == DialogResult.No)
26 SendEvent(UpdateEventType.ExitApplication);
30 adapters = Lib.FindAdapters(string.Empty);
33 while (!Lib.Open(adapters[0].ComPort, 10000))
35 DialogResult result = MessageBox.Show("Could not connect to any CEC adapter. Please check your configuration. Do you want to try again?", "Pulse-Eight USB-CEC Adapter", MessageBoxButtons.YesNo);
36 if (result == DialogResult.No)
38 SendEvent(UpdateEventType.ExitApplication);
43 SendEvent(UpdateEventType.ProgressBar, 20);
44 SendEvent(UpdateEventType.StatusText, "Sending power on commands...");
45 Lib.PowerOnDevices(CecLogicalAddress.Broadcast);
47 SendEvent(UpdateEventType.StatusText, "Detecting TV vendor...");
48 SendEvent(UpdateEventType.ProgressBar, 30);
49 SendEvent(UpdateEventType.TVVendorId, (int)Lib.GetDeviceVendorId(CecLogicalAddress.Tv));
51 SendEvent(UpdateEventType.StatusText, "Detecting menu language...");
52 SendEvent(UpdateEventType.ProgressBar, 40);
53 SendEvent(UpdateEventType.MenuLanguage, Lib.GetDeviceMenuLanguage(CecLogicalAddress.Tv));
55 SendEvent(UpdateEventType.ProgressBar, 50);
56 SendEvent(UpdateEventType.StatusText, "Detecting AVR devices...");
58 bool hasAVRDevice = Lib.IsActiveDevice(CecLogicalAddress.AudioSystem);
59 SendEvent(UpdateEventType.HasAVRDevice, hasAVRDevice);
63 SendEvent(UpdateEventType.ProgressBar, 60);
64 SendEvent(UpdateEventType.StatusText, "Detecting AVR vendor...");
65 SendEvent(UpdateEventType.AVRVendorId, (int)Lib.GetDeviceVendorId(CecLogicalAddress.AudioSystem));
68 if (!Lib.GetDevicePowerStatus(CecLogicalAddress.Tv).Equals(CecPowerStatus.On))
70 SendEvent(UpdateEventType.ProgressBar, 70);
71 SendEvent(UpdateEventType.StatusText, "Activating the source...");
72 Lib.SetActiveSource(CecDeviceType.Reserved);
75 SendEvent(UpdateEventType.ProgressBar, 80);
76 SendEvent(UpdateEventType.StatusText, "Reading device configuration...");
78 Lib.GetCurrentConfiguration(Config);
81 SendEvent(UpdateEventType.ProgressBar, 90);
82 SendEvent(UpdateEventType.StatusText, "Polling active devices");
83 SendEvent(UpdateEventType.PollDevices);
85 SendEvent(UpdateEventType.ProgressBar, 100);
86 SendEvent(UpdateEventType.StatusText, "Ready.");
89 private LibCecSharp Lib;
90 private LibCECConfiguration Config;