1,13 → 1,13 |
/********************************************************************************************************************************* |
* * |
* minimal canvas to test Abstraction layer on various Phones * |
* * |
* Author: Marcus -LiGi- Bueschleb * |
* Project-Start: 9/2007 * |
* Mailto: ligi@smart4mobile.de * |
* Licence: Creative Commons / Non Commercial * |
* Big Up: Holger&Ingo * |
*********************************************************************************************************************************/ |
/*************************************************************** |
* |
* minimal canvas to test Abstraction layer on various Phones |
* |
* Author: Marcus -LiGi- Bueschleb |
* Project-Start: 9/2007 |
* Mailto: ligi@smart4mobile.de |
* Licence: Creative Commons / Non Commercial |
* Big Up: Holger&Ingo |
***************************************************************/ |
|
import javax.microedition.lcdui.*; |
import javax.microedition.rms.*; |
14,8 → 14,8 |
|
|
public class MKMiniCanvas |
extends Canvas |
implements Runnable |
extends Canvas |
implements Runnable |
{ |
|
|
45,63 → 45,63 |
public int line_middle_y; |
|
public MKMiniCanvas(MKMiniMidlet _root) |
{ |
{ |
|
root=_root; |
root=_root; |
|
try |
{ |
lcd_img=Image.createImage("/lcd.png"); |
bt_img=Image.createImage("/bt.png"); |
bg_img=Image.createImage("/bg.jpg"); |
load_img=Image.createImage("/load.png"); |
} |
catch (Exception e) |
{ |
err+=e.toString(); |
} |
try |
{ |
lcd_img=Image.createImage("/lcd.png"); |
bt_img=Image.createImage("/bt.png"); |
bg_img=Image.createImage("/bg.jpg"); |
load_img=Image.createImage("/load.png"); |
} |
catch (Exception e) |
{ |
err+=e.toString(); |
} |
|
|
nick_line_pos_data=new int[bg_img.getWidth()]; |
roll_line_pos_data=new int[bg_img.getWidth()]; |
accnick_line_pos_data=new int[bg_img.getWidth()]; |
accroll_line_pos_data=new int[bg_img.getWidth()]; |
nick_line_pos_data=new int[bg_img.getWidth()]; |
roll_line_pos_data=new int[bg_img.getWidth()]; |
accnick_line_pos_data=new int[bg_img.getWidth()]; |
accroll_line_pos_data=new int[bg_img.getWidth()]; |
|
for (int c=0;c<bg_img.getWidth();c++) |
{ |
nick_line_pos_data[c]=-1; |
roll_line_pos_data[c]=-1; |
accnick_line_pos_data[c]=-1; |
accroll_line_pos_data[c]=-1; |
} |
for (int c=0;c<bg_img.getWidth();c++) |
{ |
nick_line_pos_data[c]=-1; |
roll_line_pos_data[c]=-1; |
accnick_line_pos_data[c]=-1; |
accroll_line_pos_data[c]=-1; |
} |
|
|
// mk = new MKCommunicator("btspp://000BCE016B5B:1"); |
//connect_mk("btspp://000BCE016B4F:1"); |
// mk = new MKCommunicator("btspp://000BCE016B5B:1"); |
//connect_mk("btspp://000BCE016B4F:1"); |
|
|
try |
{ |
RecordStore recStore = RecordStore.openRecordStore("bturl", true ); |
try |
{ |
RecordStore recStore = RecordStore.openRecordStore("bturl", true ); |
|
if (recStore.getNumRecords()==1) |
{ |
byte[] recData = new byte[recStore.getRecordSize(1)]; |
int len = recStore.getRecord(1, recData, 0); |
rescan=false; |
connect_mk(new String(recData, 0, len)); |
} |
} |
catch (Exception e) |
if (recStore.getNumRecords()==1) |
{ |
err+=e.toString(); |
byte[] recData = new byte[recStore.getRecordSize(1)]; |
int len = recStore.getRecord(1, recData, 0); |
rescan=false; |
connect_mk(new String(recData, 0, len)); |
} |
} |
catch (Exception e) |
{ |
err+=e.toString(); |
} |
|
if (mk==null) bt_scanner = new BTSearcher(); |
if (mk==null) bt_scanner = new BTSearcher(); |
|
new Thread(this).start(); |
new Thread(this).start(); |
|
} |
} |
|
boolean quit=false; |
boolean rescan=true; |
117,6 → 117,9 |
|
while(true) |
{ |
repaint(); |
serviceRepaints(); |
|
long loopStartTime = System.currentTimeMillis(); |
long sleeptime=0; |
// ticked thing |
123,11 → 126,33 |
|
frame_pos++; |
|
|
|
switch(state) |
{ |
case STATEID_MOTORTEST: |
|
if (motor_test_sel_all) |
for (int m=0;m<4;m++) |
{ |
motor_test[m]+=act_motor_increase; |
if (motor_test[m]<0)motor_test[m]=0; |
} |
else |
{ |
motor_test[act_motor]+=act_motor_increase; |
if (motor_test[act_motor]<0)motor_test[act_motor]=0; |
} |
|
mk.motor_test(motor_test); |
break; |
} |
|
try { |
nick_line_pos_data[-bg_offset] = mk.debug_data.nick_int(); |
roll_line_pos_data[-bg_offset] = mk.debug_data.roll_int(); |
accnick_line_pos_data[-bg_offset] = mk.debug_data.accnick(); |
accroll_line_pos_data[-bg_offset] = mk.debug_data.accroll(); |
nick_line_pos_data[-bg_offset] = mk.debug_data.nick_int(); |
roll_line_pos_data[-bg_offset] = mk.debug_data.roll_int(); |
accnick_line_pos_data[-bg_offset] = mk.debug_data.accnick(); |
accroll_line_pos_data[-bg_offset] = mk.debug_data.accroll(); |
} |
catch (Exception e) |
{ |
161,23 → 186,29 |
} |
if (rescan) |
{ |
if (mk!=null) mk.close_connections(true); |
mk=null; |
bt_scanner.search_again(); |
if (mk!=null) mk.close_connections(true); |
mk=null; |
bt_scanner.search_again(); |
} |
|
rescan=false; |
bg_offset--; |
if (bg_offset==-bg_img.getWidth()) |
bg_offset=0; |
com.nokia.mid.ui.DeviceControl.setLights(0,100); |
//bt.tick(); |
// every state has sth to do in tick section |
try { |
rescan=false; |
bg_offset--; |
if (bg_offset==-bg_img.getWidth()) |
bg_offset=0; |
com.nokia.mid.ui.DeviceControl.setLights(0,100); |
//bt.tick(); |
// every state has sth to do in tick section |
} |
catch (Exception e) |
{ |
|
} |
|
|
// System.gc(); |
repaint(); |
serviceRepaints(); |
// System.gc(); |
|
|
|
|
sleeptime=1000/ 15 - (int) (System.currentTimeMillis()- loopStartTime); |
184,12 → 215,12 |
|
|
if (sleeptime<0) |
sleeptime=100; // everyone has fi sleep |
sleeptime=100; // everyone has fi sleep |
|
try { Thread.sleep(sleeptime); } |
catch (Exception e) |
{ |
err="Problem Sleeping "; |
err="Problem Sleeping "; |
} |
|
} |
197,131 → 228,157 |
|
|
|
|
public int state=-1; |
|
public final static int STATEID_MOTORTEST=2; |
|
|
int local_max=-1; |
|
int[] motor_test = {0,0,0,0}; |
|
// drawing section |
public void paint(Graphics g) { |
|
try { |
|
if (mk!=null) |
{ |
line_middle_y=this.getHeight()/2; |
if (local_max<Math.abs(mk.debug_data.nick_int())) |
local_max=Math.abs(mk.debug_data.nick_int()); |
if (local_max<Math.abs(mk.debug_data.roll_int())) |
local_max=Math.abs(mk.debug_data.roll_int()); |
if (local_max<Math.abs(mk.debug_data.accnick())) |
local_max=Math.abs(mk.debug_data.accnick()); |
if (local_max<Math.abs(mk.debug_data.accroll())) |
local_max=Math.abs(mk.debug_data.accroll()); |
line_scaler= local_max/(this.getHeight()/2)+1; |
} |
int spacer=(g.getFont().getHeight()); |
g.setColor(0xFFFFFF); |
g.fillRect(0,0,this.getWidth(),this.getHeight()); |
g.drawImage(bg_img,bg_offset,0, g.TOP | g.LEFT); |
if (bg_offset+bg_img.getWidth()<this.getWidth()) |
g.drawImage(bg_img,bg_offset+bg_img.getWidth(),0, g.TOP | g.LEFT); |
if (mk!=null) |
{ |
line_middle_y=this.getHeight()/2; |
if (local_max<Math.abs(mk.debug_data.nick_int())) |
local_max=Math.abs(mk.debug_data.nick_int()); |
if (local_max<Math.abs(mk.debug_data.roll_int())) |
local_max=Math.abs(mk.debug_data.roll_int()); |
if (local_max<Math.abs(mk.debug_data.accnick())) |
local_max=Math.abs(mk.debug_data.accnick()); |
if (local_max<Math.abs(mk.debug_data.accroll())) |
local_max=Math.abs(mk.debug_data.accroll()); |
line_scaler= local_max/(this.getHeight()/2)+1; |
} |
int spacer=(g.getFont().getHeight()); |
g.setColor(0xFFFFFF); |
g.fillRect(0,0,this.getWidth(),this.getHeight()); |
g.drawImage(bg_img,bg_offset,0, g.TOP | g.LEFT); |
|
g.setColor(0x000000); |
if (bg_offset+bg_img.getWidth()<this.getWidth()) |
g.drawImage(bg_img,bg_offset+bg_img.getWidth(),0, g.TOP | g.LEFT); |
|
|
|
|
switch(state) |
{ |
case STATEID_MOTORTEST: |
for (int bar=0;bar<4;bar++) |
{ |
g.setColor(((bar==act_motor)|motor_test_sel_all)?0x44CC44:0x4444DD); |
g.fillRect(this.getWidth()/(8*2)+bar*2*this.getWidth()/8,10,this.getWidth()/8,20+motor_test[bar]); |
g.setColor(0x000000); |
g.drawString(""+motor_test[bar] ,this.getWidth()/8+bar*2*this.getWidth()/8,10,Graphics.TOP | Graphics.HCENTER); |
if(bar!=4) g.drawString(""+mk.debug_data.motor_val(bar) ,this.getWidth()/8+bar*2*this.getWidth()/8,30,Graphics.TOP | Graphics.HCENTER); |
} |
break; |
|
default: |
g.setColor(0x000000); |
|
if (mk==null) |
{ |
if (mk==null) |
{ |
|
|
if (bt_scanner.searching) |
{ |
if (bt_scanner.searching) |
{ |
|
|
g.drawString("scanning for BT-Devices",this.getWidth()/2,this.getHeight()/2+load_img.getHeight()/8,Graphics.TOP | Graphics.HCENTER); |
g.drawString("scanning for BT-Devices",this.getWidth()/2,this.getHeight()/2+load_img.getHeight()/8,Graphics.TOP | Graphics.HCENTER); |
|
g.setClip(this.getWidth()/2-load_img.getWidth()/6,this.getHeight()/2-load_img.getHeight()/8, load_img.getWidth()/4,load_img.getHeight()/3);; |
g.drawImage(load_img,this.getWidth()/2-load_img.getWidth()/8 - ((((frame_pos/3)%12)%4)*(load_img.getWidth()/4)) ,this.getHeight()/2-load_img.getHeight()/6- ((((frame_pos/3)%12)/4)*(load_img.getHeight()/3)), g.TOP | g.LEFT); |
g.drawImage(bt_img,this.getWidth()/2 ,this.getHeight()/2 , g.HCENTER | g.VCENTER); |
} |
else |
{ |
g.drawString("Press key 0-"+(bt_scanner.remote_device_count-1) + " to continue" ,0,0,Graphics.TOP | Graphics.LEFT); |
for (int i=0;i<bt_scanner.remote_device_count;i++) |
g.drawString("#"+i+">" + bt_scanner.remote_device_name[i]+"("+bt_scanner.remote_device_mac[i]+")",0,spacer+spacer*i,Graphics.TOP | Graphics.LEFT); |
g.setClip(this.getWidth()/2-load_img.getWidth()/6,this.getHeight()/2-load_img.getHeight()/8, load_img.getWidth()/4,load_img.getHeight()/3);; |
g.drawImage(load_img,this.getWidth()/2-load_img.getWidth()/8 - ((((frame_pos/3)%12)%4)*(load_img.getWidth()/4)) ,this.getHeight()/2-load_img.getHeight()/6- ((((frame_pos/3)%12)/4)*(load_img.getHeight()/3)), g.TOP | g.LEFT); |
g.drawImage(bt_img,this.getWidth()/2 ,this.getHeight()/2 , g.HCENTER | g.VCENTER); |
} |
else |
{ |
g.drawString("Press key 0-"+(bt_scanner.remote_device_count-1) + " to continue" ,0,0,Graphics.TOP | Graphics.LEFT); |
for (int i=0;i<bt_scanner.remote_device_count;i++) |
g.drawString("#"+i+">" + bt_scanner.remote_device_name[i]+"("+bt_scanner.remote_device_mac[i]+")",0,spacer+spacer*i,Graphics.TOP | Graphics.LEFT); |
|
} |
} |
|
|
|
|
} |
else // MK is connected |
{ |
int y_off=0; |
} |
else // MK is connected |
{ |
int y_off=0; |
|
g.drawString(mk.version.str+"(d:"+mk.debug_data_count+ " l:" + mk.lcd_data_count+ " v:" + mk.version_data_count+" o:"+mk.other_data_count+")",0,y_off,Graphics.TOP | Graphics.LEFT); |
g.drawString(mk.version.str+"(d:"+mk.debug_data_count+ " l:" + mk.lcd_data_count+ " v:" + mk.version_data_count+" o:"+mk.other_data_count+")",0,y_off,Graphics.TOP | Graphics.LEFT); |
|
y_off+=spacer; |
y_off+=spacer; |
|
g.drawString("n:"+mk.debug_data.nick_int() + " r:"+mk.debug_data.roll_int() + " an:"+mk.debug_data.accnick() + " ar:"+mk.debug_data.accroll() ,0,y_off,Graphics.TOP | Graphics.LEFT); |
y_off+=spacer; |
g.drawString("n:"+mk.debug_data.nick_int() + " r:"+mk.debug_data.roll_int() + " an:"+mk.debug_data.accnick() + " ar:"+mk.debug_data.accroll() ,0,y_off,Graphics.TOP | Graphics.LEFT); |
y_off+=spacer; |
|
|
g.drawString("m1:"+mk.debug_data.motor_val(0) + " m2:"+mk.debug_data.motor_val(1)+" m3:"+mk.debug_data.motor_val(2) + " m4:"+mk.debug_data.motor_val(3) ,0,y_off,Graphics.TOP | Graphics.LEFT); |
y_off+=spacer; |
g.drawString("m1:"+mk.debug_data.motor_val(0) + " m2:"+mk.debug_data.motor_val(1)+" m3:"+mk.debug_data.motor_val(2) + " m4:"+mk.debug_data.motor_val(3) ,0,y_off,Graphics.TOP | Graphics.LEFT); |
y_off+=spacer; |
|
if (mk.connected) |
{ |
g.drawString("time conn:" +((System.currentTimeMillis()- mk.connection_start_time)/1000)+"s" ,0,y_off,Graphics.TOP | Graphics.LEFT); |
y_off+=spacer; |
g.drawString("time motor>15:" +(mk_stat.motor_on_time/1000) +"s" ,0,y_off,Graphics.TOP | Graphics.LEFT); |
y_off+=spacer; |
g.drawString("time motor=15:" +(mk_stat.motor_stand_time/1000) +"s" ,0,y_off,Graphics.TOP | Graphics.LEFT); |
} |
if (mk.connected) |
{ |
g.drawString("time conn:" +((System.currentTimeMillis()- mk.connection_start_time)/1000)+"s" ,0,y_off,Graphics.TOP | Graphics.LEFT); |
y_off+=spacer; |
g.drawString("time motor>15:" +(mk_stat.motor_on_time/1000) +"s" ,0,y_off,Graphics.TOP | Graphics.LEFT); |
y_off+=spacer; |
g.drawString("time motor=15:" +(mk_stat.motor_stand_time/1000) +"s" ,0,y_off,Graphics.TOP | Graphics.LEFT); |
} |
|
|
y_off=this.getHeight()-4*19; |
y_off=this.getHeight()-4*lcd_img.getHeight(); |
|
for ( int foo=0;foo<4;foo++) |
{ |
|
for (int x=0;x<20;x++) |
{ |
g.setClip(12*x,y_off,12,19); |
g.drawImage(lcd_img,12*x-(mk.LCD.LCD_str[foo].charAt(x)-' ')*(lcd_img.getWidth()/95),y_off, g.TOP | g.LEFT); |
for ( int foo=0;foo<4;foo++) |
{ |
for (int x=0;x<20;x++) |
{ |
g.setClip((lcd_img.getWidth()/222)*x,y_off,(lcd_img.getWidth()/222),lcd_img.getHeight()); |
g.drawImage(lcd_img,(lcd_img.getWidth()/222)*x-(mk.LCD.LCD_str[foo].charAt(x)-' ')*(lcd_img.getWidth()/222),y_off, g.TOP | g.LEFT); |
|
} |
y_off+=19; |
} |
y_off+=lcd_img.getHeight(); |
} |
|
|
g.setClip(0,0,this.getWidth(),this.getHeight()); |
|
} |
|
g.setClip(0,0,this.getWidth(),this.getHeight()); |
|
|
|
|
} |
// draw lines |
} |
// draw lines |
|
for ( int x=0;x<this.getWidth();x++) |
for ( int x=0;x<this.getWidth();x++) |
|
{ |
{ |
|
int p= (((-bg_offset+x-this.getWidth()-5))); |
if (p<1) |
p+=bg_img.getWidth(); |
p%=(bg_img.getWidth()-1); |
int p= (((-bg_offset+x-this.getWidth()-5))); |
if (p<1) |
p+=bg_img.getWidth(); |
p%=(bg_img.getWidth()-1); |
|
g.setColor(0x156315); |
draw_graph_part(g,x,nick_line_pos_data[p]/line_scaler,nick_line_pos_data[p+1]/line_scaler); |
g.setColor(0xCC1315); |
draw_graph_part(g,x,roll_line_pos_data[p]/line_scaler,roll_line_pos_data[p+1]/line_scaler); |
g.setColor(0xf8ef02); |
draw_graph_part(g,x,accnick_line_pos_data[p]/line_scaler,accnick_line_pos_data[p+1]/line_scaler); |
g.setColor(0x19194d); |
draw_graph_part(g,x,accroll_line_pos_data[p]/line_scaler,accroll_line_pos_data[p+1]/line_scaler); |
g.setColor(0x156315); |
draw_graph_part(g,x,nick_line_pos_data[p]/line_scaler,nick_line_pos_data[p+1]/line_scaler); |
g.setColor(0xCC1315); |
draw_graph_part(g,x,roll_line_pos_data[p]/line_scaler,roll_line_pos_data[p+1]/line_scaler); |
g.setColor(0xf8ef02); |
draw_graph_part(g,x,accnick_line_pos_data[p]/line_scaler,accnick_line_pos_data[p+1]/line_scaler); |
g.setColor(0x19194d); |
draw_graph_part(g,x,accroll_line_pos_data[p]/line_scaler,accroll_line_pos_data[p+1]/line_scaler); |
|
|
|
} |
} |
|
} |
|
} catch (Exception e) {} |
} |
|
private void connect_mk(String url) |
343,41 → 400,99 |
/*********************************************** input Section **********************************************/ |
// keys |
public boolean fullscreen=false; |
public int act_motor=0; |
public int act_motor_increase=0; |
public boolean motor_test_sel_all=false; |
|
public void chg_state(int _state) |
{ |
state=_state; |
} |
|
|
public void keyReleased(int keyCode) |
{ |
|
switch(state) |
{ |
case STATEID_MOTORTEST: |
act_motor_increase=0; |
break; |
} |
|
} |
|
public void keyPressed(int keyCode) |
{ |
|
if ((mk==null)&&(keyCode >= this.KEY_NUM0) && (keyCode < this.KEY_NUM0+bt_scanner.remote_device_count)) |
connect_mk("btspp://"+bt_scanner.remote_device_mac[keyCode-this.KEY_NUM0] + ":1"); |
else |
switch(state) |
{ |
switch (keyCode) |
{ |
case STATEID_MOTORTEST: |
switch (getGameAction (keyCode)) |
{ |
case UP: |
act_motor_increase=-1; |
break; |
|
case KEY_STAR: |
mk.other_data_count=23; |
quit=true; |
break; |
case DOWN: |
act_motor_increase=1; |
break; |
|
case KEY_POUND: |
//rescan=true; |
fullscreen=!fullscreen; |
setFullScreenMode(fullscreen); |
break; |
} |
switch (getGameAction (keyCode)) |
case FIRE: |
motor_test_sel_all=!motor_test_sel_all; |
break; |
|
case LEFT: |
act_motor--; |
if (act_motor<0) {act_motor=0; chg_state(-1); } |
break; |
|
case RIGHT: |
act_motor++; |
act_motor%=4; |
break; |
} |
|
break; |
|
default: |
if ((mk==null)&&(keyCode >= this.KEY_NUM0) && (keyCode < this.KEY_NUM0+bt_scanner.remote_device_count)) |
connect_mk("btspp://"+bt_scanner.remote_device_mac[keyCode-this.KEY_NUM0] + ":1"); |
else |
{ |
case UP: |
mk.LCD.LCD_PREVPAGE(); |
break; |
switch (keyCode) |
{ |
|
case DOWN: |
mk.LCD.LCD_NEXTPAGE(); |
break; |
case KEY_STAR: |
mk.other_data_count=23; |
quit=true; |
break; |
|
case KEY_POUND: |
//rescan=true; |
fullscreen=!fullscreen; |
setFullScreenMode(fullscreen); |
|
break; |
} |
switch (getGameAction (keyCode)) |
{ |
case UP: |
mk.LCD.LCD_PREVPAGE(); |
break; |
|
case DOWN: |
mk.LCD.LCD_NEXTPAGE(); |
break; |
|
case RIGHT: |
state=STATEID_MOTORTEST; |
break; |
} |
} |
|
} |
|
|
return; |
} |
|