Rev 483 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
475 | ligi | 1 | |
231 | ligi | 2 | /*************************************************************** |
3 | * |
||
4 | * minimal canvas to test Abstraction layer on various Phones |
||
5 | * |
||
6 | * Author: Marcus -LiGi- Bueschleb |
||
403 | ligi | 7 | * |
8 | * see README for further Infos |
||
9 | * |
||
231 | ligi | 10 | ***************************************************************/ |
181 | ligi | 11 | |
12 | import javax.microedition.lcdui.*; |
||
208 | ligi | 13 | import javax.microedition.rms.*; |
181 | ligi | 14 | |
221 | ligi | 15 | |
181 | ligi | 16 | public class MKMiniCanvas |
231 | ligi | 17 | extends Canvas |
18 | implements Runnable |
||
181 | ligi | 19 | { |
20 | |||
390 | ligi | 21 | // name/handle for the recordStore to memorize some stuff |
303 | ligi | 22 | private final static String RECORD_STORE_NAME="bluetoothurl"; |
181 | ligi | 23 | |
208 | ligi | 24 | private BTSearcher bt_scanner; |
303 | ligi | 25 | public MKCommunicator mk=null; |
208 | ligi | 26 | private MKStatistics mk_stat=null; |
303 | ligi | 27 | private MKParamsEditor params_editor=null; |
28 | |||
29 | |||
208 | ligi | 30 | private String err=""; |
303 | ligi | 31 | private DUBwise root; |
181 | ligi | 32 | |
221 | ligi | 33 | private Image bg_img; |
34 | private Image bt_img; |
||
35 | private Image lcd_img; |
||
36 | private Image load_img; |
||
37 | |||
38 | |||
39 | public int[] nick_line_pos_data; |
||
40 | public int[] roll_line_pos_data; |
||
41 | |||
42 | public int[] accnick_line_pos_data; |
||
43 | public int[] accroll_line_pos_data; |
||
44 | |||
303 | ligi | 45 | public int lcd_char_width=0; |
46 | public int lcd_char_height=0; |
||
221 | ligi | 47 | |
48 | public int frame_pos=0; |
||
49 | |||
50 | int line_scaler=20; |
||
51 | |||
52 | public int line_middle_y; |
||
53 | |||
303 | ligi | 54 | boolean quit=false; |
55 | boolean rescan=true; |
||
56 | int bg_offset=0; |
||
57 | |||
390 | ligi | 58 | // variable to hold the current state |
303 | ligi | 59 | public int state=-1; |
390 | ligi | 60 | |
61 | // id for each state - must just be uniq - order isnt important |
||
314 | ligi | 62 | public final static int STATEID_SCANNING =0; |
63 | public final static int STATEID_DEVICESELECT =1; |
||
64 | public final static int STATEID_MAINMENU =2; |
||
65 | public final static int STATEID_MOTORTEST =3; |
||
66 | public final static int STATEID_SELECT_PARAMSET =4; |
||
67 | public final static int STATEID_EDIT_PARAMS =5; |
||
68 | public final static int STATEID_HANDLE_PARAMS =6; |
||
69 | public final static int STATEID_FLIGHTVIEW =7; |
||
475 | ligi | 70 | public final static int STATEID_RAWDEBUG =8; |
71 | // public final static int STATEID_RAWDEBUG =8; |
||
72 | public final static int STATEID_KEYCONTROL =9; |
||
303 | ligi | 73 | |
314 | ligi | 74 | |
75 | public boolean fullscreen=false; |
||
76 | public int act_motor=0; |
||
77 | public int act_motor_increase=0; |
||
78 | public boolean motor_test_sel_all=false; |
||
79 | |||
475 | ligi | 80 | public String[] main_menu_items={"Telemetry","Raw Debug", "MK-KeyControl", "Motor Test" , "Flight Settings","(NA)Tool Settings","Proxy","Change Device" , "Quit " }; |
314 | ligi | 81 | public final static int MAINMENU_TELEMETRY =0; |
475 | ligi | 82 | public final static int MAINMENU_RAWDEBUG =1+MAINMENU_TELEMETRY; |
83 | public final static int MAINMENU_KEYCONTROL =1+MAINMENU_RAWDEBUG; |
||
84 | public final static int MAINMENU_MOTORTEST =1+MAINMENU_KEYCONTROL; |
||
85 | public final static int MAINMENU_PARAMS =1+MAINMENU_MOTORTEST; |
||
86 | public final static int MAINMENU_SETTINGS =1+MAINMENU_PARAMS; |
||
87 | public final static int MAINMENU_PROXY =1+MAINMENU_SETTINGS; |
||
88 | public final static int MAINMENU_DEVICESELECT =1+MAINMENU_PROXY; |
||
89 | public final static int MAINMENU_QUIT =1+MAINMENU_DEVICESELECT; |
||
303 | ligi | 90 | |
91 | int local_max=-1; |
||
92 | |||
93 | int y_off=0; |
||
94 | int spacer=0; |
||
475 | ligi | 95 | int spacer1=0; |
96 | |||
303 | ligi | 97 | int[] motor_test = {0,0,0,0}; |
98 | |||
99 | |||
100 | String[] menu_items; |
||
101 | int act_menu_select=0; |
||
102 | |||
103 | String[] lcd_lines =null; |
||
104 | |||
105 | public void paint_menu(Graphics g) |
||
231 | ligi | 106 | { |
303 | ligi | 107 | for ( int i=0;i<menu_items.length;i++) |
108 | lcd_lines[i]=(act_menu_select==i?"# ":" ") + menu_items[i]; |
||
109 | paint_lcd(g,true); |
||
110 | } |
||
221 | ligi | 111 | |
303 | ligi | 112 | public void menu_keypress(int keyCode) |
113 | { |
||
114 | switch (getGameAction (keyCode)) |
||
115 | { |
||
116 | case UP: |
||
117 | if (act_menu_select!=0) act_menu_select--; |
||
390 | ligi | 118 | else |
119 | act_menu_select=menu_items.length-1; |
||
303 | ligi | 120 | break; |
121 | |||
122 | case DOWN: |
||
123 | if (act_menu_select<(menu_items.length-1)) act_menu_select++; |
||
390 | ligi | 124 | else act_menu_select=0; |
303 | ligi | 125 | break; |
126 | |||
127 | } |
||
128 | |||
129 | } |
||
130 | |||
131 | public void paint_lcd(Graphics g,boolean bottomup) |
||
132 | { |
||
403 | ligi | 133 | |
303 | ligi | 134 | int y; |
135 | |||
136 | for(int i=0;i<lcd_lines.length;i++) |
||
137 | for (int pos=0;pos<20;pos++) |
||
138 | { |
||
139 | if (bottomup) |
||
140 | y=this.getHeight()-(lcd_lines.length-i)*lcd_char_height; |
||
141 | else |
||
142 | y=i*lcd_char_height; |
||
143 | g.setClip((lcd_img.getWidth()/222)*pos,y,(lcd_img.getWidth()/222),lcd_img.getHeight()); |
||
144 | g.drawImage(lcd_img,(lcd_img.getWidth()/222)*pos-((pos<lcd_lines[i].length()?lcd_lines[i].charAt(pos):' ')-' ')*(lcd_img.getWidth()/222),y,g.TOP | g.LEFT); |
||
145 | |||
146 | } |
||
147 | } |
||
148 | |||
149 | public MKMiniCanvas(DUBwise _root) |
||
150 | { |
||
151 | |||
231 | ligi | 152 | root=_root; |
181 | ligi | 153 | |
303 | ligi | 154 | bt_scanner = new BTSearcher(); |
155 | params_editor = new MKParamsEditor(this); |
||
156 | mk = new MKCommunicator(); |
||
157 | mk_stat= new MKStatistics(mk); |
||
158 | |||
231 | ligi | 159 | try |
160 | { |
||
303 | ligi | 161 | // load all needed images |
231 | ligi | 162 | lcd_img=Image.createImage("/lcd.png"); |
163 | bt_img=Image.createImage("/bt.png"); |
||
485 | ligi | 164 | bg_img=Image.createImage("/starfield.jpg"); |
231 | ligi | 165 | load_img=Image.createImage("/load.png"); |
166 | } |
||
167 | catch (Exception e) |
||
168 | { |
||
169 | err+=e.toString(); |
||
170 | } |
||
303 | ligi | 171 | |
172 | lcd_char_width=lcd_img.getWidth()/222; |
||
173 | lcd_char_height=lcd_img.getHeight(); |
||
221 | ligi | 174 | |
175 | |||
231 | ligi | 176 | nick_line_pos_data=new int[bg_img.getWidth()]; |
177 | roll_line_pos_data=new int[bg_img.getWidth()]; |
||
178 | accnick_line_pos_data=new int[bg_img.getWidth()]; |
||
179 | accroll_line_pos_data=new int[bg_img.getWidth()]; |
||
221 | ligi | 180 | |
231 | ligi | 181 | for (int c=0;c<bg_img.getWidth();c++) |
182 | { |
||
183 | nick_line_pos_data[c]=-1; |
||
184 | roll_line_pos_data[c]=-1; |
||
185 | accnick_line_pos_data[c]=-1; |
||
186 | accroll_line_pos_data[c]=-1; |
||
187 | } |
||
221 | ligi | 188 | |
189 | |||
231 | ligi | 190 | try |
191 | { |
||
303 | ligi | 192 | RecordStore recStore = RecordStore.openRecordStore(RECORD_STORE_NAME , true ); |
181 | ligi | 193 | |
303 | ligi | 194 | if (recStore.getNumRecords()==2) |
208 | ligi | 195 | { |
303 | ligi | 196 | |
197 | //byte[] recData = new byte[recStore.getRecordSize(1)]; |
||
198 | //int len = recStore.getRecord(1, recData, 0); |
||
199 | |||
200 | //byte[] recData2 = new byte[recStore.getRecordSize(2)]; |
||
201 | //int len2 = recStore.getRecord(2, recData, 0); |
||
202 | |||
203 | byte[] url_data=recStore.getRecord(1); |
||
204 | byte[] name_data=recStore.getRecord(2); |
||
205 | |||
206 | connect_mk(new String(url_data, 0, url_data.length),new String(name_data, 0, name_data.length)); |
||
207 | |||
208 | ligi | 208 | } |
303 | ligi | 209 | recStore.closeRecordStore(); |
231 | ligi | 210 | } |
211 | catch (Exception e) |
||
212 | { |
||
213 | err+=e.toString(); |
||
214 | } |
||
181 | ligi | 215 | |
303 | ligi | 216 | chg_state((mk.force_disconnect)?STATEID_SCANNING:STATEID_MAINMENU); |
217 | |||
218 | |||
219 | |||
231 | ligi | 220 | new Thread(this).start(); |
181 | ligi | 221 | |
231 | ligi | 222 | } |
181 | ligi | 223 | |
224 | |||
221 | ligi | 225 | |
303 | ligi | 226 | /****************************** Thread ******************/ |
181 | ligi | 227 | // ticking runnable Section |
228 | public void run() |
||
229 | { |
||
230 | |||
303 | ligi | 231 | |
181 | ligi | 232 | while(true) |
233 | { |
||
403 | ligi | 234 | try { |
235 | |||
231 | ligi | 236 | repaint(); |
237 | serviceRepaints(); |
||
238 | |||
181 | ligi | 239 | long loopStartTime = System.currentTimeMillis(); |
240 | long sleeptime=0; |
||
241 | // ticked thing |
||
221 | ligi | 242 | |
243 | frame_pos++; |
||
244 | |||
231 | ligi | 245 | switch(state) |
246 | { |
||
483 | ligi | 247 | case STATEID_KEYCONTROL: |
248 | mk.send_keys(keycontrol_bitfield); |
||
249 | break; |
||
250 | |||
231 | ligi | 251 | case STATEID_MOTORTEST: |
252 | |||
253 | if (motor_test_sel_all) |
||
254 | for (int m=0;m<4;m++) |
||
255 | { |
||
256 | motor_test[m]+=act_motor_increase; |
||
257 | if (motor_test[m]<0)motor_test[m]=0; |
||
403 | ligi | 258 | if (motor_test[m]>255)motor_test[m]=255; |
231 | ligi | 259 | } |
260 | else |
||
261 | { |
||
262 | motor_test[act_motor]+=act_motor_increase; |
||
403 | ligi | 263 | if (motor_test[act_motor]<0) motor_test[act_motor]=0; |
264 | if (motor_test[act_motor]>255) motor_test[act_motor]=255; |
||
231 | ligi | 265 | } |
266 | |||
267 | mk.motor_test(motor_test); |
||
268 | break; |
||
303 | ligi | 269 | |
270 | case STATEID_SCANNING: |
||
390 | ligi | 271 | intro_str_delay--; |
272 | if (intro_str_delay<0) |
||
273 | { |
||
274 | intro_str_delay=1; |
||
275 | if (intro_str_pos>intro_str.length()) |
||
276 | intro_str_pos=0; |
||
277 | lcd_lines[3]=intro_str.substring(intro_str_pos, (((intro_str_pos+20)>intro_str.length())?intro_str.length():intro_str_pos+20)); |
||
278 | intro_str_pos++; |
||
279 | } |
||
280 | |||
303 | ligi | 281 | if (!bt_scanner.searching) |
282 | chg_state(STATEID_DEVICESELECT); |
||
283 | |||
390 | ligi | 284 | |
303 | ligi | 285 | break; |
286 | |||
287 | |||
288 | |||
231 | ligi | 289 | } |
290 | |||
221 | ligi | 291 | try { |
231 | ligi | 292 | nick_line_pos_data[-bg_offset] = mk.debug_data.nick_int(); |
293 | roll_line_pos_data[-bg_offset] = mk.debug_data.roll_int(); |
||
294 | accnick_line_pos_data[-bg_offset] = mk.debug_data.accnick(); |
||
295 | accroll_line_pos_data[-bg_offset] = mk.debug_data.accroll(); |
||
221 | ligi | 296 | } |
297 | catch (Exception e) |
||
298 | { |
||
299 | err+=e.toString(); |
||
300 | } |
||
301 | |||
181 | ligi | 302 | |
221 | ligi | 303 | |
304 | |||
208 | ligi | 305 | if (quit) |
306 | { |
||
221 | ligi | 307 | |
308 | |||
309 | |||
208 | ligi | 310 | try |
311 | { |
||
303 | ligi | 312 | RecordStore.deleteRecordStore(RECORD_STORE_NAME); |
313 | RecordStore recStore = RecordStore.openRecordStore(RECORD_STORE_NAME, true ); |
||
314 | recStore.addRecord(mk.mk_url.getBytes(), 0, mk.mk_url.getBytes().length); |
||
315 | recStore.addRecord(mk.name.getBytes(), 0, mk.name.getBytes().length); |
||
316 | recStore.closeRecordStore(); |
||
208 | ligi | 317 | |
318 | } |
||
319 | catch (Exception e) |
||
320 | { |
||
321 | err+=e.toString(); |
||
322 | } |
||
323 | |||
324 | root.quit(); |
||
325 | } |
||
326 | if (rescan) |
||
327 | { |
||
303 | ligi | 328 | |
329 | rescan=false; |
||
208 | ligi | 330 | } |
331 | |||
231 | ligi | 332 | try { |
303 | ligi | 333 | //rescan=false; |
231 | ligi | 334 | bg_offset--; |
335 | if (bg_offset==-bg_img.getWidth()) |
||
336 | bg_offset=0; |
||
337 | com.nokia.mid.ui.DeviceControl.setLights(0,100); |
||
338 | //bt.tick(); |
||
339 | // every state has sth to do in tick section |
||
340 | } |
||
341 | catch (Exception e) |
||
342 | { |
||
343 | |||
344 | } |
||
181 | ligi | 345 | |
346 | |||
231 | ligi | 347 | // System.gc(); |
348 | |||
349 | |||
181 | ligi | 350 | |
351 | |||
352 | sleeptime=1000/ 15 - (int) (System.currentTimeMillis()- loopStartTime); |
||
353 | |||
403 | ligi | 354 | |
355 | |||
181 | ligi | 356 | if (sleeptime<0) |
231 | ligi | 357 | sleeptime=100; // everyone has fi sleep |
181 | ligi | 358 | |
359 | try { Thread.sleep(sleeptime); } |
||
360 | catch (Exception e) |
||
361 | { |
||
231 | ligi | 362 | err="Problem Sleeping "; |
181 | ligi | 363 | } |
364 | |||
403 | ligi | 365 | } |
366 | catch (Exception e) |
||
367 | { |
||
368 | err+=e.toString(); |
||
369 | } |
||
181 | ligi | 370 | } |
371 | } |
||
372 | |||
373 | |||
374 | |||
231 | ligi | 375 | |
181 | ligi | 376 | |
377 | // drawing section |
||
378 | public void paint(Graphics g) { |
||
303 | ligi | 379 | y_off=0; |
231 | ligi | 380 | try { |
221 | ligi | 381 | |
231 | ligi | 382 | if (mk!=null) |
383 | { |
||
384 | line_middle_y=this.getHeight()/2; |
||
385 | if (local_max<Math.abs(mk.debug_data.nick_int())) |
||
386 | local_max=Math.abs(mk.debug_data.nick_int()); |
||
387 | if (local_max<Math.abs(mk.debug_data.roll_int())) |
||
388 | local_max=Math.abs(mk.debug_data.roll_int()); |
||
389 | if (local_max<Math.abs(mk.debug_data.accnick())) |
||
390 | local_max=Math.abs(mk.debug_data.accnick()); |
||
391 | if (local_max<Math.abs(mk.debug_data.accroll())) |
||
392 | local_max=Math.abs(mk.debug_data.accroll()); |
||
393 | line_scaler= local_max/(this.getHeight()/2)+1; |
||
394 | } |
||
411 | ligi | 395 | |
221 | ligi | 396 | |
475 | ligi | 397 | Font f1 = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_MEDIUM); |
398 | Font f2 = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_SMALL); |
||
399 | |||
400 | spacer=(f1.getHeight()); |
||
401 | spacer1=(f2.getHeight()); |
||
402 | |||
403 | //default Font |
||
404 | g.setFont(f1); |
||
405 | |||
411 | ligi | 406 | if (state==STATEID_EDIT_PARAMS) |
407 | { |
||
408 | g.setColor(0x000000); |
||
409 | g.fillRect(0,0,this.getWidth(),this.getHeight()); |
||
410 | } |
||
411 | else |
||
412 | { |
||
413 | g.setColor(0xFFFFFF); |
||
414 | g.fillRect(0,0,this.getWidth(),this.getHeight()); |
||
415 | g.drawImage(bg_img,bg_offset,0, g.TOP | g.LEFT); |
||
416 | |||
417 | if (bg_offset+bg_img.getWidth()<this.getWidth()) |
||
418 | g.drawImage(bg_img,bg_offset+bg_img.getWidth(),0, g.TOP | g.LEFT); |
||
419 | } |
||
231 | ligi | 420 | |
303 | ligi | 421 | g.setColor(0x000000); |
485 | ligi | 422 | g.setColor(0x2dcf20); |
231 | ligi | 423 | switch(state) |
424 | { |
||
475 | ligi | 425 | case STATEID_KEYCONTROL: |
485 | ligi | 426 | |
427 | |||
428 | y_off+=spacer; |
||
429 | g.drawString("UP&DOWN => nick",0,y_off,Graphics.TOP | Graphics.LEFT); |
||
430 | y_off+=spacer; |
||
431 | g.drawString("LEFT&RIGHT => roll",0,y_off,Graphics.TOP | Graphics.LEFT); |
||
432 | y_off+=spacer; |
||
433 | g.drawString("1&4 => altitude",0,y_off,Graphics.TOP | Graphics.LEFT); |
||
434 | |||
435 | y_off+=spacer; |
||
436 | g.drawString("2&3 => gier",0,y_off,Graphics.TOP | Graphics.LEFT); |
||
437 | |||
438 | y_off+=spacer; |
||
439 | g.drawString("Press # and * at once",0,y_off,Graphics.TOP | Graphics.LEFT); |
||
440 | y_off+=spacer; |
||
441 | g.drawString("to quit KeyControl",0,y_off,Graphics.TOP | Graphics.LEFT); |
||
442 | y_off+=spacer; |
||
443 | g.drawString("bf1:"+ keycontrol_bitfield[0] ,0,y_off,Graphics.TOP | Graphics.LEFT); |
||
444 | g.drawString("bf2:"+ keycontrol_bitfield[1] ,this.getWidth()/2,y_off,Graphics.TOP | Graphics.LEFT); |
||
445 | |||
475 | ligi | 446 | break; |
447 | |||
231 | ligi | 448 | case STATEID_MOTORTEST: |
449 | for (int bar=0;bar<4;bar++) |
||
475 | ligi | 450 | |
231 | ligi | 451 | { |
452 | g.setColor(((bar==act_motor)|motor_test_sel_all)?0x44CC44:0x4444DD); |
||
453 | g.fillRect(this.getWidth()/(8*2)+bar*2*this.getWidth()/8,10,this.getWidth()/8,20+motor_test[bar]); |
||
454 | g.setColor(0x000000); |
||
455 | g.drawString(""+motor_test[bar] ,this.getWidth()/8+bar*2*this.getWidth()/8,10,Graphics.TOP | Graphics.HCENTER); |
||
456 | if(bar!=4) g.drawString(""+mk.debug_data.motor_val(bar) ,this.getWidth()/8+bar*2*this.getWidth()/8,30,Graphics.TOP | Graphics.HCENTER); |
||
457 | } |
||
458 | break; |
||
459 | |||
303 | ligi | 460 | case STATEID_EDIT_PARAMS: |
461 | params_editor.paint(g); |
||
462 | break; |
||
221 | ligi | 463 | |
303 | ligi | 464 | case STATEID_SCANNING: |
465 | paint_lcd(g,true); |
||
466 | |||
485 | ligi | 467 | g.setClip(this.getWidth()/2-load_img.getWidth()/6+1,this.getHeight()/2-load_img.getHeight()/8+1, load_img.getWidth()/4,load_img.getHeight()/3);; |
303 | ligi | 468 | 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); |
469 | g.drawImage(bt_img,this.getWidth()/2 ,this.getHeight()/2 , g.HCENTER | g.VCENTER); |
||
470 | break; |
||
475 | ligi | 471 | |
472 | case STATEID_RAWDEBUG: |
||
473 | g.setFont(f2); |
||
474 | for (int i=0;i<16;i++) |
||
475 | { |
||
476 | g.drawString("#"+i+"->" + mk.debug_data.analog[i] ,0,y_off,Graphics.TOP | Graphics.LEFT); |
||
477 | g.drawString("#"+(16+i)+"->" + mk.debug_data.analog[16+i] ,this.getWidth()/2,y_off,Graphics.TOP | Graphics.LEFT); |
||
478 | y_off+=spacer1; |
||
479 | } |
||
480 | |||
481 | |||
482 | |||
483 | break; |
||
484 | |||
221 | ligi | 485 | |
303 | ligi | 486 | case STATEID_MAINMENU: |
487 | g.drawString("MK-Connection(" + (mk.connected?("open"+((System.currentTimeMillis()- mk.connection_start_time)/1000)+"s"):"close")+"):",0,y_off,Graphics.TOP | Graphics.LEFT); |
||
488 | y_off+=spacer; |
||
475 | ligi | 489 | g.setFont(f2); |
303 | ligi | 490 | g.drawString(" Name:" + mk.name,0,y_off,Graphics.TOP | Graphics.LEFT); |
475 | ligi | 491 | y_off+=spacer1; |
303 | ligi | 492 | g.drawString(" URL:" + mk.mk_url,0,y_off,Graphics.TOP | Graphics.LEFT); |
475 | ligi | 493 | y_off+=spacer1; |
303 | ligi | 494 | g.drawString(" Version:" + mk.version.str,0,y_off,Graphics.TOP | Graphics.LEFT); |
475 | ligi | 495 | y_off+=spacer1; |
496 | |||
497 | g.setFont(f1); |
||
498 | g.drawString("Packet Traffic:",0,y_off,Graphics.TOP | Graphics.LEFT); |
||
303 | ligi | 499 | y_off+=spacer; |
475 | ligi | 500 | g.setFont(f2); |
303 | ligi | 501 | g.drawString( " debug:"+mk.debug_data_count+ " LCD:" + mk.lcd_data_count + " vers:" + mk.version_data_count,0,y_off,Graphics.TOP | Graphics.LEFT); |
475 | ligi | 502 | y_off+=spacer1; |
303 | ligi | 503 | g.drawString( " other:"+mk.other_data_count+" params:"+mk.params_data_count,0,y_off,Graphics.TOP | Graphics.LEFT); |
221 | ligi | 504 | |
505 | |||
506 | |||
507 | |||
303 | ligi | 508 | // falltru wanted |
509 | case STATEID_SELECT_PARAMSET: |
||
325 | ligi | 510 | case STATEID_HANDLE_PARAMS: |
303 | ligi | 511 | |
512 | case STATEID_DEVICESELECT: |
||
513 | paint_menu(g); |
||
514 | break; |
||
515 | |||
516 | case STATEID_FLIGHTVIEW: |
||
517 | |||
475 | ligi | 518 | |
519 | // !!TODO!! check exactly which version those Datas where introduced |
||
520 | if (mk.version.compare(0,60)==mk.version.VERSION_PREVIOUS) |
||
521 | { |
||
522 | g.drawString("Power: " + (mk.debug_data.UBatt()/10) + "," +(mk.debug_data.UBatt()%10)+"V" ,0,y_off,Graphics.TOP | Graphics.LEFT); |
||
523 | g.drawString("Sender: " + mk.debug_data.SenderOkay(),this.getWidth()/2,y_off,Graphics.TOP | Graphics.LEFT); |
||
524 | y_off+=spacer; |
||
525 | } |
||
526 | |||
303 | ligi | 527 | 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+"p"+mk.params_data_count+")",0,y_off,Graphics.TOP | Graphics.LEFT); |
221 | ligi | 528 | |
303 | ligi | 529 | y_off+=spacer; |
221 | ligi | 530 | |
303 | ligi | 531 | 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); |
532 | y_off+=spacer; |
||
533 | |||
534 | |||
535 | 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); |
||
536 | y_off+=spacer; |
||
537 | |||
538 | if (mk.connected) |
||
539 | { |
||
540 | g.drawString("time conn:" +((System.currentTimeMillis()- mk.connection_start_time)/1000)+"s" ,0,y_off,Graphics.TOP | Graphics.LEFT); |
||
231 | ligi | 541 | y_off+=spacer; |
303 | ligi | 542 | g.drawString("time motor>15:" +(mk_stat.motor_on_time/1000) +"s" ,0,y_off,Graphics.TOP | Graphics.LEFT); |
231 | ligi | 543 | y_off+=spacer; |
303 | ligi | 544 | g.drawString("time motor=15:" +(mk_stat.motor_stand_time/1000) +"s" ,0,y_off,Graphics.TOP | Graphics.LEFT); |
545 | } |
||
221 | ligi | 546 | |
547 | |||
303 | ligi | 548 | y_off=this.getHeight()-4*lcd_img.getHeight(); |
549 | |||
550 | for ( int foo=0;foo<4;foo++) |
||
551 | { |
||
552 | for (int x=0;x<20;x++) |
||
231 | ligi | 553 | { |
303 | ligi | 554 | g.setClip((lcd_img.getWidth()/222)*x,y_off,(lcd_img.getWidth()/222),lcd_img.getHeight()); |
231 | ligi | 555 | 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); |
221 | ligi | 556 | |
231 | ligi | 557 | } |
558 | y_off+=lcd_img.getHeight(); |
||
559 | } |
||
221 | ligi | 560 | |
231 | ligi | 561 | g.setClip(0,0,this.getWidth(),this.getHeight()); |
221 | ligi | 562 | |
563 | |||
564 | |||
565 | |||
303 | ligi | 566 | |
231 | ligi | 567 | // draw lines |
221 | ligi | 568 | |
231 | ligi | 569 | for ( int x=0;x<this.getWidth();x++) |
221 | ligi | 570 | |
231 | ligi | 571 | { |
221 | ligi | 572 | |
231 | ligi | 573 | int p= (((-bg_offset+x-this.getWidth()-5))); |
574 | if (p<1) |
||
575 | p+=bg_img.getWidth(); |
||
576 | p%=(bg_img.getWidth()-1); |
||
221 | ligi | 577 | |
231 | ligi | 578 | g.setColor(0x156315); |
579 | draw_graph_part(g,x,nick_line_pos_data[p]/line_scaler,nick_line_pos_data[p+1]/line_scaler); |
||
580 | g.setColor(0xCC1315); |
||
581 | draw_graph_part(g,x,roll_line_pos_data[p]/line_scaler,roll_line_pos_data[p+1]/line_scaler); |
||
582 | g.setColor(0xf8ef02); |
||
583 | draw_graph_part(g,x,accnick_line_pos_data[p]/line_scaler,accnick_line_pos_data[p+1]/line_scaler); |
||
584 | g.setColor(0x19194d); |
||
585 | draw_graph_part(g,x,accroll_line_pos_data[p]/line_scaler,accroll_line_pos_data[p+1]/line_scaler); |
||
221 | ligi | 586 | |
587 | |||
181 | ligi | 588 | |
231 | ligi | 589 | } |
590 | |||
591 | } |
||
592 | |||
303 | ligi | 593 | |
594 | |||
231 | ligi | 595 | } catch (Exception e) {} |
181 | ligi | 596 | } |
597 | |||
303 | ligi | 598 | private void connect_mk(String url,String name) |
208 | ligi | 599 | { |
303 | ligi | 600 | mk.connect_to(url,name); |
221 | ligi | 601 | |
208 | ligi | 602 | } |
603 | |||
221 | ligi | 604 | public void draw_graph_part(Graphics g,int x,int y1,int y2) |
605 | { |
||
606 | g.fillRect(x,line_middle_y-y1,2,2 ); |
||
607 | if (y1>y2) |
||
608 | g.fillRect(x,line_middle_y-y1,2,y1-y2); |
||
609 | else |
||
610 | g.fillRect(x,line_middle_y-y2,2,y2-y1); |
||
611 | } |
||
612 | |||
181 | ligi | 613 | /*********************************************** input Section **********************************************/ |
221 | ligi | 614 | |
314 | ligi | 615 | |
475 | ligi | 616 | public final String intro_str=" Digital Ufo Broadcasting with intelligent service equipment by Marcus -LiGi- Bueschleb ; Big Up Holger&Ingo for the MikroKopter Project (http://www.mikrokopter.de) "; |
314 | ligi | 617 | |
390 | ligi | 618 | int intro_str_pos=0; |
619 | int intro_str_delay=3; |
||
620 | |||
303 | ligi | 621 | public void chg_state(int next_state) |
231 | ligi | 622 | { |
303 | ligi | 623 | act_menu_select=0; |
624 | // prepare next state |
||
625 | switch(next_state) |
||
626 | { |
||
485 | ligi | 627 | case STATEID_KEYCONTROL: |
628 | keycontrol_exit=0; |
||
629 | break; |
||
630 | |||
303 | ligi | 631 | case STATEID_SCANNING: |
390 | ligi | 632 | lcd_lines=new String[4]; |
303 | ligi | 633 | lcd_lines[0]="Scanning for Devices"; |
634 | lcd_lines[1]=" "; |
||
475 | ligi | 635 | |
636 | //#expand lcd_lines[2]="DUBwise v%VERSION% "; |
||
390 | ligi | 637 | lcd_lines[3]=intro_str.substring(0,20); |
303 | ligi | 638 | mk.close_connections(true); |
639 | |||
640 | bt_scanner.search(); |
||
641 | break; |
||
642 | |||
325 | ligi | 643 | case STATEID_HANDLE_PARAMS: |
644 | menu_items=new String[2]; |
||
645 | menu_items[0]="write to MK"; |
||
646 | menu_items[1]="Discard"; |
||
647 | lcd_lines=new String[2]; |
||
648 | |||
649 | break; |
||
650 | |||
303 | ligi | 651 | case STATEID_SELECT_PARAMSET: |
652 | menu_items=new String[5]; |
||
314 | ligi | 653 | for (int i=0;i<5;i++) |
654 | menu_items[i]=mk.params.names[i]; |
||
655 | |||
303 | ligi | 656 | lcd_lines=new String[5]; |
657 | break; |
||
658 | |||
659 | case STATEID_DEVICESELECT: |
||
390 | ligi | 660 | menu_items=new String[bt_scanner.remote_device_count+1]; |
303 | ligi | 661 | for (int i=0;i<bt_scanner.remote_device_count;i++) |
662 | menu_items[i]=bt_scanner.remote_device_name[i]; |
||
390 | ligi | 663 | menu_items[bt_scanner.remote_device_count]="scan again"; |
664 | lcd_lines=new String[bt_scanner.remote_device_count+1]; |
||
303 | ligi | 665 | break; |
666 | |||
667 | case STATEID_MAINMENU: |
||
668 | menu_items=main_menu_items; |
||
669 | lcd_lines=new String[menu_items.length]; |
||
670 | break; |
||
671 | |||
672 | } |
||
673 | |||
674 | // switch state |
||
675 | state=next_state; |
||
231 | ligi | 676 | } |
677 | |||
678 | |||
679 | public void keyReleased(int keyCode) |
||
680 | { |
||
681 | |||
682 | switch(state) |
||
683 | { |
||
684 | case STATEID_MOTORTEST: |
||
685 | act_motor_increase=0; |
||
686 | break; |
||
475 | ligi | 687 | |
688 | case STATEID_KEYCONTROL: |
||
485 | ligi | 689 | if (keyCode==KEY_POUND) |
690 | keycontrol_exit &= 255^1; |
||
691 | else |
||
692 | if (keyCode==KEY_STAR) |
||
693 | keycontrol_exit &= 255^2; |
||
694 | else |
||
475 | ligi | 695 | if ((keyCode >= this.KEY_NUM0) && (keyCode < this.KEY_NUM8)) |
696 | keycontrol_bitfield[0]&=255^( 1<<(keyCode-this.KEY_NUM0)); |
||
697 | else |
||
698 | if ((keyCode >= this.KEY_NUM8) && (keyCode <= this.KEY_NUM9)) |
||
699 | keycontrol_bitfield[1]&=255^( 1<<(keyCode-this.KEY_NUM8)); |
||
700 | else |
||
701 | switch (getGameAction (keyCode)) |
||
702 | { |
||
703 | case UP: |
||
704 | keycontrol_bitfield[1]&=255^4; |
||
705 | break; |
||
706 | |||
707 | case DOWN: |
||
708 | keycontrol_bitfield[1]&=255^8; |
||
709 | break; |
||
710 | |||
711 | |||
712 | case LEFT: |
||
713 | keycontrol_bitfield[1]&=255^16; |
||
714 | break; |
||
715 | |||
716 | case RIGHT: |
||
717 | keycontrol_bitfield[1]&=255^32; |
||
718 | break; |
||
719 | |||
720 | case FIRE: |
||
721 | keycontrol_bitfield[1]&=255^64; |
||
722 | break; |
||
723 | |||
724 | |||
725 | } |
||
726 | mk.send_keys(keycontrol_bitfield); |
||
727 | break; |
||
231 | ligi | 728 | } |
729 | |||
730 | } |
||
731 | |||
475 | ligi | 732 | |
485 | ligi | 733 | byte keycontrol_exit=0; |
734 | |||
475 | ligi | 735 | public final static int[] keycontrol_bitfield={0,0}; |
736 | |||
181 | ligi | 737 | public void keyPressed(int keyCode) |
738 | { |
||
485 | ligi | 739 | |
303 | ligi | 740 | if (keyCode==KEY_STAR) |
741 | { |
||
325 | ligi | 742 | if (state==STATEID_EDIT_PARAMS) |
485 | ligi | 743 | { |
744 | chg_state(STATEID_HANDLE_PARAMS); |
||
745 | return; |
||
746 | } |
||
325 | ligi | 747 | else |
485 | ligi | 748 | if (state!=STATEID_KEYCONTROL) |
749 | { |
||
750 | chg_state(STATEID_MAINMENU); |
||
751 | return; |
||
752 | } |
||
753 | |||
303 | ligi | 754 | } |
485 | ligi | 755 | if ((keyCode==KEY_POUND)&&(state!=STATEID_KEYCONTROL)) |
303 | ligi | 756 | { |
757 | fullscreen=!fullscreen; |
||
758 | setFullScreenMode(fullscreen); |
||
759 | return; |
||
760 | } |
||
231 | ligi | 761 | switch(state) |
208 | ligi | 762 | { |
475 | ligi | 763 | case STATEID_KEYCONTROL: |
485 | ligi | 764 | if (keyCode==KEY_POUND) |
765 | keycontrol_exit |= 1; |
||
766 | else |
||
767 | if (keyCode==KEY_STAR) |
||
768 | keycontrol_exit |= 2; |
||
769 | else |
||
475 | ligi | 770 | if ((keyCode >= this.KEY_NUM0) && (keyCode < this.KEY_NUM8)) |
771 | keycontrol_bitfield[0]|=1<<(keyCode-this.KEY_NUM0); |
||
772 | else |
||
773 | if ((keyCode >= this.KEY_NUM8) && (keyCode <= this.KEY_NUM9)) |
||
774 | keycontrol_bitfield[1]|=1<<(keyCode-this.KEY_NUM8); |
||
775 | |||
776 | else |
||
777 | switch (getGameAction (keyCode)) |
||
778 | { |
||
779 | case UP: |
||
780 | keycontrol_bitfield[1]|=4; |
||
781 | break; |
||
782 | |||
783 | case DOWN: |
||
784 | keycontrol_bitfield[1]|=8; |
||
785 | break; |
||
786 | |||
787 | |||
788 | case LEFT: |
||
789 | keycontrol_bitfield[1]|=16; |
||
790 | break; |
||
791 | |||
792 | case RIGHT: |
||
793 | keycontrol_bitfield[1]|=32; |
||
794 | break; |
||
795 | |||
796 | case FIRE: |
||
797 | keycontrol_bitfield[1]|=64; |
||
798 | break; |
||
485 | ligi | 799 | |
475 | ligi | 800 | } |
485 | ligi | 801 | if (keycontrol_exit==3) |
802 | chg_state(STATEID_MAINMENU); |
||
803 | else |
||
804 | mk.send_keys(keycontrol_bitfield); |
||
475 | ligi | 805 | break; |
806 | |||
807 | |||
231 | ligi | 808 | case STATEID_MOTORTEST: |
809 | switch (getGameAction (keyCode)) |
||
810 | { |
||
811 | case UP: |
||
812 | act_motor_increase=-1; |
||
813 | break; |
||
221 | ligi | 814 | |
231 | ligi | 815 | case DOWN: |
816 | act_motor_increase=1; |
||
817 | break; |
||
208 | ligi | 818 | |
231 | ligi | 819 | case FIRE: |
820 | motor_test_sel_all=!motor_test_sel_all; |
||
821 | break; |
||
822 | |||
823 | case LEFT: |
||
824 | act_motor--; |
||
303 | ligi | 825 | if (act_motor<0) {act_motor=0; chg_state(STATEID_MAINMENU); } |
231 | ligi | 826 | break; |
827 | |||
828 | case RIGHT: |
||
829 | act_motor++; |
||
830 | act_motor%=4; |
||
831 | break; |
||
832 | } |
||
833 | |||
834 | break; |
||
325 | ligi | 835 | case STATEID_HANDLE_PARAMS: |
836 | if ( getGameAction (keyCode)==FIRE ) |
||
837 | switch(act_menu_select) |
||
838 | { |
||
839 | case 0: |
||
840 | mk.write_params(); |
||
841 | default: |
||
842 | chg_state(STATEID_MAINMENU); |
||
843 | } |
||
844 | else |
||
845 | menu_keypress(keyCode); |
||
846 | break; |
||
303 | ligi | 847 | case STATEID_MAINMENU: |
848 | if ( getGameAction (keyCode)==FIRE ) |
||
849 | switch(act_menu_select) |
||
850 | { |
||
475 | ligi | 851 | case MAINMENU_KEYCONTROL: |
852 | chg_state(STATEID_KEYCONTROL); |
||
853 | break; |
||
854 | |||
314 | ligi | 855 | case MAINMENU_TELEMETRY : |
303 | ligi | 856 | chg_state(STATEID_FLIGHTVIEW); |
857 | break; |
||
231 | ligi | 858 | |
475 | ligi | 859 | case MAINMENU_MOTORTEST : |
303 | ligi | 860 | chg_state(STATEID_MOTORTEST); |
861 | break; |
||
862 | |||
314 | ligi | 863 | case MAINMENU_PARAMS : |
303 | ligi | 864 | chg_state(STATEID_SELECT_PARAMSET); |
865 | break; |
||
314 | ligi | 866 | case MAINMENU_SETTINGS: |
303 | ligi | 867 | break; |
475 | ligi | 868 | |
314 | ligi | 869 | case MAINMENU_PROXY: |
870 | mk.do_proxy("socket://192.168.1.42:2323"); |
||
871 | break; |
||
303 | ligi | 872 | |
314 | ligi | 873 | case MAINMENU_DEVICESELECT: |
303 | ligi | 874 | chg_state(STATEID_SCANNING); |
875 | break; |
||
876 | |||
475 | ligi | 877 | case MAINMENU_RAWDEBUG: |
878 | chg_state(STATEID_RAWDEBUG); |
||
879 | break; |
||
880 | |||
881 | case MAINMENU_QUIT: |
||
882 | // set quit Flag |
||
303 | ligi | 883 | quit=true; |
884 | break; |
||
885 | |||
886 | } |
||
887 | else menu_keypress(keyCode); |
||
888 | break; |
||
889 | |||
890 | case STATEID_SELECT_PARAMSET: |
||
891 | if ( getGameAction (keyCode)==FIRE ) |
||
892 | { |
||
314 | ligi | 893 | mk.params.act_paramset=act_menu_select; |
303 | ligi | 894 | chg_state(STATEID_EDIT_PARAMS); |
895 | } |
||
896 | else menu_keypress(keyCode); |
||
897 | break; |
||
898 | case STATEID_DEVICESELECT: |
||
390 | ligi | 899 | /* |
303 | ligi | 900 | if ((keyCode >= this.KEY_NUM0) && (keyCode < this.KEY_NUM0+bt_scanner.remote_device_count)) |
901 | { |
||
902 | connect_mk("btspp://"+bt_scanner.remote_device_mac[keyCode-this.KEY_NUM0] + ":1",bt_scanner.remote_device_name[keyCode-this.KEY_NUM0]); |
||
903 | chg_state(STATEID_MAINMENU); |
||
904 | } |
||
231 | ligi | 905 | else |
390 | ligi | 906 | */ |
907 | |||
303 | ligi | 908 | if ( getGameAction (keyCode)==FIRE ) |
909 | { |
||
390 | ligi | 910 | |
911 | if (bt_scanner.remote_device_count > act_menu_select) |
||
912 | { |
||
913 | connect_mk("btspp://"+bt_scanner.remote_device_mac[act_menu_select] + ":1",bt_scanner.remote_device_name[act_menu_select]); |
||
914 | chg_state(STATEID_MAINMENU); |
||
915 | } |
||
916 | else |
||
917 | chg_state(STATEID_SCANNING); |
||
303 | ligi | 918 | } |
919 | else menu_keypress(keyCode); |
||
390 | ligi | 920 | |
303 | ligi | 921 | break; |
922 | |||
923 | case STATEID_EDIT_PARAMS: |
||
924 | params_editor.keypress(keyCode,getGameAction (keyCode)) ; |
||
925 | break; |
||
926 | |||
927 | case STATEID_FLIGHTVIEW: |
||
928 | |||
929 | switch (getGameAction (keyCode)) |
||
208 | ligi | 930 | { |
303 | ligi | 931 | case UP: |
932 | mk.LCD.LCD_PREVPAGE(); |
||
933 | break; |
||
208 | ligi | 934 | |
303 | ligi | 935 | case DOWN: |
936 | mk.LCD.LCD_NEXTPAGE(); |
||
937 | break; |
||
231 | ligi | 938 | |
303 | ligi | 939 | case LEFT: |
940 | chg_state(STATEID_MAINMENU); |
||
941 | break; |
||
231 | ligi | 942 | |
208 | ligi | 943 | } |
303 | ligi | 944 | break; |
208 | ligi | 945 | } |
303 | ligi | 946 | |
208 | ligi | 947 | |
303 | ligi | 948 | |
181 | ligi | 949 | } |
950 | |||
951 | |||
952 | |||
953 | |||
954 | |||
955 | |||
956 | |||
957 | |||
958 | } |
||
959 | |||
960 |