iアプリで赤外線リモコン信号を送信
注意点
- IrRemoteControl.send()の引数の型は配列、IrRemoteControlFrame[]
- send()はバックグランドで実行される(デフォルトで10秒間送信される)。送信中に再度send()すると例外が発生する。
- IrRemoteControlFrame.setFrameDuration()の単位は0.1msec、他のメソッドはusec単位
- 送信するデータはメーカー、モデル、コードから構成される。詳細はhttp://homepage1.nifty.com/borlander/etc/remocon/index.html
- リモコンモニタなどで収集したデータを下にするときには、LSBファーストかどうかに注意
- IrRemoteControl.setCarrier()の引数の単位は0.1msec、他のメソッドはusec単位。highDurationとlowDurationをそれぞれ指定するので、周波数が38kHzなら、
1000/38k/210000/38k/2になる。
iアプリのコード
import com.nttdocomo.device.IrRemoteControl; import com.nttdocomo.device.IrRemoteControlFrame; import com.nttdocomo.ui.*; public class irremotetest extends IApplication { int freq = 38; // KHz int base = 425; // usec boolean status = false; IrRemoteControl irc; public void start() { irc = IrRemoteControl.getIrRemoteControl(); byte[] datas = new byte[6]; try { Dialog dia = new Dialog(Dialog.BUTTON_OK, "IRリモコンテスト"); dia.setText("送信します\n"); dia.show(); datas[0] = 1; datas[1] = 2; datas[2] = 3; datas[3] = 4; datas[4] = 5; datas[5] = 6; send(datas); Thread.sleep(10000); dia.setText("送信しました\n"); dia.show(); this.terminate(); } catch (Exception e) { } } public void send(byte[] data) { irc.setCarrier(10000 / freq / 2, 10000 / freq / 2); irc.setCode0(IrRemoteControl.PATTERN_HL, base * 1, base * 1); irc.setCode1(IrRemoteControl.PATTERN_HL, base * 1, base * 3); IrRemoteControlFrame[] ircf = new IrRemoteControlFrame[1]; IrRemoteControlFrame frame = new IrRemoteControlFrame(); frame.setFrameData(data, data.length * 8); frame.setStartHighDuration(base * 8); frame.setStartLowDuration(base * 4); frame.setStopHighDuration(base * 1); frame.setFrameDuration(data.length * 8 * base * 4 / 100 + 60 + 85); frame.setRepeatCount(IrRemoteControlFrame.COUNT_INFINITE); ircf[0] = frame; irc.send(1, ircf); status = true; } }
参考資料:ドコモの技術資料iアプリコンテンツ開発ガイド for DoJa-5.x 詳細編