cec: add SetOSDString() to the interface (not supported by all tvs)
authorLars Op den Kamp <lars@opdenkamp.eu>
Fri, 14 Oct 2011 13:59:27 +0000 (15:59 +0200)
committerLars Op den Kamp <lars@opdenkamp.eu>
Fri, 14 Oct 2011 13:59:27 +0000 (15:59 +0200)
include/cec.h
include/cecc.h
include/cectypes.h
src/lib/CECProcessor.cpp
src/lib/CECProcessor.h
src/lib/LibCEC.cpp
src/lib/LibCEC.h
src/lib/LibCECC.cpp
src/testclient/main.cpp

index bf7a4735eb7840f3e9f486f5b4212e4d9d1a08b3..c23c35a125ae83b6eeed287af8bd8a94bf4a050e 100644 (file)
@@ -129,6 +129,11 @@ namespace CEC
      * @see cec_set_inactive_view
      */
     virtual bool SetInactiveView(void) = 0;
+
+    /*!
+     * @see cec_set_osd_string
+     */
+    virtual bool SetOSDString(cec_logical_address iLogicalAddress, cec_display_control duration, const char *strMessage) = 0;
   };
 };
 
index 43e79d836b0dc2ab22e9cf8a4c8f6d9f1416cb50..c319c196da7ab33bcda88d576f4867a12d8ab0a8 100644 (file)
@@ -202,6 +202,17 @@ extern DECLSPEC int cec_set_logical_address(cec_logical_address myAddress, cec_l
  */
 extern DECLSPEC int cec_set_physical_address(uint16_t iPhysicalAddress = CEC_DEFAULT_PHYSICAL_ADDRESS);
 
+/*!
+ * @brief Display a message on the TV.
+ * @brief The message to display.
+ * @return True when the command was sent, false otherwise.
+ */
+#ifdef __cplusplus
+extern DECLSPEC int cec_set_osd_string(CEC::cec_logical_address iLogicalAddress, CEC::cec_display_control duration, const char *strMessage);
+#else
+extern DECLSPEC int cec_set_osd_string(cec_logical_address iLogicalAddress, cec_display_control duration, const char *strMessage);
+#endif
+
 #ifdef __cplusplus
 };
 #endif
index f18d928a2a3e6a15b00604bce22db834e3290691..004ea060170047888c636bf8d019791e7fd24f87 100644 (file)
@@ -151,13 +151,13 @@ typedef enum
   CEC_DEVICE_TYPE_AUDIO_SYSTEM = 5
 } ECecDeviceType;
 
-typedef enum
+typedef enum cec_display_control
 {
   CEC_DISPLAY_CONTROL_DISPLAY_FOR_DEFAULT_TIME = 0x00,
   CEC_DISPLAY_CONTROL_DISPLAY_UNTIL_CLEARED = 0x40,
   CEC_DISPLAY_CONTROL_CLEAR_PREVIOUS_MESSAGE = 0x80,
   CEC_DISPLAY_CONTROL_RESERVED_FOR_FUTURE_USE = 0xC0
-} ECecDisplayControl;
+} cec_display_control;
 
 typedef enum
 {
index 0c558450056e06cd9757bbd68b663e30daa9c39c..88541c01fb315821f402f3f62af1b3cc1c90d0f0 100644 (file)
@@ -221,6 +221,22 @@ bool CCECProcessor::SetPhysicalAddress(uint16_t iPhysicalAddress)
   return SetActiveView();
 }
 
+bool CCECProcessor::SetOSDString(cec_logical_address iLogicalAddress, cec_display_control duration, const char *strMessage)
+{
+  CStdString strLog;
+  strLog.Format("<< display message '%s'", strMessage);
+  m_controller->AddLog(CEC_LOG_NOTICE, strLog.c_str());
+
+  cec_command command;
+  cec_command::format(command, m_iLogicalAddress, iLogicalAddress, CEC_OPCODE_SET_OSD_STRING);
+  command.parameters.push_back((uint8_t)duration);
+
+  for (unsigned int iPtr = 0; iPtr < strlen(strMessage); iPtr++)
+    command.parameters.push_back(strMessage[iPtr]);
+
+  return Transmit(command);
+}
+
 bool CCECProcessor::TransmitFormatted(const cec_adapter_message &data, bool bWaitForAck /* = true */)
 {
   CLockObject lock(&m_mutex);
index 43b7a30cae32d170893d1b4b1f20ae2285f38a4a..dd0596e4e7d356e6675e4696b9851d73f6ba71a1 100644 (file)
@@ -59,6 +59,7 @@ namespace CEC
       virtual bool Transmit(const cec_command &data, bool bWaitForAck = true);
       virtual bool SetLogicalAddress(cec_logical_address iLogicalAddress);
       virtual bool SetPhysicalAddress(uint16_t iPhysicalAddress);
+      virtual bool SetOSDString(cec_logical_address iLogicalAddress, cec_display_control duration, const char *strMessage);
 
       static const char *CECVendorIdToString(const uint64_t iVendorId);
 
index 78fca2d1a610c2528bfc7cd34096e0db9ea0fbfb..a1f2650f4198305561ae6943b33c449dce7bc47d 100644 (file)
@@ -193,6 +193,11 @@ bool CLibCEC::SetInactiveView(void)
   return m_cec ? m_cec->SetInactiveView() : false;
 }
 
+bool CLibCEC::SetOSDString(cec_logical_address iLogicalAddress, cec_display_control duration, const char *strMessage)
+{
+  return m_cec ? m_cec->SetOSDString(iLogicalAddress, duration, strMessage) : false;
+}
+
 void CLibCEC::AddLog(cec_log_level level, const string &strMessage)
 {
   if (m_cec)
index 2f80720a2ec4970eae1923fcf15e7578fdc688bd..8ea0c98417dba829b9c763f349709df29836b1ec 100644 (file)
@@ -71,6 +71,7 @@ namespace CEC
       virtual bool StandbyDevices(cec_logical_address address = CECDEVICE_BROADCAST);
       virtual bool SetActiveView(void);
       virtual bool SetInactiveView(void);
+      virtual bool SetOSDString(cec_logical_address iLogicalAddress, cec_display_control duration, const char *strMessage);
     //@}
 
       virtual void AddLog(cec_log_level level, const std::string &strMessage);
index ccdd5b6a339b86762b2058db713ef0d7d6f16f70..d062dff9357f39ccdd76b6156eee1663a3ac58f2 100644 (file)
@@ -173,4 +173,11 @@ int cec_set_inactive_view(void)
   return -1;
 }
 
+int cec_set_osd_string(cec_logical_address iLogicalAddress, cec_display_control duration, const char *strMessage)
+{
+  if (cec_parser)
+    return cec_parser->SetOSDString(iLogicalAddress, duration, strMessage) ? 1 : 0;
+  return -1;
+}
+
 //@}
index cd83f10d48323566e6386a28a0346fc306956c8f..2939c6034f646e33aa4067b94205342ef7dd1909 100644 (file)
@@ -183,6 +183,9 @@ void show_console_help(void)
   "pa {physical_address}     change the physical address of the CEC adapter." << endl <<
   "[pa 10 00]                physical address 1.0.0.0" << endl <<
   endl <<
+  "osd {addr} {string}       set OSD message on the specified device." << endl <<
+  "[osd 0 Test Message]      displays 'Test Message' on the TV" << endl <<
+  endl <<
   "[ping]                    send a ping command to the CEC adapter." << endl <<
   "[bl]                      to let the adapter enter the bootloader, to upgrade" << endl <<
   "                          the flash rom." << endl <<
@@ -339,6 +342,25 @@ int main (int argc, char *argv[])
             parser->SetPhysicalAddress(iPhysicalAddress);
           }
         }
+        else if (command == "osd")
+        {
+          bool bFirstWord(false);
+          string strAddr, strMessage, strWord;
+          uint8_t iAddr;
+          if (GetWord(input, strAddr) && HexStrToInt(strAddr, iAddr) && iAddr < 0xF)
+          {
+            while (GetWord(input, strWord))
+            {
+              if (bFirstWord)
+              {
+                bFirstWord = false;
+                strMessage.append(" ");
+              }
+              strMessage.append(strWord);
+            }
+            parser->SetOSDString((cec_logical_address) iAddr, CEC_DISPLAY_CONTROL_DISPLAY_FOR_DEFAULT_TIME, strMessage.c_str());
+          }
+        }
         else if (command == "ping")
         {
           parser->PingAdapter();