Removing the else does make CECToggleState work more as expected. It can now wake the TV/AVR from standby. There are a couple of catches though.
As expected if the TV is shut off by some means other than a kodi CEC command kodi is still in the active source state. The CECToggleState must be sent twice to turn on the TV/AVR. Better than not being able to turn it on.
The part I don’t get is that when I trigger it via a remote button when toggling from off to on the key gets processed twice.
Here’s the log from turning things off (active → standby)
2024-04-04 23:30:04.047 T:4418 debug <general>: CLibInputKeyboard::ProcessKey - using delay: 500ms repeat: 33ms
2024-04-04 23:30:04.047 T:5991 debug <general>: Thread Timer start, auto delete: false
2024-04-04 23:30:04.068 T:4413 debug <general>: Keyboard: scancode: 0x3, sym: 0x32, unicode: 0x32, modifier: 0x0
2024-04-04 23:30:04.068 T:4413 debug <general>: HandleKey: action CECToggleState [122], toggling state of playing device
2024-04-04 23:30:04.068 T:4413 debug <general>: ToggleDeviceState - putting CEC device on standby...
2024-04-04 23:30:04.070 T:4477 debug <general>: ProcessStandbyDevices - sending inactive source commands
2024-04-04 23:30:04.070 T:4476 debug <general>: CecLogMessage - marking Playback 2 (8) as inactive source
2024-04-04 23:30:04.070 T:4476 debug <general>: CecLogMessage - >> source deactivated: Playback 2 (8)
2024-04-04 23:30:04.110 T:4476 debug <general>: CecLogMessage - << Playback 2 (8) -> broadcast (F): inactive source
2024-04-04 23:30:04.110 T:4476 debug <general>: CecLogMessage - << 80:9d:34:00
2024-04-04 23:30:04.197 T:5991 debug <general>: Thread Timer 3535782400 terminating
2024-04-04 23:30:04.250 T:4413 debug <general>: Keyboard: scancode: 0x3, sym: 0x32, unicode: 0x32, modifier: 0x0
Here’s from turning things on (standby->active)
2024-04-04 23:31:42.666 T:4418 debug <general>: CLibInputKeyboard::ProcessKey - using delay: 500ms repeat: 33ms
2024-04-04 23:31:42.666 T:6022 debug <general>: Thread Timer start, auto delete: false
2024-04-04 23:31:42.671 T:4413 debug <general>: Keyboard: scancode: 0x3, sym: 0x32, unicode: 0x32, modifier: 0x0
2024-04-04 23:31:42.671 T:4413 debug <general>: HandleKey: action CECToggleState [122], toggling state of playing device
2024-04-04 23:31:42.672 T:4413 debug <general>: ToggleDeviceState - waking up CEC device...
2024-04-04 23:31:42.672 T:4413 debug <general>: HandleKey: two (0xf032) pressed, window 10004, action is CECToggleState
2024-04-04 23:31:42.672 T:4413 debug <general>: ToggleDeviceState - waking up CEC device...
2024-04-04 23:31:42.675 T:4476 debug <general>: CecLogMessage - making Playback 2 (8) the active source
2024-04-04 23:31:42.675 T:4476 debug <general>: CecLogMessage - marking TV (0) as inactive source
2024-04-04 23:31:42.675 T:4476 debug <general>: CecLogMessage - >> source activated: Playback 2 (8)
2024-04-04 23:31:42.675 T:4476 debug <general>: CecLogMessage - sending active source message for 'Playback 2'
2024-04-04 23:31:42.675 T:4476 debug <general>: CecLogMessage - << powering on 'TV' (0)
2024-04-04 23:31:42.676 T:4476 debug <general>: CecLogMessage - << 80:04
2024-04-04 23:31:42.732 T:4476 debug <general>: CecLogMessage - << Playback 2 (8) -> broadcast (F): active source (3400)
2024-04-04 23:31:42.732 T:4476 debug <general>: CecLogMessage - << 8f:82:34:00
2024-04-04 23:31:42.826 T:6022 debug <general>: Thread Timer 3535782400 terminating
2024-04-04 23:31:42.849 T:4476 debug <general>: CecLogMessage - << Playback 2 (8) -> TV (0): menu state 'activated'
2024-04-04 23:31:42.849 T:4476 debug <general>: CecLogMessage - << 80:8e:00
2024-04-04 23:31:42.854 T:4413 debug <general>: Keyboard: scancode: 0x3, sym: 0x32, unicode: 0x32, modifier: 0x0
Why is there a second HandleKey entry? It can cause things to immediately turn back off. I have no idea why one way gets one HandleKey event and the other two.
I’m playing with this as I’m using an Ugoos AM6b+ which has an encrypted bootloader so no BL301 injection. And it’s recovery from standby via CEC/external remotes it not very reliable.
Anyone else have a ready to go solution for this situation?