[cec] simplify 'wake_devices' and 'standby_devices' settings by showing an enum inste...
authorLars Op den Kamp <lars@opdenkamp.eu>
Sun, 7 Oct 2012 11:00:33 +0000 (13:00 +0200)
committerLars Op den Kamp <lars@opdenkamp.eu>
Tue, 9 Oct 2012 00:02:44 +0000 (02:02 +0200)
language/English/strings.po
system/peripherals.xml
xbmc/peripherals/devices/PeripheralCecAdapter.cpp
xbmc/peripherals/devices/PeripheralCecAdapter.h

index fc23d6b..7cbb301 100644 (file)
@@ -11033,3 +11033,7 @@ msgctxt "#36038"
 msgid "Amplifier / AVR device"
 msgstr ""
 
+msgctxt "#36039"
+msgid "TV and AVR device (explicit)"
+msgstr ""
+
index 26c3494..5e41d75 100644 (file)
   <peripheral vendor_product="2708:1001" bus="rpi" name="Raspberry Pi CEC Adapter" mapTo="cec">
     <setting key="enabled" type="bool" value="1" label="305" order="1" />
     <setting key="activate_source" type="bool" value="1" label="36020" order="2" />
-    <setting key="wake_devices" type="string" value="0" label="36007" order="3" />
-    <setting key="standby_devices" type="string" value="0" label="36008" order="4" />
-    <setting key="cec_standby_screensaver" type="bool" value="0" label="36009" order="5" />
-    <setting key="standby_pc_on_tv_standby" type="enum" value="13011" label="36029" order="6" lvalues="36028|13005|13011" />
-    <setting key="standby_tv_on_pc_standby" type="bool" value="1" label="36026" order="7" />
-    <setting key="send_inactive_source" type="bool" value="1" label="36025" order="8" />
+    <setting key="wake_devices" type="enum" value="36037" label="36007" lvalues="36037|36038|36039|231" order="3" />
+    <setting key="standby_devices" type="enum" value="36037" label="36008" lvalues="36037|36038|36039|231" order="4" />
+    <setting key="send_inactive_source" type="bool" value="1" label="36025" order="5" />
+    <setting key="cec_standby_screensaver" type="bool" value="0" label="36009" order="7" />
+    <setting key="standby_pc_on_tv_standby" type="enum" value="13011" label="36029" order="7" lvalues="36028|13005|13011" />
+    <setting key="standby_tv_on_pc_standby" type="bool" value="1" label="36026" order="8" />
     <setting key="use_tv_menu_language" type="bool" value="1" label="36018" order="9" />
 
     <setting key="tv_vendor" type="int" value="0" configurable="0" />
     <setting key="cec_hdmi_port" type="int" value="1" label="36015" configurable="0" />
     <setting key="connected_device" type="int" label="36019" value="0" configurable="0" />
     <setting key="port" type="string" value="" label="36022" configurable="0" />
+    <setting key="wake_devices_advanced" type="string" value="" configurable="0" />
+    <setting key="standby_devices_advanced" type="string" value="" configurable="0" />
   </peripheral>
 
   <peripheral vendor_product="2548:1001,2548:1002" bus="usb" name="Pulse-Eight CEC Adapter" mapTo="cec">
     <setting key="enabled" type="bool" value="1" label="305" order="1" />
     <setting key="activate_source" type="bool" value="1" label="36020" order="2" />
-    <setting key="wake_devices" type="string" value="0" label="36007" order="3" />
-    <setting key="standby_devices" type="string" value="0" label="36008" order="4" />
-    <setting key="cec_standby_screensaver" type="bool" value="0" label="36009" order="5" />
-    <setting key="standby_pc_on_tv_standby" type="enum" value="13011" label="36029" order="6" lvalues="36028|13005|13011" />
-    <setting key="standby_tv_on_pc_standby" type="bool" value="1" label="36026" order="7" />
-    <setting key="send_inactive_source" type="bool" value="1" label="36025" order="8" />
+    <setting key="wake_devices" type="enum" value="36037" label="36007" lvalues="36037|36038|36039|231" order="3" />
+    <setting key="standby_devices" type="enum" value="36037" label="36008" lvalues="36037|36038|36039|231" order="4" />
+    <setting key="send_inactive_source" type="bool" value="1" label="36025" order="5" />
+    <setting key="cec_standby_screensaver" type="bool" value="0" label="36009" order="6" />
+    <setting key="standby_pc_on_tv_standby" type="enum" value="13011" label="36029" order="7" lvalues="36028|13005|13011" />
+    <setting key="standby_tv_on_pc_standby" type="bool" value="1" label="36026" order="8" />
     <setting key="use_tv_menu_language" type="bool" value="1" label="36018" order="9" />
     <setting key="pause_playback_on_deactivate" type="bool" value="1" label="36033" order="10" />
     <setting key="connected_device" type="enum" label="36019" value="36037" lvalues="36037|36038" order="11" />
@@ -48,6 +50,8 @@
     <setting key="tv_vendor" type="int" value="0" configurable="0" />
     <setting key="device_name" type="string" value="XBMC" configurable="0" />
     <setting key="device_type" type="int" value="1" configurable="0" />
+    <setting key="wake_devices_advanced" type="string" value="" configurable="0" />
+    <setting key="standby_devices_advanced" type="string" value="" configurable="0" />
   </peripheral>
 
   <peripheral vendor_product="15C2:32,15C2:33,15C2:34,15C2:35,15C2:36,15C2:37,15C2:38,15C2:39,15C2:3A,15C2:3B,15C2:3C,15C2:3D,15C2:3E,15C2:3F,15C2:41,15C2:42,15C2:43,15C2:44,15C2:45,15C2:46" bus="usb" name="iMON HID device" mapTo="imon">
index 6f20476..3c6d712 100644 (file)
@@ -53,6 +53,8 @@ using namespace std;
 
 #define LOCALISED_ID_TV           36037
 #define LOCALISED_ID_AVR          36038
+#define LOCALISED_ID_TV_AVR       36039
+#define LOCALISED_ID_NONE         231
 
 class DllLibCECInterface
 {
@@ -186,6 +188,12 @@ bool CPeripheralCecAdapter::InitialiseFeature(const PeripheralFeature feature)
 {
   if (feature == FEATURE_CEC && !m_bStarted && GetSettingBool("enabled"))
   {
+    // hide settings that have an override set
+    if (!GetSettingString("wake_devices_advanced").IsEmpty())
+      SetSettingVisible("wake_devices", false);
+    if (!GetSettingString("standby_devices_advanced").IsEmpty())
+      SetSettingVisible("standby_devices", false);
+
     SetConfigurationFromSettings();
     m_callbacks.Clear();
     m_callbacks.CBCecLogMessage           = &CecLogMessage;
@@ -1252,19 +1260,11 @@ void CPeripheralCecAdapter::SetConfigurationFromLibCEC(const CEC::libcec_configu
 
   // set the devices to wake when starting
   m_configuration.wakeDevices = config.wakeDevices;
-  CStdString strWakeDevices;
-  for (unsigned int iPtr = CECDEVICE_TV; iPtr <= CECDEVICE_BROADCAST; iPtr++)
-    if (config.wakeDevices[iPtr])
-      strWakeDevices.AppendFormat(" %X", iPtr);
-  bChanged |= SetSetting("wake_devices", strWakeDevices.Trim());
+  bChanged |= WriteLogicalAddresses(config.wakeDevices, "wake_devices", "wake_devices_advanced");
 
   // set the devices to power off when stopping
   m_configuration.powerOffDevices = config.powerOffDevices;
-  CStdString strPowerOffDevices;
-  for (unsigned int iPtr = CECDEVICE_TV; iPtr <= CECDEVICE_BROADCAST; iPtr++)
-    if (config.powerOffDevices[iPtr])
-      strPowerOffDevices.AppendFormat(" %X", iPtr);
-  bChanged |= SetSetting("standby_devices", strPowerOffDevices.Trim());
+  bChanged |= WriteLogicalAddresses(config.powerOffDevices, "standby_devices", "standby_devices_advanced");
 
   // set the boolean settings
   m_configuration.bUseTVMenuLanguage = config.bUseTVMenuLanguage;
@@ -1349,14 +1349,20 @@ void CPeripheralCecAdapter::SetConfigurationFromSettings(void)
     m_configuration.tvVendor = iVendor;
 
   // read the devices to wake when starting
-  CStdString strWakeDevices = CStdString(GetSettingString("wake_devices")).Trim();
+  CStdString strWakeDevices = CStdString(GetSettingString("wake_devices_advanced")).Trim();
   m_configuration.wakeDevices.Clear();
-  ReadLogicalAddresses(strWakeDevices, m_configuration.wakeDevices);
+  if (!strWakeDevices.IsEmpty())
+    ReadLogicalAddresses(strWakeDevices, m_configuration.wakeDevices);
+  else
+    ReadLogicalAddresses(GetSettingInt("wake_devices"), m_configuration.wakeDevices);
 
   // read the devices to power off when stopping
-  CStdString strStandbyDevices = CStdString(GetSettingString("standby_devices")).Trim();
+  CStdString strStandbyDevices = CStdString(GetSettingString("standby_devices_advanced")).Trim();
   m_configuration.powerOffDevices.Clear();
-  ReadLogicalAddresses(strStandbyDevices, m_configuration.powerOffDevices);
+  if (!strStandbyDevices.IsEmpty())
+    ReadLogicalAddresses(strStandbyDevices, m_configuration.powerOffDevices);
+  else
+    ReadLogicalAddresses(GetSettingInt("standby_devices"), m_configuration.powerOffDevices);
 
   // read the boolean settings
   m_configuration.bUseTVMenuLanguage   = GetSettingBool("use_tv_menu_language") ? 1 : 0;
@@ -1384,6 +1390,51 @@ void CPeripheralCecAdapter::ReadLogicalAddresses(const CStdString &strString, ce
   }
 }
 
+void CPeripheralCecAdapter::ReadLogicalAddresses(int iLocalisedId, cec_logical_addresses &addresses)
+{
+  addresses.Clear();
+  switch (iLocalisedId)
+  {
+  case LOCALISED_ID_TV:
+    addresses.Set(CECDEVICE_TV);
+    break;
+  case LOCALISED_ID_AVR:
+    addresses.Set(CECDEVICE_AUDIOSYSTEM);
+    break;
+  case LOCALISED_ID_TV_AVR:
+    addresses.Set(CECDEVICE_TV);
+    addresses.Set(CECDEVICE_AUDIOSYSTEM);
+    break;
+  case LOCALISED_ID_NONE:
+  default:
+    break;
+  }
+}
+
+bool CPeripheralCecAdapter::WriteLogicalAddresses(const cec_logical_addresses& addresses, const string& strSettingName, const string& strAdvancedSettingName)
+{
+  bool bChanged(false);
+
+  // only update the advanced setting if it was set by the user
+  if (!GetSettingString(strAdvancedSettingName).IsEmpty())
+  {
+    CStdString strPowerOffDevices;
+    for (unsigned int iPtr = CECDEVICE_TV; iPtr <= CECDEVICE_BROADCAST; iPtr++)
+      if (addresses[iPtr])
+        strPowerOffDevices.AppendFormat(" %X", iPtr);
+    bChanged = SetSetting(strAdvancedSettingName, strPowerOffDevices.Trim());
+  }
+
+  int iSettingPowerOffDevices = LOCALISED_ID_NONE;
+  if (addresses[CECDEVICE_TV] && addresses[CECDEVICE_AUDIOSYSTEM])
+    iSettingPowerOffDevices = LOCALISED_ID_TV_AVR;
+  else if (addresses[CECDEVICE_TV])
+    iSettingPowerOffDevices = LOCALISED_ID_TV;
+  else if (addresses[CECDEVICE_AUDIOSYSTEM])
+    iSettingPowerOffDevices = LOCALISED_ID_AVR;
+  return SetSetting(strSettingName, iSettingPowerOffDevices) || bChanged;
+}
+
 CPeripheralCecAdapterUpdateThread::CPeripheralCecAdapterUpdateThread(CPeripheralCecAdapter *adapter, libcec_configuration *configuration) :
     CThread("CEC Adapter Update Thread"),
     m_adapter(adapter),
index b992aa3..d1d939e 100644 (file)
@@ -119,6 +119,8 @@ namespace PERIPHERALS
     void SetConfigurationFromLibCEC(const CEC::libcec_configuration &config);
     void SetVersionInfo(const CEC::libcec_configuration &configuration);
     static void ReadLogicalAddresses(const CStdString &strString, CEC::cec_logical_addresses &addresses);
+    static void ReadLogicalAddresses(int iLocalisedId, CEC::cec_logical_addresses &addresses);
+    bool WriteLogicalAddresses(const CEC::cec_logical_addresses& addresses, const std::string& strSettingName, const std::string& strAdvancedSettingName);
     static int CecKeyPress(void *cbParam, const CEC::cec_keypress key);
     void PushCecKeypress(const CecButtonPress &key);
     static int CecLogMessage(void *cbParam, const CEC::cec_log_message message);