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