Rev 211 | Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
206 | ligi | 1 | /*************************************************************** |
2 | * |
||
3 | * User Interface ( Canvas ) of DUBwise |
||
4 | * |
||
5 | * Author: Marcus -LiGi- Bueschleb |
||
6 | * Mailto: LiGi @at@ LiGi DOTT de |
||
7 | * |
||
8 | ***************************************************************/ |
||
9 | |||
10 | import javax.microedition.lcdui.*; |
||
11 | |||
12 | |||
13 | import javax.microedition.media.*; |
||
14 | import javax.microedition.media.control.*; |
||
15 | |||
16 | |||
17 | //#if fileapi=="on" |
||
18 | import javax.microedition.io.*; |
||
19 | import javax.microedition.midlet.*; |
||
20 | import javax.microedition.io.file.*; |
||
21 | |||
22 | import java.io.*; |
||
23 | import java.util.*; |
||
24 | //#endif |
||
25 | |||
26 | public class DUBwiseCanvas |
||
27 | extends Canvas |
||
28 | implements Runnable,org.ligi.ufo.DUBwiseDefinitions |
||
29 | { |
||
30 | |||
31 | //#if fileapi=="on" |
||
32 | public final static int MAX_FILELIST_LENGTH=100; |
||
33 | public final static int MAX_PATH_DEPTH=10; |
||
34 | |||
35 | byte act_path_depth=0; |
||
36 | String[] act_path_arr; |
||
37 | |||
38 | |||
39 | public String act_path() |
||
40 | { |
||
41 | String res=""; |
||
42 | for (int i=0;i<act_path_depth;i++) |
||
43 | res+=act_path_arr[i]; |
||
44 | return res; |
||
45 | } |
||
46 | |||
47 | String[] file_list; |
||
48 | int file_list_length=0; |
||
49 | //#endif |
||
50 | |||
51 | |||
52 | |||
53 | boolean ipinput4proxy; |
||
54 | byte ipinput_pos=0; |
||
55 | int[] act_edit_ip; |
||
56 | |||
57 | int canvas_width=100; |
||
58 | int canvas_height=100; |
||
59 | |||
60 | |||
61 | |||
62 | |||
63 | // public String ip_digit_zeroes(int digit) |
||
64 | //{ return "" + digit/100 + "" + (digit/10)%10 + "" + (digit)%10; } |
||
65 | |||
66 | |||
67 | |||
68 | int heading_offset=0; |
||
69 | int act_wp; |
||
70 | |||
71 | |||
72 | |||
73 | //#if bluetooth=="on" |
||
74 | private BTSearcher bt_scanner; |
||
75 | //#endif |
||
76 | |||
77 | public org.ligi.ufo.MKCommunicator mk=null; |
||
78 | // private MKStatistics mk_stat=null; |
||
79 | private MKParamsEditor params_editor=null; |
||
80 | public DUBwiseDebug debug=null; |
||
81 | public DUBwiseHelper helper=null; |
||
82 | |||
83 | |||
84 | //#if voice_mode!="no_voice" |
||
85 | private MKStatusVoice status_voice; |
||
86 | //#endif |
||
87 | |||
88 | |||
89 | private DUBwise root; |
||
90 | public DUBwiseSettings settings; |
||
91 | // public UFOProber mk.ufo_prober; |
||
92 | |||
93 | private Image bg_img; |
||
94 | private Image lcd_img; |
||
95 | private Image symbols_img; |
||
96 | private Image err_img; |
||
97 | |||
98 | |||
99 | int max_lines; |
||
100 | |||
101 | |||
102 | public byte act_motor=0; |
||
103 | public byte act_motor_increase=0; |
||
104 | public boolean motor_test_sel_all=false; |
||
105 | |||
106 | |||
107 | /* Graph Vars */ |
||
108 | public final static int GRAPH_COUNT=4; |
||
109 | public final static int[] graph_colors={0x156315,0xCC1315,0xf8ef02,0x19194d}; |
||
110 | public int[] graph_sources={0,1,2,3}; |
||
111 | public String[] graph_names={"nick int","roll int","nick acc","roll acc"}; |
||
112 | public int[][] graph_data; |
||
113 | |||
114 | public int lcd_char_width=0; |
||
115 | public int lcd_char_height=0; |
||
116 | |||
117 | public int frame_pos=0; |
||
118 | |||
119 | // public byte mk.user_intent=USER_INTENT_NONE; |
||
120 | |||
121 | int line_scaler=20; |
||
122 | |||
123 | int rawdebug_cursor_y=0; |
||
124 | int rawdebug_off_y=0; |
||
125 | |||
126 | public int line_middle_y; |
||
127 | |||
128 | boolean quit=false; |
||
129 | |||
130 | int bg_offset=0; |
||
131 | |||
132 | // variable to hold the current state |
||
133 | public byte state=-1; |
||
134 | |||
135 | int local_max=-1; |
||
136 | |||
137 | int y_off=0; |
||
138 | int spacer=0; |
||
139 | int spacer1=0; |
||
140 | |||
141 | int[] motor_test = {0,0,0,0}; |
||
142 | |||
143 | |||
144 | String[] menu_items; |
||
145 | byte[] menu_actions; |
||
146 | int act_menu_select=0; |
||
147 | |||
148 | String[] lcd_lines =null; |
||
149 | |||
150 | |||
151 | public void setup_menu(String[] items , byte[] actions) |
||
152 | { |
||
153 | menu_items=items; |
||
154 | menu_actions=actions; |
||
155 | lcd_lines=new String[menu_items.length]; |
||
156 | } |
||
157 | |||
158 | public void paint_menu(Graphics g) |
||
159 | { |
||
160 | for ( int i=0;i<menu_items.length;i++) |
||
161 | { |
||
162 | if ((frame_pos%3)!=0) |
||
163 | { |
||
164 | lcd_lines[i]=(act_menu_select==i?">":" ") + menu_items[i]; |
||
165 | for ( int ii=0;ii<(18-menu_items[i].length());ii++) |
||
166 | lcd_lines[i]+=" "; |
||
167 | if (act_menu_select==i) |
||
168 | lcd_lines[i]+="<"; |
||
169 | } |
||
170 | else |
||
171 | lcd_lines[i]=" " + menu_items[i]; |
||
172 | |||
173 | |||
174 | } |
||
175 | paint_lcd(g,true); |
||
176 | } |
||
177 | |||
178 | public void menu_keypress(int keyCode) |
||
179 | { |
||
180 | debug.log("Menu with KeyCode:"+keyCode); |
||
181 | switch (getGameAction (keyCode)) |
||
182 | { |
||
183 | case UP: |
||
184 | if (act_menu_select!=0) act_menu_select--; |
||
185 | else |
||
186 | act_menu_select=menu_items.length-1; |
||
187 | break; |
||
188 | |||
189 | case DOWN: |
||
190 | if (act_menu_select<(menu_items.length-1)) act_menu_select++; |
||
191 | else act_menu_select=0; |
||
192 | break; |
||
193 | |||
194 | } |
||
195 | |||
196 | } |
||
197 | |||
198 | public boolean cam_condition() |
||
199 | { |
||
200 | return (mk.stick_data.stick[5]>100); |
||
201 | } |
||
202 | |||
203 | // int lcd_top=25; |
||
204 | |||
205 | public void paint_lcd(Graphics g,boolean bottomup) |
||
206 | { |
||
207 | |||
208 | int y; |
||
209 | |||
210 | int lcd_top= (state==STATEID_EDIT_PARAMS?0:25); |
||
211 | max_lines=(canvas_height-lcd_top)/lcd_char_height; |
||
212 | |||
213 | int spacer_left_right=(canvas_width-(20*(lcd_img.getWidth()/222)))/2; |
||
214 | // for(int i=0;i<lcd_lines.length;i++) |
||
215 | |||
216 | int display_lines=(lcd_lines.length>max_lines?max_lines:lcd_lines.length); |
||
217 | |||
218 | |||
219 | int lcd_off= (state==STATEID_EDIT_PARAMS?params_editor.act_y:act_menu_select)-display_lines+1; |
||
220 | if ( lcd_off<0) lcd_off=0; |
||
221 | |||
222 | for(int i=0;i<display_lines;i++) |
||
223 | for (int pos=0;pos<20;pos++) |
||
224 | { |
||
225 | if (bottomup) |
||
226 | y=canvas_height-(display_lines-i)*lcd_char_height; |
||
227 | else |
||
228 | y=i*lcd_char_height; |
||
229 | g.setClip((lcd_img.getWidth()/222)*pos+spacer_left_right,y,(lcd_img.getWidth()/222),lcd_img.getHeight()); |
||
230 | g.drawImage(lcd_img,spacer_left_right+(lcd_img.getWidth()/222)*pos-((pos<lcd_lines[i+lcd_off].length()?lcd_lines[i+lcd_off].charAt(pos):' ')-' ')*(lcd_img.getWidth()/222),y,g.TOP | g.LEFT); |
||
231 | |||
232 | } |
||
233 | } |
||
234 | |||
235 | public void load_images() |
||
236 | { |
||
237 | try |
||
238 | { |
||
239 | bg_img=null; |
||
240 | lcd_img=null; |
||
241 | |||
242 | // load all needed images |
||
243 | switch (settings.act_skin) |
||
244 | { |
||
245 | case SKINID_DARK: |
||
246 | lcd_img=Image.createImage("/lcd_green.png"); |
||
247 | if (settings.do_scrollbg) bg_img=Image.createImage("/starfield.jpg"); break; |
||
248 | |||
249 | case SKINID_LIGHT: |
||
250 | lcd_img=Image.createImage("/lcd_blue.png"); |
||
251 | if (settings.do_scrollbg) bg_img=Image.createImage("/clouds.jpg"); |
||
252 | break; |
||
253 | } |
||
254 | |||
255 | |||
256 | // bt_img=Image.createImage("/bt.png"); |
||
257 | symbols_img=Image.createImage("/symbols.png"); |
||
258 | // load_img=Image.createImage("/load.png"); |
||
259 | |||
260 | lcd_char_width=lcd_img.getWidth()/222; |
||
261 | lcd_char_height=lcd_img.getHeight(); |
||
262 | |||
263 | |||
264 | |||
265 | if (bg_img!=null) |
||
266 | graph_data=new int[GRAPH_COUNT][bg_img.getWidth()]; |
||
267 | else |
||
268 | graph_data=new int[GRAPH_COUNT][this.getWidth()*2]; |
||
269 | |||
270 | for (int c=0;c<graph_data[0].length;c++) |
||
271 | for (int d=0;d<GRAPH_COUNT;d++) |
||
272 | graph_data[d][c]=-1; |
||
273 | /* |
||
274 | nick_line_pos_data=new int[graph_data[0].length]; |
||
275 | roll_line_pos_data=new int[graph_data[0].length]; |
||
276 | accnick_line_pos_data=new int[graph_data[0].length]; |
||
277 | accroll_line_pos_data=new int[graph_data[0].length]; |
||
278 | |||
279 | for (int c=0;c<graph_data[0].length;c++) |
||
280 | { |
||
281 | nick_line_pos_data[c]=-1; |
||
282 | roll_line_pos_data[c]=-1; |
||
283 | accnick_line_pos_data[c]=-1; |
||
284 | accroll_line_pos_data[c]=-1; |
||
285 | } |
||
286 | */ |
||
287 | try { |
||
288 | err_img=null; |
||
289 | if (settings.do_scrollbg) err_img=Image.createImage("/preflight.jpg"); |
||
290 | } |
||
291 | catch (Exception e) { } |
||
292 | |||
293 | } |
||
294 | |||
295 | catch (Exception e) |
||
296 | { |
||
297 | debug.err(e.toString()); |
||
298 | } |
||
299 | |||
300 | } |
||
301 | |||
302 | public DUBwiseCanvas(DUBwise _root) |
||
303 | { |
||
304 | |||
305 | // mk = new MKCommunicator(root); |
||
306 | |||
307 | //#if fileapi=="on" |
||
308 | // file |
||
309 | file_list= new String[MAX_FILELIST_LENGTH]; |
||
310 | act_path_arr=new String[MAX_PATH_DEPTH]; |
||
311 | // end file |
||
312 | //#endif |
||
313 | |||
314 | root=_root; |
||
315 | |||
316 | mk = new org.ligi.ufo.MKCommunicator(); |
||
317 | helper = new DUBwiseHelper(); |
||
318 | settings = new DUBwiseSettings(); |
||
319 | debug = new DUBwiseDebug(this); |
||
320 | |||
321 | //#if bluetooth=="on" |
||
322 | bt_scanner = new BTSearcher(); |
||
323 | //#endif |
||
324 | |||
325 | params_editor = new MKParamsEditor(this); |
||
326 | // mk.ufo_prober = new UFOProber(); |
||
327 | |||
328 | // mk = new MKCommunicator(root); |
||
329 | // mk_stat = new MKStatistics(mk); |
||
330 | |||
331 | |||
332 | |||
333 | //#if voice_mode!="no_voice" |
||
334 | status_voice=new MKStatusVoice(mk,this); |
||
335 | //#endif |
||
336 | |||
337 | |||
338 | |||
339 | load_images(); |
||
340 | |||
341 | if (settings.connection_url!="") |
||
342 | connect_mk(settings.connection_url,settings.connection_name); |
||
343 | |||
344 | chg_state(STATEID_MAINMENU); |
||
345 | |||
346 | |||
347 | |||
348 | new Thread(this).start(); |
||
349 | |||
350 | } |
||
351 | |||
352 | |||
353 | |||
354 | |||
355 | /****************************** Thread ******************/ |
||
356 | // ticking runnable Section |
||
357 | public void run() |
||
358 | { |
||
359 | |||
360 | |||
361 | while(true) |
||
362 | { |
||
363 | try { |
||
364 | |||
365 | |||
366 | repaint(); |
||
367 | serviceRepaints(); |
||
368 | |||
369 | System.gc(); |
||
370 | long loopStartTime = System.currentTimeMillis(); |
||
371 | long sleeptime=0; |
||
372 | // ticked thing |
||
373 | |||
374 | frame_pos++; |
||
375 | |||
376 | if (mk.ufo_prober.change_notify) |
||
377 | { |
||
378 | mk.ufo_prober.change_notify=false; |
||
379 | if (mk.ufo_prober.is_incompatible()) |
||
380 | { |
||
381 | mk.error_str="incompatible Device"; |
||
382 | chg_state(STATEID_NC_ERRORS); |
||
383 | } |
||
384 | else |
||
385 | if (state==STATEID_MAINMENU) |
||
386 | chg_state(STATEID_MAINMENU); // reload mainmenu ( changed content ) |
||
387 | } |
||
388 | |||
389 | |||
390 | switch(state) |
||
391 | { |
||
392 | case STATEID_CAMMODE: |
||
393 | |||
394 | try |
||
395 | { |
||
396 | if(cam_condition()) |
||
397 | { |
||
398 | cam_img=null; |
||
399 | debug.log("get snap\n"); |
||
400 | cam_raw = mVideoControl.getSnapshot(null); |
||
401 | |||
402 | try { Thread.sleep(4000); } |
||
403 | catch (Exception e) |
||
404 | { |
||
405 | debug.log("Problem Sleeping "); |
||
406 | |||
407 | } |
||
408 | } |
||
409 | else |
||
410 | { |
||
411 | if (cam_img==null) |
||
412 | cam_img = Image.createImage(cam_raw, 0, cam_raw.length); |
||
413 | } |
||
414 | } |
||
415 | catch ( Exception e) |
||
416 | { |
||
417 | debug.log(e.toString()); |
||
418 | } |
||
419 | break; |
||
420 | case STATEID_KEYCONTROL: |
||
421 | mk.send_keys(keycontrol_bitfield); |
||
422 | break; |
||
423 | |||
424 | case STATEID_NC_ERRORS: |
||
425 | lcd_lines[0]=""+mk.error_str; |
||
426 | break; |
||
427 | |||
428 | case STATEID_READ_PARAMS: |
||
429 | if (mk.watchdog.act_paramset==5) |
||
430 | chg_state(STATEID_SELECT_PARAMSET); |
||
431 | else |
||
432 | { |
||
433 | lcd_lines[0]="Reading Settings "; |
||
434 | lcd_lines[1]=mk.watchdog.act_paramset+"/5 |"+ (mk.watchdog.act_paramset>0?"#":"_") + (mk.watchdog.act_paramset>1?"#":"_") + (mk.watchdog.act_paramset>2?"#":"_")+ (mk.watchdog.act_paramset>3?"#":"_")+ (mk.watchdog.act_paramset>4?"#":"_") + "| "; |
||
435 | |||
436 | if (mk.params.found_incompatible) |
||
437 | { |
||
438 | mk.error_str="incompatible params"; |
||
439 | chg_state(STATEID_NC_ERRORS); |
||
440 | } |
||
441 | |||
442 | } |
||
443 | break; |
||
444 | |||
445 | |||
446 | |||
447 | |||
448 | |||
449 | case STATEID_MOTORTEST: |
||
450 | |||
451 | if (motor_test_sel_all) |
||
452 | for (int m=0;m<4;m++) |
||
453 | { |
||
454 | motor_test[m]+=act_motor_increase; |
||
455 | if (motor_test[m]<0)motor_test[m]=0; |
||
456 | if (motor_test[m]>255)motor_test[m]=255; |
||
457 | } |
||
458 | else |
||
459 | { |
||
460 | motor_test[act_motor]+=act_motor_increase; |
||
461 | if (motor_test[act_motor]<0) motor_test[act_motor]=0; |
||
462 | if (motor_test[act_motor]>255) motor_test[act_motor]=255; |
||
463 | } |
||
464 | |||
465 | mk.motor_test(motor_test); |
||
466 | break; |
||
467 | |||
468 | case STATEID_IPINPUT: |
||
469 | if (ipinput4proxy) |
||
470 | act_edit_ip=settings.act_proxy_ip; |
||
471 | else |
||
472 | act_edit_ip=settings.act_conn_ip; |
||
473 | |||
474 | lcd_lines[1]=helper.ip_str(act_edit_ip,true); |
||
475 | |||
476 | |||
477 | lcd_lines[2]=""; |
||
478 | for(int foo=0;foo<20;foo++) |
||
479 | { |
||
480 | if (foo==ipinput_pos) |
||
481 | lcd_lines[2]+="^"; |
||
482 | else |
||
483 | lcd_lines[2]+=" "; |
||
484 | } |
||
485 | break; |
||
486 | |||
487 | case STATEID_MAINMENU: |
||
488 | |||
489 | break; |
||
490 | |||
491 | //#if bluetooth=="on" |
||
492 | case STATEID_SCANNING: |
||
493 | /*intro_str_delay--; |
||
494 | if (intro_str_delay<0) |
||
495 | { |
||
496 | intro_str_delay=1; |
||
497 | if (intro_str_pos>intro_str.length()) |
||
498 | intro_str_pos=0; |
||
499 | lcd_lines[3]=intro_str.substring(intro_str_pos, (((intro_str_pos+20)>intro_str.length())?intro_str.length():intro_str_pos+20)); |
||
500 | intro_str_pos++; |
||
501 | } |
||
502 | */ |
||
503 | lcd_lines[2]="found " + bt_scanner.remote_device_count; |
||
504 | |||
505 | if (!bt_scanner.searching) |
||
506 | chg_state(STATEID_DEVICESELECT); |
||
507 | |||
508 | |||
509 | break; |
||
510 | //#endif |
||
511 | |||
512 | |||
513 | } |
||
514 | |||
515 | if (quit) |
||
516 | { |
||
517 | settings.save(); |
||
518 | root.quit(); |
||
519 | } |
||
520 | |||
521 | try { |
||
522 | //rescan=false; |
||
523 | bg_offset--; |
||
524 | if (bg_offset==-graph_data[0].length) |
||
525 | bg_offset=0; |
||
526 | //#if devicecontrol=="on" |
||
527 | if (settings.keep_lighton) com.nokia.mid.ui.DeviceControl.setLights(0,100); |
||
528 | //#endif |
||
529 | } |
||
530 | catch (Exception e) { } |
||
531 | |||
532 | |||
533 | sleeptime=1000/ 15 - (int) (System.currentTimeMillis()- loopStartTime); |
||
534 | |||
535 | if (sleeptime<0) |
||
536 | sleeptime=100; // everyone has fi sleep |
||
537 | |||
538 | try { Thread.sleep(sleeptime); } |
||
539 | catch (Exception e) |
||
540 | { |
||
541 | debug.log("Problem Sleeping "); |
||
542 | } |
||
543 | |||
544 | } |
||
545 | catch (Exception e) |
||
546 | { |
||
547 | debug.log("E!:"+e.getMessage()); |
||
548 | |||
549 | } |
||
550 | } |
||
551 | } |
||
552 | |||
553 | |||
554 | |||
555 | boolean firstrun=true; |
||
556 | |||
557 | public int skin_bg_color() |
||
558 | { |
||
559 | |||
560 | switch (settings.act_skin) |
||
561 | { |
||
562 | case SKINID_DARK: |
||
563 | return 0x000000; |
||
564 | |||
565 | default: |
||
566 | case SKINID_LIGHT: |
||
567 | return 0xFFFFFF; |
||
568 | } |
||
569 | } |
||
570 | |||
571 | |||
572 | public int skin_fg_color() |
||
573 | { |
||
574 | |||
575 | switch (settings.act_skin) |
||
576 | { |
||
577 | case SKINID_DARK: |
||
578 | return 0xFFFFFF; |
||
579 | |||
580 | default: |
||
581 | case SKINID_LIGHT: |
||
582 | return 0x000000; |
||
583 | } |
||
584 | } |
||
585 | |||
586 | // drawing section |
||
587 | public void paint(Graphics g) { |
||
588 | |||
589 | canvas_width=this.getWidth(); |
||
590 | canvas_height=this.getHeight(); |
||
591 | |||
592 | if (debug.showing) |
||
593 | { |
||
594 | debug.paint(g); |
||
595 | return; |
||
596 | } |
||
597 | |||
598 | |||
599 | if (firstrun) |
||
600 | { |
||
601 | if (settings.fullscreen) setFullScreenMode(settings.fullscreen); |
||
602 | firstrun=false; |
||
603 | } |
||
604 | y_off=0; |
||
605 | |||
606 | |||
607 | |||
608 | try { |
||
609 | |||
610 | if (mk!=null) |
||
611 | { |
||
612 | line_middle_y=canvas_height/2; |
||
613 | if (local_max<Math.abs(mk.debug_data.nick_int())) |
||
614 | local_max=Math.abs(mk.debug_data.nick_int()); |
||
615 | if (local_max<Math.abs(mk.debug_data.roll_int())) |
||
616 | local_max=Math.abs(mk.debug_data.roll_int()); |
||
617 | if (local_max<Math.abs(mk.debug_data.accnick())) |
||
618 | local_max=Math.abs(mk.debug_data.accnick()); |
||
619 | if (local_max<Math.abs(mk.debug_data.accroll())) |
||
620 | local_max=Math.abs(mk.debug_data.accroll()); |
||
621 | line_scaler= local_max/(canvas_height/2)+1; |
||
622 | } |
||
623 | |||
624 | |||
625 | Font f1 = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_MEDIUM); |
||
626 | Font f2 = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_SMALL); |
||
627 | |||
628 | spacer=(f1.getHeight()); |
||
629 | spacer1=(f2.getHeight()); |
||
630 | |||
631 | //default Font |
||
632 | g.setFont(f1); |
||
633 | |||
634 | |||
635 | //draw background |
||
636 | if ((!settings.do_scrollbg) || (state==STATEID_EDIT_PARAMS)) |
||
637 | { |
||
638 | g.setColor(0xdedfff); |
||
639 | g.fillRect(0,0,canvas_width,symbols_img.getHeight()); |
||
640 | |||
641 | g.setColor(skin_bg_color()); |
||
642 | g.fillRect(0,symbols_img.getHeight(),canvas_width,canvas_height-symbols_img.getHeight()); |
||
643 | |||
644 | |||
645 | } |
||
646 | else |
||
647 | { |
||
648 | g.setColor(0xFFFFFF); |
||
649 | g.fillRect(0,0,canvas_width,canvas_height); |
||
650 | g.drawImage(bg_img,bg_offset,0, g.TOP | g.LEFT); |
||
651 | |||
652 | if (bg_offset+bg_img.getWidth()<canvas_width) |
||
653 | g.drawImage(bg_img,bg_offset+bg_img.getWidth(),0, g.TOP | g.LEFT); |
||
654 | } |
||
655 | |||
656 | |||
657 | //int bar=0; |
||
658 | // for ( int bar=0;bar<3;bar++) |
||
659 | if (settings.do_scrollbg) |
||
660 | for ( int bar=0;bar<canvas_width/(symbols_img.getWidth()/10)+1;bar++) |
||
661 | { |
||
662 | g.setClip(bar*(symbols_img.getWidth()/10),0,(symbols_img.getWidth()/10),symbols_img.getHeight());; |
||
663 | g.drawImage(symbols_img,bar*(symbols_img.getWidth()/10),0, g.TOP | g.LEFT); |
||
664 | } |
||
665 | |||
666 | int symbol_left=0; |
||
667 | |||
668 | g.setClip(symbol_left,0,(symbols_img.getWidth()/10),symbols_img.getHeight());; |
||
669 | if ((mk.ufo_prober.is_navi()||mk.ufo_prober.is_mk())) |
||
670 | { |
||
671 | |||
672 | if (((mk.stats.bytes_in>>3)&1)==1) |
||
673 | g.drawImage(symbols_img,(-2)*(symbols_img.getWidth()/10),0, g.TOP | g.LEFT); |
||
674 | else |
||
675 | g.drawImage(symbols_img,(-3)*(symbols_img.getWidth()/10),0, g.TOP | g.LEFT); |
||
676 | |||
677 | |||
678 | int symbol_spacer=5; |
||
679 | symbol_left+=symbol_spacer+(symbols_img.getWidth()/10); |
||
680 | g.setClip(symbol_left,0,(symbols_img.getWidth()/10),symbols_img.getHeight());; |
||
681 | |||
682 | g.drawImage(symbols_img,symbol_left+(-4)*(symbols_img.getWidth()/10),0, g.TOP | g.LEFT); |
||
683 | g.setClip(0,0,canvas_width,canvas_height); |
||
684 | g.setColor(0x03035a); |
||
685 | |||
686 | symbol_left+=2+(symbols_img.getWidth()/10); |
||
687 | g.drawString("" + (mk.UBatt()/10) + "," +(mk.UBatt()%10)+"V" , symbol_left,y_off,Graphics.TOP | Graphics.LEFT); |
||
688 | |||
689 | |||
690 | symbol_left+= g.getFont().stringWidth("88,8V");//; |
||
691 | g.setClip(symbol_left,0,(symbols_img.getWidth()/10),symbols_img.getHeight()); |
||
692 | g.drawImage(symbols_img,(-6)*(symbols_img.getWidth()/10) + symbol_left,0, g.TOP | g.LEFT); |
||
693 | |||
694 | g.setClip(0,0,canvas_width,canvas_height); |
||
695 | |||
696 | symbol_left+=2+(symbols_img.getWidth()/10); |
||
697 | g.drawString(""+mk.SenderOkay() ,symbol_left,y_off,Graphics.TOP | Graphics.LEFT); |
||
698 | |||
699 | |||
700 | symbol_left+= g.getFont().stringWidth("8")+symbol_spacer; //,0,(symbols_img.getWidth()/10)+2; |
||
701 | |||
702 | |||
703 | |||
704 | |||
705 | if (mk.ufo_prober.is_navi()) |
||
706 | { |
||
707 | |||
708 | |||
709 | g.setClip(symbol_left,0,(symbols_img.getWidth()/10),symbols_img.getHeight()); |
||
710 | g.drawImage(symbols_img,(-5)*(symbols_img.getWidth()/10) + symbol_left,0, g.TOP | g.LEFT); |
||
711 | g.setClip(0,0,canvas_width,canvas_height); |
||
712 | symbol_left+=2+(symbols_img.getWidth()/10); |
||
713 | g.drawString(""+mk.gps_position.SatsInUse ,symbol_left,y_off,Graphics.TOP | Graphics.LEFT); |
||
714 | |||
715 | } |
||
716 | |||
717 | } |
||
718 | |||
719 | else |
||
720 | g.drawImage(symbols_img,(-1)*(symbols_img.getWidth()/10),0, g.TOP | g.LEFT); |
||
721 | |||
722 | // if (mk.connected) |
||
723 | |||
724 | |||
725 | // unclip |
||
726 | g.setClip(0,0,canvas_width,canvas_height); |
||
727 | |||
728 | y_off+=symbols_img.getHeight(); |
||
729 | g.setColor(skin_fg_color()); |
||
730 | |||
731 | switch(state) |
||
732 | { |
||
733 | |||
734 | |||
735 | case STATEID_DATABUFF: |
||
736 | g.setFont(f2); |
||
737 | |||
738 | y_off=canvas_height-spacer1; |
||
739 | |||
740 | for (int pos_y=0;pos_y<(((canvas_height-spacer1)/spacer1));pos_y++) |
||
741 | { |
||
742 | |||
743 | g.drawString(mk.get_buff(pos_y) ,0,y_off,Graphics.TOP | Graphics.LEFT); |
||
744 | y_off-=spacer1; |
||
745 | } |
||
746 | break; |
||
747 | case STATEID_NC_ERRORS: |
||
748 | if (settings.do_scrollbg) |
||
749 | { |
||
750 | int err_img_left=(canvas_width-err_img.getWidth()/2)/2; |
||
751 | int err_img_top=(canvas_height-err_img.getHeight())/2; |
||
752 | g.setClip(err_img_left,err_img_top,err_img.getWidth()/2,err_img.getHeight()); |
||
753 | g.drawImage(err_img,err_img_left-err_img.getWidth()/2,err_img_top, g.TOP | g.LEFT); |
||
754 | } |
||
755 | paint_lcd(g,true); |
||
756 | |||
757 | break; |
||
758 | |||
759 | case STATEID_GPSVIEW: |
||
760 | |||
761 | g.setFont(f2); |
||
762 | |||
763 | g.setStrokeStyle(Graphics.SOLID); |
||
764 | g.setColor(0x0000ff); |
||
765 | |||
766 | |||
767 | // g.fillArc(0, 0, canvas_width, canvas_width, 0,45); |
||
768 | |||
769 | /* |
||
770 | int start_angle=(360+mk.gps_position.angle2wp(act_wp) - ((360+mk.debug_data.analog[26]-heading_offset)%360))%360; |
||
771 | // start_angle=0; |
||
772 | start_angle=(360-start_angle +90 -(45/2))%360; |
||
773 | |||
774 | g.fillArc(0, 0, canvas_width, canvas_width, start_angle,45); |
||
775 | */ |
||
776 | // g.drawArc(1, 1, canvas_width-2, canvas_width-2, start_angle,45); |
||
777 | // g.drawArc(2, 2, canvas_width-4, canvas_width-4, start_angle ,45); |
||
778 | |||
779 | |||
780 | g.setColor(skin_fg_color()); |
||
781 | |||
782 | g.drawString("Used Sats: " + mk.gps_position.SatsInUse + " | Packages: " + mk.stats.navi_data_count ,0,y_off,Graphics.TOP | Graphics.LEFT); |
||
783 | y_off+=spacer1; |
||
784 | |||
785 | g.drawString("Lat: " + mk.gps_position.Latitude_str() ,0,y_off,Graphics.TOP | Graphics.LEFT); |
||
786 | y_off+=spacer1; |
||
787 | |||
788 | g.drawString("Long: " + mk.gps_position.Longitude_str() ,0,y_off,Graphics.TOP | Graphics.LEFT); |
||
789 | y_off+=spacer1; |
||
790 | |||
791 | g.drawString("Altitude: " + mk.gps_position.Altitude ,0,y_off,Graphics.TOP | Graphics.LEFT); |
||
792 | y_off+=spacer1; |
||
793 | |||
794 | |||
795 | g.drawString("Target-Lat: " + mk.gps_position.TargetLatitude_str() ,0,y_off,Graphics.TOP | Graphics.LEFT); |
||
796 | y_off+=spacer1; |
||
797 | g.drawString("Target-Long: " + mk.gps_position.TargetLongitude_str() ,0,y_off,Graphics.TOP | Graphics.LEFT); |
||
798 | y_off+=spacer1; |
||
799 | |||
800 | g.drawString("Target-Alt: " + mk.gps_position.TargetAltitude ,0,y_off,Graphics.TOP | Graphics.LEFT); |
||
801 | y_off+=spacer1; |
||
802 | |||
803 | |||
804 | g.drawString("Home-Lat: " + mk.gps_position.HomeLatitude_str() ,0,y_off,Graphics.TOP | Graphics.LEFT); |
||
805 | y_off+=spacer1; |
||
806 | |||
807 | g.drawString("Home-Long: " + mk.gps_position.HomeLongitude_str() ,0,y_off,Graphics.TOP | Graphics.LEFT); |
||
808 | y_off+=spacer1; |
||
809 | |||
810 | g.drawString("Home-Alt: " + mk.gps_position.HomeAltitude ,0,y_off,Graphics.TOP | Graphics.LEFT); |
||
811 | |||
812 | y_off+=spacer1; |
||
813 | g.drawString("Distance : " + mk.gps_position.Distance2Target ,0,y_off,Graphics.TOP | Graphics.LEFT); |
||
814 | y_off+=spacer1; |
||
815 | g.drawString("Angle: " + mk.gps_position.Angle2Target ,0,y_off,Graphics.TOP | Graphics.LEFT); |
||
816 | y_off+=spacer1; |
||
817 | |||
818 | g.drawString("WayPoints: " + mk.gps_position.WayPointNumber + "/" + mk.gps_position.WayPointIndex ,0,y_off,Graphics.TOP | Graphics.LEFT); |
||
819 | y_off+=spacer; |
||
820 | |||
821 | |||
822 | |||
823 | /* |
||
824 | g.drawString("" + mk.gps_position.NameWP[act_wp] ,0,y_off,Graphics.TOP | Graphics.LEFT); |
||
825 | y_off+=spacer; |
||
826 | |||
827 | g.drawString("Lat: " + mk.gps_position.WP_Latitude_str(act_wp) ,0,y_off,Graphics.TOP | Graphics.LEFT); |
||
828 | y_off+=spacer; |
||
829 | |||
830 | g.drawString("Long: " + mk.gps_position.WP_Longitude_str(act_wp) ,0,y_off,Graphics.TOP | Graphics.LEFT); |
||
831 | y_off+=spacer; |
||
832 | |||
833 | |||
834 | g.drawString("Distance: " + mk.gps_position.distance2wp(act_wp) ,0,y_off,Graphics.TOP | Graphics.LEFT); |
||
835 | y_off+=spacer; |
||
836 | |||
837 | g.drawString("Angle: " + mk.gps_position.angle2wp(act_wp) ,0,y_off,Graphics.TOP | Graphics.LEFT); |
||
838 | y_off+=spacer; |
||
839 | |||
840 | g.drawString("Compas Heading: " + (360+mk.debug_data.analog[26]-heading_offset)%360) + "(" +mk.debug_data.analog[26] +")" ,0,y_off,Graphics.TOP | Graphics.LEFT); |
||
841 | y_off+=spacer; |
||
842 | */ |
||
843 | |||
844 | |||
845 | break; |
||
846 | |||
847 | case STATEID_FLASHING: |
||
848 | int msg_pos=0; |
||
849 | while (mk.flash_msgs[msg_pos]!=null) |
||
850 | { |
||
851 | g.drawString(mk.flash_msgs[msg_pos] ,0,y_off,Graphics.TOP | Graphics.LEFT); |
||
852 | y_off+=spacer; |
||
853 | msg_pos++; |
||
854 | } |
||
855 | break; |
||
856 | |||
857 | case STATEID_CAMMODE: |
||
858 | |||
859 | if (cam_img!=null) |
||
860 | g.drawImage(cam_img,0,0,g.TOP | g.LEFT); |
||
861 | g.drawString("condition: " + cam_condition() ,0,y_off,Graphics.TOP | Graphics.LEFT); |
||
862 | y_off+=spacer; |
||
863 | g.drawString("width " + cam_img.getWidth(),0,y_off,Graphics.TOP | Graphics.LEFT); |
||
864 | y_off+=spacer; |
||
865 | g.drawString("height " + cam_img.getHeight(),0,y_off,Graphics.TOP | Graphics.LEFT); |
||
866 | y_off+=spacer; |
||
867 | break; |
||
868 | |||
869 | case STATEID_STICKVIEW: |
||
870 | |||
871 | for(int tmp_y=0;tmp_y<10;tmp_y++) |
||
872 | { |
||
873 | g.drawString(""+tmp_y+"(" + mk.params.stick_names[tmp_y] + ")=>"+mk.stick_data.stick[tmp_y],0,y_off,Graphics.TOP | Graphics.LEFT); |
||
874 | y_off+=spacer; |
||
875 | } |
||
876 | break; |
||
877 | |||
878 | case STATEID_KEYCONTROL: |
||
879 | |||
880 | |||
881 | y_off+=spacer; |
||
882 | g.drawString("UP&DOWN => nick",0,y_off,Graphics.TOP | Graphics.LEFT); |
||
883 | y_off+=spacer; |
||
884 | g.drawString("LEFT&RIGHT => roll",0,y_off,Graphics.TOP | Graphics.LEFT); |
||
885 | y_off+=spacer; |
||
886 | g.drawString("1&4 => altitude",0,y_off,Graphics.TOP | Graphics.LEFT); |
||
887 | |||
888 | y_off+=spacer; |
||
889 | g.drawString("2&3 => gier",0,y_off,Graphics.TOP | Graphics.LEFT); |
||
890 | |||
891 | y_off+=spacer; |
||
892 | g.drawString("Press # and * at once",0,y_off,Graphics.TOP | Graphics.LEFT); |
||
893 | y_off+=spacer; |
||
894 | g.drawString("to quit KeyControl",0,y_off,Graphics.TOP | Graphics.LEFT); |
||
895 | y_off+=spacer; |
||
896 | g.drawString("bf1:"+ keycontrol_bitfield[0] ,0,y_off,Graphics.TOP | Graphics.LEFT); |
||
897 | g.drawString("bf2:"+ keycontrol_bitfield[1] ,canvas_width/2,y_off,Graphics.TOP | Graphics.LEFT); |
||
898 | |||
899 | break; |
||
900 | |||
901 | case STATEID_MOTORTEST: |
||
902 | for (int bar=0;bar<4;bar++) |
||
903 | |||
904 | { |
||
905 | g.setColor(((bar==act_motor)|motor_test_sel_all)?0x44CC44:0x4444DD); |
||
906 | g.fillRect(canvas_width/(8*2)+bar*2*canvas_width/8,y_off+10,canvas_width/8,y_off+20+motor_test[bar]); |
||
907 | g.setColor(0x000000); |
||
908 | g.drawString(""+motor_test[bar] ,canvas_width/8+bar*2*canvas_width/8,y_off+10,Graphics.TOP | Graphics.HCENTER); |
||
909 | g.drawString(""+mk.debug_data.motor_val(bar) ,canvas_width/8+bar*2*canvas_width/8,y_off+25,Graphics.TOP | Graphics.HCENTER); |
||
910 | } |
||
911 | break; |
||
912 | |||
913 | case STATEID_EDIT_PARAMS: |
||
914 | params_editor.paint(g); |
||
915 | break; |
||
916 | |||
917 | case STATEID_SELECT_COMPORT: |
||
918 | g.drawString("ports: " + System.getProperty("microedition.commports"),0,y_off,Graphics.TOP | Graphics.LEFT); |
||
919 | y_off+=spacer; |
||
920 | paint_menu(g); |
||
921 | break; |
||
922 | |||
923 | //#if fileapi=="on" |
||
924 | case STATEID_FILEOPEN: |
||
925 | y_off+=spacer; |
||
926 | g.drawString("act_path" + act_path() ,0,y_off,Graphics.TOP | Graphics.LEFT); |
||
927 | paint_menu(g); |
||
928 | break; |
||
929 | //#endif |
||
930 | case STATEID_ABOUT: |
||
931 | case STATEID_IPINPUT: |
||
932 | paint_lcd(g,true); |
||
933 | break; |
||
934 | |||
935 | case STATEID_READ_PARAMS: |
||
936 | paint_lcd(g,true); |
||
937 | break; |
||
938 | |||
939 | |||
940 | //#if bluetooth=="on" |
||
941 | case STATEID_SCANNING: |
||
942 | paint_lcd(g,true); |
||
943 | break; |
||
944 | //#endif |
||
945 | case STATEID_RAWDEBUG: |
||
946 | g.setFont(f2); |
||
947 | rawdebug_off_y=0; |
||
948 | if ((rawdebug_cursor_y+3)*spacer1>canvas_height) |
||
949 | rawdebug_off_y=((rawdebug_cursor_y+3)*spacer1-canvas_height)/spacer1; |
||
950 | for (int i=0;i<(canvas_height/spacer1)-1;i++) |
||
951 | { |
||
952 | if (i+rawdebug_off_y==rawdebug_cursor_y) |
||
953 | { |
||
954 | g.setColor(0x0000CC); |
||
955 | g.fillRect(0,y_off,canvas_width,spacer1); |
||
956 | |||
957 | g.setColor(skin_fg_color()); |
||
958 | |||
959 | |||
960 | } |
||
961 | if (i+rawdebug_off_y<32) //todo better style |
||
962 | g.drawString(mk.debug_data.names[i+rawdebug_off_y] + mk.debug_data.analog[i+rawdebug_off_y] ,0,y_off,Graphics.TOP | Graphics.LEFT); |
||
963 | |||
964 | y_off+=spacer1; |
||
965 | |||
966 | } |
||
967 | |||
968 | |||
969 | |||
970 | break; |
||
971 | |||
972 | |||
973 | case STATEID_CONN_DETAILS: |
||
974 | g.setFont(f1); |
||
975 | g.drawString("Connection::",0,y_off,Graphics.TOP | Graphics.LEFT); |
||
976 | y_off+=spacer; |
||
977 | g.setFont(f2); |
||
978 | |||
979 | g.drawString(" URL:" + mk.mk_url,0,y_off,Graphics.TOP | Graphics.LEFT); |
||
980 | y_off+=spacer1; |
||
981 | |||
982 | g.drawString(" Name:" + mk.name,0,y_off,Graphics.TOP | Graphics.LEFT); |
||
983 | y_off+=spacer1; |
||
984 | |||
985 | g.drawString(" "+mk.ufo_prober.extended_name()+ " (" + (mk.connected?("open"+((System.currentTimeMillis()- mk.connection_start_time)/1000)+"s"):"closed")+"):",0,y_off,Graphics.TOP | Graphics.LEFT); |
||
986 | y_off+=spacer1; |
||
987 | g.drawString(" Version:" + mk.version.str ,0,y_off,Graphics.TOP | Graphics.LEFT); |
||
988 | y_off+=spacer1; |
||
989 | g.drawString(" Slave-Addr:" + mk.slave_addr,0,y_off,Graphics.TOP | Graphics.LEFT); |
||
990 | |||
991 | paint_menu(g); |
||
992 | |||
993 | break; |
||
994 | |||
995 | case STATEID_TRAFFIC: |
||
996 | |||
997 | g.setFont(f1); |
||
998 | g.drawString("Packet Traffic (over "+mk.conn_time_in_s()+"s):",0,y_off,Graphics.TOP | Graphics.LEFT); |
||
999 | y_off+=spacer; |
||
1000 | g.setFont(f2); |
||
1001 | g.drawString( ">>in:"+mk.stats.bytes_in+ " bytes => " + mk.stats.bytes_in/mk.conn_time_in_s() + " bytes/s",0,y_off,Graphics.TOP | Graphics.LEFT); |
||
1002 | y_off+=spacer1; |
||
1003 | |||
1004 | |||
1005 | |||
1006 | |||
1007 | g.drawString( " debug:"+mk.stats.debug_data_count+ " LCD:" + mk.stats.lcd_data_count + " vers:" + mk.stats.version_data_count,0,y_off,Graphics.TOP | Graphics.LEFT); |
||
1008 | y_off+=spacer1; |
||
1009 | g.drawString( " other:"+mk.stats.other_data_count+" params:"+mk.stats.params_data_count + " GPS:"+mk.stats.navi_data_count ,0,y_off,Graphics.TOP | Graphics.LEFT); |
||
1010 | y_off+=spacer1; |
||
1011 | g.drawString( " debug_names:" + mk.stats.debug_names_count + " angles:" + mk.stats.angle_data_count ,0,y_off,Graphics.TOP | Graphics.LEFT); |
||
1012 | |||
1013 | |||
1014 | y_off+=spacer1+3; |
||
1015 | g.drawString( "<<out:"+mk.stats.bytes_out + " bytes =>" + mk.stats.bytes_out/mk.conn_time_in_s() + "bytes/s", 0,y_off,Graphics.TOP | Graphics.LEFT); |
||
1016 | y_off+=spacer1; |
||
1017 | g.drawString( " LCD:" + mk.stats.lcd_data_request_count + " vers:" + mk.stats.version_data_request_count,0,y_off,Graphics.TOP | Graphics.LEFT); |
||
1018 | y_off+=spacer1; |
||
1019 | g.drawString( " params:"+mk.stats.params_data_request_count ,0,y_off,Graphics.TOP | Graphics.LEFT); |
||
1020 | y_off+=spacer1; |
||
1021 | |||
1022 | paint_menu(g); |
||
1023 | break; |
||
1024 | |||
1025 | case STATEID_PROXY: |
||
1026 | g.setFont(f1); |
||
1027 | g.drawString("Host:",0,y_off,Graphics.TOP | Graphics.LEFT); |
||
1028 | y_off+=spacer; |
||
1029 | g.setFont(f2); |
||
1030 | g.drawString(" " + mk.proxy.url + "("+((mk.proxy.connected)?"open":"closed") +")",0,y_off,Graphics.TOP | Graphics.LEFT); |
||
1031 | y_off+=spacer1; |
||
1032 | |||
1033 | |||
1034 | |||
1035 | break; |
||
1036 | |||
1037 | |||
1038 | case STATEID_MAINMENU: |
||
1039 | |||
1040 | case STATEID_SETTINGSMENU: |
||
1041 | // falltru wanted |
||
1042 | case STATEID_SELECT_PARAMSET: |
||
1043 | case STATEID_HANDLE_PARAMS: |
||
1044 | |||
1045 | case STATEID_DEVICESELECT: |
||
1046 | |||
1047 | paint_menu(g); |
||
1048 | break; |
||
1049 | |||
1050 | |||
1051 | case STATEID_GRAPH: |
||
1052 | |||
1053 | g.setClip(0,0,canvas_width,canvas_height); |
||
1054 | |||
1055 | g.setStrokeStyle(Graphics.DOTTED); |
||
1056 | g.setColor(0xe1dddd); |
||
1057 | |||
1058 | for (int d=0;d<GRAPH_COUNT;d++) |
||
1059 | { |
||
1060 | g.setColor(graph_colors[d]); |
||
1061 | g.fillRect(0,y_off +spacer1/2-2 ,20,4); |
||
1062 | g.setColor(skin_fg_color()); |
||
1063 | g.drawString(graph_names[d],23,y_off,Graphics.TOP | Graphics.LEFT); |
||
1064 | y_off+=spacer1; |
||
1065 | |||
1066 | } |
||
1067 | |||
1068 | /* |
||
1069 | g.drawString("scale:"+scale + "line scaler" + line_scaler,0,y_off,Graphics.TOP | Graphics.LEFT); |
||
1070 | |||
1071 | |||
1072 | int jump=0; |
||
1073 | g.drawLine(0,line_middle_y,canvas_width,line_middle_y); |
||
1074 | |||
1075 | while (jump<canvas_height/2) |
||
1076 | { |
||
1077 | g.drawLine(0,line_middle_y - jump/line_scaler,canvas_width,line_middle_y - jump/line_scaler); |
||
1078 | g.drawLine(0,line_middle_y + jump/line_scaler,canvas_width,line_middle_y + jump/line_scaler); |
||
1079 | jump+=scale; |
||
1080 | } |
||
1081 | */ |
||
1082 | |||
1083 | |||
1084 | |||
1085 | for (int gr=0;gr<GRAPH_COUNT;gr++) |
||
1086 | { |
||
1087 | |||
1088 | g.setColor(graph_colors[gr]); |
||
1089 | try { |
||
1090 | graph_data[gr][-bg_offset]=mk.debug_data.analog[graph_sources[gr]]; |
||
1091 | } |
||
1092 | catch (Exception e) |
||
1093 | { |
||
1094 | debug.log("E!:" + e.getMessage()); |
||
1095 | |||
1096 | } |
||
1097 | |||
1098 | |||
1099 | |||
1100 | for ( int x=0;x<canvas_width;x++) |
||
1101 | { |
||
1102 | int p= (((-bg_offset+x-canvas_width-5))); |
||
1103 | if (p<1) |
||
1104 | p+=graph_data[0].length; |
||
1105 | p%=(graph_data[0].length-1); |
||
1106 | |||
1107 | draw_graph_part(g,x,graph_data[gr][p]/line_scaler,graph_data[gr][p+1]/line_scaler); |
||
1108 | |||
1109 | } |
||
1110 | } |
||
1111 | |||
1112 | break; |
||
1113 | |||
1114 | case STATEID_FLIGHTVIEW: |
||
1115 | /* |
||
1116 | g.setClip(canvas_width/2-load_img.getWidth()/6+1,canvas_height/2-load_img.getHeight()/8+1, load_img.getWidth()/4,load_img.getHeight()/3);; |
||
1117 | if (( mk.LCD.init_state!=-1)||(mk.LCD.act_mk_page!=mk.LCD.act_user_page)) g.drawImage(load_img,canvas_width/2-load_img.getWidth()/8 - ((((frame_pos/3)%12)%4)*(load_img.getWidth()/4)) ,canvas_height/2-load_img.getHeight()/6- ((((frame_pos/3)%12)/4)*(load_img.getHeight()/3)), g.TOP | g.LEFT); |
||
1118 | |||
1119 | */ |
||
1120 | /* |
||
1121 | // !!TODO!! check exactly which version those Datas where introduced |
||
1122 | if (mk.version.compare(0,60)==mk.version.VERSION_PREVIOUS) |
||
1123 | { |
||
1124 | g.drawString("Voltage: " + (mk.debug_data.UBatt()/10) + "," +(mk.debug_data.UBatt()%10)+"V" ,0,y_off,Graphics.TOP | Graphics.LEFT); |
||
1125 | g.drawString("Sender: " + mk.debug_data.SenderOkay(),canvas_width/2,y_off,Graphics.TOP | Graphics.LEFT); |
||
1126 | y_off+=spacer; |
||
1127 | } |
||
1128 | |||
1129 | 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); |
||
1130 | |||
1131 | y_off+=spacer; |
||
1132 | |||
1133 | 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); |
||
1134 | y_off+=spacer; |
||
1135 | |||
1136 | |||
1137 | 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); |
||
1138 | y_off+=spacer; |
||
1139 | |||
1140 | if (mk.connected) |
||
1141 | { |
||
1142 | g.drawString("time conn:" +((System.currentTimeMillis()- mk.connection_start_time)/1000)+"s" ,0,y_off,Graphics.TOP | Graphics.LEFT); |
||
1143 | y_off+=spacer; |
||
1144 | g.drawString("time motor>15:" +(mk_stat.motor_on_time/1000) +"s" ,0,y_off,Graphics.TOP | Graphics.LEFT); |
||
1145 | y_off+=spacer; |
||
1146 | g.drawString("time motor=15:" +(mk_stat.motor_stand_time/1000) +"s" ,0,y_off,Graphics.TOP | Graphics.LEFT); |
||
1147 | y_off+=spacer; |
||
1148 | g.drawString("lcd:" + mk.LCD.act_mk_page + "/" + mk.LCD.pages + " ( wanted: " + mk.LCD.act_user_page + "state:" + mk.LCD.init_state +")" ,0,y_off,Graphics.TOP | Graphics.LEFT); |
||
1149 | |||
1150 | y_off+=spacer; |
||
1151 | g.drawString("lcd-key:" + mk.LCD.act_key ,0,y_off,Graphics.TOP | Graphics.LEFT); |
||
1152 | |||
1153 | } |
||
1154 | */ |
||
1155 | |||
1156 | int spacer_left_right=(canvas_width-(20*(lcd_img.getWidth()/222)))/2; |
||
1157 | |||
1158 | y_off=canvas_height-4*lcd_img.getHeight(); |
||
1159 | |||
1160 | for ( int foo=0;foo<4;foo++) |
||
1161 | { |
||
1162 | for (int x=0;x<20;x++) |
||
1163 | { |
||
1164 | g.setClip(spacer_left_right+(lcd_img.getWidth()/222)*x,y_off,(lcd_img.getWidth()/222),lcd_img.getHeight()); |
||
1165 | g.drawImage(lcd_img,spacer_left_right+(lcd_img.getWidth()/222)*x-(mk.LCD.get_act_page()[foo].charAt(x)-' ')*(lcd_img.getWidth()/222),y_off, g.TOP | g.LEFT); |
||
1166 | |||
1167 | } |
||
1168 | y_off+=lcd_img.getHeight(); |
||
1169 | } |
||
1170 | |||
1171 | g.setClip(0,0,canvas_width,canvas_height); |
||
1172 | |||
1173 | } |
||
1174 | |||
1175 | |||
1176 | |||
1177 | } catch (Exception e) {} |
||
1178 | |||
1179 | } |
||
1180 | Player mPlayer; |
||
1181 | VideoControl mVideoControl; |
||
1182 | Image cam_img; |
||
1183 | int cam_img_seq=0; |
||
1184 | byte[] cam_raw; |
||
1185 | |||
1186 | private void connect_mk(String url,String name) |
||
1187 | { |
||
1188 | // mk.ufo_prober.bluetooth_probe(url); |
||
1189 | settings.connection_url=url; |
||
1190 | settings.connection_name=name; |
||
1191 | mk.connect_to(url,name); |
||
1192 | } |
||
1193 | |||
1194 | public void draw_graph_part(Graphics g,int x,int y1,int y2) |
||
1195 | { |
||
1196 | if ( canvas_width>200) |
||
1197 | { |
||
1198 | g.fillRect(x,line_middle_y-y1,1,1 ); |
||
1199 | if (y1>y2) |
||
1200 | g.fillRect(x,line_middle_y-y1,1,y1-y2); |
||
1201 | else |
||
1202 | g.fillRect(x,line_middle_y-y2,1,y2-y1); |
||
1203 | |||
1204 | } |
||
1205 | else |
||
1206 | { |
||
1207 | g.fillRect(x,line_middle_y-y1,1,1 ); |
||
1208 | if (y1>y2) |
||
1209 | g.fillRect(x,line_middle_y-y1,1,y1-y2); |
||
1210 | else |
||
1211 | g.fillRect(x,line_middle_y-y2,1,y2-y1); |
||
1212 | } |
||
1213 | |||
1214 | } |
||
1215 | |||
1216 | |||
1217 | /*********************************************** input Section **********************************************/ |
||
1218 | |||
1219 | |||
1220 | |||
1221 | // 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) "; |
||
1222 | |||
1223 | // int intro_str_pos=0; |
||
1224 | // int intro_str_delay=3; |
||
1225 | boolean init_bootloader=false; |
||
1226 | |||
1227 | public void chg_state(byte next_state) |
||
1228 | { |
||
1229 | if (next_state!=state)act_menu_select=0; |
||
1230 | // prepare next state |
||
1231 | switch(next_state) |
||
1232 | { |
||
1233 | |||
1234 | case STATEID_FLIGHTVIEW: |
||
1235 | mk.user_intent=USER_INTENT_LCD; |
||
1236 | break; |
||
1237 | case STATEID_FLASHING: |
||
1238 | mk.bootloader_intension_flash=true; |
||
1239 | init_bootloader=true; |
||
1240 | break; |
||
1241 | |||
1242 | //#if fileapi=="on" |
||
1243 | case STATEID_FILEOPEN: |
||
1244 | if (act_path_depth==0) |
||
1245 | { |
||
1246 | Enumeration drives = FileSystemRegistry.listRoots(); |
||
1247 | int tmp_i=0; |
||
1248 | while(drives.hasMoreElements()) |
||
1249 | { |
||
1250 | file_list[tmp_i]= (String) drives.nextElement(); |
||
1251 | tmp_i++; |
||
1252 | |||
1253 | if (MAX_FILELIST_LENGTH<tmp_i) |
||
1254 | break; |
||
1255 | } |
||
1256 | menu_items=new String[tmp_i]; |
||
1257 | lcd_lines=new String[tmp_i]; |
||
1258 | file_list_length=tmp_i; |
||
1259 | |||
1260 | for(tmp_i=0;tmp_i<file_list_length;tmp_i++) |
||
1261 | menu_items[tmp_i]=file_list[tmp_i]; |
||
1262 | |||
1263 | } |
||
1264 | else |
||
1265 | { |
||
1266 | |||
1267 | try { |
||
1268 | FileConnection fc = (FileConnection) Connector.open("file:///"+act_path()); |
||
1269 | Enumeration filelist = fc.list("*", true); |
||
1270 | int tmp_i=0; |
||
1271 | while(filelist.hasMoreElements()) { |
||
1272 | file_list[tmp_i] = (String) filelist.nextElement(); |
||
1273 | tmp_i++; |
||
1274 | /* fc = (FileConnection) |
||
1275 | Connector.open("file:///CFCard/" + fileName); |
||
1276 | if(fc.isDirectory()) { |
||
1277 | System.out.println("\tDirectory Name: " + fileName); |
||
1278 | } else { |
||
1279 | System.out.println |
||
1280 | ("\tFile Name: " + fileName + |
||
1281 | "\tSize: "+fc.fileSize()); |
||
1282 | }*/ |
||
1283 | |||
1284 | } |
||
1285 | |||
1286 | menu_items=new String[tmp_i+1]; |
||
1287 | lcd_lines=new String[tmp_i+1]; |
||
1288 | file_list_length=tmp_i+1; |
||
1289 | |||
1290 | menu_items[0]=".."; |
||
1291 | for(tmp_i=1;tmp_i<file_list_length;tmp_i++) |
||
1292 | menu_items[tmp_i]=file_list[tmp_i-1]; |
||
1293 | |||
1294 | |||
1295 | fc.close(); |
||
1296 | } catch (IOException ioe) { |
||
1297 | System.out.println(ioe.getMessage()); |
||
1298 | } |
||
1299 | } |
||
1300 | |||
1301 | |||
1302 | break; |
||
1303 | //#endif |
||
1304 | |||
1305 | case STATEID_STICKVIEW: |
||
1306 | mk.user_intent=USER_INTENT_RCDATA; |
||
1307 | break; |
||
1308 | case STATEID_SELECT_COMPORT: |
||
1309 | menu_items=new String[6]; |
||
1310 | lcd_lines=new String[6]; |
||
1311 | |||
1312 | menu_items[0]="com0"; |
||
1313 | menu_items[1]="com1"; |
||
1314 | menu_items[2]="com2"; |
||
1315 | menu_items[3]="com3"; |
||
1316 | menu_items[4]="com4"; |
||
1317 | |||
1318 | menu_items[5]="back"; |
||
1319 | break; |
||
1320 | |||
1321 | |||
1322 | case STATEID_NC_ERRORS: |
||
1323 | lcd_lines=new String[1]; |
||
1324 | lcd_lines[0]=""+mk.error_str; |
||
1325 | break; |
||
1326 | |||
1327 | case STATEID_ABOUT: |
||
1328 | lcd_lines=credits; |
||
1329 | act_menu_select=max_lines-1; |
||
1330 | break; |
||
1331 | case STATEID_CONN_DETAILS: |
||
1332 | setup_menu(conn_details_menu_items,conn_details_menu_actions); |
||
1333 | break; |
||
1334 | |||
1335 | case STATEID_TRAFFIC: |
||
1336 | setup_menu(onlyback_menu_items,back_to_conndetails_actions); |
||
1337 | /* |
||
1338 | menu_items=new String[1]; |
||
1339 | lcd_lines=new String[1]; |
||
1340 | menu_items[0]="back"; |
||
1341 | */ |
||
1342 | break; |
||
1343 | case STATEID_CAMMODE: |
||
1344 | |||
1345 | if (mVideoControl==null) |
||
1346 | try |
||
1347 | { |
||
1348 | debug.log("creating player\n"); |
||
1349 | mPlayer = Manager.createPlayer("capture://video?encoding=png&width=2048&height=1536"); |
||
1350 | |||
1351 | debug.log("realizing player\n"); |
||
1352 | mPlayer.realize(); |
||
1353 | |||
1354 | debug.log("get_videocontrol\n"); |
||
1355 | |||
1356 | mVideoControl = (VideoControl)mPlayer.getControl("VideoControl"); |
||
1357 | |||
1358 | debug.log("switching Canvas\n"); |
||
1359 | mVideoControl.initDisplayMode(VideoControl.USE_DIRECT_VIDEO, this); |
||
1360 | |||
1361 | debug.log("get snap\n"); |
||
1362 | byte[] raw = mVideoControl.getSnapshot(null); |
||
1363 | |||
1364 | } |
||
1365 | catch ( Exception e) |
||
1366 | { |
||
1367 | debug.log(e.toString()); |
||
1368 | } |
||
1369 | |||
1370 | |||
1371 | break; |
||
1372 | case STATEID_KEYCONTROL: |
||
1373 | keycontrol_exit=0; |
||
1374 | break; |
||
1375 | |||
1376 | case STATEID_READ_PARAMS: |
||
1377 | mk.user_intent=USER_INTENT_PARAMS; |
||
1378 | lcd_lines=new String[2]; |
||
1379 | lcd_lines[0]="Reading Settings "; |
||
1380 | lcd_lines[1]=mk.watchdog.act_paramset+"/5 |"+ (mk.watchdog.act_paramset>0?"#":"_") + (mk.watchdog.act_paramset>1?"#":"_") + (mk.watchdog.act_paramset>2?"#":"_")+ (mk.watchdog.act_paramset>3?"#":"_")+ (mk.watchdog.act_paramset>4?"#":"_") + "| "; |
||
1381 | |||
1382 | break; |
||
1383 | |||
1384 | case STATEID_IPINPUT: |
||
1385 | |||
1386 | lcd_lines=new String[3]; |
||
1387 | lcd_lines[0]="Address (IP:Port): "; |
||
1388 | break; |
||
1389 | |||
1390 | //#if bluetooth=="on" |
||
1391 | case STATEID_SCANNING: |
||
1392 | lcd_lines=new String[3]; |
||
1393 | lcd_lines[0]="Searching for"; |
||
1394 | lcd_lines[1]="Bluetooth Devices"; |
||
1395 | lcd_lines[2]="found"; |
||
1396 | |||
1397 | mk.close_connections(true); |
||
1398 | bt_scanner.search(); |
||
1399 | break; |
||
1400 | //#endif |
||
1401 | |||
1402 | case STATEID_HANDLE_PARAMS: |
||
1403 | menu_items=handle_params_menu_items; |
||
1404 | menu_actions=handle_params_menu_actions; |
||
1405 | lcd_lines=new String[menu_items.length]; |
||
1406 | |||
1407 | break; |
||
1408 | |||
1409 | case STATEID_SELECT_PARAMSET: |
||
1410 | menu_items=new String[5]; |
||
1411 | for (int i=0;i<5;i++) |
||
1412 | menu_items[i]=mk.params.names[i] + ((i==mk.params.active_paramset)?"*":""); |
||
1413 | |||
1414 | lcd_lines=new String[5]; |
||
1415 | break; |
||
1416 | |||
1417 | //#if bluetooth=="on" |
||
1418 | case STATEID_DEVICESELECT: |
||
1419 | |||
1420 | menu_items=new String[bt_scanner.remote_device_count+2]; |
||
1421 | lcd_lines=new String[bt_scanner.remote_device_count+2]; |
||
1422 | |||
1423 | for (int i=0;i<bt_scanner.remote_device_count;i++) |
||
1424 | menu_items[i]=bt_scanner.remote_device_name[i]; |
||
1425 | menu_items[bt_scanner.remote_device_count]="scan again"; |
||
1426 | menu_items[bt_scanner.remote_device_count+1]="cancel"; |
||
1427 | |||
1428 | break; |
||
1429 | //#endif |
||
1430 | |||
1431 | case STATEID_MAINMENU: |
||
1432 | if (mk.ufo_prober.is_navi()) |
||
1433 | setup_menu(main_menu_items_navi,main_menu_actions_navi); |
||
1434 | else if (mk.ufo_prober.is_mk()) |
||
1435 | setup_menu(main_menu_items_mk,main_menu_actions_mk); |
||
1436 | else if (mk.ufo_prober.is_mk3mag()) |
||
1437 | setup_menu(main_menu_items_mk3mag,main_menu_actions_mk3mag); |
||
1438 | else if (mk.ufo_prober.is_incompatible()) |
||
1439 | setup_menu(main_menu_items_incompatible,main_menu_actions_incompatible); |
||
1440 | else // no connection |
||
1441 | setup_menu(main_menu_items_no_connection,main_menu_actions_no_connection); |
||
1442 | break; |
||
1443 | |||
1444 | case STATEID_SETTINGSMENU: |
||
1445 | |||
1446 | menu_items=new String[settings_menu_items.length]; |
||
1447 | for(int cnt=0;cnt<settings_menu_items.length;cnt++) |
||
1448 | menu_items[cnt]=settings_menu_items[cnt]; |
||
1449 | |||
1450 | menu_items[0]+=(settings.act_skin==SKINID_DARK)?"Dark":"Light"; |
||
1451 | menu_items[1]+=(!settings.do_sound)?"Off":"On"; |
||
1452 | menu_items[2]+=(!settings.do_vibra)?"Off":"On"; |
||
1453 | menu_items[3]+=(!settings.do_scrollbg)?"Off":"On"; |
||
1454 | menu_items[4]+=(!settings.fullscreen)?"Off":"On"; |
||
1455 | |||
1456 | //#if devicecontrol=="on" |
||
1457 | menu_items[5]+=(!settings.keep_lighton)?"Off":"On"; |
||
1458 | //#endif |
||
1459 | menu_actions=settings_menu_actions; |
||
1460 | lcd_lines=new String[menu_items.length]; |
||
1461 | break; |
||
1462 | |||
1463 | case STATEID_RAWDEBUG: |
||
1464 | mk.user_intent=USER_INTENT_RAWDEBUG; |
||
1465 | break; |
||
1466 | |||
1467 | |||
1468 | case STATEID_GRAPH: |
||
1469 | mk.user_intent=USER_INTENT_GRAPH; |
||
1470 | break; |
||
1471 | |||
1472 | } |
||
1473 | mk.watchdog.resend_timeout=0; |
||
1474 | |||
1475 | // switch state |
||
1476 | state=next_state; |
||
1477 | } // void chg_state |
||
1478 | |||
1479 | |||
1480 | public void keyReleased(int keyCode) |
||
1481 | { |
||
1482 | |||
1483 | switch(state) |
||
1484 | { |
||
1485 | case STATEID_MOTORTEST: |
||
1486 | act_motor_increase=0; |
||
1487 | break; |
||
1488 | |||
1489 | case STATEID_KEYCONTROL: |
||
1490 | if (keyCode==KEY_POUND) |
||
1491 | keycontrol_exit &= 255^1; |
||
1492 | else |
||
1493 | if (keyCode==KEY_STAR) |
||
1494 | keycontrol_exit &= 255^2; |
||
1495 | else |
||
1496 | if ((keyCode >= this.KEY_NUM0) && (keyCode < this.KEY_NUM8)) |
||
1497 | keycontrol_bitfield[0]&=255^( 1<<(keyCode-this.KEY_NUM0)); |
||
1498 | else |
||
1499 | if ((keyCode >= this.KEY_NUM8) && (keyCode <= this.KEY_NUM9)) |
||
1500 | keycontrol_bitfield[1]&=255^( 1<<(keyCode-this.KEY_NUM8)); |
||
1501 | else |
||
1502 | switch (getGameAction (keyCode)) |
||
1503 | { |
||
1504 | case UP: |
||
1505 | keycontrol_bitfield[1]&=255^4; |
||
1506 | break; |
||
1507 | |||
1508 | case DOWN: |
||
1509 | keycontrol_bitfield[1]&=255^8; |
||
1510 | break; |
||
1511 | |||
1512 | |||
1513 | case LEFT: |
||
1514 | keycontrol_bitfield[1]&=255^16; |
||
1515 | break; |
||
1516 | |||
1517 | case RIGHT: |
||
1518 | keycontrol_bitfield[1]&=255^32; |
||
1519 | break; |
||
1520 | |||
1521 | case FIRE: |
||
1522 | keycontrol_bitfield[1]&=255^64; |
||
1523 | break; |
||
1524 | |||
1525 | |||
1526 | } |
||
1527 | mk.send_keys(keycontrol_bitfield); |
||
1528 | break; |
||
1529 | } |
||
1530 | |||
1531 | } |
||
1532 | |||
1533 | |||
1534 | byte keycontrol_exit=0; |
||
1535 | |||
1536 | public final static int[] keycontrol_bitfield={0,0}; |
||
1537 | |||
1538 | |||
1539 | public void pointerPressed (int pointer_x, int pointer_y) |
||
1540 | { |
||
1541 | if (pointer_y<lcd_img.getHeight()) |
||
1542 | keyPressed(KEY_STAR); |
||
1543 | else |
||
1544 | switch(state) |
||
1545 | { |
||
1546 | case STATEID_CONN_DETAILS: |
||
1547 | case STATEID_SETTINGSMENU: |
||
1548 | case STATEID_FILEOPEN: |
||
1549 | case STATEID_TRAFFIC: |
||
1550 | case STATEID_SELECT_COMPORT: |
||
1551 | case STATEID_MAINMENU: |
||
1552 | case STATEID_SELECT_PARAMSET: |
||
1553 | case STATEID_DEVICESELECT: |
||
1554 | |||
1555 | if (pointer_y>canvas_height-lcd_img.getHeight()*menu_items.length) |
||
1556 | { |
||
1557 | act_menu_select=(pointer_y-(canvas_height-lcd_img.getHeight()*menu_items.length))/lcd_img.getHeight(); |
||
1558 | keyPressed(getKeyCode(FIRE)); |
||
1559 | } |
||
1560 | break; |
||
1561 | } |
||
1562 | } |
||
1563 | |||
1564 | public void keyPressed(int keyCode) |
||
1565 | { |
||
1566 | debug.log("KeyCode:"+keyCode); |
||
1567 | // key-actions common in all states |
||
1568 | debug.process_key(keyCode); |
||
1569 | |||
1570 | /* |
||
1571 | if ((keyCode==KEY_NUM9)) |
||
1572 | { chg_state(STATEID_FLASHING); } |
||
1573 | */ |
||
1574 | |||
1575 | |||
1576 | |||
1577 | |||
1578 | if ((keyCode==KEY_STAR) || (keyCode==113)) |
||
1579 | { |
||
1580 | if (state==STATEID_EDIT_PARAMS) |
||
1581 | { |
||
1582 | chg_state(STATEID_HANDLE_PARAMS); |
||
1583 | return; |
||
1584 | } |
||
1585 | else |
||
1586 | if (state!=STATEID_KEYCONTROL) |
||
1587 | { |
||
1588 | chg_state(STATEID_MAINMENU); |
||
1589 | return; |
||
1590 | } |
||
1591 | |||
1592 | } |
||
1593 | if ((keyCode==KEY_POUND)&&(state!=STATEID_KEYCONTROL)) |
||
1594 | { |
||
1595 | settings.fullscreen=!settings.fullscreen; |
||
1596 | setFullScreenMode(settings.fullscreen); |
||
1597 | return; |
||
1598 | } |
||
1599 | |||
1600 | // key actions per state |
||
1601 | switch(state) |
||
1602 | { |
||
1603 | |||
1604 | case STATEID_NC_ERRORS: |
||
1605 | chg_state(STATEID_MAINMENU); |
||
1606 | break; |
||
1607 | case STATEID_IPINPUT: |
||
1608 | if ((keyCode>=KEY_NUM0)&&(keyCode<=KEY_NUM9)) |
||
1609 | { |
||
1610 | act_edit_ip[ipinput_pos/4]=helper.mod_decimal(act_edit_ip[ipinput_pos/4],(ipinput_pos<15?2:3)-(ipinput_pos%4),0,(keyCode-KEY_NUM0),9); |
||
1611 | |||
1612 | if(ipinput_pos<19) ipinput_pos++; |
||
1613 | if ((ipinput_pos<18)&&(((ipinput_pos+1)%4)==0))ipinput_pos++; |
||
1614 | } |
||
1615 | else |
||
1616 | switch (getGameAction (keyCode)) |
||
1617 | { |
||
1618 | case LEFT: |
||
1619 | if(ipinput_pos>0) ipinput_pos--; |
||
1620 | if (((ipinput_pos+1)%4)==0)ipinput_pos--; |
||
1621 | break; |
||
1622 | |||
1623 | case RIGHT: |
||
1624 | if(ipinput_pos<19) ipinput_pos++; |
||
1625 | if(ipinput_pos<18)if (((ipinput_pos+1)%4)==0)ipinput_pos++; |
||
1626 | break; |
||
1627 | |||
1628 | case UP: |
||
1629 | act_edit_ip[ipinput_pos/4]=helper.mod_decimal(act_edit_ip[ipinput_pos/4],(ipinput_pos<15?2:3)-(ipinput_pos%4),1,-1,9); |
||
1630 | |||
1631 | break; |
||
1632 | |||
1633 | case DOWN: |
||
1634 | act_edit_ip[ipinput_pos/4]=helper.mod_decimal(act_edit_ip[ipinput_pos/4],(ipinput_pos<15?2:3)-(ipinput_pos%4),-1,-1,9); |
||
1635 | |||
1636 | |||
1637 | case FIRE: |
||
1638 | if (ipinput4proxy) |
||
1639 | { |
||
1640 | settings.act_proxy_ip=act_edit_ip; |
||
1641 | mk.do_proxy("socket://"+helper.ip_str(settings.act_proxy_ip,false)); |
||
1642 | chg_state(STATEID_PROXY); |
||
1643 | } |
||
1644 | else |
||
1645 | { |
||
1646 | settings.act_conn_ip=act_edit_ip; |
||
1647 | connect_mk("socket://"+helper.ip_str(settings.act_conn_ip,false),"TCP/IP Connection"); |
||
1648 | chg_state(STATEID_CONN_DETAILS); |
||
1649 | } |
||
1650 | |||
1651 | break; |
||
1652 | |||
1653 | } |
||
1654 | break; |
||
1655 | |||
1656 | case STATEID_GPSVIEW: |
||
1657 | if (keyCode == this.KEY_NUM0) |
||
1658 | mk.set_gps_target(mk.gps_position.Latitude,mk.gps_position.Longitude); |
||
1659 | |||
1660 | |||
1661 | |||
1662 | if (keyCode == this.KEY_NUM1) |
||
1663 | mk.gps_position.push_wp(); |
||
1664 | if (keyCode == this.KEY_NUM2) |
||
1665 | chg_state(STATEID_FILEOPEN); |
||
1666 | if (keyCode == this.KEY_NUM3) |
||
1667 | mk.set_gps_target(mk.gps_position.LatWP[act_wp],mk.gps_position.LongWP[act_wp]); |
||
1668 | |||
1669 | if (keyCode == this.KEY_NUM4) |
||
1670 | mk.gps_position.next_gps_format(); |
||
1671 | |||
1672 | if (keyCode == this.KEY_NUM5) |
||
1673 | heading_offset= mk.debug_data.analog[26]; |
||
1674 | |||
1675 | switch (getGameAction (keyCode)) |
||
1676 | { |
||
1677 | case UP: |
||
1678 | if (act_wp!=0) act_wp--; |
||
1679 | break; |
||
1680 | |||
1681 | case DOWN: |
||
1682 | if (act_wp<mk.gps_position.last_wp) act_wp++; |
||
1683 | |||
1684 | break; |
||
1685 | |||
1686 | |||
1687 | } |
||
1688 | |||
1689 | |||
1690 | break; |
||
1691 | |||
1692 | case STATEID_ABOUT: |
||
1693 | |||
1694 | switch (getGameAction (keyCode)) |
||
1695 | { |
||
1696 | case UP: |
||
1697 | if (act_menu_select>=max_lines) |
||
1698 | act_menu_select--; |
||
1699 | break; |
||
1700 | |||
1701 | case DOWN: |
||
1702 | if (act_menu_select<lcd_lines.length-1) |
||
1703 | act_menu_select++; |
||
1704 | |||
1705 | break; |
||
1706 | |||
1707 | |||
1708 | } |
||
1709 | |||
1710 | |||
1711 | break; |
||
1712 | |||
1713 | |||
1714 | case STATEID_RAWDEBUG: |
||
1715 | |||
1716 | switch (getGameAction (keyCode)) |
||
1717 | { |
||
1718 | case UP: |
||
1719 | if (rawdebug_cursor_y==0) |
||
1720 | rawdebug_cursor_y=31; |
||
1721 | else |
||
1722 | rawdebug_cursor_y--; |
||
1723 | break; |
||
1724 | |||
1725 | case DOWN: |
||
1726 | if (rawdebug_cursor_y==31) |
||
1727 | rawdebug_cursor_y=0; |
||
1728 | else |
||
1729 | rawdebug_cursor_y++; |
||
1730 | break; |
||
1731 | |||
1732 | |||
1733 | } |
||
1734 | break; |
||
1735 | case STATEID_KEYCONTROL: |
||
1736 | if (keyCode==KEY_POUND) |
||
1737 | keycontrol_exit |= 1; |
||
1738 | else |
||
1739 | if (keyCode==KEY_STAR) |
||
1740 | keycontrol_exit |= 2; |
||
1741 | else |
||
1742 | if ((keyCode >= this.KEY_NUM0) && (keyCode < this.KEY_NUM8)) |
||
1743 | keycontrol_bitfield[0]|=1<<(keyCode-this.KEY_NUM0); |
||
1744 | else |
||
1745 | if ((keyCode >= this.KEY_NUM8) && (keyCode <= this.KEY_NUM9)) |
||
1746 | keycontrol_bitfield[1]|=1<<(keyCode-this.KEY_NUM8); |
||
1747 | |||
1748 | else |
||
1749 | switch (getGameAction (keyCode)) |
||
1750 | { |
||
1751 | case UP: |
||
1752 | keycontrol_bitfield[1]|=4; |
||
1753 | break; |
||
1754 | |||
1755 | case DOWN: |
||
1756 | keycontrol_bitfield[1]|=8; |
||
1757 | break; |
||
1758 | |||
1759 | |||
1760 | case LEFT: |
||
1761 | keycontrol_bitfield[1]|=16; |
||
1762 | break; |
||
1763 | |||
1764 | case RIGHT: |
||
1765 | keycontrol_bitfield[1]|=32; |
||
1766 | break; |
||
1767 | |||
1768 | case FIRE: |
||
1769 | keycontrol_bitfield[1]|=64; |
||
1770 | break; |
||
1771 | |||
1772 | } |
||
1773 | if (keycontrol_exit==3) |
||
1774 | chg_state(STATEID_MAINMENU); |
||
1775 | else |
||
1776 | mk.send_keys(keycontrol_bitfield); |
||
1777 | break; |
||
1778 | |||
1779 | |||
1780 | case STATEID_MOTORTEST: |
||
1781 | switch (getGameAction (keyCode)) |
||
1782 | { |
||
1783 | case UP: |
||
1784 | act_motor_increase=-1; |
||
1785 | break; |
||
1786 | |||
1787 | case DOWN: |
||
1788 | act_motor_increase=1; |
||
1789 | break; |
||
1790 | |||
1791 | case FIRE: |
||
1792 | motor_test_sel_all=!motor_test_sel_all; |
||
1793 | break; |
||
1794 | |||
1795 | case LEFT: |
||
1796 | act_motor--; |
||
1797 | if (act_motor<0) {act_motor=0; chg_state(STATEID_MAINMENU); } |
||
1798 | break; |
||
1799 | |||
1800 | case RIGHT: |
||
1801 | act_motor++; |
||
1802 | act_motor%=4; |
||
1803 | break; |
||
1804 | } |
||
1805 | |||
1806 | break; |
||
1807 | |||
1808 | case STATEID_SELECT_COMPORT: |
||
1809 | if ( getGameAction (keyCode)==FIRE ) |
||
1810 | { |
||
1811 | |||
1812 | if (act_menu_select<menu_items.length) |
||
1813 | connect_mk("comm:com"+act_menu_select+";baudrate=57600","com"+act_menu_select); |
||
1814 | |||
1815 | chg_state(STATEID_CONN_DETAILS); |
||
1816 | } |
||
1817 | else |
||
1818 | menu_keypress(keyCode); |
||
1819 | break; |
||
1820 | |||
1821 | /* |
||
1822 | case STATEID_HANDLsE_PARAMS: |
||
1823 | |||
1824 | menu_keypress(keyCode); |
||
1825 | break; |
||
1826 | */ |
||
1827 | /* |
||
1828 | case STATEID_TRAFFIC: |
||
1829 | if ( getGameAction (keyCode)==FIRE ) |
||
1830 | chg_state(STATEID_CONN_DETAILS); |
||
1831 | else |
||
1832 | menu_keypress(keyCode); |
||
1833 | break; |
||
1834 | */ |
||
1835 | //#if fileapi=="on" |
||
1836 | case STATEID_FILEOPEN: |
||
1837 | if ( getGameAction (keyCode)==FIRE ) |
||
1838 | { |
||
1839 | if ((act_menu_select==0)&&(act_path_depth!=0)) |
||
1840 | { |
||
1841 | act_path_depth--; |
||
1842 | //act_path=act_path.substring(0,act_path.substring(0,act_path.length()-2).indexOf('/') ); |
||
1843 | |||
1844 | //act_path=last_path; |
||
1845 | } |
||
1846 | else |
||
1847 | { |
||
1848 | //last_path=act_path; |
||
1849 | if (act_path_depth==0) |
||
1850 | act_path_arr[act_path_depth++]=file_list[act_menu_select]; |
||
1851 | else |
||
1852 | act_path_arr[act_path_depth++]=file_list[act_menu_select-1]; |
||
1853 | } |
||
1854 | act_menu_select=0; |
||
1855 | chg_state(STATEID_FILEOPEN); |
||
1856 | |||
1857 | } |
||
1858 | else |
||
1859 | menu_keypress(keyCode); |
||
1860 | break; |
||
1861 | |||
1862 | //#endif |
||
1863 | |||
1864 | |||
1865 | // handle menue |
||
1866 | case STATEID_TRAFFIC: |
||
1867 | case STATEID_CONN_DETAILS: |
||
1868 | case STATEID_HANDLE_PARAMS: |
||
1869 | case STATEID_SETTINGSMENU: |
||
1870 | case STATEID_MAINMENU: |
||
1871 | |||
1872 | if ( getGameAction (keyCode)==FIRE ) |
||
1873 | { |
||
1874 | switch(menu_actions[act_menu_select]) |
||
1875 | { |
||
1876 | |||
1877 | case ACTIONID_BACK_TO_CONNDETAILS: |
||
1878 | chg_state(STATEID_CONN_DETAILS); |
||
1879 | break; |
||
1880 | |||
1881 | case ACTIONID_RESET_PARAMS: |
||
1882 | state=STATEID_FLASHING; |
||
1883 | mk.bootloader_intension_flash=false; |
||
1884 | init_bootloader=true; |
||
1885 | break; |
||
1886 | |||
1887 | case ACTIONID_FLASH: |
||
1888 | |||
1889 | chg_state(STATEID_FLASHING); |
||
1890 | |||
1891 | //chg_state(STATEID_FLASHING); |
||
1892 | break; |
||
1893 | |||
1894 | case ACTIONID_DATABUFF: |
||
1895 | chg_state(STATEID_DATABUFF); |
||
1896 | break; |
||
1897 | |||
1898 | case ACTIONID_NC_ERRORS: |
||
1899 | chg_state(STATEID_NC_ERRORS); |
||
1900 | break; |
||
1901 | |||
1902 | case ACTIONID_ABOUT: |
||
1903 | chg_state(STATEID_ABOUT); |
||
1904 | break; |
||
1905 | |||
1906 | case ACTIONID_CONN_DETAILS: |
||
1907 | chg_state(STATEID_CONN_DETAILS); |
||
1908 | break; |
||
1909 | |||
1910 | case ACTIONID_QUIT: |
||
1911 | quit=true; |
||
1912 | break; |
||
1913 | |||
1914 | case ACTIONID_SWITCH_NC: |
||
1915 | mk.switch_to_navi(); |
||
1916 | break; |
||
1917 | |||
1918 | case ACTIONID_SWITCH_FC: |
||
1919 | mk.switch_to_fc(); |
||
1920 | break; |
||
1921 | |||
1922 | case ACTIONID_SWITCH_MK3MAG: |
||
1923 | mk.switch_to_mk3mag(); |
||
1924 | break; |
||
1925 | |||
1926 | case ACTIONID_GRAPH: |
||
1927 | chg_state(STATEID_GRAPH); |
||
1928 | break; |
||
1929 | |||
1930 | case ACTIONID_KEYCONTROL: |
||
1931 | chg_state(STATEID_KEYCONTROL); |
||
1932 | break; |
||
1933 | |||
1934 | case ACTIONID_LCD : |
||
1935 | chg_state(STATEID_FLIGHTVIEW); |
||
1936 | break; |
||
1937 | |||
1938 | |||
1939 | case ACTIONID_PROXY: |
||
1940 | |||
1941 | chg_state(STATEID_IPINPUT); |
||
1942 | break; |
||
1943 | |||
1944 | case ACTIONID_DEVICESELECT: |
||
1945 | chg_state(STATEID_SCANNING); |
||
1946 | break; |
||
1947 | |||
1948 | case ACTIONID_RAWDEBUG: |
||
1949 | chg_state(STATEID_RAWDEBUG); |
||
1950 | break; |
||
1951 | |||
1952 | case ACTIONID_SETTINGS: |
||
1953 | chg_state(STATEID_SETTINGSMENU); |
||
1954 | break; |
||
1955 | |||
1956 | case ACTIONID_RCDATA: |
||
1957 | chg_state(STATEID_STICKVIEW); |
||
1958 | break; |
||
1959 | |||
1960 | case ACTIONID_CAM: |
||
1961 | chg_state(STATEID_CAMMODE); |
||
1962 | break; |
||
1963 | |||
1964 | case ACTIONID_GPSDATA: |
||
1965 | chg_state(STATEID_GPSVIEW); |
||
1966 | break; |
||
1967 | |||
1968 | |||
1969 | case ACTIONID_MOTORTEST : |
||
1970 | chg_state(STATEID_MOTORTEST); |
||
1971 | break; |
||
1972 | |||
1973 | |||
1974 | case ACTIONID_EDIT_PARAMS: |
||
1975 | if (mk.watchdog.act_paramset<5) |
||
1976 | chg_state(STATEID_READ_PARAMS); |
||
1977 | else |
||
1978 | chg_state(STATEID_SELECT_PARAMSET); |
||
1979 | |||
1980 | break; |
||
1981 | |||
1982 | case ACTIONID_CHANGESKIN: |
||
1983 | settings.act_skin++; |
||
1984 | settings.act_skin=(byte)(settings.act_skin%2); |
||
1985 | load_images(); |
||
1986 | chg_state(STATEID_SETTINGSMENU); |
||
1987 | break; |
||
1988 | case ACTIONID_SOUNDTOGGLE: |
||
1989 | settings.do_sound=!settings.do_sound; |
||
1990 | chg_state(STATEID_SETTINGSMENU); |
||
1991 | break; |
||
1992 | case ACTIONID_VIBRATOGGLE: |
||
1993 | settings.do_vibra=!settings.do_vibra; |
||
1994 | chg_state(STATEID_SETTINGSMENU); |
||
1995 | break; |
||
1996 | |||
1997 | case ACTIONID_GRAPHTOGGLE: |
||
1998 | settings.do_scrollbg=!settings.do_scrollbg; |
||
1999 | load_images(); |
||
2000 | chg_state(STATEID_SETTINGSMENU); |
||
2001 | break; |
||
2002 | |||
2003 | |||
2004 | case ACTIONID_FULLSCREENTOGGLE: |
||
2005 | settings.fullscreen=!settings.fullscreen; |
||
2006 | setFullScreenMode(settings.fullscreen); |
||
2007 | chg_state(STATEID_SETTINGSMENU); |
||
2008 | break; |
||
2009 | |||
2010 | //#if devicecontrol=="on" |
||
2011 | case ACTIONID_LIGHTTOGGLE: |
||
2012 | settings.keep_lighton =!settings.keep_lighton; |
||
2013 | chg_state(STATEID_SETTINGSMENU); |
||
2014 | break; |
||
2015 | //#endif |
||
2016 | |||
2017 | |||
2018 | case ACTIONID_WRITE_PARAMS: |
||
2019 | mk.write_params(); |
||
2020 | chg_state(STATEID_MAINMENU); |
||
2021 | break; |
||
2022 | |||
2023 | case ACTIONID_UNDO_PARAMS: |
||
2024 | mk.params.use_backup(); |
||
2025 | chg_state(STATEID_MAINMENU); |
||
2026 | break; |
||
2027 | |||
2028 | case ACTIONID_MAINMENU: |
||
2029 | chg_state(STATEID_MAINMENU); |
||
2030 | break; |
||
2031 | |||
2032 | case ACTIONID_DEBUG: |
||
2033 | debug.showing=true; |
||
2034 | break; |
||
2035 | |||
2036 | |||
2037 | |||
2038 | |||
2039 | case ACTIONID_TRAFFIC: |
||
2040 | chg_state(STATEID_TRAFFIC); |
||
2041 | break; |
||
2042 | |||
2043 | case ACTIONID_CONNECT_TCP: |
||
2044 | ipinput4proxy=false; |
||
2045 | chg_state(STATEID_IPINPUT); |
||
2046 | break; |
||
2047 | |||
2048 | case ACTIONID_SCAN_BT: |
||
2049 | chg_state(STATEID_SCANNING); |
||
2050 | break; |
||
2051 | |||
2052 | case ACTIONID_SELECT_COM: |
||
2053 | chg_state(STATEID_SELECT_COMPORT); |
||
2054 | break; |
||
2055 | |||
2056 | case ACTIONID_PROXY_INPUT: |
||
2057 | ipinput4proxy=true; |
||
2058 | chg_state(STATEID_IPINPUT); |
||
2059 | break; |
||
2060 | |||
2061 | } |
||
2062 | |||
2063 | } |
||
2064 | |||
2065 | else menu_keypress(keyCode); |
||
2066 | |||
2067 | break; |
||
2068 | |||
2069 | case STATEID_SELECT_PARAMSET: |
||
2070 | if ( getGameAction (keyCode)==FIRE ) |
||
2071 | { |
||
2072 | if ( mk.params.field[act_menu_select]!=null) |
||
2073 | { |
||
2074 | mk.params.act_paramset=act_menu_select; |
||
2075 | chg_state(STATEID_EDIT_PARAMS); |
||
2076 | } |
||
2077 | } |
||
2078 | else menu_keypress(keyCode); |
||
2079 | break; |
||
2080 | |||
2081 | //#if bluetooth=="on" |
||
2082 | case STATEID_DEVICESELECT: |
||
2083 | |||
2084 | if ( getGameAction (keyCode)==FIRE ) |
||
2085 | { |
||
2086 | |||
2087 | if (bt_scanner.remote_device_count > act_menu_select) |
||
2088 | { |
||
2089 | connect_mk("btspp://"+bt_scanner.remote_device_mac[act_menu_select] + ":1",bt_scanner.remote_device_name[act_menu_select]); |
||
2090 | chg_state(STATEID_CONN_DETAILS); |
||
2091 | } |
||
2092 | else |
||
2093 | { |
||
2094 | if (bt_scanner.remote_device_count == act_menu_select) |
||
2095 | chg_state(STATEID_SCANNING); |
||
2096 | else |
||
2097 | chg_state(STATEID_CONN_DETAILS); |
||
2098 | } |
||
2099 | |||
2100 | } |
||
2101 | else menu_keypress(keyCode); |
||
2102 | |||
2103 | break; |
||
2104 | //#endif |
||
2105 | |||
2106 | |||
2107 | case STATEID_EDIT_PARAMS: |
||
2108 | params_editor.keypress(keyCode,getGameAction (keyCode)) ; |
||
2109 | break; |
||
2110 | |||
2111 | case STATEID_FLIGHTVIEW: |
||
2112 | |||
2113 | if ((keyCode >= this.KEY_NUM0) && (keyCode <= this.KEY_NUM9)) |
||
2114 | mk.LCD.set_page(keyCode-this.KEY_NUM0); |
||
2115 | else |
||
2116 | switch (getGameAction (keyCode)) |
||
2117 | { |
||
2118 | case LEFT: |
||
2119 | case UP: |
||
2120 | mk.LCD.LCD_PREVPAGE(); |
||
2121 | break; |
||
2122 | |||
2123 | case RIGHT: |
||
2124 | case DOWN: |
||
2125 | mk.LCD.LCD_NEXTPAGE(); |
||
2126 | break; |
||
2127 | |||
2128 | |||
2129 | |||
2130 | } |
||
2131 | break; |
||
2132 | } |
||
2133 | |||
2134 | |||
2135 | |||
2136 | } |
||
2137 | |||
2138 | |||
2139 | |||
2140 | |||
2141 | |||
2142 | |||
2143 | |||
2144 | |||
2145 | } |
||
2146 | |||
2147 |