2 * This file is part of the libCEC(R) library.
4 * libCEC(R) is Copyright (C) 2011-2012 Pulse-Eight Limited. All rights reserved.
5 * libCEC(R) is an original work, containing original code.
7 * libCEC(R) is a trademark of Pulse-Eight Limited.
9 * This program is dual-licensed; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 * Alternatively, you can license this library under a commercial license,
25 * please contact Pulse-Eight Licensing for more information.
27 * For more information contact:
28 * Pulse-Eight Licensing <license@pulse-eight.com>
29 * http://www.pulse-eight.com/
30 * http://www.pulse-eight.net/
33 #include "VLCommandHandler.h"
34 #include "../devices/CECBusDevice.h"
35 #include "../CECProcessor.h"
36 #include "../LibCEC.h"
38 #define VL_POWER_CHANGE 0x20
39 #define VL_POWERED_UP 0x00
40 #define VL_POWERED_DOWN 0x01
43 using namespace PLATFORM
;
45 CVLCommandHandler::CVLCommandHandler(CCECBusDevice
*busDevice
) :
46 CCECCommandHandler(busDevice
),
47 m_bActiveSourcePending(false),
48 m_bPowerUpEventReceived(false)
50 m_vendorId
= CEC_VENDOR_PANASONIC
;
52 /* use the VL commandhandler for the primary device that is handled by libCEC */
53 if (busDevice
->GetLogicalAddress() == CECDEVICE_TV
)
55 CCECBusDevice
*primary
= m_processor
->GetPrimaryDevice();
56 if (primary
&& m_busDevice
->GetLogicalAddress() != primary
->GetLogicalAddress())
58 primary
->SetVendorId(CEC_VENDOR_PANASONIC
);
59 primary
->ReplaceHandler(false);
64 bool CVLCommandHandler::InitHandler(void)
66 CCECBusDevice
*primary
= m_processor
->GetPrimaryDevice();
67 if (primary
->GetType() == CEC_DEVICE_TYPE_RECORDING_DEVICE
)
68 return m_processor
->ChangeDeviceType(CEC_DEVICE_TYPE_RECORDING_DEVICE
, CEC_DEVICE_TYPE_PLAYBACK_DEVICE
);
70 return CCECCommandHandler::InitHandler();
73 bool CVLCommandHandler::HandleDeviceVendorCommandWithId(const cec_command
&command
)
75 if (command
.initiator
== CECDEVICE_TV
&&
76 command
.destination
== CECDEVICE_BROADCAST
&&
77 command
.parameters
.At(3) == VL_POWER_CHANGE
)
79 if (command
.parameters
.At(4) == VL_POWERED_UP
)
81 CLibCEC::AddLog(CEC_LOG_DEBUG
, "TV powered up");
83 CLockObject
lock(m_mutex
);
84 m_bPowerUpEventReceived
= true;
86 m_processor
->TransmitPendingActiveSourceCommands();
88 else if (command
.parameters
.At(4) == VL_POWERED_DOWN
)
89 CLibCEC::AddLog(CEC_LOG_DEBUG
, "TV powered down");
90 else if (command
.parameters
.At(4) == VL_POWERED_DOWN
)
91 CLibCEC::AddLog(CEC_LOG_DEBUG
, "unknown vendor command");
96 return CCECCommandHandler::HandleDeviceVendorCommandWithId(command
);
99 bool CVLCommandHandler::TransmitActiveSource(const cec_logical_address iInitiator
, uint16_t iPhysicalAddress
)
101 bool bPowerUpEventReceived(false);
103 CCECBusDevice
*tv
= m_processor
->m_busDevices
[CECDEVICE_TV
];
104 if (tv
&& tv
->GetVendorId(false) == CEC_VENDOR_PANASONIC
)
106 CVLCommandHandler
*handler
= static_cast<CVLCommandHandler
*>(tv
->GetHandler());
107 bPowerUpEventReceived
= handler
? handler
->PowerUpEventReceived() : false;
110 if (!bPowerUpEventReceived
)
112 CLockObject
lock(m_mutex
);
113 // wait until we received the event
114 m_bActiveSourcePending
= true;
119 // transmit standard active source message
120 return CCECCommandHandler::TransmitActiveSource(iInitiator
, iPhysicalAddress
);
124 bool CVLCommandHandler::TransmitPendingActiveSourceCommands(void)
126 bool bTransmitCommand(false);
128 CLockObject
lock(m_mutex
);
129 bTransmitCommand
= m_bActiveSourcePending
;
130 m_bActiveSourcePending
= false;
133 if (bTransmitCommand
)
135 CLibCEC::AddLog(CEC_LOG_DEBUG
, "transmitting delayed activate source command");
136 return CCECCommandHandler::TransmitActiveSource(m_busDevice
->GetLogicalAddress(), m_busDevice
->GetPhysicalAddress());
141 bool CVLCommandHandler::PowerUpEventReceived(void)
144 CLockObject
lock(m_mutex
);
145 if (m_bPowerUpEventReceived
)
149 cec_power_status powerStatus
= m_busDevice
->GetPowerStatus();
151 CLockObject
lock(m_mutex
);
152 m_bPowerUpEventReceived
= (powerStatus
== CEC_POWER_STATUS_ON
);
153 return m_bPowerUpEventReceived
;