typo
[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);
f916b582 21 if (adapters.Length == 0)
a70f3777 22 {
f916b582
LOK
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)
e23f490f
LOK
25 {
26 SendEvent(UpdateEventType.ExitApplication);
27 return;
28 }
f916b582
LOK
29 else
30 adapters = Lib.FindAdapters(string.Empty);
31 }
32
33 while (!Lib.Open(adapters[0].ComPort, 10000))
34 {
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)
e23f490f
LOK
37 {
38 SendEvent(UpdateEventType.ExitApplication);
39 return;
40 }
a70f3777
LOK
41 }
42
6d866874 43 SendEvent(UpdateEventType.ProgressBar, 20);
68b94c34
LOK
44 SendEvent(UpdateEventType.StatusText, "Sending power on commands...");
45 Lib.PowerOnDevices(CecLogicalAddress.Broadcast);
46
47 SendEvent(UpdateEventType.StatusText, "Detecting TV vendor...");
48 SendEvent(UpdateEventType.ProgressBar, 30);
006b76b9
LOK
49 SendEvent(UpdateEventType.TVVendorId, (int)Lib.GetDeviceVendorId(CecLogicalAddress.Tv));
50
f976869e 51 SendEvent(UpdateEventType.StatusText, "Detecting menu language...");
68b94c34 52 SendEvent(UpdateEventType.ProgressBar, 40);
f976869e
LOK
53 SendEvent(UpdateEventType.MenuLanguage, Lib.GetDeviceMenuLanguage(CecLogicalAddress.Tv));
54
68b94c34 55 SendEvent(UpdateEventType.ProgressBar, 50);
006b76b9
LOK
56 SendEvent(UpdateEventType.StatusText, "Detecting AVR devices...");
57
58 bool hasAVRDevice = Lib.IsActiveDevice(CecLogicalAddress.AudioSystem);
59 SendEvent(UpdateEventType.HasAVRDevice, hasAVRDevice);
60
61 if (hasAVRDevice)
62 {
68b94c34 63 SendEvent(UpdateEventType.ProgressBar, 60);
006b76b9
LOK
64 SendEvent(UpdateEventType.StatusText, "Detecting AVR vendor...");
65 SendEvent(UpdateEventType.AVRVendorId, (int)Lib.GetDeviceVendorId(CecLogicalAddress.AudioSystem));
66 }
67
68 if (!Lib.GetDevicePowerStatus(CecLogicalAddress.Tv).Equals(CecPowerStatus.On))
69 {
68b94c34 70 SendEvent(UpdateEventType.ProgressBar, 70);
4555ed72
LOK
71 SendEvent(UpdateEventType.StatusText, "Activating the source...");
72 Lib.SetActiveSource(CecDeviceType.Reserved);
006b76b9
LOK
73 }
74
68b94c34 75 SendEvent(UpdateEventType.ProgressBar, 80);
006b76b9
LOK
76 SendEvent(UpdateEventType.StatusText, "Reading device configuration...");
77
4555ed72
LOK
78 Lib.GetCurrentConfiguration(Config);
79 SendEvent(Config);
006b76b9 80
68b94c34 81 SendEvent(UpdateEventType.ProgressBar, 90);
6d866874
LOK
82 SendEvent(UpdateEventType.StatusText, "Polling active devices");
83 SendEvent(UpdateEventType.PollDevices);
84
006b76b9
LOK
85 SendEvent(UpdateEventType.ProgressBar, 100);
86 SendEvent(UpdateEventType.StatusText, "Ready.");
87 }
88
89 private LibCecSharp Lib;
4555ed72 90 private LibCECConfiguration Config;
006b76b9
LOK
91 }
92}