- if (control.InvokeRequired)
- {
- SetComboBoxItemsCallback d = new SetComboBoxItemsCallback(SetComboBoxItems);
- try
- {
- this.Invoke(d, new object[] { control, selectedText, val });
- }
- catch (Exception) { }
- }
- else
- {
- control.Items.Clear();
- control.Items.AddRange(val);
- control.Text = selectedText;
- }
- }
-
- private void ProcessEventHandler(object src, UpdateEvent updateEvent)
- {
- switch (updateEvent.Type)
- {
- case UpdateEventType.StatusText:
- SetControlText(lStatus, updateEvent.StringValue);
- break;
- case UpdateEventType.PhysicalAddress:
- Config.PhysicalAddress = (ushort)updateEvent.IntValue;
- SetControlText(tbPhysicalAddress, string.Format("{0,4:X}", updateEvent.IntValue));
- break;
- case UpdateEventType.ProgressBar:
- SetProgressValue(pProgress, updateEvent.IntValue);
- break;
- case UpdateEventType.TVVendorId:
- TVVendor = (CecVendorId)updateEvent.IntValue;
- UpdateSelectedDevice();
- break;
- case UpdateEventType.BaseDevicePhysicalAddress:
- SetControlText(lConnectedPhysicalAddress, string.Format("Address: {0,4:X}", updateEvent.IntValue));
- break;
- case UpdateEventType.BaseDevice:
- Config.BaseDevice = (CecLogicalAddress)updateEvent.IntValue;
- break;
- case UpdateEventType.HDMIPort:
- Config.HDMIPort = (byte)updateEvent.IntValue;
- break;
- case UpdateEventType.MenuLanguage:
- SetControlText(cbUseTVMenuLanguage, "Use the TV's language setting" + (updateEvent.StringValue.Length > 0 ? " (" + updateEvent.StringValue + ")" : ""));
- break;
- case UpdateEventType.HasAVRDevice:
- if (HasAVRDevice != updateEvent.BoolValue)
- {
- HasAVRDevice = updateEvent.BoolValue;
- UpdateSelectedDevice();
- }
- break;
- case UpdateEventType.AVRVendorId:
- AVRVendor = (CecVendorId)updateEvent.IntValue;
- UpdateSelectedDevice();
- break;
- case UpdateEventType.Configuration:
- Config = updateEvent.ConfigValue;
- SetControlText(tbPhysicalAddress, string.Format("{0,4:X}", Config.PhysicalAddress));
- SetControlText(cbConnectedDevice, Config.BaseDevice == CecLogicalAddress.AudioSystem ? AVRVendorString : TVVendorString);
- SetControlText(cbPortNumber, Config.HDMIPort.ToString());
- SetCheckboxChecked(cbUseTVMenuLanguage, Config.UseTVMenuLanguage);
- SetCheckboxChecked(cbPowerOnStartup, Config.PowerOnStartup);
- SetCheckboxChecked(cbPowerOffShutdown, Config.PowerOffShutdown);
- SetCheckboxChecked(cbPowerOffScreensaver, Config.PowerOffScreensaver);
- SetCheckboxChecked(cbPowerOffOnStandby, Config.PowerOffOnStandby);
- UpdateSelectedDevice();
- break;
- case UpdateEventType.ProcessCompleted:
- ActiveProcess = null;
- SetControlsEnabled(true);
- break;
- }
- }
-
- private void UpdateSelectedDevice()
- {
- if (HasAVRDevice)
- SetComboBoxItems(this.cbConnectedDevice, Config.BaseDevice == CecLogicalAddress.AudioSystem ? AVRVendorString : TVVendorString, new object[] { TVVendorString, AVRVendorString });
- else
- SetComboBoxItems(this.cbConnectedDevice, TVVendorString, new object[] { TVVendorString });
- }
-
- public string TVVendorString
- {
- get
- {
- return TVVendor != CecVendorId.Unknown ?
- "Television (" + Lib.ToString(TVVendor) + ")" :
- "Television";
- }
- }
-
- public string AVRVendorString
- {
- get
- {
- return AVRVendor != CecVendorId.Unknown ?
- "AVR (" + Lib.ToString(AVRVendor) + ")" :
- "AVR";
- }
- }
-
- protected bool HasAVRDevice;
- protected CecVendorId TVVendor = CecVendorId.Unknown;
- protected CecVendorId AVRVendor = CecVendorId.Unknown;
- protected CecLogicalAddress SelectedConnectedDevice = CecLogicalAddress.Unknown;
-
- protected LibCECConfiguration Config;
- protected LibCecSharp Lib;
- private CecCallbackWrapper Callbacks;
- private UpdateProcess ActiveProcess = null;
-
- public void SetConnectedDevice(CecLogicalAddress address, int portnumber)
- {
- if (ActiveProcess == null)
- {
- SetControlsEnabled(false);
- ActiveProcess = new UpdateConnectedDevice(ref Lib, address, portnumber);
- ActiveProcess.EventHandler += new EventHandler<UpdateEvent>(ProcessEventHandler);
- (new Thread(new ThreadStart(ActiveProcess.Run))).Start();
- }
- }
-
- private void connectedDevice_SelectedIndexChanged(object sender, EventArgs e)
- {
- SelectedConnectedDevice = (this.cbConnectedDevice.Text.Equals(AVRVendorString)) ? CecLogicalAddress.AudioSystem : CecLogicalAddress.Tv;
- int iPortNumber = 0;
- if (!int.TryParse(cbPortNumber.Text, out iPortNumber))
- iPortNumber = 1;
- SetConnectedDevice(SelectedConnectedDevice, iPortNumber);