X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcec-config-gui%2FCecConfigGUI.cs;h=46efb7951436816d62628590c6db19667fe1fb57;hb=9465b147bebb736351f32e92413a0eb0302028bc;hp=b1731cfa2c8dfdcae7bb92ece32b03fab0c9a482;hpb=75af24f133bfd316bc69a9b63e190047186f169a;p=deb_libcec.git diff --git a/src/cec-config-gui/CecConfigGUI.cs b/src/cec-config-gui/CecConfigGUI.cs index b1731cf..46efb79 100644 --- a/src/cec-config-gui/CecConfigGUI.cs +++ b/src/cec-config-gui/CecConfigGUI.cs @@ -1,7 +1,5 @@ using System; using System.Collections.Generic; -using System.ComponentModel; -using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; @@ -14,6 +12,14 @@ using System.Xml; namespace CecConfigGui { + internal enum ConfigTab + { + Configuration, + KeyConfiguration, + Tester, + Log + } + public partial class CecConfigGUI : AsyncForm { public CecConfigGUI() @@ -22,26 +28,19 @@ namespace CecConfigGui Config.DeviceTypes.Types[0] = CecDeviceType.RecordingDevice; Config.DeviceName = "CEC Config"; Config.GetSettingsFromROM = true; - Config.ClientVersion = CecClientVersion.Version1_5_0; + Config.ClientVersion = CecClientVersion.Version2_0_0; Callbacks = new CecCallbackWrapper(this); Config.SetCallbacks(Callbacks); LoadXMLConfiguration(ref Config); Lib = new LibCecSharp(Config); + Lib.InitVideoStandalone(); InitializeComponent(); LoadButtonConfiguration(); - //TODO read the com port setting from the configuration - CecAdapter[] adapters = Lib.FindAdapters(string.Empty); - if (adapters.Length == 0 || !Lib.Open(adapters[0].ComPort, 10000)) - { - MessageBox.Show("Could not connect to any CEC adapter. Please check your configuration and try again.", "Pulse-Eight USB-CEC Adapter", MessageBoxButtons.OK); - Application.Exit(); - } - ActiveProcess = new ConnectToDevice(ref Lib, Config); - ActiveProcess.EventHandler += new EventHandler(ProcessEventHandler); - (new Thread(new ThreadStart(ActiveProcess.Run))).Start(); + ActiveProcess.EventHandler += ProcessEventHandler; + (new Thread(ActiveProcess.Run)).Start(); } private bool LoadXMLConfiguration(ref LibCECConfiguration config) @@ -136,7 +135,7 @@ namespace CecConfigGui case "wake_devices": { config.WakeDevices.Clear(); - string[] split = value.Split(new char[] { ' ' }); + string[] split = value.Split(new[] { ' ' }); foreach (string dev in split) { byte iLogicalAddress; @@ -162,6 +161,10 @@ namespace CecConfigGui case "port": //TODO break; + // 1.5.1 settings + case "send_inactive_source": + config.SendInactiveSource = value.Equals("1") || value.ToLower().Equals("true") || value.ToLower().Equals("yes"); + break; default: break; } @@ -178,85 +181,85 @@ namespace CecConfigGui private void LoadButtonConfiguration() { //TODO load the real configuration - this.cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Select", (new CecSharp.CecKeypress() { Keycode = 0x00 }), string.Empty)); - this.cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Up", (new CecSharp.CecKeypress() { Keycode = 0x01 }), string.Empty)); - this.cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Down", (new CecSharp.CecKeypress() { Keycode = 0x02 }), string.Empty)); - this.cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Left", (new CecSharp.CecKeypress() { Keycode = 0x03 }), string.Empty)); - this.cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Right", (new CecSharp.CecKeypress() { Keycode = 0x04 }), string.Empty)); - this.cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Right+Up", (new CecSharp.CecKeypress() { Keycode = 0x05 }), string.Empty)); - this.cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Right+Down", (new CecSharp.CecKeypress() { Keycode = 0x06 }), string.Empty)); - this.cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Left+Up", (new CecSharp.CecKeypress() { Keycode = 0x07 }), string.Empty)); - this.cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Left+Down", (new CecSharp.CecKeypress() { Keycode = 0x08 }), string.Empty)); - this.cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Root menu", (new CecSharp.CecKeypress() { Keycode = 0x09 }), string.Empty)); - this.cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Setup menu", (new CecSharp.CecKeypress() { Keycode = 0x0A }), string.Empty)); - this.cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Contents menu", (new CecSharp.CecKeypress() { Keycode = 0x0B }), string.Empty)); - this.cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Favourite menu", (new CecSharp.CecKeypress() { Keycode = 0x0C }), string.Empty)); - this.cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Exit", (new CecSharp.CecKeypress() { Keycode = 0x0D }), string.Empty)); - this.cecButtonConfigBindingSource.Add(new CecButtonConfigItem("0", (new CecSharp.CecKeypress() { Keycode = 0x20 }), string.Empty)); - this.cecButtonConfigBindingSource.Add(new CecButtonConfigItem("1", (new CecSharp.CecKeypress() { Keycode = 0x21 }), string.Empty)); - this.cecButtonConfigBindingSource.Add(new CecButtonConfigItem("2", (new CecSharp.CecKeypress() { Keycode = 0x22 }), string.Empty)); - this.cecButtonConfigBindingSource.Add(new CecButtonConfigItem("3", (new CecSharp.CecKeypress() { Keycode = 0x23 }), string.Empty)); - this.cecButtonConfigBindingSource.Add(new CecButtonConfigItem("4", (new CecSharp.CecKeypress() { Keycode = 0x24 }), string.Empty)); - this.cecButtonConfigBindingSource.Add(new CecButtonConfigItem("5", (new CecSharp.CecKeypress() { Keycode = 0x25 }), string.Empty)); - this.cecButtonConfigBindingSource.Add(new CecButtonConfigItem("6", (new CecSharp.CecKeypress() { Keycode = 0x26 }), string.Empty)); - this.cecButtonConfigBindingSource.Add(new CecButtonConfigItem("7", (new CecSharp.CecKeypress() { Keycode = 0x27 }), string.Empty)); - this.cecButtonConfigBindingSource.Add(new CecButtonConfigItem("8", (new CecSharp.CecKeypress() { Keycode = 0x28 }), string.Empty)); - this.cecButtonConfigBindingSource.Add(new CecButtonConfigItem("9", (new CecSharp.CecKeypress() { Keycode = 0x29 }), string.Empty)); - this.cecButtonConfigBindingSource.Add(new CecButtonConfigItem(".", (new CecSharp.CecKeypress() { Keycode = 0x2A }), string.Empty)); - this.cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Enter", (new CecSharp.CecKeypress() { Keycode = 0x2B }), string.Empty)); - this.cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Clear", (new CecSharp.CecKeypress() { Keycode = 0x2C }), string.Empty)); - this.cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Next favourite", (new CecSharp.CecKeypress() { Keycode = 0x2F }), string.Empty)); - this.cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Channel up", (new CecSharp.CecKeypress() { Keycode = 0x30 }), string.Empty)); - this.cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Channel down", (new CecSharp.CecKeypress() { Keycode = 0x31 }), string.Empty)); - this.cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Previous channel", (new CecSharp.CecKeypress() { Keycode = 0x32 }), string.Empty)); - this.cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Sound select", (new CecSharp.CecKeypress() { Keycode = 0x33 }), string.Empty)); - this.cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Input select", (new CecSharp.CecKeypress() { Keycode = 0x34 }), string.Empty)); - this.cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Display information", (new CecSharp.CecKeypress() { Keycode = 0x35 }), string.Empty)); - this.cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Help", (new CecSharp.CecKeypress() { Keycode = 0x36 }), string.Empty)); - this.cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Page up", (new CecSharp.CecKeypress() { Keycode = 0x37 }), string.Empty)); - this.cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Page down", (new CecSharp.CecKeypress() { Keycode = 0x38 }), string.Empty)); - this.cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Power", (new CecSharp.CecKeypress() { Keycode = 0x40 }), string.Empty)); - this.cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Volume up", (new CecSharp.CecKeypress() { Keycode = 0x41 }), string.Empty)); - this.cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Volume down", (new CecSharp.CecKeypress() { Keycode = 0x42 }), string.Empty)); - this.cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Mute", (new CecSharp.CecKeypress() { Keycode = 0x43 }), string.Empty)); - this.cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Play", (new CecSharp.CecKeypress() { Keycode = 0x44 }), string.Empty)); - this.cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Stop", (new CecSharp.CecKeypress() { Keycode = 0x45 }), string.Empty)); - this.cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Pause", (new CecSharp.CecKeypress() { Keycode = 0x46 }), string.Empty)); - this.cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Record", (new CecSharp.CecKeypress() { Keycode = 0x47 }), string.Empty)); - this.cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Rewind", (new CecSharp.CecKeypress() { Keycode = 0x48 }), string.Empty)); - this.cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Fast forward", (new CecSharp.CecKeypress() { Keycode = 0x49 }), string.Empty)); - this.cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Eject", (new CecSharp.CecKeypress() { Keycode = 0x4A }), string.Empty)); - this.cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Forward", (new CecSharp.CecKeypress() { Keycode = 0x4B }), string.Empty)); - this.cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Backward", (new CecSharp.CecKeypress() { Keycode = 0x4C }), string.Empty)); - this.cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Stop record", (new CecSharp.CecKeypress() { Keycode = 0x4D }), string.Empty)); - this.cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Pause record", (new CecSharp.CecKeypress() { Keycode = 0x4E }), string.Empty)); - this.cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Angle", (new CecSharp.CecKeypress() { Keycode = 0x50 }), string.Empty)); - this.cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Sub picture", (new CecSharp.CecKeypress() { Keycode = 0x51 }), string.Empty)); - this.cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Video on demand", (new CecSharp.CecKeypress() { Keycode = 0x52 }), string.Empty)); - this.cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Electronic program guide", (new CecSharp.CecKeypress() { Keycode = 0x53 }), string.Empty)); - this.cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Timer programming", (new CecSharp.CecKeypress() { Keycode = 0x54 }), string.Empty)); - this.cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Initial configuration", (new CecSharp.CecKeypress() { Keycode = 0x55 }), string.Empty)); - this.cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Play (function)", (new CecSharp.CecKeypress() { Keycode = 0x60 }), string.Empty)); - this.cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Pause play (function)", (new CecSharp.CecKeypress() { Keycode = 0x61 }), string.Empty)); - this.cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Record (function)", (new CecSharp.CecKeypress() { Keycode = 0x62 }), string.Empty)); - this.cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Pause record (function)", (new CecSharp.CecKeypress() { Keycode = 0x63 }), string.Empty)); - this.cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Stop (function)", (new CecSharp.CecKeypress() { Keycode = 0x64 }), string.Empty)); - this.cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Mute (function)", (new CecSharp.CecKeypress() { Keycode = 0x65 }), string.Empty)); - this.cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Restore volume", (new CecSharp.CecKeypress() { Keycode = 0x66 }), string.Empty)); - this.cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Tune", (new CecSharp.CecKeypress() { Keycode = 0x67 }), string.Empty)); - this.cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Select media", (new CecSharp.CecKeypress() { Keycode = 0x68 }), string.Empty)); - this.cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Select AV input", (new CecSharp.CecKeypress() { Keycode = 0x69 }), string.Empty)); - this.cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Select audio input", (new CecSharp.CecKeypress() { Keycode = 0x6A }), string.Empty)); - this.cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Power toggle", (new CecSharp.CecKeypress() { Keycode = 0x6B }), string.Empty)); - this.cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Power off", (new CecSharp.CecKeypress() { Keycode = 0x6C }), string.Empty)); - this.cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Power on", (new CecSharp.CecKeypress() { Keycode = 0x6D }), string.Empty)); - this.cecButtonConfigBindingSource.Add(new CecButtonConfigItem("F1 (blue)", (new CecSharp.CecKeypress() { Keycode = 0x71 }), string.Empty)); - this.cecButtonConfigBindingSource.Add(new CecButtonConfigItem("F2 (red)", (new CecSharp.CecKeypress() { Keycode = 0x72 }), string.Empty)); - this.cecButtonConfigBindingSource.Add(new CecButtonConfigItem("F3 (green)", (new CecSharp.CecKeypress() { Keycode = 0x73 }), string.Empty)); - this.cecButtonConfigBindingSource.Add(new CecButtonConfigItem("F4 (yellow)", (new CecSharp.CecKeypress() { Keycode = 0x74 }), string.Empty)); - this.cecButtonConfigBindingSource.Add(new CecButtonConfigItem("F5", (new CecSharp.CecKeypress() { Keycode = 0x75 }), string.Empty)); - this.cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Data", (new CecSharp.CecKeypress() { Keycode = 0x76 }), string.Empty)); - this.cecButtonConfigBindingSource.Add(new CecButtonConfigItem("(Samsung) Return", (new CecSharp.CecKeypress() { Keycode = 0x91 }), string.Empty)); + cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Select", (new CecKeypress { Keycode = CecUserControlCode.Select }), string.Empty)); + cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Up", (new CecKeypress { Keycode = CecUserControlCode.Up }), string.Empty)); + cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Down", (new CecKeypress { Keycode = CecUserControlCode.Down }), string.Empty)); + cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Left", (new CecKeypress { Keycode = CecUserControlCode.Left }), string.Empty)); + cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Right", (new CecKeypress { Keycode = CecUserControlCode.Right }), string.Empty)); + cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Right+Up", (new CecKeypress { Keycode = CecUserControlCode.RightUp }), string.Empty)); + cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Right+Down", (new CecKeypress { Keycode = CecUserControlCode.RightDown }), string.Empty)); + cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Left+Up", (new CecKeypress { Keycode = CecUserControlCode.LeftUp }), string.Empty)); + cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Left+Down", (new CecKeypress { Keycode = CecUserControlCode.LeftDown }), string.Empty)); + cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Root menu", (new CecKeypress { Keycode = CecUserControlCode.RootMenu }), string.Empty)); + cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Setup menu", (new CecKeypress { Keycode = CecUserControlCode.SetupMenu }), string.Empty)); + cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Contents menu", (new CecKeypress { Keycode = CecUserControlCode.ContentsMenu }), string.Empty)); + cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Favourite menu", (new CecKeypress { Keycode = CecUserControlCode.FavoriteMenu }), string.Empty)); + cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Exit", (new CecKeypress { Keycode = CecUserControlCode.Exit }), string.Empty)); + cecButtonConfigBindingSource.Add(new CecButtonConfigItem("0", (new CecKeypress { Keycode = CecUserControlCode.Number0 }), string.Empty)); + cecButtonConfigBindingSource.Add(new CecButtonConfigItem("1", (new CecKeypress { Keycode = CecUserControlCode.Number1 }), string.Empty)); + cecButtonConfigBindingSource.Add(new CecButtonConfigItem("2", (new CecKeypress { Keycode = CecUserControlCode.Number2 }), string.Empty)); + cecButtonConfigBindingSource.Add(new CecButtonConfigItem("3", (new CecKeypress { Keycode = CecUserControlCode.Number3 }), string.Empty)); + cecButtonConfigBindingSource.Add(new CecButtonConfigItem("4", (new CecKeypress { Keycode = CecUserControlCode.Number4 }), string.Empty)); + cecButtonConfigBindingSource.Add(new CecButtonConfigItem("5", (new CecKeypress { Keycode = CecUserControlCode.Number5 }), string.Empty)); + cecButtonConfigBindingSource.Add(new CecButtonConfigItem("6", (new CecKeypress { Keycode = CecUserControlCode.Number6 }), string.Empty)); + cecButtonConfigBindingSource.Add(new CecButtonConfigItem("7", (new CecKeypress { Keycode = CecUserControlCode.Number7 }), string.Empty)); + cecButtonConfigBindingSource.Add(new CecButtonConfigItem("8", (new CecKeypress { Keycode = CecUserControlCode.Number8 }), string.Empty)); + cecButtonConfigBindingSource.Add(new CecButtonConfigItem("9", (new CecKeypress { Keycode = CecUserControlCode.Number9 }), string.Empty)); + cecButtonConfigBindingSource.Add(new CecButtonConfigItem(".", (new CecKeypress { Keycode = CecUserControlCode.Dot }), string.Empty)); + cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Enter", (new CecKeypress { Keycode = CecUserControlCode.Enter }), string.Empty)); + cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Clear", (new CecKeypress { Keycode = CecUserControlCode.Clear }), string.Empty)); + cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Next favourite", (new CecKeypress { Keycode = CecUserControlCode.NextFavorite }), string.Empty)); + cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Channel up", (new CecKeypress { Keycode = CecUserControlCode.ChannelUp }), string.Empty)); + cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Channel down", (new CecKeypress { Keycode = CecUserControlCode.ChannelDown }), string.Empty)); + cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Previous channel", (new CecKeypress { Keycode = CecUserControlCode.PreviousChannel }), string.Empty)); + cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Sound select", (new CecKeypress { Keycode = CecUserControlCode.SoundSelect }), string.Empty)); + cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Input select", (new CecKeypress { Keycode = CecUserControlCode.InputSelect }), string.Empty)); + cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Display information", (new CecKeypress { Keycode = CecUserControlCode.DisplayInformation }), string.Empty)); + cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Help", (new CecKeypress { Keycode = CecUserControlCode.Help }), string.Empty)); + cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Page up", (new CecKeypress { Keycode = CecUserControlCode.PageUp }), string.Empty)); + cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Page down", (new CecKeypress { Keycode = CecUserControlCode.PageDown }), string.Empty)); + cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Power", (new CecKeypress { Keycode = CecUserControlCode.Power }), string.Empty)); + cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Volume up", (new CecKeypress { Keycode = CecUserControlCode.VolumeUp }), string.Empty)); + cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Volume down", (new CecKeypress { Keycode = CecUserControlCode.VolumeDown }), string.Empty)); + cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Mute", (new CecKeypress { Keycode = CecUserControlCode.Mute }), string.Empty)); + cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Play", (new CecKeypress { Keycode = CecUserControlCode.Play }), string.Empty)); + cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Stop", (new CecKeypress { Keycode = CecUserControlCode.Stop }), string.Empty)); + cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Pause", (new CecKeypress { Keycode = CecUserControlCode.Pause }), string.Empty)); + cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Record", (new CecKeypress { Keycode = CecUserControlCode.Record }), string.Empty)); + cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Rewind", (new CecKeypress { Keycode = CecUserControlCode.Rewind }), string.Empty)); + cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Fast forward", (new CecKeypress { Keycode = CecUserControlCode.FastForward }), string.Empty)); + cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Eject", (new CecKeypress { Keycode = CecUserControlCode.Eject }), string.Empty)); + cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Forward", (new CecKeypress { Keycode = CecUserControlCode.Forward }), string.Empty)); + cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Backward", (new CecKeypress { Keycode = CecUserControlCode.Backward }), string.Empty)); + cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Stop record", (new CecKeypress { Keycode = CecUserControlCode.StopRecord }), string.Empty)); + cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Pause record", (new CecKeypress { Keycode = CecUserControlCode.PauseRecord }), string.Empty)); + cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Angle", (new CecKeypress { Keycode = CecUserControlCode.Angle }), string.Empty)); + cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Sub picture", (new CecKeypress { Keycode = CecUserControlCode.SubPicture }), string.Empty)); + cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Video on demand", (new CecKeypress { Keycode = CecUserControlCode.VideoOnDemand }), string.Empty)); + cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Electronic program guide", (new CecKeypress { Keycode = CecUserControlCode.ElectronicProgramGuide }), string.Empty)); + cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Timer programming", (new CecKeypress { Keycode = CecUserControlCode.TimerProgramming }), string.Empty)); + cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Initial configuration", (new CecKeypress { Keycode = CecUserControlCode.InitialConfiguration }), string.Empty)); + cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Play (function)", (new CecKeypress { Keycode = CecUserControlCode.PlayFunction }), string.Empty)); + cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Pause play (function)", (new CecKeypress { Keycode = CecUserControlCode.PausePlayFunction }), string.Empty)); + cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Record (function)", (new CecKeypress { Keycode = CecUserControlCode.RecordFunction }), string.Empty)); + cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Pause record (function)", (new CecKeypress { Keycode = CecUserControlCode .PauseRecordFunction }), string.Empty)); + cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Stop (function)", (new CecKeypress { Keycode = CecUserControlCode.StopFunction }), string.Empty)); + cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Mute (function)", (new CecKeypress { Keycode = CecUserControlCode.MuteFunction }), string.Empty)); + cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Restore volume", (new CecKeypress { Keycode = CecUserControlCode.RestoreVolumeFunction }), string.Empty)); + cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Tune", (new CecKeypress { Keycode = CecUserControlCode.TuneFunction }), string.Empty)); + cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Select media", (new CecKeypress { Keycode = CecUserControlCode.SelectMediaFunction }), string.Empty)); + cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Select AV input", (new CecKeypress { Keycode = CecUserControlCode.SelectAVInputFunction }), string.Empty)); + cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Select audio input", (new CecKeypress { Keycode = CecUserControlCode.SelectAudioInputFunction }), string.Empty)); + cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Power toggle", (new CecKeypress { Keycode = CecUserControlCode.PowerToggleFunction }), string.Empty)); + cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Power off", (new CecKeypress { Keycode = CecUserControlCode.PowerOffFunction }), string.Empty)); + cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Power on", (new CecKeypress { Keycode = CecUserControlCode.PowerOnFunction }), string.Empty)); + cecButtonConfigBindingSource.Add(new CecButtonConfigItem("F1 (blue)", (new CecKeypress { Keycode = CecUserControlCode.F1Blue }), string.Empty)); + cecButtonConfigBindingSource.Add(new CecButtonConfigItem("F2 (red)", (new CecKeypress { Keycode = CecUserControlCode.F2Red }), string.Empty)); + cecButtonConfigBindingSource.Add(new CecButtonConfigItem("F3 (green)", (new CecKeypress { Keycode = CecUserControlCode.F3Green }), string.Empty)); + cecButtonConfigBindingSource.Add(new CecButtonConfigItem("F4 (yellow)", (new CecKeypress { Keycode = CecUserControlCode.F4Yellow }), string.Empty)); + cecButtonConfigBindingSource.Add(new CecButtonConfigItem("F5", (new CecKeypress { Keycode = CecUserControlCode.F5 }), string.Empty)); + cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Data", (new CecKeypress { Keycode = CecUserControlCode.Data }), string.Empty)); + cecButtonConfigBindingSource.Add(new CecButtonConfigItem("Return (Samsung)", (new CecKeypress { Keycode = CecUserControlCode.SamsungReturn }), string.Empty)); } private void ProcessEventHandler(object src, UpdateEvent updateEvent) @@ -271,6 +274,7 @@ namespace CecConfigGui SetControlText(tbPhysicalAddress, string.Format("{0,4:X}", updateEvent.IntValue)); break; case UpdateEventType.ProgressBar: + SetControlVisible(pProgress, true); SetProgressValue(pProgress, updateEvent.IntValue); break; case UpdateEventType.TVVendorId: @@ -305,23 +309,140 @@ namespace CecConfigGui ConfigurationChanged(updateEvent.ConfigValue); SuppressUpdates = false; break; + case UpdateEventType.PollDevices: + CheckActiveDevices(); + break; case UpdateEventType.ProcessCompleted: ActiveProcess = null; SetControlsEnabled(true); + if (UpdatingInfoPanel != null) + { + UpdatingInfoPanel.SetControlEnabled(UpdatingInfoPanel.bUpdate, true); + UpdatingInfoPanel = null; + } + SetControlVisible(pProgress, false); + break; + case UpdateEventType.ExitApplication: + ActiveProcess = null; + SetControlsEnabled(false); + SetControlVisible(pProgress, false); + Application.Exit(); break; } } - public void SetPhysicalAddress(ushort physicalAddress) + private void SetControlsEnabled(bool val) + { + SetControlEnabled(cbPortNumber, val && !cbOverrideAddress.Checked); + SetControlEnabled(cbConnectedDevice, cbConnectedDevice.Items.Count > 1 && !cbOverrideAddress.Checked && val); + SetControlEnabled(cbOverrideAddress, val); + SetControlEnabled(tbPhysicalAddress, val && !Config.AutodetectAddress && cbOverrideAddress.Checked); + SetControlEnabled(cbDeviceType, val); + SetControlEnabled(cbUseTVMenuLanguage, val); + SetControlEnabled(cbActivateSource, val); + SetControlEnabled(cbPowerOffScreensaver, val); + SetControlEnabled(cbPowerOffOnStandby, val); + SetControlEnabled(cbWakeDevices, val); + SetControlEnabled(cbPowerOffDevices, val); + SetControlEnabled(cbVendorOverride, val); + SetControlEnabled(cbVendorId, val && cbVendorOverride.Checked); + SetControlEnabled(cbSendInactiveSource, val); + SetControlEnabled(bClose, val); + SetControlEnabled(bSaveConfig, val); + SetControlEnabled(bReloadConfig, val); + SetControlEnabled(bRescanDevices, val); + + SetControlEnabled(bSendImageViewOn, val); + SetControlEnabled(bStandby, val); + SetControlEnabled(bActivateSource, val); + SetControlEnabled(bScan, val); + + bool enableVolumeButtons = (GetTargetDevice() == CecLogicalAddress.AudioSystem) && val; + SetControlEnabled(bVolUp, enableVolumeButtons); + SetControlEnabled(bVolDown, enableVolumeButtons); + SetControlEnabled(bMute, enableVolumeButtons); + } + + private void tabControl1_SelectedIndexChanged(object sender, EventArgs e) + { + switch (tabControl1.SelectedIndex) + { + case 0: + SelectedTab = ConfigTab.Configuration; + break; + case 1: + SelectedTab = ConfigTab.KeyConfiguration; + break; + case 2: + SelectedTab = ConfigTab.Tester; + break; + case 3: + SelectedTab = ConfigTab.Log; + UpdateLog(); + break; + default: + SelectedTab = ConfigTab.Configuration; + break; + } + } + + protected override void Dispose(bool disposing) + { + if (disposing) + { + Lib.DisableCallbacks(); + Lib.StandbyDevices(CecLogicalAddress.Broadcast); + Lib.Close(); + } + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Actions + public void ReloadXmlConfiguration() + { + LoadXMLConfiguration(ref Config); + Lib.SetConfiguration(Config); + ConfigurationChanged(Config); + } + + public void UpdateInfoPanel(DeviceInformation panel) { if (!SuppressUpdates && ActiveProcess == null) + { + SetControlsEnabled(false); + UpdatingInfoPanel = panel; + panel.SetControlEnabled(panel.bUpdate, false); + ActiveProcess = new UpdateDeviceInfo(this, ref Lib, panel); + ActiveProcess.EventHandler += ProcessEventHandler; + (new Thread(ActiveProcess.Run)).Start(); + } + } + + public void SetPhysicalAddress(ushort physicalAddress) + { + if (!SuppressUpdates && ActiveProcess == null && cbOverrideAddress.Checked) { SetControlsEnabled(false); SetControlText(cbPortNumber, string.Empty); SetControlText(cbConnectedDevice, string.Empty); ActiveProcess = new UpdatePhysicalAddress(ref Lib, physicalAddress); - ActiveProcess.EventHandler += new EventHandler(ProcessEventHandler); - (new Thread(new ThreadStart(ActiveProcess.Run))).Start(); + ActiveProcess.EventHandler += ProcessEventHandler; + (new Thread(ActiveProcess.Run)).Start(); + } + } + + public void UpdateConfigurationAsync() + { + if (!SuppressUpdates && ActiveProcess == null) + { + SetControlsEnabled(false); + ActiveProcess = new UpdateConfiguration(ref Lib, Config); + ActiveProcess.EventHandler += ProcessEventHandler; + (new Thread(ActiveProcess.Run)).Start(); } } @@ -331,8 +452,8 @@ namespace CecConfigGui { SetControlsEnabled(false); ActiveProcess = new SendImageViewOn(ref Lib, address); - ActiveProcess.EventHandler += new EventHandler(ProcessEventHandler); - (new Thread(new ThreadStart(ActiveProcess.Run))).Start(); + ActiveProcess.EventHandler += ProcessEventHandler; + (new Thread(ActiveProcess.Run)).Start(); } } @@ -342,8 +463,8 @@ namespace CecConfigGui { SetControlsEnabled(false); ActiveProcess = new SendActivateSource(ref Lib, address); - ActiveProcess.EventHandler += new EventHandler(ProcessEventHandler); - (new Thread(new ThreadStart(ActiveProcess.Run))).Start(); + ActiveProcess.EventHandler += ProcessEventHandler; + (new Thread(ActiveProcess.Run)).Start(); } } @@ -353,8 +474,8 @@ namespace CecConfigGui { SetControlsEnabled(false); ActiveProcess = new SendStandby(ref Lib, address); - ActiveProcess.EventHandler += new EventHandler(ProcessEventHandler); - (new Thread(new ThreadStart(ActiveProcess.Run))).Start(); + ActiveProcess.EventHandler += ProcessEventHandler; + (new Thread(ActiveProcess.Run)).Start(); } } @@ -364,43 +485,24 @@ namespace CecConfigGui { SetControlsEnabled(false); ActiveProcess = new ShowDeviceInfo(this, ref Lib, address); - ActiveProcess.EventHandler += new EventHandler(ProcessEventHandler); - (new Thread(new ThreadStart(ActiveProcess.Run))).Start(); + ActiveProcess.EventHandler += ProcessEventHandler; + (new Thread(ActiveProcess.Run)).Start(); } } + #endregion - private void SetControlsEnabled(bool val) + #region Configuration tab + private void cbOverrideAddress_CheckedChanged(object sender, EventArgs e) { - SetControlEnabled(cbPortNumber, val); - SetControlEnabled(cbConnectedDevice, cbConnectedDevice.Items.Count > 1 ? val : false); - SetControlEnabled(tbPhysicalAddress, val); - SetControlEnabled(cbDeviceType, false); // TODO not implemented yet - SetControlEnabled(cbUseTVMenuLanguage, val); - SetControlEnabled(cbActivateSource, val); - SetControlEnabled(cbPowerOffScreensaver, val); - SetControlEnabled(cbPowerOffOnStandby, val); - SetControlEnabled(cbWakeDevices, false); // TODO not implemented yet - SetControlEnabled(cbPowerOffDevices, false); // TODO not implemented yet - SetControlEnabled(cbVendorOverride, false); // TODO not implemented yet - SetControlEnabled(cbVendorId, false); // TODO not implemented yet - SetControlEnabled(bClose, val); - SetControlEnabled(bSave, val); - - SetControlEnabled(bSendImageViewOn, val); - SetControlEnabled(bStandby, val); - SetControlEnabled(bActivateSource, val); - SetControlEnabled(bScan, val); - - bool enableVolumeButtons = (GetTargetDevice() == CecLogicalAddress.AudioSystem) && val; - SetControlEnabled(bVolUp, enableVolumeButtons); - SetControlEnabled(bVolDown, enableVolumeButtons); - SetControlEnabled(bMute, enableVolumeButtons); + SetControlEnabled(tbPhysicalAddress, ((CheckBox)sender).Checked); + SetControlEnabled(cbPortNumber, !((CheckBox)sender).Checked); + SetControlEnabled(cbConnectedDevice, !((CheckBox)sender).Checked && cbConnectedDevice.Items.Count > 1); } - #region Configuration tab private void tbPhysicalAddress_TextChanged(object sender, EventArgs e) { - if (tbPhysicalAddress.Text.Length != 4) + if (tbPhysicalAddress.Text.Length != 4 || + cbOverrideAddress.Checked) return; ushort physicalAddress = 0; if (!ushort.TryParse(tbPhysicalAddress.Text, NumberStyles.AllowHexSpecifier, null, out physicalAddress)) @@ -412,9 +514,9 @@ namespace CecConfigGui private void UpdateSelectedDevice() { if (HasAVRDevice) - SetComboBoxItems(this.cbConnectedDevice, Config.BaseDevice == CecLogicalAddress.AudioSystem ? AVRVendorString : TVVendorString, new object[] { TVVendorString, AVRVendorString }); + SetComboBoxItems(cbConnectedDevice, Config.BaseDevice == CecLogicalAddress.AudioSystem ? AVRVendorString : TVVendorString, new object[] { TVVendorString, AVRVendorString }); else - SetComboBoxItems(this.cbConnectedDevice, TVVendorString, new object[] { TVVendorString }); + SetComboBoxItems(cbConnectedDevice, TVVendorString, new object[] { TVVendorString }); } public void SetConnectedDevice(CecLogicalAddress address, int portnumber) @@ -423,8 +525,8 @@ namespace CecConfigGui { SetControlsEnabled(false); ActiveProcess = new UpdateConnectedDevice(ref Lib, address, portnumber); - ActiveProcess.EventHandler += new EventHandler(ProcessEventHandler); - (new Thread(new ThreadStart(ActiveProcess.Run))).Start(); + ActiveProcess.EventHandler += ProcessEventHandler; + (new Thread(ActiveProcess.Run)).Start(); } } @@ -435,7 +537,7 @@ namespace CecConfigGui private void bCancel_Click(object sender, EventArgs e) { - this.Dispose(); + Dispose(); } private void bSave_Click(object sender, EventArgs e) @@ -446,82 +548,167 @@ namespace CecConfigGui Config.ActivateSource = cbActivateSource.Checked; Config.PowerOffScreensaver = cbPowerOffScreensaver.Checked; Config.PowerOffOnStandby = cbPowerOffOnStandby.Checked; + Config.SendInactiveSource = cbSendInactiveSource.Checked; + Config.WakeDevices = WakeDevices; + Config.PowerOffDevices = PowerOffDevices; - if (!Lib.CanPersistConfiguration()) + /* save settings in the eeprom */ + Lib.PersistConfiguration(Config); + + /* and in xml */ + if (ActiveProcess == null) { - if (ActiveProcess == null) + SetControlsEnabled(false); + string xbmcDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\XBMC\userdata\peripheral_data"; + string defaultDir = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); + + SaveFileDialog dialog = new SaveFileDialog() { - SetControlsEnabled(false); - string xbmcDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\XBMC\userdata\peripheral_data"; - string defaultDir = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); + Title = "Where do you want to store the settings?", + InitialDirectory = Directory.Exists(xbmcDir) ? xbmcDir : defaultDir, + FileName = "usb_2548_1001.xml", + Filter = "xml files (*.xml)|*.xml|All files (*.*)|*.*", + FilterIndex = 1 + }; - SaveFileDialog dialog = new SaveFileDialog() + if (dialog.ShowDialog() == DialogResult.OK) + { + FileStream fs = null; + string error = string.Empty; + try { - Title = "Where do you want to store the settings?", - InitialDirectory = Directory.Exists(xbmcDir) ? xbmcDir : defaultDir, - FileName = "usb_2548_1001.xml", - Filter = "xml files (*.xml)|*.xml|All files (*.*)|*.*", - FilterIndex = 1 - }; - - if (dialog.ShowDialog() == DialogResult.OK) + fs = (FileStream)dialog.OpenFile(); + } + catch (Exception ex) { - FileStream fs = (FileStream)dialog.OpenFile(); - if (fs == null) - { - MessageBox.Show("Cannot open '" + dialog.FileName + "' for writing", "Pulse-Eight USB-CEC Adapter", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - else - { - StreamWriter writer = new StreamWriter(fs); - StringBuilder output = new StringBuilder(); - output.AppendLine(""); - output.AppendLine(""); - output.AppendLine(""); - output.AppendLine(""); - output.AppendLine(""); - output.AppendLine(""); - output.AppendLine(""); - output.AppendLine(""); - output.AppendLine(""); - output.AppendLine(""); - - // only supported by 1.5.0+ clients - output.AppendLine(""); - output.AppendLine(""); - output.AppendLine(""); - - output.Append(""); - - output.Append(""); - - output.AppendLine(""); - writer.Write(output.ToString()); - writer.Close(); - fs.Close(); - fs.Dispose(); - MessageBox.Show("Settings are stored.", "Pulse-Eight USB-CEC Adapter", MessageBoxButtons.OK, MessageBoxIcon.Information); - } + error = ex.Message; + } + if (fs == null) + { + MessageBox.Show("Cannot open '" + dialog.FileName + "' for writing" + (error.Length > 0 ? ": " + error : string.Empty ), "Pulse-Eight USB-CEC Adapter", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + else + { + StreamWriter writer = new StreamWriter(fs); + StringBuilder output = new StringBuilder(); + output.AppendLine(""); + output.AppendLine(""); + output.AppendLine(""); + output.AppendLine(""); + output.AppendLine(""); + output.AppendLine(""); + output.AppendLine(""); + output.AppendLine(""); + output.AppendLine(""); + output.AppendLine(""); + + // only supported by 1.5.0+ clients + output.AppendLine(""); + output.AppendLine(""); + output.AppendLine(""); + output.AppendLine(""); + output.AppendLine(""); + + output.Append(""); + + output.Append(""); + + // only supported by 1.5.1+ clients + output.AppendLine(""); + output.AppendLine(""); + + output.AppendLine(""); + writer.Write(output.ToString()); + writer.Close(); + fs.Close(); + fs.Dispose(); + MessageBox.Show("Settings are stored.", "Pulse-Eight USB-CEC Adapter", MessageBoxButtons.OK, MessageBoxIcon.Information); } - SetControlsEnabled(true); } + SetControlsEnabled(true); + } + } + + private void bReloadConfig_Click(object sender, EventArgs e) + { + if (Lib.CanPersistConfiguration()) + { + Lib.GetCurrentConfiguration(Config); + ConfigurationChanged(Config); } else { - if (!Lib.PersistConfiguration(Config)) - MessageBox.Show("Could not persist the new settings.", "Pulse-Eight USB-CEC Adapter", MessageBoxButtons.OK, MessageBoxIcon.Error); - else - MessageBox.Show("Settings are stored.", "Pulse-Eight USB-CEC Adapter", MessageBoxButtons.OK, MessageBoxIcon.Information); + ReloadXmlConfiguration(); + } + } + + private void cbVendorOverride_CheckedChanged(object sender, EventArgs e) + { + if (cbVendorOverride.Checked) + { + cbVendorId.Enabled = true; + switch (cbVendorId.Text) + { + case "LG": + Config.TvVendor = CecVendorId.LG; + break; + case "Onkyo": + Config.TvVendor = CecVendorId.Onkyo; + break; + case "Panasonic": + Config.TvVendor = CecVendorId.Panasonic; + break; + case "Philips": + Config.TvVendor = CecVendorId.Philips; + break; + case "Pioneer": + Config.TvVendor = CecVendorId.Pioneer; + break; + case "Samsung": + Config.TvVendor = CecVendorId.Samsung; + break; + case "Sony": + Config.TvVendor = CecVendorId.Sony; + break; + case "Yamaha": + Config.TvVendor = CecVendorId.Yamaha; + break; + default: + Config.TvVendor = CecVendorId.Unknown; + break; + } + } + else + { + cbVendorId.Enabled = false; + Config.TvVendor = CecVendorId.Unknown; + } + } + + private void cbDeviceType_SelectedIndexChanged(object sender, EventArgs e) + { + CecDeviceType type = SelectedDeviceType; + if (type != Config.DeviceTypes.Types[0]) + { + Config.DeviceTypes.Types[0] = type; + if (!DeviceChangeWarningDisplayed) + { + DeviceChangeWarningDisplayed = true; + MessageBox.Show("You have changed the device type. Save the configuration, and restart the application to use the new setting.", "Pulse-Eight USB-CEC Adapter", MessageBoxButtons.OK, MessageBoxIcon.Warning); + } } - SetControlsEnabled(true); } #endregion @@ -531,10 +718,10 @@ namespace CecConfigGui { if (dgButtons.InvokeRequired) { - SelectKeypressRowCallback d = new SelectKeypressRowCallback(SelectKeypressRow); + SelectKeypressRowCallback d = SelectKeypressRow; try { - this.Invoke(d, new object[] { key }); + Invoke(d, new object[] { key }); } catch (Exception) { } } @@ -570,22 +757,61 @@ namespace CecConfigGui #endregion #region CEC Tester tab + public void CheckActiveDevices() + { + CecLogicalAddresses activeDevices = Lib.GetActiveDevices(); + List deviceList = new List(); + foreach (CecLogicalAddress activeDevice in activeDevices.Addresses) + { + if (activeDevice != CecLogicalAddress.Unknown) + deviceList.Add(string.Format("{0,1:X} : {1}", (int)activeDevice, Lib.ToString(activeDevice))); + } + deviceList.Add(string.Format("{0,1:X} : {1}", (int)CecLogicalAddress.Broadcast, Lib.ToString(CecLogicalAddress.Broadcast))); + + SetActiveDevices(deviceList.ToArray()); + } + + delegate void SetActiveDevicesCallback(string[] activeDevices); + private void SetActiveDevices(string[] activeDevices) + { + if (cbCommandDestination.InvokeRequired) + { + SetActiveDevicesCallback d = SetActiveDevices; + try + { + Invoke(d, new object[] { activeDevices }); + } + catch (Exception) { } + } + else + { + cbCommandDestination.Items.Clear(); + foreach (string item in activeDevices) + cbCommandDestination.Items.Add(item); + } + } + delegate CecLogicalAddress GetTargetDeviceCallback(); private CecLogicalAddress GetTargetDevice() { - if (this.cbCommandDestination.InvokeRequired) + if (cbCommandDestination.InvokeRequired) { - GetTargetDeviceCallback d = new GetTargetDeviceCallback(GetTargetDevice); + GetTargetDeviceCallback d = GetTargetDevice; CecLogicalAddress retval = CecLogicalAddress.Unknown; try { - retval = (CecLogicalAddress)this.Invoke(d, new object[] { }); + retval = (CecLogicalAddress)Invoke(d, new object[] { }); } catch (Exception) { } return retval; } - switch (this.cbCommandDestination.Text.Substring(0, 1).ToLower()) + return GetLogicalAddressFromString(cbCommandDestination.Text); + } + + private CecLogicalAddress GetLogicalAddressFromString(string name) + { + switch (name.Substring(0, 1).ToLower()) { case "0": return CecLogicalAddress.Tv; @@ -647,9 +873,11 @@ namespace CecConfigGui private void cbCommandDestination_SelectedIndexChanged(object sender, EventArgs e) { bool enableVolumeButtons = (GetTargetDevice() == CecLogicalAddress.AudioSystem); - this.bVolUp.Enabled = enableVolumeButtons; - this.bVolDown.Enabled = enableVolumeButtons; - this.bMute.Enabled = enableVolumeButtons; + bVolUp.Enabled = enableVolumeButtons; + bVolDown.Enabled = enableVolumeButtons; + bMute.Enabled = enableVolumeButtons; + bActivateSource.Enabled = (GetTargetDevice() != CecLogicalAddress.Broadcast); + bScan.Enabled = (GetTargetDevice() != CecLogicalAddress.Broadcast); } private void bVolUp_Click(object sender, EventArgs e) @@ -672,64 +900,84 @@ namespace CecConfigGui Lib.MuteAudio(true); SetControlsEnabled(true); } + + private void bRescanDevices_Click(object sender, EventArgs e) + { + if (!SuppressUpdates && ActiveProcess == null) + { + SetControlsEnabled(false); + ActiveProcess = new RescanDevices(ref Lib); + ActiveProcess.EventHandler += ProcessEventHandler; + (new Thread(ActiveProcess.Run)).Start(); + } + } #endregion #region Log tab - delegate void AddLogMessageCallback(CecLogMessage message); - private void AddLogMessage(CecLogMessage message) + delegate void UpdateLogCallback(); + private void UpdateLog() { if (tbLog.InvokeRequired) { - AddLogMessageCallback d = new AddLogMessageCallback(AddLogMessage); + UpdateLogCallback d = UpdateLog; try { - this.Invoke(d, new object[] { message }); + Invoke(d, new object[] { }); } catch (Exception) { } } else { - string strLevel = ""; - bool display = false; - switch (message.Level) - { - case CecLogLevel.Error: - strLevel = "ERROR: "; - display = cbLogError.Checked; - break; - case CecLogLevel.Warning: - strLevel = "WARNING: "; - display = cbLogWarning.Checked; - break; - case CecLogLevel.Notice: - strLevel = "NOTICE: "; - display = cbLogNotice.Checked; - break; - case CecLogLevel.Traffic: - strLevel = "TRAFFIC: "; - display = cbLogTraffic.Checked; - break; - case CecLogLevel.Debug: - strLevel = "DEBUG: "; - display = cbLogDebug.Checked; - break; - default: - break; - } + tbLog.Text = Log; + tbLog.Select(tbLog.Text.Length, 0); + tbLog.ScrollToCaret(); + } + } - if (display) - { - string strLog = string.Format("{0} {1,16} {2}", strLevel, message.Time, message.Message) + System.Environment.NewLine; - tbLog.Text += strLog; - tbLog.Select(tbLog.Text.Length, 0); - tbLog.ScrollToCaret(); - } + private void AddLogMessage(CecLogMessage message) + { + string strLevel = ""; + bool display = false; + switch (message.Level) + { + case CecLogLevel.Error: + strLevel = "ERROR: "; + display = cbLogError.Checked; + break; + case CecLogLevel.Warning: + strLevel = "WARNING: "; + display = cbLogWarning.Checked; + break; + case CecLogLevel.Notice: + strLevel = "NOTICE: "; + display = cbLogNotice.Checked; + break; + case CecLogLevel.Traffic: + strLevel = "TRAFFIC: "; + display = cbLogTraffic.Checked; + break; + case CecLogLevel.Debug: + strLevel = "DEBUG: "; + display = cbLogDebug.Checked; + break; + default: + break; } + + if (display) + { + string strLog = string.Format("{0} {1,16} {2}", strLevel, message.Time, message.Message) + System.Environment.NewLine; + Log += strLog; + } + + if (SelectedTab == ConfigTab.Log) + UpdateLog(); } private void bClearLog_Click(object sender, EventArgs e) { - tbLog.Text = string.Empty; + Log = string.Empty; + UpdateLog(); } private void bSaveLog_Click(object sender, EventArgs e) @@ -753,7 +1001,7 @@ namespace CecConfigGui else { StreamWriter writer = new StreamWriter(fs); - writer.Write(tbLog.Text); + writer.Write(Log); writer.Close(); fs.Close(); fs.Dispose(); @@ -770,11 +1018,45 @@ namespace CecConfigGui SetControlText(tbPhysicalAddress, string.Format("{0,4:X}", Config.PhysicalAddress)); SetControlText(cbConnectedDevice, Config.BaseDevice == CecLogicalAddress.AudioSystem ? AVRVendorString : TVVendorString); SetControlText(cbPortNumber, Config.HDMIPort.ToString()); + switch (config.DeviceTypes.Types[0]) + { + case CecDeviceType.RecordingDevice: + SetControlText(cbDeviceType, "Recorder"); + break; + case CecDeviceType.PlaybackDevice: + SetControlText(cbDeviceType, "Player"); + break; + case CecDeviceType.Tuner: + SetControlText(cbDeviceType, "Tuner"); + break; + default: + SetControlText(cbDeviceType, "Recorder"); + break; + } + if (config.TvVendor != CecVendorId.Unknown) + { + SetCheckboxChecked(cbVendorOverride, true); + SetControlText(cbVendorId, Lib.ToString(config.TvVendor)); + } + else + { + SetCheckboxChecked(cbVendorOverride, false); + SetControlText(cbVendorId, Lib.ToString(TVVendor)); + } + SetCheckboxChecked(cbUseTVMenuLanguage, Config.UseTVMenuLanguage); SetCheckboxChecked(cbActivateSource, Config.ActivateSource); SetCheckboxChecked(cbPowerOffScreensaver, Config.PowerOffScreensaver); SetCheckboxChecked(cbPowerOffOnStandby, Config.PowerOffOnStandby); + SetCheckboxChecked(cbSendInactiveSource, Config.SendInactiveSource); UpdateSelectedDevice(); + + for (int iPtr = 0; iPtr < 15; iPtr++) + SetCheckboxItemChecked(cbWakeDevices, iPtr, Config.WakeDevices.IsSet((CecLogicalAddress)iPtr)); + for (int iPtr = 0; iPtr < 15; iPtr++) + SetCheckboxItemChecked(cbPowerOffDevices, iPtr, Config.PowerOffDevices.IsSet((CecLogicalAddress)iPtr)); + + SetControlText(this, "Pulse-Eight USB-CEC Adapter - libCEC " + Lib.ToString(Config.ServerVersion)); return 1; } @@ -791,7 +1073,11 @@ namespace CecConfigGui public int ReceiveLogMessage(CecLogMessage message) { - AddLogMessage(message); + try + { + AddLogMessage(message); + } + catch (Exception) { } return 1; } #endregion @@ -839,6 +1125,21 @@ namespace CecConfigGui return (cbConnectedDevice.Text.Equals(AVRVendorString)) ? CecLogicalAddress.AudioSystem : CecLogicalAddress.Tv; } } + public CecDeviceType SelectedDeviceType + { + get + { + switch (cbDeviceType.Text.ToLower()) + { + case "player": + return CecDeviceType.PlaybackDevice; + case "tuner": + return CecDeviceType.Tuner; + default: + return CecDeviceType.RecordingDevice; + } + } + } public int SelectedPortNumber { get @@ -853,7 +1154,37 @@ namespace CecConfigGui protected LibCecSharp Lib; private CecCallbackWrapper Callbacks; private UpdateProcess ActiveProcess = null; - private bool SuppressUpdates = false; + private bool SuppressUpdates = true; + private ConfigTab SelectedTab = ConfigTab.Configuration; + private string Log = string.Empty; + private DeviceInformation UpdatingInfoPanel = null; + private bool DeviceChangeWarningDisplayed = false; + public CecLogicalAddresses WakeDevices + { + get + { + CecLogicalAddresses addr = new CecLogicalAddresses(); + foreach (object item in cbWakeDevices.CheckedItems) + { + string c = item as string; + addr.Set(GetLogicalAddressFromString(c)); + } + return addr; + } + } + public CecLogicalAddresses PowerOffDevices + { + get + { + CecLogicalAddresses addr = new CecLogicalAddresses(); + foreach (object item in cbPowerOffDevices.CheckedItems) + { + string c = item as string; + addr.Set(GetLogicalAddressFromString(c)); + } + return addr; + } + } #endregion }