* http://www.pulse-eight.net/
*/
-#include "../../include/cec.h"
+#include "../env.h"
+#include "../include/cec.h"
#include <cstdio>
#include <fcntl.h>
#include <fstream>
#include <string>
#include <sstream>
+#include <signal.h>
#include "../lib/platform/threads/mutex.h"
#include "../lib/platform/util/timeutils.h"
#include "../lib/implementations/CECCommandHandler.h"
+#include "../lib/platform/util/StdString.h"
using namespace CEC;
using namespace std;
return true;
}
-int CecLogMessage(void *UNUSED(cbParam), const cec_log_message &message)
+int CecLogMessage(void *UNUSED(cbParam), const cec_log_message message)
{
switch (message.level)
{
return 0;
}
-int CecKeyPress(void *UNUSED(cbParam), const cec_keypress &key)
+int CecKeyPress(void *UNUSED(cbParam), const cec_keypress key)
{
g_lastKey = key.keycode;
g_keyEvent.Signal();
return 0;
}
-int CecCommand(void *UNUSED(cbParam), const cec_command &command)
+int CecCommand(void *UNUSED(cbParam), const cec_command command)
{
g_lastCommand = command.opcode;
g_responseEvent.Signal();
g_config.Clear();
snprintf(g_config.strDeviceName, 13, "CEC-config");
g_config.callbackParam = NULL;
- g_config.clientVersion = (uint32_t)CEC_CLIENT_VERSION_1_6_2;
+ g_config.clientVersion = (uint32_t)CEC_CLIENT_VERSION_2_0_2;
g_callbacks.CBCecLogMessage = &CecLogMessage;
g_callbacks.CBCecKeyPress = &CecKeyPress;
g_callbacks.CBCecCommand = &CecCommand;
g_config.callbacks = &g_callbacks;
- g_config.deviceTypes.add(type);
+ g_config.deviceTypes.Add(type);
g_parser = LibCecInitialise(&g_config);
if (!g_parser)
return false;
+ // init video on targets that need this
+ g_parser->InitVideoStandalone();
+
CStdString strPort;
cec_adapter devices[10];
uint8_t iDevicesFound = g_parser->FindAdapters(devices, 10, NULL);
uint64_t iNow = GetTimeMs();
uint64_t iTarget = iNow + iTimeout;
+ currentTvPower = g_parser->GetDevicePowerStatus(CECDEVICE_TV);
if (currentTvPower != CEC_POWER_STATUS_ON)
{
- currentTvPower = g_parser->GetDevicePowerStatus(CECDEVICE_TV);
- if (currentTvPower != CEC_POWER_STATUS_ON)
+ PrintToStdOut("Sending 'power on' command to the TV\n=== Please wait ===");
+ g_parser->PowerOnDevices(CECDEVICE_TV);
+ while (iTarget > iNow)
{
- PrintToStdOut("Sending 'power on' command to the TV\n=== Please wait ===");
- g_parser->PowerOnDevices(CECDEVICE_TV);
- while (iTarget > iNow)
- {
- g_responseEvent.Wait((uint32_t)(iTarget - iNow));
- if (g_lastCommand == CEC_OPCODE_REQUEST_ACTIVE_SOURCE)
- break;
- iNow = GetTimeMs();
- }
+ g_responseEvent.Wait((uint32_t)(iTarget - iNow));
+ if (g_lastCommand == CEC_OPCODE_REQUEST_ACTIVE_SOURCE)
+ break;
+ iNow = GetTimeMs();
}
}
return currentTvPower == CEC_POWER_STATUS_ON;
}
+void sighandler(int iSignal)
+{
+ PrintToStdOut("signal caught: %d - exiting", iSignal);
+
+ g_parser->Close();
+ UnloadLibCec(g_parser);
+
+ exit(1);
+}
+
int main (int UNUSED(argc), char *UNUSED(argv[]))
{
+ if (signal(SIGINT, sighandler) == SIG_ERR)
+ {
+ PrintToStdOut("can't register sighandler");
+ return -1;
+ }
+
g_callbacks.Clear();
g_config.Clear();
PrintToStdOut("=== USB-CEC Adapter Configuration ===\n");
CStdString strWakeDevices;
for (uint8_t iPtr = 0; iPtr < 16; iPtr++)
if (g_config.wakeDevices[iPtr])
- strWakeDevices.AppendFormat(" %d" + iPtr);
+ strWakeDevices.AppendFormat(" %d", iPtr);
CStdString strStandbyDevices;
for (uint8_t iPtr = 0; iPtr < 16; iPtr++)
if (g_config.powerOffDevices[iPtr])
- strStandbyDevices.AppendFormat(" %d" + iPtr);
+ strStandbyDevices.AppendFormat(" %d", iPtr);
configOutput <<
"<settings>\n" <<