cec: moved the autodetect address api call to libcec_configuration. only send power...
[deb_libcec.git] / src / cec-config-gui / actions / ConnectToDevice.cs
CommitLineData
4555ed72 1using CecSharp;
006b76b9 2using System.Windows.Forms;
006b76b9
LOK
3
4namespace CecConfigGui.actions
5{
6 class ConnectToDevice : UpdateProcess
7 {
4555ed72 8 public ConnectToDevice(ref LibCecSharp lib, LibCECConfiguration config)
006b76b9
LOK
9 {
10 Lib = lib;
4555ed72 11 Config = config;
006b76b9
LOK
12 }
13
14 public override void Process()
15 {
a70f3777
LOK
16 SendEvent(UpdateEventType.StatusText, "Opening connection...");
17 SendEvent(UpdateEventType.ProgressBar, 10);
18
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))
22 {
23 MessageBox.Show("Could not connect to any CEC adapter. Please check your configuration and try again.", "Pulse-Eight USB-CEC Adapter", MessageBoxButtons.OK);
24 Application.Exit();
25 }
26
006b76b9 27 SendEvent(UpdateEventType.StatusText, "Detecting TV vendor...");
6d866874 28 SendEvent(UpdateEventType.ProgressBar, 20);
006b76b9
LOK
29 SendEvent(UpdateEventType.TVVendorId, (int)Lib.GetDeviceVendorId(CecLogicalAddress.Tv));
30
f976869e 31 SendEvent(UpdateEventType.StatusText, "Detecting menu language...");
6d866874 32 SendEvent(UpdateEventType.ProgressBar, 30);
f976869e
LOK
33 SendEvent(UpdateEventType.MenuLanguage, Lib.GetDeviceMenuLanguage(CecLogicalAddress.Tv));
34
6d866874 35 SendEvent(UpdateEventType.ProgressBar, 40);
006b76b9
LOK
36 SendEvent(UpdateEventType.StatusText, "Detecting AVR devices...");
37
38 bool hasAVRDevice = Lib.IsActiveDevice(CecLogicalAddress.AudioSystem);
39 SendEvent(UpdateEventType.HasAVRDevice, hasAVRDevice);
40
41 if (hasAVRDevice)
42 {
6d866874 43 SendEvent(UpdateEventType.ProgressBar, 50);
006b76b9
LOK
44 SendEvent(UpdateEventType.StatusText, "Detecting AVR vendor...");
45 SendEvent(UpdateEventType.AVRVendorId, (int)Lib.GetDeviceVendorId(CecLogicalAddress.AudioSystem));
46 }
47
48 if (!Lib.GetDevicePowerStatus(CecLogicalAddress.Tv).Equals(CecPowerStatus.On))
49 {
6d866874 50 SendEvent(UpdateEventType.ProgressBar, 60);
4555ed72
LOK
51 SendEvent(UpdateEventType.StatusText, "Activating the source...");
52 Lib.SetActiveSource(CecDeviceType.Reserved);
006b76b9
LOK
53 }
54
6d866874 55 SendEvent(UpdateEventType.ProgressBar, 70);
006b76b9
LOK
56 SendEvent(UpdateEventType.StatusText, "Reading device configuration...");
57
4555ed72
LOK
58 Lib.GetCurrentConfiguration(Config);
59 SendEvent(Config);
006b76b9 60
6d866874
LOK
61 SendEvent(UpdateEventType.ProgressBar, 80);
62 SendEvent(UpdateEventType.StatusText, "Polling active devices");
63 SendEvent(UpdateEventType.PollDevices);
64
006b76b9
LOK
65 SendEvent(UpdateEventType.ProgressBar, 100);
66 SendEvent(UpdateEventType.StatusText, "Ready.");
67 }
68
69 private LibCecSharp Lib;
4555ed72 70 private LibCECConfiguration Config;
006b76b9
LOK
71 }
72}