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"
37 #include "../CECClient.h"
39 #define VL_POWER_CHANGE 0x20
40 #define VL_POWERED_UP 0x00
41 #define VL_POWERED_DOWN 0x01
44 using namespace PLATFORM
;
46 #define LIB_CEC m_busDevice->GetProcessor()->GetLib()
47 #define ToString(p) LIB_CEC->ToString(p)
49 CVLCommandHandler::CVLCommandHandler(CCECBusDevice
*busDevice
) :
50 CCECCommandHandler(busDevice
),
51 m_bActiveSourcePending(false),
52 m_bPowerUpEventReceived(false)
54 m_vendorId
= CEC_VENDOR_PANASONIC
;
57 bool CVLCommandHandler::InitHandler(void)
59 CCECBusDevice
*primary
= m_processor
->GetPrimaryDevice();
60 if (primary
&& primary
->GetLogicalAddress() != CECDEVICE_UNREGISTERED
)
62 /* use the VL commandhandler for the primary device that is handled by libCEC */
63 if (m_busDevice
->GetLogicalAddress() == CECDEVICE_TV
)
65 if (primary
&& m_busDevice
->GetLogicalAddress() != primary
->GetLogicalAddress())
67 primary
->SetVendorId(CEC_VENDOR_PANASONIC
);
68 primary
->ReplaceHandler(false);
72 if (primary
->GetType() == CEC_DEVICE_TYPE_RECORDING_DEVICE
)
73 return m_processor
->GetPrimaryClient()->ChangeDeviceType(CEC_DEVICE_TYPE_RECORDING_DEVICE
, CEC_DEVICE_TYPE_PLAYBACK_DEVICE
);
76 return CCECCommandHandler::InitHandler();
79 bool CVLCommandHandler::HandleDeviceVendorCommandWithId(const cec_command
&command
)
81 if (command
.initiator
== CECDEVICE_TV
&&
82 command
.destination
== CECDEVICE_BROADCAST
&&
83 command
.parameters
.At(3) == VL_POWER_CHANGE
)
85 if (command
.parameters
.At(4) == VL_POWERED_UP
)
87 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "TV powered up");
89 CLockObject
lock(m_mutex
);
90 m_bPowerUpEventReceived
= true;
92 m_processor
->TransmitPendingActiveSourceCommands();
94 else if (command
.parameters
.At(4) == VL_POWERED_DOWN
)
95 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "TV powered down");
96 else if (command
.parameters
.At(4) == VL_POWERED_DOWN
)
97 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "unknown vendor command");
102 return CCECCommandHandler::HandleDeviceVendorCommandWithId(command
);
105 bool CVLCommandHandler::TransmitActiveSource(const cec_logical_address iInitiator
, uint16_t iPhysicalAddress
)
107 bool bPowerUpEventReceived(false);
109 CCECBusDevice
*tv
= m_processor
->GetDevice(CECDEVICE_TV
);
110 if (tv
&& tv
->GetCurrentVendorId() == CEC_VENDOR_PANASONIC
)
112 CVLCommandHandler
*handler
= static_cast<CVLCommandHandler
*>(tv
->GetHandler());
113 bPowerUpEventReceived
= handler
? handler
->PowerUpEventReceived() : false;
116 if (!bPowerUpEventReceived
)
118 CLockObject
lock(m_mutex
);
119 // wait until we received the event
120 m_bActiveSourcePending
= true;
125 // transmit standard active source message
126 return CCECCommandHandler::TransmitActiveSource(iInitiator
, iPhysicalAddress
) &&
127 TransmitMenuState(iInitiator
, CECDEVICE_TV
, CEC_MENU_STATE_ACTIVATED
);
131 bool CVLCommandHandler::TransmitPendingActiveSourceCommands(void)
133 bool bTransmitCommand(false);
135 CLockObject
lock(m_mutex
);
136 bTransmitCommand
= m_bActiveSourcePending
;
137 m_bActiveSourcePending
= false;
140 if (bTransmitCommand
)
142 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "transmitting delayed activate source command");
143 return CCECCommandHandler::TransmitActiveSource(m_busDevice
->GetLogicalAddress(), m_busDevice
->GetCurrentPhysicalAddress()) &&
144 TransmitMenuState(m_busDevice
->GetLogicalAddress(), CECDEVICE_TV
, CEC_MENU_STATE_ACTIVATED
);
149 bool CVLCommandHandler::PowerUpEventReceived(void)
152 CLockObject
lock(m_mutex
);
153 if (m_bPowerUpEventReceived
)
157 cec_power_status powerStatus
= m_busDevice
->GetCurrentPowerStatus();
159 CLockObject
lock(m_mutex
);
160 m_bPowerUpEventReceived
= (powerStatus
== CEC_POWER_STATUS_ON
);
161 return m_bPowerUpEventReceived
;