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