cec-config-gui: make the progress bar invisible when done. disable the physical addre...
[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
6d866874 27 SendEvent(UpdateEventType.ProgressBar, 20);
68b94c34
LOK
28 SendEvent(UpdateEventType.StatusText, "Sending power on commands...");
29 Lib.PowerOnDevices(CecLogicalAddress.Broadcast);
30
31 SendEvent(UpdateEventType.StatusText, "Detecting TV vendor...");
32 SendEvent(UpdateEventType.ProgressBar, 30);
006b76b9
LOK
33 SendEvent(UpdateEventType.TVVendorId, (int)Lib.GetDeviceVendorId(CecLogicalAddress.Tv));
34
f976869e 35 SendEvent(UpdateEventType.StatusText, "Detecting menu language...");
68b94c34 36 SendEvent(UpdateEventType.ProgressBar, 40);
f976869e
LOK
37 SendEvent(UpdateEventType.MenuLanguage, Lib.GetDeviceMenuLanguage(CecLogicalAddress.Tv));
38
68b94c34 39 SendEvent(UpdateEventType.ProgressBar, 50);
006b76b9
LOK
40 SendEvent(UpdateEventType.StatusText, "Detecting AVR devices...");
41
42 bool hasAVRDevice = Lib.IsActiveDevice(CecLogicalAddress.AudioSystem);
43 SendEvent(UpdateEventType.HasAVRDevice, hasAVRDevice);
44
45 if (hasAVRDevice)
46 {
68b94c34 47 SendEvent(UpdateEventType.ProgressBar, 60);
006b76b9
LOK
48 SendEvent(UpdateEventType.StatusText, "Detecting AVR vendor...");
49 SendEvent(UpdateEventType.AVRVendorId, (int)Lib.GetDeviceVendorId(CecLogicalAddress.AudioSystem));
50 }
51
52 if (!Lib.GetDevicePowerStatus(CecLogicalAddress.Tv).Equals(CecPowerStatus.On))
53 {
68b94c34 54 SendEvent(UpdateEventType.ProgressBar, 70);
4555ed72
LOK
55 SendEvent(UpdateEventType.StatusText, "Activating the source...");
56 Lib.SetActiveSource(CecDeviceType.Reserved);
006b76b9
LOK
57 }
58
68b94c34 59 SendEvent(UpdateEventType.ProgressBar, 80);
006b76b9
LOK
60 SendEvent(UpdateEventType.StatusText, "Reading device configuration...");
61
4555ed72
LOK
62 Lib.GetCurrentConfiguration(Config);
63 SendEvent(Config);
006b76b9 64
68b94c34 65 SendEvent(UpdateEventType.ProgressBar, 90);
6d866874
LOK
66 SendEvent(UpdateEventType.StatusText, "Polling active devices");
67 SendEvent(UpdateEventType.PollDevices);
68
006b76b9
LOK
69 SendEvent(UpdateEventType.ProgressBar, 100);
70 SendEvent(UpdateEventType.StatusText, "Ready.");
71 }
72
73 private LibCecSharp Lib;
4555ed72 74 private LibCECConfiguration Config;
006b76b9
LOK
75 }
76}