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