OrangePi-PCを使ってみる

オンボードの赤外線受信(Debian Stretch編)

Debian stretchになってlircのセットアップも随分と変わりました。
最初にlircパッケージをインストールします。
$ sudo apt update
$ sudo apt install lirc

Debian jessieでは[/etc/lirc/hardware.conf]にドライバーやデバイスを設定していましたが、
stretchでは[/etc/lirc/lirc_options.conf]にこれ らの情報を設定します。
$ sudo vi /etc/lirc/lirc_options.conf
[lircd]
nodaemon        = False
driver          = default
device          = /dev/lirc0
output          = /var/run/lirc/lircd
pidfile         = /var/run/lirc/lircd.pid
plugindir       = /usr/lib/arm-linux-gnueabihf/lirc/plugins
permission      = 666
allow-simulate  = No
repeat-max      = 600

ここでリブートします。
再起動後に一旦lircサービスを止め、mode2コマンドを実行します。
mode2コマンド実行中にリモコンを発射し、ずらずらコードが表示されればドライバーとデバイスの登録は完了です。
$ sudo service --status-all | grep lirc
[sudo] password for orangepi:
 [ + ]  lircd
 [ + ]  lircmd

$ sudo systemctl stop lircd
Warning: Stopping lircd.service, but it can still be activated by:
  lircd.socket

$ sudo service --status-all | grep lirc
 [ - ]  lircd
 [ - ]  lircmd

$ mode2 -d /dev/lirc0
Using driver default on device /dev/lirc0
Trying device: /dev/lirc0
Using device: /dev/lirc0

ここでリモコンを発射!!
すらずらコードが表示されればOK

pulse 8984
space 4488
pulse 560
space 576
pulse 568
space 552

次にリモコンの学習を行います。
リモコン学習のコマンドもjessieとは少し違います。
jessieの時はコマンドの一番最後の引数で出力するファイル名を指定していましたが、stretchではリモコン学習の途中でファイル名を指 定します。
また途中で以下のメッセージが表示されます。

It is very important that you press many different buttons randomly
and hold them down for approximately one second. Each button should
generate at least one dot but never more than ten dots of output.
Don't stop pressing buttons until two lines of dots (2x80) have
been generated.


ざっくり翻訳すると

あなたが多くの違う種類のボタンを無作為に押すことは非常に重要である
そして、約1秒の間ボタンを押しなさい。
個々のボタンは最低1つのドットを生成しなければならない。
しかし、決して 10ドットを超えてはならない。
ドット(2x80)の2本のラインがするまで、ボタンを押すのをやめてはならない。

要するに違う種類のボタンをたくさん押しなさいということです。
jessieの時は同じボタンを押し続けても、先に進むことができましたが、stretchで同じボタンを押し続けると
先に進むことができません。
$ sudo irrecord -n -d /dev/lirc0
Running as regular user orangepi
Using driver default on device /dev/lirc0

(中略)
Please take the time to finish the file as described in
https://sourceforge.net/p/lirc-remotes/wiki/Checklist/ an send it
to  <lirc@bartelmus.de> so it can be made available to others.

Press RETURN to continue.
(Enterキー)

Checking for ambient light  creating too much disturbances.
Please don't press any buttons, just wait a few seconds...

No significant noise (received 0 bytes)

Enter name of remote (only ascii, no spaces) :kodak  → 出力ファイル名
Using kodak.lircd.conf as output filename

Now start pressing buttons on your remote control.

It is very important that you press many different buttons randomly
and hold them down for approximately one second. Each button should
generate at least one dot but never more than ten dots of output.
Don't stop pressing buttons until two lines of dots (2x80) have
been generated.

Press RETURN now to start recording.(Enter キー)
(できるだけ沢山の種類のリモコンのボタンを押す)
................................................................................
Got gap (142151 us)}

Please keep on pressing buttons like described above.
(できるだけ沢山の種類のリモコンのボタンを押す...ここは疲れます)
................................................................................
................................................................................
................................................................................
................................................................................
................................................................................
................................................................................
.....

Please enter the name for the next button (press <ENTER> to finish recording)
halt → (登録するボタンの名前)

Now hold down button "halt".
(haltボタンとして登録するボタンを1回だけ押す)

Please enter the name for the next button (press <ENTER> to finish recording)
reboot → (登録するボタンの名前)

Now hold down button "reboot".
(rebootボタンとして登録するボタンを1回だけ押す)

(登録したいボタンについて、ひたすら繰り返す)

Please enter the name for the next button (press <ENTER> to finish recording)(Enter キー)

Checking for toggle bit mask.
Please press an arbitrary button repeatedly as fast as possible.
Make sure you keep pressing the SAME button and that you DON'T HOLD
the button down!.
If you can't see any dots appear, wait a bit between button presses.

Press RETURN to continue.(Enter キー)
(適当にリモコンのボタンを押 す)
..........
Toggle bit mask is 0xaaaa.

Successfully written config file kodak.lircd.conf

これでカレントディレクトリに「kodak.lircd.conf」が出来上がりますが、そのままでは使えません。
以下の様にコード部分を変更する必要が有ります。

【変更前】
      begin codes
          halt                     0x00FFA25D 0xBEA62244
          reboot                   0x00FF629D 0xBEA62244
          wifi                     0x00FFE21D 0xBEA62244
          up                       0x00FF02FD 0xBEA62244
          down                     0x00FF9867 0xBEA62244
          left                     0x00FFE01F 0xBEA62244
          right                    0x00FF906F 0xBEA62244
          ok                       0x00FFA857 0xBEA62244
          back                     0x00FF22DD 0xBEA62244
          menu                     0x00FFC23D 0xBEA62244
          play                     0x00FF18E7 0xBEA62244
          stop                     0x00FF38C7 0xBEA62244
          prev                     0x00FF10EF 0xBEA62244
          next                     0x00FF5AA5 0xBEA62244
          vol_up                   0x00FF52AD 0xBEA62244
          vol_down                 0x00FF42BD 0xBEA62244
          vol_mute                 0x00FF4AB5 0xBEA62244
      end codes

【変更後】
      begin codes
          halt                     0x00FFA25D
          reboot                   0x00FF629D
          wifi                     0x00FFE21D
          up                       0x00FF02FD
          down                     0x00FF9867
          left                     0x00FFE01F
          right                    0x00FF906F
          ok                       0x00FFA857
          back                     0x00FF22DD
          menu                     0x00FFC23D
          play                     0x00FF18E7
          stop                     0x00FF38C7
          prev                     0x00FF10EF
          next                     0x00FF5AA5
          vol_up                   0x00FF52AD
          vol_down                 0x00FF42BD
          vol_mute                 0x00FF4AB5
      end codes

変更後のファイルを所定の場所(/etc/lirc/lircd.conf.d/)に移動します。
また、元からある定義ファイル(/etc/lirc/lircd.conf.d/devinput.lircd.conf)は、どのようなリモコ ンなのか不明なので、消してしまいます。
lircdを再起動し、irsendで登録内容を確認します。
$ sudo cp kodak.lircd.conf /etc/lirc/lircd.conf.d/

$ sudo rm /etc/lirc/lircd.conf.d/devinput.lircd.conf

$ sudo systemctl start lircd

$ irsend LIST "" ""

kodak

$ irsend LIST kodak ""
0000000000ffa25d halt
0000000000ff629d reboot
0000000000ffe21d wifi
0000000000ff02fd up
0000000000ff9867 down
0000000000ffe01f left
0000000000ff906f right
0000000000ffa857 ok
0000000000ff22dd back
0000000000ffc23d menu
0000000000ff18e7 play
0000000000ff38c7 stop
0000000000ff10ef prev
0000000000ff5aa5 next
0000000000ff52ad vol_up
0000000000ff42bd vol_down
0000000000ff4ab5 vol_mute

再起動後に、irwコマンドを起動し、コマンド実行中にリモコンを発射します。
登録されているコードが表示されれば、学習結果の登録もOKです。
$ irw
0000000000ff02fd 00 UP kodak
0000000000ff02fd 01 UP kodak
0000000000ffa857 00 OK kodak
0000000000ffa857 01 OK kodak
0000000000ff9867 00 DOWN kodak
0000000000ff9867 01 DOWN kodak
0000000000ffe01f 00 LEFT kodak
0000000000ffe01f 01 LEFT kodak
0000000000ffe01f 02 LEFT kodak

最後に[/etc/lirc/irexec.lircrc]を作成して完了です。
これも最初からあるファイルは、どのようなリモコンのコードなのか不明なので、新しく作り直します。
button=XXXXの部分は「/etc/lirc/lircd.conf.d/my.conf」に定義したボタン名称
config=XXXXの部分はそのボタン が押されたときに、実行するコマンドです。
#
# Initial test configuration for systemwide irexec service.
#
# Note that the system-wide service is useful only in corner-cases.
# Most scenarios are better off with a session service as described in the
# Configuration Guide. However, note that both can also be combined.
#
# Also note that the system-wide service runs without a terminal. To
# check the output generated use something like
# 'journalctl -b0 /usr/bin/irexec'. This service just echoes some keys
# commonly available.
#

begin
 button = halt
 prog   = irexec
 config = sudo shutdown -h now
end

begin
 button = reboot
 prog   = irexec
 config = sudo shutdown -r now
end

以下のコマンドでirexecサービスを有効にします。
$ sudo systemctl enable irexec --now

$ sudo systemctl status irexec

これで、システム起動時にirexecが自動的にデーモンで起動し、リモコンを受け付けます。
$ ps -ef | grep irexec
root       265     1  0 11:49 ?        00:00:00 /usr/bin/irexec /etc/lirc/irexe .lircrc
pi         534   522  0 11:50 pts/0    00:00:00 grep --color=auto irexec

リモコンを操作すると、irexecデーモンがボタンに応じたコマンドを実行してくれます。
ただし、実行するコマンドによっては、パスワードなしでsudoできるようにしておく必要があります。
これをしないと、sudoコマンドを実行したときにパスワード入力待ちになってしまいます。
こちらの手順で、パスワードの入力無しにsudoコマンドを実行で きるよう になります。

次回は赤外線LEDを使った赤外線送信を紹介します。