Subversion Repositories FlightCtrl

Compare Revisions

Ignore whitespace Rev 220 → Rev 221

/branches/ligi_j2me/README
32,6 → 32,9
* 0.18 - Remember URL ( bt-mac ) on quit
* 0.19 - better handling of MK Version
* 0.23 - care for Version while parsing DebugData - MK0.64 compatible now (0.20-0.23 - n1 bugfixing With CaSCade)
* 0.24 - adding some GFX
* 0.25 - adding Graph ( Nick int;Roll int; nick acc ;roll acc)
* 0.26 - more Visuals
*
* Online Link to this Document:
* http://mikrocontroller.cco-ev.de/mikroviewvc/FlightCtrl/branches/ligi_j2me/README?view=markup
40,7 → 43,7
 
Install:
- If u know how to handle JAR/JADs take the ones from the bin directory.
- If u dont visit http://www.getjar.com/products/12587/MKMiniMidlet
- If u dont visit http://www.getjar.com/products/12587/MKMiniMidlet ( SVN might be more recent)
 
Compile:
- install some tools to fullfill Compile-Dependencys ( see below )
63,11 → 66,12
KEY 1..X to select device
KEY UP to go Page up in MK-LCD
KEY DOWN to go Page up in MK-LCD
KEY # to Rescan
KEY # toggle Fullscreen
KEY * to Quit
 
Tested on:
SE - K800i
SE - W800i
Nokia 6234
Nokia N80 ( Font is too Big - but API worx)
6230i ( without copter )
82,5 → 86,6
- Visualisation of DebugData
- making lib to be useable with desktop JAVA / will be sceduled after bluecove for linux is ready ( anounced for next Version)
- triangulate MK by BT rssi
- trigger cammera shot via FC
- tbc
/branches/ligi_j2me/bin/midp2_minimal/MKMiniMidlet.jad
1,5 → 1,5
MIDlet-Jar-URL: MKMiniMidlet.jar
MIDlet-Jar-Size: 8814
MIDlet-Jar-Size: 59446
MIDlet-Name: MKMiniMidlet
MIDlet-Vendor: LiGi
MIDlet-Version: 0.23
/branches/ligi_j2me/bin/midp2_minimal/MKMiniMidlet.jar
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/branches/ligi_j2me/build.xml
23,7 → 23,7
manifest="${build_dir}/bin/MANIFEST.MF"
name="${project_name}"
vendor="LiGi"
version="0.18">
version="0.26">
<attribute name="MIDletX-No-Command" value="true"/>
 
<midlet name="${project_name}" class="${project_name}" />
/branches/ligi_j2me/res/bg.jpg
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+application/octet-stream
\ No newline at end of property
/branches/ligi_j2me/res/bt.png
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+application/octet-stream
\ No newline at end of property
/branches/ligi_j2me/res/lcd.png
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+application/octet-stream
\ No newline at end of property
/branches/ligi_j2me/res/load.png
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+application/octet-stream
\ No newline at end of property
/branches/ligi_j2me/src/MKCommunicator.java
35,6 → 35,7
public MKLCD LCD;
public MKVersion version;
public MKDebugData debug_data;
public MKWatchDog watchdog;
 
public long connection_start_time=-1;
77,7 → 78,12
connection_start_time=System.currentTimeMillis();
connected=true; // if we get here everything seems to be OK
get_version();
lcd_data_count=0;
debug_data_count=0;
version_data_count=0;
 
LCD= new MKLCD(this);
watchdog=new MKWatchDog(this);
}
catch (Exception ex)
{
203,11 → 209,6
case '3':
LCD.handle_lcd_data(Decode64(data,3,20),data[2]-(int)'0');
lcd_data_count++;
// decoded_data=
 
// if ((data[2]-(int)'0')!=3)
// get_LCD();
break;
 
default:
225,9 → 226,9
 
public boolean force_disconnect=false;
 
public void close_connections()
public void close_connections(boolean force)
{
force_disconnect=true;
force_disconnect=force;
try{ reader.close(); }
catch (Exception inner_ex) { }
 
274,7 → 275,7
{
msg="Problem reading from MK";
// close the connection
close_connections();
close_connections(false);
 
 
}
/branches/ligi_j2me/src/MKDebugData.java
21,8 → 21,13
private int i;
 
public int motor_val(int id) { return analog[12+id]; }
public int nick_int() { return analog[1]; }
public int roll_int() { return analog[2]; }
public int accnick() { return analog[3]; }
public int accroll() { return analog[4]; }
 
 
 
public MKDebugData()
{
analog=new int[32];
40,12 → 45,20
if (version.compare(0,60)==version.VERSION_PREVIOUS)
{
for (i=0;i<16;i++)
analog[i]=(in_arr[1+i*2]<<8) | in_arr[2+i*2];
{
analog[i]=(int)((in_arr[1+i*2]<<8) | in_arr[2+i*2]);
if ((analog[i]&(2<<14))!=0)
analog[i]=-(analog[i]&(0xFFFF-1))^(0xFFFF-1);
}
}
else
{
for (i=0;i<16;i++)
analog[i]=(in_arr[17+i*2]<<8) | in_arr[18+i*2];
{
analog[i]=(int)((in_arr[17+i*2]<<8) | in_arr[18+i*2]);
if ((analog[i]&(2<<14))!=0)
analog[i]=-(analog[i]&(0xFFFF-1))^(0xFFFF-1);
}
}
 
motor_complete=motor_val(0)+motor_val(1)+motor_val(2)+motor_val(3);
/branches/ligi_j2me/src/MKMiniCanvas.java
12,6 → 12,7
import javax.microedition.lcdui.*;
import javax.microedition.rms.*;
 
 
public class MKMiniCanvas
extends Canvas
implements Runnable
24,10 → 25,57
private String err="";
private MKMiniMidlet root;
 
private Image bg_img;
private Image bt_img;
private Image lcd_img;
private Image load_img;
 
 
public int[] nick_line_pos_data;
public int[] roll_line_pos_data;
 
public int[] accnick_line_pos_data;
public int[] accroll_line_pos_data;
 
 
public int frame_pos=0;
int line_scaler=20;
 
public int line_middle_y;
 
public MKMiniCanvas(MKMiniMidlet _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();
}
 
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;
}
// mk = new MKCommunicator("btspp://000BCE016B5B:1");
//connect_mk("btspp://000BCE016B4F:1");
 
57,8 → 105,11
 
boolean quit=false;
boolean rescan=true;
int bg_offset=0;
 
 
/********************************************************** Thread ***********************************************************/
// ticking runnable Section
public void run()
69,9 → 120,28
long loopStartTime = System.currentTimeMillis();
long sleeptime=0;
// ticked thing
frame_pos++;
 
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();
}
catch (Exception e)
{
err+=e.toString();
}
 
 
if (quit)
{
 
 
try
{
RecordStore recStore = RecordStore.openRecordStore("bturl", true );
91,13 → 161,15
}
if (rescan)
{
if (mk!=null) mk.close_connections();
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
126,27 → 198,59
 
int local_max=-1;
 
// drawing section
public void paint(Graphics g) {
 
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);
 
g.setColor(0x000000);
if (mk==null)
{
if (bt_scanner.searching)
g.drawString("scanning for BT-Devices",0,0,Graphics.TOP | Graphics.LEFT);
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);
 
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.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;
154,23 → 258,14
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;
for ( int foo=0;foo<4;foo++)
{
g.drawString(mk.LCD.LCD_str[foo],0,y_off,Graphics.TOP | Graphics.LEFT);
y_off+=spacer;
}
try {
g.drawString("motor1:"+mk.debug_data.analog[12],0,y_off,Graphics.TOP | Graphics.LEFT);
 
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("motor2:"+mk.debug_data.analog[13],0,y_off,Graphics.TOP | Graphics.LEFT);
 
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("motor3:"+mk.debug_data.analog[14],0,y_off,Graphics.TOP | Graphics.LEFT);
y_off+=spacer;
g.drawString("motor4:"+mk.debug_data.analog[15],0,y_off,Graphics.TOP | Graphics.LEFT);
y_off+=spacer;
}
catch (Exception e) { }
 
if (mk.connected)
{
g.drawString("time conn:" +((System.currentTimeMillis()- mk.connection_start_time)/1000)+"s" ,0,y_off,Graphics.TOP | Graphics.LEFT);
180,8 → 275,53
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;
 
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);
 
}
y_off+=19;
 
 
}
 
g.setClip(0,0,this.getWidth(),this.getHeight());
 
 
 
}
// draw lines
 
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);
 
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);
 
}
}
 
private void connect_mk(String url)
188,10 → 328,22
{
mk = new MKCommunicator(url);
mk_stat= new MKStatistics(mk);
 
}
 
public void draw_graph_part(Graphics g,int x,int y1,int y2)
{
g.fillRect(x,line_middle_y-y1,2,2 );
if (y1>y2)
g.fillRect(x,line_middle_y-y1,2,y1-y2);
else
g.fillRect(x,line_middle_y-y2,2,y2-y1);
}
 
/*********************************************** input Section **********************************************/
// keys
public boolean fullscreen=false;
 
public void keyPressed(int keyCode)
{
201,6 → 353,7
{
switch (keyCode)
{
case KEY_STAR:
mk.other_data_count=23;
quit=true;
207,7 → 360,9
break;
 
case KEY_POUND:
rescan=true;
//rescan=true;
fullscreen=!fullscreen;
setFullScreenMode(fullscreen);
break;
}
switch (getGameAction (keyCode))
/branches/ligi_j2me/src/MKStatistics.java
27,7 → 27,7
 
 
 
private long last_run_ms=-1;
private long last_run_ms=0;
private long last_step=-1;
 
public void run()
37,10 → 37,11
if (mk.connected)
{
last_step=System.currentTimeMillis()-last_run_ms;
 
if (last_run_ms!=-1)
if (last_run_ms!=0)
{
last_step=System.currentTimeMillis()-last_run_ms;
 
if (mk.debug_data.motor_complete>0)
motor_sum+=mk.debug_data.motor_complete;
49,6 → 50,7
if (mk.debug_data.motor_complete==60)
motor_stand_time+=last_step;
}
last_run_ms=System.currentTimeMillis();
}
/branches/ligi_j2me/src/MKWatchDog.java
0,0 → 1,53
/**********************************************************************************************************************************
* Statistics from MK-Connection ( needed for 2. Thread and Readability of Code ) *
* *
* Author: Marcus -LiGi- Bueschleb *
* Project-Start: 9/2007 *
* Version: 0.07 *
* Mailto: ligi@smart4mobile.de *
* Licence: Creative Commons / Non Commercial *
* Big Up: Holger&Ingo *
*********************************************************************************************************************************/
 
public class MKWatchDog
implements Runnable
{
 
MKCommunicator mk=null;
 
int debug_data_count_buff=-123;
 
public MKWatchDog(MKCommunicator _mk)
{
mk=_mk;
new Thread( this ).start(); // fire up main Thread
}
 
public void run()
{
while(true)
{
try { Thread.sleep(1500); }
catch (Exception e) { }
if (mk.connected)
{
if (debug_data_count_buff==mk.debug_data_count)
mk.close_connections(false);
debug_data_count_buff=mk.debug_data_count;
if (mk.version.major==-1)
mk.get_version();
if (mk.lcd_data_count==0)
mk.LCD.trigger_LCD();
}
else
{
}
 
}
}
 
}