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