| 1 | using System; |
| 2 | using System.Collections.Generic; |
| 3 | using System.Text; |
| 4 | using CecSharp; |
| 5 | |
| 6 | namespace CecConfigGui.actions |
| 7 | { |
| 8 | class UpdateConnectedDevice : UpdateProcess |
| 9 | { |
| 10 | public UpdateConnectedDevice(ref LibCecSharp lib, CecLogicalAddress address, int portNumber) |
| 11 | { |
| 12 | Lib = lib; |
| 13 | Address = address; |
| 14 | PortNumber = portNumber; |
| 15 | } |
| 16 | |
| 17 | public override void Process() |
| 18 | { |
| 19 | SendEvent(UpdateEventType.StatusText, "Requesting physical address..."); |
| 20 | SendEvent(UpdateEventType.ProgressBar, 0); |
| 21 | |
| 22 | ushort iPhysicalAddress = Lib.GetDevicePhysicalAddress(Address); |
| 23 | SendEvent(UpdateEventType.BaseDevicePhysicalAddress, iPhysicalAddress); |
| 24 | |
| 25 | SendEvent(UpdateEventType.StatusText, "Setting new configuration..."); |
| 26 | SendEvent(UpdateEventType.ProgressBar, 25); |
| 27 | |
| 28 | if (!Lib.SetHDMIPort(Address, (byte)PortNumber)) |
| 29 | { |
| 30 | SendEvent(UpdateEventType.StatusText, "Could not activate the new source"); |
| 31 | } |
| 32 | else |
| 33 | { |
| 34 | LibCECConfiguration config = new LibCECConfiguration(); |
| 35 | Lib.GetCurrentConfiguration(config); |
| 36 | |
| 37 | SendEvent(UpdateEventType.StatusText, "Activating source..."); |
| 38 | SendEvent(UpdateEventType.ProgressBar, 50); |
| 39 | Lib.SetActiveSource(config.DeviceTypes.Types[0]); |
| 40 | |
| 41 | SendEvent(UpdateEventType.StatusText, "Reading configuration..."); |
| 42 | SendEvent(UpdateEventType.ProgressBar, 75); |
| 43 | Lib.GetCurrentConfiguration(config); |
| 44 | |
| 45 | SendEvent(config); |
| 46 | SendEvent(UpdateEventType.StatusText, "Ready."); |
| 47 | } |
| 48 | SendEvent(UpdateEventType.ProgressBar, 100); |
| 49 | } |
| 50 | |
| 51 | private LibCecSharp Lib; |
| 52 | private CecLogicalAddress Address; |
| 53 | private int PortNumber; |
| 54 | } |
| 55 | } |