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
;
53 bool CVLCommandHandler::InitHandler(void)
55 CCECBusDevice
*primary
= m_processor
->GetPrimaryDevice();
56 if (primary
->GetType() == CEC_DEVICE_TYPE_RECORDING_DEVICE
)
57 return m_processor
->ChangeDeviceType(CEC_DEVICE_TYPE_RECORDING_DEVICE
, CEC_DEVICE_TYPE_PLAYBACK_DEVICE
);
59 return CCECCommandHandler::InitHandler();
62 bool CVLCommandHandler::HandleDeviceVendorCommandWithId(const cec_command
&command
)
64 if (command
.initiator
== CECDEVICE_TV
&&
65 command
.destination
== CECDEVICE_BROADCAST
&&
66 command
.parameters
.At(3) == VL_POWER_CHANGE
)
68 if (command
.parameters
.At(4) == VL_POWERED_UP
)
70 CLibCEC::AddLog(CEC_LOG_DEBUG
, "TV powered up");
72 CLockObject
lock(m_mutex
);
73 m_bPowerUpEventReceived
= true;
75 m_processor
->TransmitPendingActiveSourceCommands();
77 else if (command
.parameters
.At(4) == VL_POWERED_DOWN
)
78 CLibCEC::AddLog(CEC_LOG_DEBUG
, "TV powered down");
79 else if (command
.parameters
.At(4) == VL_POWERED_DOWN
)
80 CLibCEC::AddLog(CEC_LOG_DEBUG
, "unknown vendor command");
85 return CCECCommandHandler::HandleDeviceVendorCommandWithId(command
);
88 bool CVLCommandHandler::TransmitActiveSource(const cec_logical_address iInitiator
, uint16_t iPhysicalAddress
)
90 bool bPowerUpEventReceived(false);
93 CLockObject
lock(m_mutex
);
94 if (!m_bPowerUpEventReceived
)
96 // just assume it's been sent when the tv is powered on
97 cec_power_status powerStatus
= m_processor
->m_busDevices
[CECDEVICE_TV
]->GetPowerStatus();
98 m_bPowerUpEventReceived
= (powerStatus
== CEC_POWER_STATUS_ON
);
100 bPowerUpEventReceived
= m_bPowerUpEventReceived
;
103 if (!bPowerUpEventReceived
)
105 CLockObject
lock(m_mutex
);
106 // wait until we received the event
107 m_bActiveSourcePending
= true;
112 // transmit standard active source message
113 return CCECCommandHandler::TransmitActiveSource(iInitiator
, iPhysicalAddress
);
117 bool CVLCommandHandler::TransmitPendingActiveSourceCommands(void)
119 bool bTransmitCommand(false);
121 CLockObject
lock(m_mutex
);
122 bTransmitCommand
= m_bActiveSourcePending
;
123 m_bActiveSourcePending
= false;
126 if (bTransmitCommand
)
128 CLibCEC::AddLog(CEC_LOG_DEBUG
, "transmitting delayed activate source command");
129 return CCECCommandHandler::TransmitActiveSource(m_busDevice
->GetLogicalAddress(), m_busDevice
->GetPhysicalAddress(false, true));