From 81b18a627e74f6a6f9b781243c5d2dbde1928a7f Mon Sep 17 00:00:00 2001 From: Andrew Barbaccia Date: Sun, 8 Dec 2013 01:13:06 +0000 Subject: [PATCH 1/3] Fixed --donotactivate switch. Code pulled from phippodoplis patch in comments. --- src/libcec.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libcec.cpp b/src/libcec.cpp index 77b6fab..01d7bed 100644 --- a/src/libcec.cpp +++ b/src/libcec.cpp @@ -123,6 +123,7 @@ ICECAdapter * Cec::CecInit(const char * name, CecCallback * callback) { callbacks.CBCecConfigurationChanged = &::cecConfigurationChanged; config.callbackParam = callback; config.callbacks = &callbacks; + config.bActivateSource = false; // LibCecInitialise is noisy, so we redirect cout to nowhere RedirectStreamBuffer redirect(cout, 0); From 91bf2e6b33fbaff5393d9ff7628b1dc0795cdc7e Mon Sep 17 00:00:00 2001 From: Andrew Barbaccia Date: Thu, 12 Dec 2013 01:47:53 +0000 Subject: [PATCH 2/3] Initial code to create FIFO at /dev/cecfifo for CEC transmission --- src/libcec.cpp | 19 ++++++++++++++++++- src/libcec.h | 3 +++ src/main.cpp | 28 +++++++++++++++++++++++++--- 3 files changed, 46 insertions(+), 4 deletions(-) diff --git a/src/libcec.cpp b/src/libcec.cpp index 01d7bed..ecdd12b 100644 --- a/src/libcec.cpp +++ b/src/libcec.cpp @@ -33,6 +33,7 @@ using std::endl; using std::hex; using std::map; using std::ostream; +using std::string; // cecloader has to be after some #includes and using namespaces :( using std::cout; @@ -162,7 +163,7 @@ void Cec::open() { if (!cec->Open(devices[0].comm)) { throw std::runtime_error("Failed to open adapter"); } - + LOG4CPLUS_INFO(logger, "Opened " << devices[0].path); } @@ -179,6 +180,10 @@ void Cec::makeActive() { } +bool Cec::transmit(const CEC::cec_command &cmd) { + return cec->Transmit(cmd); +} + /** * Prints the name of all found adapters @@ -312,6 +317,18 @@ map & Cec::setupUserControlCodeName() { return cecUserControlCodeName; } +CEC::cec_command * StrToCecCommand(const char * strCmd) { + //take string input xx:xx:xx or yy yy yy and convert to type cec_command + CEC::cec_command * cmd = new CEC::cec_command; + char * buffer = new char[100]; + buffer = strdup(strCmd); + + for(char * c = strtok (buffer, ": ");c;c=strtok(NULL,": ")) { + cmd->PushBack(strtol(c, NULL, 16)); + } + return cmd; +} + std::ostream& operator<<(std::ostream &out, const cec_user_control_code code) { map::const_iterator it; diff --git a/src/libcec.h b/src/libcec.h index 8133ebc..e13eb1e 100644 --- a/src/libcec.h +++ b/src/libcec.h @@ -57,6 +57,8 @@ class Cec { void makeActive(); + bool transmit(const CEC::cec_command &cmd); + // These are just wrapper functions, to map C callbacks to C++ friend int cecLogMessage (void *cbParam, const CEC::cec_log_message &message); friend int cecKeyPress (void *cbParam, const CEC::cec_keypress &key); @@ -64,6 +66,7 @@ class Cec { friend int cecConfigurationChanged (void *cbParam, const CEC::libcec_configuration & configuration); }; +CEC::cec_command * StrToCecCommand(const char *); // Some helper << methods std::ostream& operator<<(std::ostream &out, const CEC::cec_log_message & message); diff --git a/src/main.cpp b/src/main.cpp index 9053853..0c8ec4f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -9,6 +9,7 @@ #include "main.h" #define VERSION "libcec-daemon v0.9" +#define FIFO_FILE "/dev/cecfifo" #define CEC_NAME "linux PC" #define UINPUT_NAME "libcec-daemon" @@ -16,11 +17,15 @@ #include #include #include +#include #include #include #include #include #include +#include +#include +#include #include #include "accumulator.hpp" @@ -38,6 +43,7 @@ using std::endl; using std::min; using std::string; using std::vector; +using std::ios_base; static Logger logger = Logger::getInstance("main"); @@ -70,10 +76,26 @@ void Main::loop() { cec.makeActive(); } + // Notes + // + // Transmit + // Error catching + + mkfifo(FIFO_FILE, 0666); + chmod(FIFO_FILE, 0666); + + char * strCommand = new char[100]; + + int fdfifo = open(FIFO_FILE, O_RDONLY | O_NONBLOCK); + FILE *fpfifo = fdopen(fdfifo,"r"); + while (running) { - LOG4CPLUS_TRACE_STR(logger, "Loop"); - sleep(1); - } + while (fgets(strCommand,100,fpfifo) != NULL) { + cec.transmit( *(StrToCecCommand(strCommand)) ); + cout << strCommand << endl; + } + } + cec.close(); } From 048e59f88775bccc9eb574eaec26c6704d0535e6 Mon Sep 17 00:00:00 2001 From: Andrew Barbaccia Date: Thu, 12 Dec 2013 01:52:09 +0000 Subject: [PATCH 3/3] Revert "Initial code to create FIFO at /dev/cecfifo for CEC transmission" This reverts commit 91bf2e6b33fbaff5393d9ff7628b1dc0795cdc7e. --- src/libcec.cpp | 19 +------------------ src/libcec.h | 3 --- src/main.cpp | 28 +++------------------------- 3 files changed, 4 insertions(+), 46 deletions(-) diff --git a/src/libcec.cpp b/src/libcec.cpp index ecdd12b..01d7bed 100644 --- a/src/libcec.cpp +++ b/src/libcec.cpp @@ -33,7 +33,6 @@ using std::endl; using std::hex; using std::map; using std::ostream; -using std::string; // cecloader has to be after some #includes and using namespaces :( using std::cout; @@ -163,7 +162,7 @@ void Cec::open() { if (!cec->Open(devices[0].comm)) { throw std::runtime_error("Failed to open adapter"); } - + LOG4CPLUS_INFO(logger, "Opened " << devices[0].path); } @@ -180,10 +179,6 @@ void Cec::makeActive() { } -bool Cec::transmit(const CEC::cec_command &cmd) { - return cec->Transmit(cmd); -} - /** * Prints the name of all found adapters @@ -317,18 +312,6 @@ map & Cec::setupUserControlCodeName() { return cecUserControlCodeName; } -CEC::cec_command * StrToCecCommand(const char * strCmd) { - //take string input xx:xx:xx or yy yy yy and convert to type cec_command - CEC::cec_command * cmd = new CEC::cec_command; - char * buffer = new char[100]; - buffer = strdup(strCmd); - - for(char * c = strtok (buffer, ": ");c;c=strtok(NULL,": ")) { - cmd->PushBack(strtol(c, NULL, 16)); - } - return cmd; -} - std::ostream& operator<<(std::ostream &out, const cec_user_control_code code) { map::const_iterator it; diff --git a/src/libcec.h b/src/libcec.h index e13eb1e..8133ebc 100644 --- a/src/libcec.h +++ b/src/libcec.h @@ -57,8 +57,6 @@ class Cec { void makeActive(); - bool transmit(const CEC::cec_command &cmd); - // These are just wrapper functions, to map C callbacks to C++ friend int cecLogMessage (void *cbParam, const CEC::cec_log_message &message); friend int cecKeyPress (void *cbParam, const CEC::cec_keypress &key); @@ -66,7 +64,6 @@ class Cec { friend int cecConfigurationChanged (void *cbParam, const CEC::libcec_configuration & configuration); }; -CEC::cec_command * StrToCecCommand(const char *); // Some helper << methods std::ostream& operator<<(std::ostream &out, const CEC::cec_log_message & message); diff --git a/src/main.cpp b/src/main.cpp index 0c8ec4f..9053853 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -9,7 +9,6 @@ #include "main.h" #define VERSION "libcec-daemon v0.9" -#define FIFO_FILE "/dev/cecfifo" #define CEC_NAME "linux PC" #define UINPUT_NAME "libcec-daemon" @@ -17,15 +16,11 @@ #include #include #include -#include #include #include #include #include #include -#include -#include -#include #include #include "accumulator.hpp" @@ -43,7 +38,6 @@ using std::endl; using std::min; using std::string; using std::vector; -using std::ios_base; static Logger logger = Logger::getInstance("main"); @@ -76,26 +70,10 @@ void Main::loop() { cec.makeActive(); } - // Notes - // - // Transmit - // Error catching - - mkfifo(FIFO_FILE, 0666); - chmod(FIFO_FILE, 0666); - - char * strCommand = new char[100]; - - int fdfifo = open(FIFO_FILE, O_RDONLY | O_NONBLOCK); - FILE *fpfifo = fdopen(fdfifo,"r"); - while (running) { - while (fgets(strCommand,100,fpfifo) != NULL) { - cec.transmit( *(StrToCecCommand(strCommand)) ); - cout << strCommand << endl; - } - } - + LOG4CPLUS_TRACE_STR(logger, "Loop"); + sleep(1); + } cec.close(); }