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 || !Lib.Open(adapters[0].ComPort, 10000))
23 MessageBox.Show("Could not connect to any CEC adapter. Please check your configuration and try again.", "Pulse-Eight USB-CEC Adapter", MessageBoxButtons.OK);
27 SendEvent(UpdateEventType.StatusText, "Detecting TV vendor...");
28 SendEvent(UpdateEventType.ProgressBar, 20);
29 SendEvent(UpdateEventType.TVVendorId, (int)Lib.GetDeviceVendorId(CecLogicalAddress.Tv));
31 SendEvent(UpdateEventType.StatusText, "Detecting menu language...");
32 SendEvent(UpdateEventType.ProgressBar, 30);
33 SendEvent(UpdateEventType.MenuLanguage, Lib.GetDeviceMenuLanguage(CecLogicalAddress.Tv));
35 SendEvent(UpdateEventType.ProgressBar, 40);
36 SendEvent(UpdateEventType.StatusText, "Detecting AVR devices...");
38 bool hasAVRDevice = Lib.IsActiveDevice(CecLogicalAddress.AudioSystem);
39 SendEvent(UpdateEventType.HasAVRDevice, hasAVRDevice);
43 SendEvent(UpdateEventType.ProgressBar, 50);
44 SendEvent(UpdateEventType.StatusText, "Detecting AVR vendor...");
45 SendEvent(UpdateEventType.AVRVendorId, (int)Lib.GetDeviceVendorId(CecLogicalAddress.AudioSystem));
48 if (!Lib.GetDevicePowerStatus(CecLogicalAddress.Tv).Equals(CecPowerStatus.On))
50 SendEvent(UpdateEventType.ProgressBar, 60);
51 SendEvent(UpdateEventType.StatusText, "Activating the source...");
52 Lib.SetActiveSource(CecDeviceType.Reserved);
55 SendEvent(UpdateEventType.ProgressBar, 70);
56 SendEvent(UpdateEventType.StatusText, "Reading device configuration...");
58 Lib.GetCurrentConfiguration(Config);
61 SendEvent(UpdateEventType.ProgressBar, 80);
62 SendEvent(UpdateEventType.StatusText, "Polling active devices");
63 SendEvent(UpdateEventType.PollDevices);
65 SendEvent(UpdateEventType.ProgressBar, 100);
66 SendEvent(UpdateEventType.StatusText, "Ready.");
69 private LibCecSharp Lib;
70 private LibCECConfiguration Config;