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)
27 adapters = Lib.FindAdapters(string.Empty);
30 while (!Lib.Open(adapters[0].ComPort, 10000))
32 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);
33 if (result == DialogResult.No)
37 SendEvent(UpdateEventType.ProgressBar, 20);
38 SendEvent(UpdateEventType.StatusText, "Sending power on commands...");
39 Lib.PowerOnDevices(CecLogicalAddress.Broadcast);
41 SendEvent(UpdateEventType.StatusText, "Detecting TV vendor...");
42 SendEvent(UpdateEventType.ProgressBar, 30);
43 SendEvent(UpdateEventType.TVVendorId, (int)Lib.GetDeviceVendorId(CecLogicalAddress.Tv));
45 SendEvent(UpdateEventType.StatusText, "Detecting menu language...");
46 SendEvent(UpdateEventType.ProgressBar, 40);
47 SendEvent(UpdateEventType.MenuLanguage, Lib.GetDeviceMenuLanguage(CecLogicalAddress.Tv));
49 SendEvent(UpdateEventType.ProgressBar, 50);
50 SendEvent(UpdateEventType.StatusText, "Detecting AVR devices...");
52 bool hasAVRDevice = Lib.IsActiveDevice(CecLogicalAddress.AudioSystem);
53 SendEvent(UpdateEventType.HasAVRDevice, hasAVRDevice);
57 SendEvent(UpdateEventType.ProgressBar, 60);
58 SendEvent(UpdateEventType.StatusText, "Detecting AVR vendor...");
59 SendEvent(UpdateEventType.AVRVendorId, (int)Lib.GetDeviceVendorId(CecLogicalAddress.AudioSystem));
62 if (!Lib.GetDevicePowerStatus(CecLogicalAddress.Tv).Equals(CecPowerStatus.On))
64 SendEvent(UpdateEventType.ProgressBar, 70);
65 SendEvent(UpdateEventType.StatusText, "Activating the source...");
66 Lib.SetActiveSource(CecDeviceType.Reserved);
69 SendEvent(UpdateEventType.ProgressBar, 80);
70 SendEvent(UpdateEventType.StatusText, "Reading device configuration...");
72 Lib.GetCurrentConfiguration(Config);
75 SendEvent(UpdateEventType.ProgressBar, 90);
76 SendEvent(UpdateEventType.StatusText, "Polling active devices");
77 SendEvent(UpdateEventType.PollDevices);
79 SendEvent(UpdateEventType.ProgressBar, 100);
80 SendEvent(UpdateEventType.StatusText, "Ready.");
83 private LibCecSharp Lib;
84 private LibCECConfiguration Config;