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