cec: handle the bWait parameter in TransmitKeypress() and TransmitKeyRelease()
[deb_libcec.git] / src / testclient / main.cpp
index d1ca8c19616a3b43446f5a0494588affd9e1c0eb..9a0bf3a6130c9c7466f72945f96e2c0c010fe9fa 100644 (file)
@@ -53,7 +53,8 @@ int                  g_cecLogLevel(CEC_LOG_ALL);
 ofstream             g_logOutput;
 bool                 g_bShortLog(false);
 CStdString           g_strPort;
-int8_t               g_iHDMIPort(-1);
+uint8_t              g_iHDMIPort(CEC_DEFAULT_HDMI_PORT);
+cec_logical_address  g_iBaseDevice((cec_logical_address)CEC_DEFAULT_BASE_DEVICE);
 cec_device_type_list g_typeList;
 bool                 g_bSingleCommand(false);
 
@@ -186,6 +187,8 @@ void ShowHelpCommandLine(const char* strExec)
       "  -l --list-devices           List all devices on this system" << endl <<
       "  -t --type {p|r|t|a}         The device type to use. More than one is possible." << endl <<
       "  -p --port {int}             The HDMI port to use as active source." << endl <<
+      "  -b --base {int}             The logical address of the device to with this " << endl <<
+      "                              adapter is connected." << endl <<
       "  -f --log-file {file}        Writes all libCEC log message to a file" << endl <<
       "  -sf --short-log-file {file} Writes all libCEC log message without timestamps" << endl <<
       "                              and log levels to a file." << endl <<
@@ -233,6 +236,7 @@ void ShowHelpConsole(void)
   "[la] {logical address}    change the logical address of the CEC adapter." << endl <<
   "[p] {device} {port}       change the HDMI port number of the CEC adapter." << endl <<
   "[pa] {physical address}   change the physical address of the CEC adapter." << endl <<
+  "[as]                      make the CEC adapter the active source." << endl <<
   "[osd] {addr} {string}     set OSD message on the specified device." << endl <<
   "[ver] {addr}              get the CEC version of the specified device." << endl <<
   "[ven] {addr}              get the vendor ID of the specified device." << endl <<
@@ -419,6 +423,18 @@ bool ProcessCommandOSD(ICECAdapter *parser, const string &command, string &argum
   return false;
 }
 
+bool ProcessCommandAS(ICECAdapter *parser, const string &command, string &arguments)
+{
+  if (command == "as")
+  {
+    parser->SetActiveView();
+    return true;
+  }
+
+  return false;
+}
+
+
 bool ProcessCommandPING(ICECAdapter *parser, const string &command, string &arguments)
 {
   if (command == "ping")
@@ -593,7 +609,7 @@ bool ProcessCommandNAME(ICECAdapter *parser, const string &command, string &argu
       int iDev = atoi(strDev);
       if (iDev >= 0 && iDev < 15)
       {
-        cec_osd_name name = parser->GetOSDName((cec_logical_address)iDev);
+        cec_osd_name name = parser->GetDeviceOSDName((cec_logical_address)iDev);
         cout << "OSD name of device " << iDev << " is '" << name.name << "'" << endl;
       }
       return true;
@@ -725,7 +741,7 @@ bool ProcessCommandSCAN(ICECAdapter *parser, const string &command, string &argu
         uint16_t iPhysicalAddress = parser->GetDevicePhysicalAddress((cec_logical_address)iPtr);
         cec_version iCecVersion   = parser->GetDeviceCecVersion((cec_logical_address)iPtr);
         cec_power_status power    = parser->GetDevicePowerStatus((cec_logical_address)iPtr);
-        cec_osd_name osdName      = parser->GetOSDName((cec_logical_address)iPtr);
+        cec_osd_name osdName      = parser->GetDeviceOSDName((cec_logical_address)iPtr);
         CStdString strAddr;
         strAddr.Format("%04x", iPhysicalAddress);
         cec_menu_language lang;
@@ -767,6 +783,7 @@ bool ProcessConsoleCommand(ICECAdapter *parser, string &input)
       ProcessCommandLA(parser, command, input) ||
       ProcessCommandP(parser, command, input) ||
       ProcessCommandPA(parser, command, input) ||
+      ProcessCommandAS(parser, command, input) ||
       ProcessCommandOSD(parser, command, input) ||
       ProcessCommandPING(parser, command, input) ||
       ProcessCommandVOLUP(parser, command, input) ||
@@ -795,7 +812,7 @@ bool ProcessCommandLineArguments(int argc, char *argv[])
 {
   bool bReturn(true);
   int iArgPtr = 1;
-  while (iArgPtr < argc)
+  while (iArgPtr < argc && bReturn)
   {
     if (argc >= iArgPtr + 1)
     {
@@ -885,6 +902,7 @@ bool ProcessCommandLineArguments(int argc, char *argv[])
         {
           ListDevices(parser);
           UnloadLibCec(parser);
+          parser = NULL;
         }
         bReturn = false;
       }
@@ -900,13 +918,24 @@ bool ProcessCommandLineArguments(int argc, char *argv[])
         ShowHelpCommandLine(argv[0]);
         return 0;
       }
+      else if (!strcmp(argv[iArgPtr], "-b") ||
+               !strcmp(argv[iArgPtr], "--base"))
+      {
+        if (argc >= iArgPtr + 2)
+        {
+          g_iBaseDevice = (cec_logical_address)atoi(argv[iArgPtr + 1]);
+          cout << "using base device '" << (int)g_iBaseDevice << "'" << endl;
+          ++iArgPtr;
+        }
+        ++iArgPtr;
+      }
       else if (!strcmp(argv[iArgPtr], "-p") ||
                !strcmp(argv[iArgPtr], "--port"))
       {
         if (argc >= iArgPtr + 2)
         {
           g_iHDMIPort = (int8_t)atoi(argv[iArgPtr + 1]);
-          cout << "using HDMI port '" << g_iHDMIPort << "'" << endl;
+          cout << "using HDMI port '" << (int)g_iHDMIPort << "'" << endl;
           ++iArgPtr;
         }
         ++iArgPtr;
@@ -985,13 +1014,8 @@ int main (int argc, char *argv[])
     }
   }
 
-  if (g_iHDMIPort > 0)
-  {
-    parser->SetHDMIPort((cec_logical_address)CEC_DEFAULT_BASE_DEVICE, (uint8_t)g_iHDMIPort);
-    FlushLog(parser);
-  }
-
-  cout << "scanning the CEC bus..." << endl;
+  parser->SetHDMIPort(g_iBaseDevice, g_iHDMIPort);
+  cout << "opening a connection to the CEC adapter..." << endl;
 
   if (!parser->Open(g_strPort.c_str()))
   {