- if (bPowerOn)
- {
- device->ActivateSource();
- }
- else
- {
- device->MarkAsInactiveSource();
- device->TransmitInactiveSource();
- device->SetMenuState(CEC_MENU_STATE_DEACTIVATED);
- }
+ if (command.parameters[0] == CEC_USER_CONTROL_CODE_POWER ||
+ command.parameters[0] == CEC_USER_CONTROL_CODE_POWER_ON_FUNCTION)
+ {
+ bool bPowerOn(true);
+
+ // CEC_USER_CONTROL_CODE_POWER operates as a toggle
+ // assume CEC_USER_CONTROL_CODE_POWER_ON_FUNCTION does not
+ if (command.parameters[0] == CEC_USER_CONTROL_CODE_POWER)
+ {
+ cec_power_status status = device->GetCurrentPowerStatus();
+ bPowerOn = !(status == CEC_POWER_STATUS_ON || status == CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON);