Skip to content

Commit

Permalink
fix hdmi cec from deep standby and logical address is not ready yet
Browse files Browse the repository at this point in the history
  • Loading branch information
TangoCash committed Nov 25, 2022
1 parent b52b8e5 commit d2ea368
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
23 changes: 20 additions & 3 deletions src/driver/hdmi_cec.cpp
Expand Up @@ -104,7 +104,7 @@ bool hdmi_cec::SetCECMode(VIDEO_HDMI_CEC_MODE cecOnOff)
{
physicalAddress[0] = 0x10;
physicalAddress[1] = 0x00;
logicalAddress = 1;
logicalAddress = 0xFF;

if (cecOnOff == VIDEO_HDMI_CEC_MODE_OFF)
{
Expand Down Expand Up @@ -156,6 +156,8 @@ void hdmi_cec::GetCECAddressInfo()
memcpy(physicalAddress, addressinfo.physical, sizeof(physicalAddress));
ReportPhysicalAddress();
}
if (logicalAddress != 0xFF)
Ping();
}
}
}
Expand Down Expand Up @@ -184,7 +186,7 @@ void hdmi_cec::SendCECMessage(struct cec_message &txmessage, int sleeptime)
sprintf(str + (i * 6), "[0x%02X]", txmessage.data[i]);
}

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);
cecprintf(YELLOW, "queue message to %s (0x%02X) '%s' (%s)", txmessage.destination == 0xf ? "all" : ToString((cec_logical_address)txmessage.destination), txmessage.destination, ToString((cec_opcode)txmessage.data[0]), str);
struct cec_message_fb message;
message.address = txmessage.destination;
message.length = txmessage.length;
Expand All @@ -193,12 +195,15 @@ void hdmi_cec::SendCECMessage(struct cec_message &txmessage, int sleeptime)
msg_que.push_back(message);
mutex.unlock();

if (hdmiFd >= 0)
if (hdmiFd >= 0 && running && logicalAddress != 0xFF)
{
mutex.lock();

for (std::vector<cec_message_fb>::iterator it = msg_que.begin(); it != msg_que.end(); ++it)
{
cecprintf(YELLOW, "send message %s to %s (0x%02X>>0x%02X) '%s' (%s)", ToString((cec_logical_address)logicalAddress), (*it).address == 0xf ? "all" : ToString((cec_logical_address)(*it).address), logicalAddress, (*it).address, ToString((cec_opcode)(*it).data[0]), str);
::write(hdmiFd, &(*it), 2 + (*it).length);
}

msg_que.clear();
mutex.unlock();
Expand Down Expand Up @@ -305,6 +310,16 @@ void hdmi_cec::RequestTVPowerStatus()
SendCECMessage(message);
}

void hdmi_cec::Ping()
{
struct cec_message pingmessage;
pingmessage.initiator = logicalAddress;
pingmessage.destination = CECDEVICE_TV;
pingmessage.data[0] = CEC_OPCODE_NONE;
pingmessage.length = 1;
SendCECMessage(pingmessage);
}

long hdmi_cec::translateKey(unsigned char code)
{
long key = 0;
Expand Down Expand Up @@ -523,6 +538,8 @@ void hdmi_cec::run()
std::array<struct epoll_event, EPOLL_MAX_EVENTS> events;
cecprintf(GREEN, "thread started...");

Ping();

while (running)
{
n = epoll_wait(epollfd, events.data(), EPOLL_MAX_EVENTS, EPOLL_WAIT_TIMEOUT);
Expand Down
1 change: 1 addition & 0 deletions src/driver/hdmi_cec.h
Expand Up @@ -110,6 +110,7 @@ class hdmi_cec : public OpenThreads::Thread
void SendCECMessage(struct cec_message &message, int sleeptime = 250);
void SetCECState(bool state);
void ReportPhysicalAddress();
void Ping();
bool standby_cec_activ;
void vol_up();
void vol_down();
Expand Down

0 comments on commit d2ea368

Please sign in to comment.