2008年9月17日水曜日

iアプリ作成

とりあえず、テスト的にiアプリを組んでみる。

Vistaだからなのか、JDK1.6だからなのか、自宅の環境だと、どうもDojo-5.1が不安定すぎるような気がする。

そうこうして、1時間ばかりで、

とりあえず、それっぽく作ってみた。
フレームのスタート部が13msにしなければならないけど、どうやっても10ms以上にできないし、データ部のパルスが1つ削れない状態なんだけどね。
 
import java.io.*;
import java.util.*;

import com.nttdocomo.device.*;
import com.nttdocomo.ui.*;

public class RemoteTest extends IApplication {

int freq = 38; // KHz
int base = 1000; // usec
boolean status = false;

IrRemoteControl irc;

public void start() {
irc = IrRemoteControl.getIrRemoteControl();
byte[] datas = createData("11111100");

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

send(datas);
Thread.sleep(10000);

dia.setText("送信しました\n");
dia.show();

} catch (Exception e) {
dia.setText("エラー"+ e.getMessage());
dia.show();
}

this.terminate();
return;
}

public byte[] createData(String source) {
int len = source.length() % 8;
if(len>0) {
source += "00000000".substring(0,8-len);
}
try {
ByteArrayOutputStream out = new ByteArrayOutputStream();
for(int i=0; i < source.length() ; i+=8 ) {
int buf = Integer.parseInt( source.substring(i,i+8), 2 );
out.write(buf);
}
out.close();
return out.toByteArray();
} catch(Exception e) {
return new byte[0];
}
}

public void send(byte[] data) {
irc.setCarrier(10000 / freq / 2, 10000 / freq / 2);
irc.setCode0(IrRemoteControl.PATTERN_HL, base * 1, base * 4);
irc.setCode1(IrRemoteControl.PATTERN_HL, base * 1, base * 1);

IrRemoteControlFrame frame1 = new IrRemoteControlFrame();
frame1.setFrameData(data, data.length * 8);
frame1.setStartHighDuration(base*10);
frame1.setStartLowDuration(base*3);
frame1.setStopHighDuration(0);
frame1.setFrameDuration(470 * 10);
frame1.setRepeatCount(1);

IrRemoteControlFrame[] ircf = new IrRemoteControlFrame[] {frame1};
irc.send(1, ircf);
status = true;
return;
}
}

かなりいい加減なんだけど、ためしにK20Dに向けてみたら、シャッター落ちるでやんの。

こっちも、かなりいい加減な作りなのね。

0 件のコメント: