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