We want to send the following HDMI CEC commands from the Android Box to the TV:
- get TV status (is it turned ON or OFF?)
- get TV's current active source (HDMI1/HDMI2/...)
- turn ON TV
- turn off TV (standby)
- switch HDMI source from HDMI1 to HDMI2
You can read more about CEC frames here: Understanding HDMI CEC frame
You can send HDMI CEC commands directly from the RPI with cec-utils.
You can get TV status with RPI and libcec with:
$ echo 'scan' | cec-client -s -d 1
# Result
CEC bus information
===================
device #0: TV
address: 0.0.0.0
active source: no
vendor: Sony
osd string: TV
CEC version: 1.4
power status: standby
language: eng
device #1: Recorder 1
address: 1.0.0.0
active source: no
vendor: Pulse Eight
osd string: CECTester
CEC version: 1.4
power status: on
language: eng
device #4: Playback 1
address: 3.0.0.0
active source: no
vendor: Sony
osd string: PlayStation 4
CEC version: 1.3a
power status: standby
language: ???
Flirc is an USB IR transciever (transmitter & receiver) Flirc CLI
It has an library written in C language, maybe we can use it in our Flutter code using dart:ffi:
https://docs.flutter.dev/development/platform-integration/android/c-interop https://stackoverflow.com/questions/67793076/how-to-call-a-native-c-function-from-flutter
To use C code in your Flutter program, use the dart:ffi library (currently in beta).
Step 1: Use 3rd party library Flirc code
Step 2: Add C/C++ sources
Step 3: Load the code using the FFI library
- Understanding HDMI CEC frame
- What is CEC? Why? How?
- Nuvoton - HDMI-CEC Application Note & Sample Code
- Consumer Electronics Control (CEC specification)
- Tv on/off is working everytime on most TVs.
- It fails to work for turning TV ON after some runs on LG TV
- Switching HDMI sources works the first time to switch to HDMI1 or HDMI2
- it stops working after the first time and it randomly starts working after couple of minutes (5 - 10min) when testing on LG TV