diff --git a/src/driver/hdmi_cec.cpp b/src/driver/hdmi_cec.cpp index d0d13cd34..0b8d12041 100644 --- a/src/driver/hdmi_cec.cpp +++ b/src/driver/hdmi_cec.cpp @@ -39,7 +39,6 @@ #include "hdmi_cec_types.h" #include -#include #include #define RED "\x1B[31m" @@ -63,6 +62,17 @@ #define RC_DEVICE "/dev/input/event1" #endif +#define cecprintf(color, fmt, args...) \ + do { \ + if (access("/tmp/hdmicec.txt", 0 ) == 0) {\ + time_t t; time(&t); char *ctime_no_newline;ctime_no_newline = strtok(ctime(&t), "\n");\ + FILE *logfile = fopen ("/tmp/hdmicec.txt","a"); \ + fprintf(logfile, "%s - [hdmi-cec] " fmt "\n", ctime_no_newline, ## args); \ + fclose (logfile); \ + }\ + printf( "%s[hdmi-cec] " fmt "\n" NORMAL, color, ## args); \ + } while(0) + hdmi_cec::hdmi_cec() { standby_cec_activ = autoview_cec_activ = muted = false; @@ -99,11 +109,11 @@ bool hdmi_cec::SetCECMode(VIDEO_HDMI_CEC_MODE cecOnOff) if (cecOnOff == VIDEO_HDMI_CEC_MODE_OFF) { Stop(); - dprintf(DEBUG_NORMAL, GREEN" [CEC] switch off %s\n" NORMAL, __func__); + cecprintf(GREEN, " switch off %s", __func__); return false; } - dprintf(DEBUG_NORMAL, GREEN" [CEC] switch on %s\n" NORMAL, __func__); + cecprintf(GREEN, " switch on %s", __func__); if (hdmiFd == -1) { @@ -138,11 +148,11 @@ void hdmi_cec::GetCECAddressInfo() { deviceType = addressinfo.type; logicalAddress = addressinfo.logical; - dprintf(DEBUG_NORMAL, GREEN" [CEC] %s: detected physical address: 0x%02X:0x%02X (Type: 0x%02X/Logical: 0x%02X)\n" NORMAL, __func__, physicalAddress[0], physicalAddress[1], deviceType, logicalAddress); + cecprintf(GREEN, "%s: detected physical address: 0x%02X:0x%02X (Type: 0x%02X/Logical: 0x%02X)", __func__, physicalAddress[0], physicalAddress[1], deviceType, logicalAddress); if (memcmp(physicalAddress, addressinfo.physical, sizeof(physicalAddress))) { - dprintf(DEBUG_NORMAL, YELLOW" [CEC] %s: detected physical address change: 0x%02X:0x%02X --> 0x%02X:0x%02X\n" NORMAL, __func__, physicalAddress[0], physicalAddress[1], addressinfo.physical[0], addressinfo.physical[1]); + cecprintf(YELLOW, "%s: detected physical address change: 0x%02X:0x%02X --> 0x%02X:0x%02X", __func__, physicalAddress[0], physicalAddress[1], addressinfo.physical[0], addressinfo.physical[1]); memcpy(physicalAddress, addressinfo.physical, sizeof(physicalAddress)); ReportPhysicalAddress(); } @@ -174,7 +184,7 @@ void hdmi_cec::SendCECMessage(struct cec_message &txmessage, int sleeptime) sprintf(str + (i * 6), "[0x%02X]", txmessage.data[i]); } - dprintf(DEBUG_NORMAL, YELLOW" [CEC] send message %s to %s (0x%02X>>0x%02X) '%s' (%s)\n" NORMAL, ToString((cec_logical_address)txmessage.initiator), txmessage.destination == 0xf ? "all" : ToString((cec_logical_address)txmessage.destination), txmessage.initiator, txmessage.destination, ToString((cec_opcode)txmessage.data[0]), str); + cecprintf(YELLOW, "send message %s to %s (0x%02X>>0x%02X) '%s' (%s)", ToString((cec_logical_address)txmessage.initiator), txmessage.destination == 0xf ? "all" : ToString((cec_logical_address)txmessage.destination), txmessage.initiator, txmessage.destination, ToString((cec_opcode)txmessage.data[0]), str); struct cec_message_fb message; message.address = txmessage.destination; message.length = txmessage.length; @@ -478,7 +488,7 @@ bool hdmi_cec::Start() if (hdmiFd == -1) return false; - dprintf(DEBUG_NORMAL, GREEN" [CEC] thread starting...\n" NORMAL); + cecprintf(GREEN, "thread starting..."); running = true; OpenThreads::Thread::setSchedulePriority(THREAD_PRIORITY_MIN); return (OpenThreads::Thread::start() == 0); @@ -511,7 +521,7 @@ void hdmi_cec::run() event.events = EPOLLPRI | EPOLLIN; epoll_ctl(epollfd, EPOLL_CTL_ADD, hdmiFd, &event); std::array events; - dprintf(DEBUG_NORMAL, GREEN" [CEC] thread started...\n" NORMAL); + cecprintf(GREEN, "thread started..."); while (running) { @@ -555,7 +565,7 @@ void hdmi_cec::run() sprintf(str + (j * 6), "[0x%02X]", rxmessage.data[j]); } - dprintf(DEBUG_NORMAL, GREEN" [CEC] received message %s to %s (0x%02X>>0x%02X) '%s' (%s)\n" NORMAL, ToString((cec_logical_address)rxmessage.initiator), rxmessage.destination == 0xf ? "all" : ToString((cec_logical_address)rxmessage.destination), rxmessage.initiator, rxmessage.destination, ToString((cec_opcode)rxmessage.opcode), str); + cecprintf(GREEN, "received message %s to %s (0x%02X>>0x%02X) '%s' (%s)", ToString((cec_logical_address)rxmessage.initiator), rxmessage.destination == 0xf ? "all" : ToString((cec_logical_address)rxmessage.destination), rxmessage.initiator, rxmessage.destination, ToString((cec_opcode)rxmessage.opcode), str); switch (rxmessage.opcode) { @@ -602,19 +612,19 @@ void hdmi_cec::run() case CEC_OPCODE_FEATURE_ABORT: { - dprintf(DEBUG_NORMAL, GREEN" [CEC] decoded message feature '%s' not supported (%s)\n" NORMAL, ToString((cec_opcode)rxmessage.data[1]), ToString((cec_error_id)rxmessage.data[2])); + cecprintf(GREEN, "decoded message feature '%s' not supported (%s)", ToString((cec_opcode)rxmessage.data[1]), ToString((cec_error_id)rxmessage.data[2])); break; } case CEC_OPCODE_SET_OSD_NAME: { - dprintf(DEBUG_NORMAL, GREEN" [CEC] decoded message '%s' \n" NORMAL, (char *)rxmessage.data + 1); + cecprintf(GREEN, "decoded message '%s'", (char *)rxmessage.data + 1); break; } case CEC_OPCODE_REQUEST_ACTIVE_SOURCE: { - dprintf(DEBUG_NORMAL, CYAN" [CEC] active_source=%s neutrino standby=%s\n" NORMAL, active_source ? "yes" : "no", CNeutrinoApp::getInstance()->getMode() == NeutrinoModes::mode_standby ? "yes" : "no"); + cecprintf(CYAN, "active_source=%s neutrino standby=%s", active_source ? "yes" : "no", CNeutrinoApp::getInstance()->getMode() == NeutrinoModes::mode_standby ? "yes" : "no"); if (CNeutrinoApp::getInstance()->getMode() == NeutrinoModes::mode_standby && active_source) g_RCInput->postMsg(NeutrinoMessages::STANDBY_OFF, (neutrino_msg_data_t)"cec"); SendActiveSource(); @@ -627,9 +637,9 @@ void hdmi_cec::run() volume = ((rxmessage.data[1] & 0x7F) / 127.0) * 100.0; if (muted) - dprintf(DEBUG_NORMAL, GREEN" [CEC] %s volume muted\n" NORMAL, ToString((cec_logical_address)rxmessage.initiator)); + cecprintf(GREEN, "%s volume muted", ToString((cec_logical_address)rxmessage.initiator)); else - dprintf(DEBUG_NORMAL, GREEN" [CEC] %s volume %d \n" NORMAL, ToString((cec_logical_address)rxmessage.initiator), volume); + cecprintf(GREEN, "%s volume %d", ToString((cec_logical_address)rxmessage.initiator), volume); break; } @@ -640,7 +650,7 @@ void hdmi_cec::run() uint64_t iVendorId = ((uint64_t)rxmessage.data[1] << 16) + ((uint64_t)rxmessage.data[2] << 8) + (uint64_t)rxmessage.data[3]; - dprintf(DEBUG_NORMAL, GREEN" [CEC] decoded message '%s' (%s)\n" NORMAL, ToString((cec_opcode)rxmessage.opcode), ToString((cec_vendor_id)iVendorId)); + cecprintf(GREEN, "decoded message '%s' (%s)", ToString((cec_opcode)rxmessage.opcode), ToString((cec_vendor_id)iVendorId)); break; } @@ -659,14 +669,14 @@ void hdmi_cec::run() { if ((rxmessage.data[1] == CEC_POWER_STATUS_ON) || (rxmessage.data[1] == CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON)) { - dprintf(DEBUG_NORMAL, GREEN" [CEC] %s reporting state on (%d)\n" NORMAL, ToString((cec_logical_address)rxmessage.initiator), rxmessage.data[1]); + cecprintf(GREEN, "%s reporting state on (%d)", ToString((cec_logical_address)rxmessage.initiator), rxmessage.data[1]); if (rxmessage.initiator == CECDEVICE_TV) tv_off = false; } else { - dprintf(DEBUG_NORMAL, GREEN" [CEC] %s reporting state off (%d)\n" NORMAL, ToString((cec_logical_address)rxmessage.initiator), rxmessage.data[1]); + cecprintf(GREEN, "%s reporting state off (%d)", ToString((cec_logical_address)rxmessage.initiator), rxmessage.data[1]); if (rxmessage.initiator == CECDEVICE_TV) tv_off = true; @@ -697,7 +707,7 @@ void hdmi_cec::run() if (strcmp(msgpath, phypath) == 0) { - dprintf(DEBUG_NORMAL, CYAN" [CEC] received streampath (%s) change to me (%s) -> wake up \n" NORMAL, msgpath, phypath); + cecprintf(CYAN, "received streampath (%s) change to me (%s) -> wake up", msgpath, phypath); if (CNeutrinoApp::getInstance()->getMode() == NeutrinoModes::mode_standby && g_settings.hdmi_cec_wakeup) g_RCInput->postMsg(NeutrinoMessages::STANDBY_OFF, (neutrino_msg_data_t)"cec"); @@ -707,7 +717,7 @@ void hdmi_cec::run() } else { - dprintf(DEBUG_NORMAL, CYAN" [CEC] received streampath (%s) change away from me (%s) -> go to sleep\n" NORMAL, msgpath, phypath); + cecprintf(CYAN, "received streampath (%s) change away from me (%s) -> go to sleep", msgpath, phypath); if (CNeutrinoApp::getInstance()->getMode() != NeutrinoModes::mode_standby && g_settings.hdmi_cec_sleep) g_RCInput->postMsg(NeutrinoMessages::STANDBY_ON, (neutrino_msg_data_t)"cec"); @@ -727,7 +737,7 @@ void hdmi_cec::run() case CEC_OPCODE_USER_CONTROL_RELEASE: /* key released */ { long code = translateKey(pressedkey); - dprintf(DEBUG_NORMAL, GREEN" [CEC] decoded key %s (%ld)\n" NORMAL, ToString((cec_user_control_code)pressedkey), code); + cecprintf(GREEN, "decoded key %s (%ld)", ToString((cec_user_control_code)pressedkey), code); if (code == KEY_POWER || code == KEY_POWERON) { @@ -752,7 +762,7 @@ void hdmi_cec::handleCode(long code, bool keypressed) if (evd < 0) { - dprintf(DEBUG_NORMAL, RED" [CEC] opening " RC_DEVICE " failed" NORMAL); + cecprintf(RED, "opening " RC_DEVICE " failed"); return; } @@ -760,7 +770,7 @@ void hdmi_cec::handleCode(long code, bool keypressed) { if (rc_send(evd, code, CEC_KEY_PRESSED) < 0) { - dprintf(DEBUG_NORMAL, RED" [CEC] writing 'KEY_PRESSED' event failed" NORMAL); + cecprintf(RED, "writing 'KEY_PRESSED' event failed"); close(evd); return; } @@ -771,7 +781,7 @@ void hdmi_cec::handleCode(long code, bool keypressed) { if (rc_send(evd, code, CEC_KEY_RELEASED) < 0) { - dprintf(DEBUG_NORMAL, RED" [CEC] writing 'KEY_RELEASED' event failed" NORMAL); + cecprintf(RED, "writing 'KEY_RELEASED' event failed"); close(evd); return; }