namespace CecConfigGui
{
+ internal enum ConfigTab
+ {
+ Configuration,
+ KeyConfiguration,
+ Tester,
+ Log
+ }
+
public partial class CecConfigGUI : AsyncForm
{
public CecConfigGUI()
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<UpdateEvent>(ProcessEventHandler);
(new Thread(new ThreadStart(ActiveProcess.Run))).Start();
}
}
+ private void SetControlsEnabled(bool val)
+ {
+ 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, val);
+ SetControlEnabled(cbVendorId, val && cbVendorOverride.Checked);
+ SetControlEnabled(bClose, val);
+ SetControlEnabled(bSaveConfig, val);
+ SetControlEnabled(bReloadConfig, 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;
+ }
+ }
+
+ #region Actions
+ public void ReloadXMLConfiguration()
+ {
+ LoadXMLConfiguration(ref Config);
+ Lib.SetConfiguration(Config);
+ ConfigurationChanged(Config);
+ }
+
public void SetPhysicalAddress(ushort physicalAddress)
{
if (!SuppressUpdates && ActiveProcess == null)
(new Thread(new ThreadStart(ActiveProcess.Run))).Start();
}
}
-
- private void SetControlsEnabled(bool val)
- {
- 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);
- }
+ #endregion
#region Configuration tab
private void tbPhysicalAddress_TextChanged(object sender, EventArgs e)
if (dialog.ShowDialog() == DialogResult.OK)
{
- FileStream fs = (FileStream)dialog.OpenFile();
+ FileStream fs = null;
+ string error = string.Empty;
+ try
+ {
+ fs = (FileStream)dialog.OpenFile();
+ }
+ catch (Exception ex)
+ {
+ error = ex.Message;
+ }
if (fs == null)
{
- MessageBox.Show("Cannot open '" + dialog.FileName + "' for writing", "Pulse-Eight USB-CEC Adapter", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ MessageBox.Show("Cannot open '" + dialog.FileName + "' for writing" + (error.Length > 0 ? ": " + error : string.Empty ), "Pulse-Eight USB-CEC Adapter", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
}
SetControlsEnabled(true);
}
+
+ private void bReloadConfig_Click(object sender, EventArgs e)
+ {
+ if (Lib.CanPersistConfiguration())
+ {
+ Lib.GetCurrentConfiguration(Config);
+ ConfigurationChanged(Config);
+ }
+ else
+ {
+ 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;
+ }
+ }
#endregion
#region Key configuration tab
#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 = new UpdateLogCallback(UpdateLog);
try
{
- this.Invoke(d, new object[] { message });
+ this.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)
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);
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;
#endregion
}