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.ProgressBar, 20);
28 SendEvent(UpdateEventType.StatusText, "Sending power on commands...");
29 Lib.PowerOnDevices(CecLogicalAddress.Broadcast);
31 SendEvent(UpdateEventType.StatusText, "Detecting TV vendor...");
32 SendEvent(UpdateEventType.ProgressBar, 30);
33 SendEvent(UpdateEventType.TVVendorId, (int)Lib.GetDeviceVendorId(CecLogicalAddress.Tv));
35 SendEvent(UpdateEventType.StatusText, "Detecting menu language...");
36 SendEvent(UpdateEventType.ProgressBar, 40);
37 SendEvent(UpdateEventType.MenuLanguage, Lib.GetDeviceMenuLanguage(CecLogicalAddress.Tv));
39 SendEvent(UpdateEventType.ProgressBar, 50);
40 SendEvent(UpdateEventType.StatusText, "Detecting AVR devices...");
42 bool hasAVRDevice = Lib.IsActiveDevice(CecLogicalAddress.AudioSystem);
43 SendEvent(UpdateEventType.HasAVRDevice, hasAVRDevice);
47 SendEvent(UpdateEventType.ProgressBar, 60);
48 SendEvent(UpdateEventType.StatusText, "Detecting AVR vendor...");
49 SendEvent(UpdateEventType.AVRVendorId, (int)Lib.GetDeviceVendorId(CecLogicalAddress.AudioSystem));
52 if (!Lib.GetDevicePowerStatus(CecLogicalAddress.Tv).Equals(CecPowerStatus.On))
54 SendEvent(UpdateEventType.ProgressBar, 70);
55 SendEvent(UpdateEventType.StatusText, "Activating the source...");
56 Lib.SetActiveSource(CecDeviceType.Reserved);
59 SendEvent(UpdateEventType.ProgressBar, 80);
60 SendEvent(UpdateEventType.StatusText, "Reading device configuration...");
62 Lib.GetCurrentConfiguration(Config);
65 SendEvent(UpdateEventType.ProgressBar, 90);
66 SendEvent(UpdateEventType.StatusText, "Polling active devices");
67 SendEvent(UpdateEventType.PollDevices);
69 SendEvent(UpdateEventType.ProgressBar, 100);
70 SendEvent(UpdateEventType.StatusText, "Ready.");
73 private LibCecSharp Lib;
74 private LibCECConfiguration Config;