2010年6月29日火曜日

NEX用 リモコンアプリ

最近、なかなかまとまった時間がとれず、アプリを作っている暇がありません。
2時間ぐらいあれば、なんとかなりそうな気がするんだけどね。
うし君の相手に、大忙しなのさ。

まぁ、とりあえず、NEX-5のシャッタを切るだけのものなら、
 
import com.nttdocomo.device.*;
import com.nttdocomo.ui.*;
public class RemoteTest3 extends IApplication {

int freq = 38; // KHz
int base = 100; // usec

IrRemoteControl irc;

public void start() {
irc = IrRemoteControl.getIrRemoteControl();

Dialog dia = new Dialog(Dialog.BUTTON_OK, "IRリモコンテスト");
try {
dia.setText("送信します\n");
dia.show();

irc.setCarrier(5000/freq, 5000/freq ); //一般的なキャリア
//0:High=0.6ms,Low=0.6ms
irc.setCode0(IrRemoteControl.PATTERN_HL, base*6, base*6);
//1:High=1.2ms,Low=0.6ms
irc.setCode1(IrRemoteControl.PATTERN_HL, base*12, base*6);

//開始フレーム
IrRemoteControlFrame frame1 = new IrRemoteControlFrame();
frame1.setFrameData(
new byte[]{(byte)0xB4,(byte)0xB8,(byte)0xF0}, 20);
//1011 0100 1011 1000 1111
frame1.setStartHighDuration(base*24); //スタートはH 2.4ms
frame1.setStartLowDuration(base*6); //L 0.6ms
frame1.setStopHighDuration(0); //ストップパルスは使わない
frame1.setFrameDuration(45 * 10); //フレーム長(0.1ms)
frame1.setRepeatCount(5);

//空フレーム
IrRemoteControlFrame frame2 = new IrRemoteControlFrame();
frame2.setFrameData(new byte[]{(byte)0x0}, 0);
frame2.setStartHighDuration(0);
frame2.setStartLowDuration(base*1);
frame2.setStopHighDuration(0);
frame2.setFrameDuration(1000 * 10);
frame2.setRepeatCount(IrRemoteControlFrame.COUNT_INFINITE);

IrRemoteControlFrame[] ircf
= new IrRemoteControlFrame[] {frame1,frame2};
irc.send(ircf.length, ircf); //送信
Thread.sleep(1000); //1秒間
irc.stop();
dia.setText("送信しました\n");
dia.show();
} catch (Exception e) {
dia.setText("エラー"+ e.getMessage());
dia.show();
}
this.terminate();
return;
}
}
こんな感じで、

こんな感じ。

0 件のコメント: