Raspberry pi は良いおもちゃ

ネットワークブリッジしてたり、usb pam やったり、Minecraftやったり、ちょっと遊ぶにはすごく便利。最近はラジオを聞くラジオサーバーとして活用している。
Raspi の HDMIの出力を制御する
Raspi のHDMI出力を制御するには
tvservice -p tvservice -o
tvservice コマンドを通して、RaspiのHDMIポートの出力をオン・オフできる。テレビモニタによってはON/OFF連動してたりするので、これだけで制御することが出来たりする。
TV制御の cec の信号を送る /usr/bin/cec-client
AppleTV のtvOS でテレビの電源を制御したりしてて、AppleTVすげぇとか言ってるブログを見かけたりする。それCECな。tvOSがCESでテレビリモコンを乗っ取って身近になったCEC。
Raspi にもCECを扱えるように/usr/bin/cec-clientが用意されている。tvOSなどなくてもRaspiとSSHで生活には十分な利便性が得られるのであった。
takuya@raspi:~$ cec-client -l Found devices: 1 device: 1 com port: RPI vendor id: 2708 product id: 1001 firmware version: 1 type: Raspberry Pi
sudo aptitude install cec-utils でインストール出来ます。
HDMI CECでテレビの電源オン・オフ
テレビ電源をオンにするには
echo 'on 0' | cec-client -s
テレビの電源をオフにするには。
echo 'standby 0' | cec-client -s
Raspi にHDMIの入力を設定するには
echo 'as 0' | cec-client -s
単純に cec-client を起動すると
cec-client を単純に使うとキーボードから対話コンソールとして使える。
cec-client No device type given. Using 'recording device' CEC Parser created - libCEC version 2.2.0 no serial port given. trying autodetect: path: Raspberry Pi com port: RPI opening a connection to the CEC adapter... DEBUG: [ 139] unregistering all CEC clients DEBUG: [ 142] Broadcast (F): osd name set to 'Broadcast' DEBUG: [ 144] InitHostCEC - vchiq_initialise succeeded DEBUG: [ 146] InitHostCEC - vchi_initialise succeeded (略) DEBUG: [ 1492] expected response received (90: report power status) waiting for input # ←ここで、キーボードからの入力待ち standby 0 NOTICE: [ 9189] << putting 'TV' (0) in standby mode TRAFFIC: [ 9190] << 10:36 # ←ここで、キーボードからの入力待ち on 0 NOTICE: [ 15032] << powering on 'TV' (0) TRAFFIC: [ 15032] << 10:04 TRAFFIC: [ 15417] >> 01:83 DEBUG: [ 15417] >> TV (0) -> Recorder 1 (1): give physical address (83)
help で使い方
help
================================================================================
Available commands:
[tx] {bytes} transfer bytes over the CEC line.
[txn] {bytes} transfer bytes but don't wait for transmission ACK.
[on] {address} power on the device with the given logical address.
[standby] {address} put the device with the given address in standby mode.
[la] {logical address} change the logical address of the CEC adapter.
[p] {device} {port} change the HDMI port number of the CEC adapter.
[pa] {physical address} change the physical address of the CEC adapter.
[as] make the CEC adapter the active source.
[is] mark the CEC adapter as inactive source.
[osd] {addr} {string} set OSD message on the specified device.
[ver] {addr} get the CEC version of the specified device.
[ven] {addr} get the vendor ID of the specified device.
[lang] {addr} get the menu language of the specified device.
[pow] {addr} get the power status of the specified device.
[name] {addr} get the OSD name of the specified device.
[poll] {addr} poll the specified device.
[lad] lists active devices on the bus
[ad] {addr} checks whether the specified device is active.
[at] {type} checks whether the specified device type is active.
[sp] {addr} makes the specified physical address active.
[spl] {addr} makes the specified logical address active.
[volup] send a volume up command to the amp if present
[voldown] send a volume down command to the amp if present
[mute] send a mute/unmute command to the amp if present
[self] show the list of addresses controlled by libCEC
[scan] scan the CEC bus and display device info
[mon] {1|0} enable or disable CEC bus monitoring.
[log] {1 - 31} change the log level. see cectypes.h for values.
[ping] send a ping command to the CEC adapter.
[bl] to let the adapter enter the bootloader, to upgrade
the flash rom.
[r] reconnect to the CEC adapter.
[h] or [help] show this help.
[q] or [quit] to quit the CEC test client and switch off all
connected CEC devices.
================================================================================
mute や volume up/down があるんですね。osd で画面に文字列出せるみたいだけど、私の手元のシャープ製のテレビでは動かなかった。
万が一 cec-clientが見つからない時
sudo apt install cec-utils
raspi にかぎらずHDMI出力アレば使えるはず
cec 関連はHDMIが搭載されてるLinuxであれば基本的に使えるはず。
続編
Rapiをリモコン操作して、omxplayer をTVのリモコンで操作する。 - それマグで!
参考資料
Using cec-client to Control HDMI Devices | End Point
https://www.raspberrypi.org/forums/viewtopic.php?f=29&t=53481
Use RPi to change HDMI-Input to non-CEC device - Raspberry Pi Forums
http://manpages.ubuntu.com/manpages/precise/man1/cec-client.1.html