Raspberry Pi: Power On / Off A TV Connected Via HDMI-CEC

Raspberry Pi: Power On / Off A TV Connected Via HDMI-CEC



sudo apt install cec-utils


In this example,
  • Samsung TV
  • STB connected to HDMI-1
  • Raspberry Pi connected to HDMI-3

First, scan the CEC bus for available devices:
$ echo "scan" | cec-client RPI -s -d 1
opening a connection to the CEC adapter...
requesting CEC bus information ...
ERROR:   [           13691] failed to request the physical address
CEC bus information
===================
device #0: TV
address:       0.0.0.0
active source: no
vendor:        Toshiba
osd string:    TV
CEC version:   1.3a
power status:  on
language:      chi


device #1: Recorder 1
address:       3.0.0.0
active source: no
vendor:        Toshiba
osd string:    CECTester
CEC version:   1.4
power status:  on
language:      eng


device #3: Tuner 1
address:       f.f.f.f
active source: no
vendor:        Unknown
osd string:    Tuner 1
CEC version:   unknown
power status:  unknown
language:      ???

In this result,
  • device number 0 with the 0.0.0.0 address is my Samsung TV.
  • device number 1 with the 3.0.0.0 address is my Raspberry Pi device.
  • device number 3 with the f.f.f.f address is my STBi device.

The single command can only be effective when the device issuing commands is the active channel.
Some useful commands:
  • power on the TV
  • 0 is the TV device's number.
    echo 'on  0 ' | cec-client -s -d 1
    
  • power off the TV
  • echo 'standby  0 ' | cec-client -s -d 1
    
  • makes the CEC client as the active source
  • echo 'as' | cec-client -s -d 1
    
  • get the power status of the TV
  • echo 'pow  0 ' | cec-client -s -d 1
    

The better way is to transfer command bytes(HDMI-CEC Frames) over the CEC line from the CEC client device(#1) to other devices(TV:#0, broadcast:F).
  • Turn TV off
  • pi@raspberrypi:~ $ echo "tx 10:36" | cec-client RPI -s -d 4 
    
  • activate 1.0.0.0 (HDMI-1) as the input source
  • pi@raspberrypi:~ $ echo "tx 1F:82:10:00" | cec-client -s -d 4
    
  • activate 3.0.0.0 (HDMI-3) as the input source
  • pi@raspberrypi:~ $ echo "tx 1F:82:30:00" | cec-client -s -d 4
    

CEC Addressing



To allow CEC to be able to address specific physical devices and control switches, all devices shall have a physical address. This connectivity has to be worked out whenever a new device is added to the cluster. The physical address discovery process uses only the DDC/EDID(Display Data Channel/Extended Display Identification Data) mechanism and can be applied to all HDMI Sinks and Repeaters, not only to CEC-capable devices.

After discovering their own physical address, the CEC devices transmit their physical and logical addresses to all other
devices, thus allowing any device to create a map of the network.

Physical Address Discovery


The physical address of each node is determined through the physical address discovery process. This process is dynamic in that it automatically adjusts physical addresses as required as devices are physically or electrically added or removed from the device tree.

All Sinks and Repeaters shall perform the steps of physical address discovery and propagation even if those devices are not CEC-capable. Sources are not required to determine their own physical address unless they are CEC-capable.

All addresses are 4 digits long allowing for a 5–device-deep hierarchy. All are identified in the form of n.n.n.n in the following description.


Logical Address

Each device appearing on the control signal line has a logical address which is allocated to only one device in the system.
This logical address defines a device type as well as being a unique identifier.
LogicalAddress Device
0TV
1Recording Device 1
2Recording Device 2
3Tuner 1
4Playback Device 1
5Audio System
6Tuner 2
7Tuner 3
8Playback Device 2
9Recording Device 3
10Tuner 4
11Playback Device 3
12Reserved
13Reserved
14Free Use
15Unregistered (as initiator address)Broadcast (as destination address)





HDMI-CEC message format


The Raspberry Pi (Broadcom BCM2835 SoC) hardware has integrated support for CEC (Consumer Electronics Control) over the HDMI port.
CEC (Consumer Electronics Control) is the control protocol found in HDMI.
CEC frames consist of a header block and optionally data blocks 1 and 2, which holds the opcode and its parameters, respectively. The header is a single byte which consists of the initiator and destination logical address, each of which are 4 bits.

Let's use the famous CEC-O-MATIC sample:
F0:64:00:48:65:6C:6C:6F:20:77:6F:72:6C:64
  • The 1st byte
  • The first byte (F0) consists of the logical address source (or "initiator", first character) and destination (or "target", second character) addresses of the messages. This sample message is from an unregistered device (F) to the TV (0.) List of logical addresses.
  • The 2nd byte
  • The second byte (64) is the command number. 64 is the "set OSD string" command. You can find a list of commands in the HDMI spec or in CEC-O-MATIC
  • Then, depending on the command, the following bytes are the parameters of the command.
  • In our example, 00 is the "display control" parameter set to "display for default time", and 48:65:6C:6C:6F:20:77:6F:72:6C:64 is the "OSD String" parameter set to "Hello world".

留言

熱門文章