Rev 210 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 210 | Rev 221 | ||
---|---|---|---|
Line 10... | Line 10... | ||
10 | *********************************************************************************************************************************/ |
10 | *********************************************************************************************************************************/ |
Line 11... | Line 11... | ||
11 | 11 | ||
12 | import javax.microedition.lcdui.*; |
12 | import javax.microedition.lcdui.*; |
Line -... | Line 13... | ||
- | 13 | import javax.microedition.rms.*; |
|
13 | import javax.microedition.rms.*; |
14 | |
14 | 15 | ||
15 | public class MKMiniCanvas |
16 | public class MKMiniCanvas |
16 | extends Canvas |
17 | extends Canvas |
Line 22... | Line 23... | ||
22 | private MKCommunicator mk=null; |
23 | private MKCommunicator mk=null; |
23 | private MKStatistics mk_stat=null; |
24 | private MKStatistics mk_stat=null; |
24 | private String err=""; |
25 | private String err=""; |
25 | private MKMiniMidlet root; |
26 | private MKMiniMidlet root; |
Line -... | Line 27... | ||
- | 27 | ||
- | 28 | private Image bg_img; |
|
- | 29 | private Image bt_img; |
|
- | 30 | private Image lcd_img; |
|
- | 31 | private Image load_img; |
|
- | 32 | ||
- | 33 | ||
- | 34 | public int[] nick_line_pos_data; |
|
- | 35 | public int[] roll_line_pos_data; |
|
- | 36 | ||
- | 37 | public int[] accnick_line_pos_data; |
|
- | 38 | public int[] accroll_line_pos_data; |
|
- | 39 | ||
- | 40 | ||
- | 41 | public int frame_pos=0; |
|
- | 42 | ||
- | 43 | int line_scaler=20; |
|
- | 44 | ||
- | 45 | public int line_middle_y; |
|
26 | 46 | ||
27 | public MKMiniCanvas(MKMiniMidlet _root) |
47 | public MKMiniCanvas(MKMiniMidlet _root) |
- | 48 | { |
|
28 | { |
49 | |
Line -... | Line 50... | ||
- | 50 | root=_root; |
|
- | 51 | ||
- | 52 | try |
|
- | 53 | { |
|
- | 54 | lcd_img=Image.createImage("/lcd.png"); |
|
- | 55 | bt_img=Image.createImage("/bt.png"); |
|
- | 56 | bg_img=Image.createImage("/bg.jpg"); |
|
- | 57 | load_img=Image.createImage("/load.png"); |
|
- | 58 | } |
|
- | 59 | catch (Exception e) |
|
- | 60 | { |
|
- | 61 | err+=e.toString(); |
|
- | 62 | } |
|
- | 63 | ||
- | 64 | ||
- | 65 | nick_line_pos_data=new int[bg_img.getWidth()]; |
|
- | 66 | roll_line_pos_data=new int[bg_img.getWidth()]; |
|
- | 67 | accnick_line_pos_data=new int[bg_img.getWidth()]; |
|
- | 68 | accroll_line_pos_data=new int[bg_img.getWidth()]; |
|
- | 69 | ||
- | 70 | for (int c=0;c<bg_img.getWidth();c++) |
|
- | 71 | { |
|
- | 72 | nick_line_pos_data[c]=-1; |
|
- | 73 | roll_line_pos_data[c]=-1; |
|
- | 74 | accnick_line_pos_data[c]=-1; |
|
- | 75 | accroll_line_pos_data[c]=-1; |
|
- | 76 | } |
|
29 | root=_root; |
77 | |
30 | 78 | ||
Line 31... | Line 79... | ||
31 | // mk = new MKCommunicator("btspp://000BCE016B5B:1"); |
79 | // mk = new MKCommunicator("btspp://000BCE016B5B:1"); |
Line 55... | Line 103... | ||
55 | 103 | ||
Line 56... | Line 104... | ||
56 | } |
104 | } |
57 | 105 | ||
- | 106 | boolean quit=false; |
|
- | 107 | boolean rescan=true; |
|
Line -... | Line 108... | ||
- | 108 | int bg_offset=0; |
|
58 | boolean quit=false; |
109 | |
59 | boolean rescan=true; |
110 | |
60 | 111 | ||
61 | 112 | ||
Line 62... | Line 113... | ||
62 | /********************************************************** Thread ***********************************************************/ |
113 | /********************************************************** Thread ***********************************************************/ |
63 | // ticking runnable Section |
114 | // ticking runnable Section |
64 | public void run() |
115 | public void run() |
65 | { |
116 | { |
66 | 117 | ||
- | 118 | while(true) |
|
- | 119 | { |
|
- | 120 | long loopStartTime = System.currentTimeMillis(); |
|
- | 121 | long sleeptime=0; |
|
- | 122 | // ticked thing |
|
- | 123 | ||
- | 124 | frame_pos++; |
|
- | 125 | ||
- | 126 | try { |
|
- | 127 | nick_line_pos_data[-bg_offset] = mk.debug_data.nick_int(); |
|
- | 128 | roll_line_pos_data[-bg_offset] = mk.debug_data.roll_int(); |
|
- | 129 | accnick_line_pos_data[-bg_offset] = mk.debug_data.accnick(); |
|
- | 130 | accroll_line_pos_data[-bg_offset] = mk.debug_data.accroll(); |
|
- | 131 | } |
|
- | 132 | catch (Exception e) |
|
- | 133 | { |
|
Line 67... | Line 134... | ||
67 | while(true) |
134 | err+=e.toString(); |
68 | { |
135 | } |
- | 136 | ||
- | 137 | ||
- | 138 | ||
69 | long loopStartTime = System.currentTimeMillis(); |
139 | |
70 | long sleeptime=0; |
140 | if (quit) |
71 | // ticked thing |
141 | { |
Line 72... | Line 142... | ||
72 | 142 | ||
Line 89... | Line 159... | ||
89 | 159 | ||
90 | root.quit(); |
160 | root.quit(); |
91 | } |
161 | } |
92 | if (rescan) |
162 | if (rescan) |
93 | { |
163 | { |
94 | if (mk!=null) mk.close_connections(); |
164 | if (mk!=null) mk.close_connections(true); |
95 | mk=null; |
165 | mk=null; |
96 | bt_scanner.search_again(); |
166 | bt_scanner.search_again(); |
Line 97... | Line 167... | ||
97 | } |
167 | } |
98 | 168 | ||
- | 169 | rescan=false; |
|
- | 170 | bg_offset--; |
|
99 | rescan=false; |
171 | if (bg_offset==-bg_img.getWidth()) |
100 | 172 | bg_offset=0; |
|
101 | com.nokia.mid.ui.DeviceControl.setLights(0,100); |
173 | com.nokia.mid.ui.DeviceControl.setLights(0,100); |
Line 124... | Line 196... | ||
124 | } |
196 | } |
Line -... | Line 197... | ||
- | 197 | ||
Line 125... | Line 198... | ||
125 | 198 | ||
126 | 199 | ||
127 | 200 | ||
- | 201 | int local_max=-1; |
|
- | 202 | ||
- | 203 | // drawing section |
|
- | 204 | public void paint(Graphics g) { |
|
- | 205 | ||
- | 206 | if (mk!=null) |
|
- | 207 | { |
|
- | 208 | line_middle_y=this.getHeight()/2; |
|
- | 209 | if (local_max<Math.abs(mk.debug_data.nick_int())) |
|
- | 210 | local_max=Math.abs(mk.debug_data.nick_int()); |
|
- | 211 | if (local_max<Math.abs(mk.debug_data.roll_int())) |
|
- | 212 | local_max=Math.abs(mk.debug_data.roll_int()); |
|
- | 213 | if (local_max<Math.abs(mk.debug_data.accnick())) |
|
128 | 214 | local_max=Math.abs(mk.debug_data.accnick()); |
|
129 | 215 | if (local_max<Math.abs(mk.debug_data.accroll())) |
|
130 | // drawing section |
216 | local_max=Math.abs(mk.debug_data.accroll()); |
- | 217 | line_scaler= local_max/(this.getHeight()/2)+1; |
|
- | 218 | } |
|
- | 219 | int spacer=(g.getFont().getHeight()); |
|
- | 220 | g.setColor(0xFFFFFF); |
|
131 | public void paint(Graphics g) { |
221 | g.fillRect(0,0,this.getWidth(),this.getHeight()); |
Line 132... | Line 222... | ||
132 | 222 | g.drawImage(bg_img,bg_offset,0, g.TOP | g.LEFT); |
|
133 | int spacer=(g.getFont().getHeight()); |
223 | if (bg_offset+bg_img.getWidth()<this.getWidth()) |
- | 224 | g.drawImage(bg_img,bg_offset+bg_img.getWidth(),0, g.TOP | g.LEFT); |
|
- | 225 | ||
134 | g.setColor(0xFFFFFF); |
226 | g.setColor(0x000000); |
- | 227 | ||
- | 228 | if (mk==null) |
|
- | 229 | { |
|
135 | g.fillRect(0,0,this.getWidth(),this.getHeight()); |
230 | |
- | 231 | ||
- | 232 | if (bt_scanner.searching) |
|
- | 233 | { |
|
- | 234 | ||
136 | g.setColor(0x000000); |
235 | |
- | 236 | g.drawString("scanning for BT-Devices",this.getWidth()/2,this.getHeight()/2+load_img.getHeight()/8,Graphics.TOP | Graphics.HCENTER); |
|
137 | 237 | ||
138 | if (mk==null) |
238 | g.setClip(this.getWidth()/2-load_img.getWidth()/6,this.getHeight()/2-load_img.getHeight()/8, load_img.getWidth()/4,load_img.getHeight()/3);; |
139 | { |
239 | 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); |
140 | if (bt_scanner.searching) |
240 | g.drawImage(bt_img,this.getWidth()/2 ,this.getHeight()/2 , g.HCENTER | g.VCENTER); |
141 | g.drawString("scanning for BT-Devices",0,0,Graphics.TOP | Graphics.LEFT); |
241 | } |
142 | else |
242 | else |
- | 243 | { |
|
- | 244 | g.drawString("Press key 0-"+(bt_scanner.remote_device_count-1) + " to continue" ,0,0,Graphics.TOP | Graphics.LEFT); |
|
- | 245 | for (int i=0;i<bt_scanner.remote_device_count;i++) |
|
- | 246 | g.drawString("#"+i+">" + bt_scanner.remote_device_name[i]+"("+bt_scanner.remote_device_mac[i]+")",0,spacer+spacer*i,Graphics.TOP | Graphics.LEFT); |
|
143 | { |
247 | |
144 | g.drawString("Press key 0-"+(bt_scanner.remote_device_count-1) + " to continue" ,0,0,Graphics.TOP | Graphics.LEFT); |
248 | } |
145 | for (int i=0;i<bt_scanner.remote_device_count;i++) |
249 | |
146 | g.drawString("#"+i+">" + bt_scanner.remote_device_name[i]+"("+bt_scanner.remote_device_mac[i]+")",0,spacer+spacer*i,Graphics.TOP | Graphics.LEFT); |
250 | |
Line 147... | Line 251... | ||
147 | 251 | ||
Line 148... | Line 252... | ||
148 | } |
252 | |
149 | } |
- | |
150 | else // MK is connected |
- | |
151 | { |
- | |
152 | int y_off=0; |
- | |
153 | - | ||
154 | 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+")",0,y_off,Graphics.TOP | Graphics.LEFT); |
253 | } |
155 | - | ||
156 | y_off+=spacer; |
- | |
157 | for ( int foo=0;foo<4;foo++) |
- | |
158 | { |
- | |
159 | g.drawString(mk.LCD.LCD_str[foo],0,y_off,Graphics.TOP | Graphics.LEFT); |
254 | else // MK is connected |
160 | y_off+=spacer; |
255 | { |
- | 256 | int y_off=0; |
|
- | 257 | ||
161 | } |
258 | 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+")",0,y_off,Graphics.TOP | Graphics.LEFT); |
162 | try { |
259 | |
163 | g.drawString("motor1:"+mk.debug_data.analog[12],0,y_off,Graphics.TOP | Graphics.LEFT); |
260 | y_off+=spacer; |
164 | y_off+=spacer; |
- | |
165 | g.drawString("motor2:"+mk.debug_data.analog[13],0,y_off,Graphics.TOP | Graphics.LEFT); |
- | |
166 | y_off+=spacer; |
261 | |
167 | g.drawString("motor3:"+mk.debug_data.analog[14],0,y_off,Graphics.TOP | Graphics.LEFT); |
262 | 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); |
168 | y_off+=spacer; |
263 | y_off+=spacer; |
169 | g.drawString("motor4:"+mk.debug_data.analog[15],0,y_off,Graphics.TOP | Graphics.LEFT); |
264 | |
170 | y_off+=spacer; |
265 | |
171 | 266 | 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); |
|
172 | } |
267 | y_off+=spacer; |
173 | catch (Exception e) { } |
268 | |
Line -... | Line 269... | ||
- | 269 | if (mk.connected) |
|
- | 270 | { |
|
- | 271 | g.drawString("time conn:" +((System.currentTimeMillis()- mk.connection_start_time)/1000)+"s" ,0,y_off,Graphics.TOP | Graphics.LEFT); |
|
- | 272 | y_off+=spacer; |
|
- | 273 | g.drawString("time motor>15:" +(mk_stat.motor_on_time/1000) +"s" ,0,y_off,Graphics.TOP | Graphics.LEFT); |
|
- | 274 | y_off+=spacer; |
|
- | 275 | g.drawString("time motor=15:" +(mk_stat.motor_stand_time/1000) +"s" ,0,y_off,Graphics.TOP | Graphics.LEFT); |
|
- | 276 | } |
|
- | 277 | ||
- | 278 | ||
- | 279 | y_off=this.getHeight()-4*19; |
|
- | 280 | ||
- | 281 | for ( int foo=0;foo<4;foo++) |
|
- | 282 | { |
|
- | 283 | ||
- | 284 | for (int x=0;x<20;x++) |
|
- | 285 | { |
|
- | 286 | g.setClip(12*x,y_off,12,19); |
|
- | 287 | g.drawImage(lcd_img,12*x-(mk.LCD.LCD_str[foo].charAt(x)-' ')*(lcd_img.getWidth()/95),y_off, g.TOP | g.LEFT); |
|
- | 288 | ||
- | 289 | } |
|
- | 290 | y_off+=19; |
|
- | 291 | ||
174 | if (mk.connected) |
292 | |
- | 293 | ||
- | 294 | } |
|
- | 295 | ||
- | 296 | g.setClip(0,0,this.getWidth(),this.getHeight()); |
|
- | 297 | ||
- | 298 | ||
- | 299 | ||
- | 300 | ||
- | 301 | } |
|
- | 302 | // draw lines |
|
- | 303 | ||
- | 304 | for ( int x=0;x<this.getWidth();x++) |
|
- | 305 | ||
- | 306 | { |
|
- | 307 | ||
- | 308 | int p= (((-bg_offset+x-this.getWidth()-5))); |
|
- | 309 | if (p<1) |
|
- | 310 | p+=bg_img.getWidth(); |
|
- | 311 | p%=(bg_img.getWidth()-1); |
|
- | 312 | ||
- | 313 | g.setColor(0x156315); |
|
Line -... | Line 314... | ||
- | 314 | draw_graph_part(g,x,nick_line_pos_data[p]/line_scaler,nick_line_pos_data[p+1]/line_scaler); |
|
175 | { |
315 | g.setColor(0xCC1315); |
Line 176... | Line 316... | ||
176 | g.drawString("time conn:" +((System.currentTimeMillis()- mk.connection_start_time)/1000)+"s" ,0,y_off,Graphics.TOP | Graphics.LEFT); |
316 | draw_graph_part(g,x,roll_line_pos_data[p]/line_scaler,roll_line_pos_data[p+1]/line_scaler); |
177 | y_off+=spacer; |
317 | g.setColor(0xf8ef02); |
178 | g.drawString("time motor>15:" +(mk_stat.motor_on_time/1000) +"s" ,0,y_off,Graphics.TOP | Graphics.LEFT); |
318 | draw_graph_part(g,x,accnick_line_pos_data[p]/line_scaler,accnick_line_pos_data[p+1]/line_scaler); |
179 | y_off+=spacer; |
319 | g.setColor(0x19194d); |
- | 320 | draw_graph_part(g,x,accroll_line_pos_data[p]/line_scaler,accroll_line_pos_data[p+1]/line_scaler); |
|
- | 321 | ||
- | 322 | ||
- | 323 | ||
- | 324 | } |
|
- | 325 | } |
|
- | 326 | ||
- | 327 | private void connect_mk(String url) |
|
- | 328 | { |
|
- | 329 | mk = new MKCommunicator(url); |
|
180 | g.drawString("time motor=15:" +(mk_stat.motor_stand_time/1000) +"s" ,0,y_off,Graphics.TOP | Graphics.LEFT); |
330 | mk_stat= new MKStatistics(mk); |
Line 181... | Line 331... | ||
181 | } |
331 | |
182 | 332 | } |
|
- | 333 | ||
- | 334 | public void draw_graph_part(Graphics g,int x,int y1,int y2) |
|
183 | } |
335 | { |
184 | 336 | g.fillRect(x,line_middle_y-y1,2,2 ); |
|
Line 185... | Line 337... | ||
185 | } |
337 | if (y1>y2) |
186 | 338 | g.fillRect(x,line_middle_y-y1,2,y1-y2); |
|
187 | private void connect_mk(String url) |
339 | else |
188 | { |
340 | g.fillRect(x,line_middle_y-y2,2,y2-y1); |
189 | mk = new MKCommunicator(url); |
341 | } |
190 | mk_stat= new MKStatistics(mk); |
342 | |
- | 343 | /*********************************************** input Section **********************************************/ |
|
191 | } |
344 | // keys |
192 | 345 | public boolean fullscreen=false; |
|
193 | /*********************************************** input Section **********************************************/ |
346 | |
194 | // keys |
347 | public void keyPressed(int keyCode) |
Line 195... | Line 348... | ||
195 | public void keyPressed(int keyCode) |
348 | { |
196 | { |
349 | |
- | 350 | if ((mk==null)&&(keyCode >= this.KEY_NUM0) && (keyCode < this.KEY_NUM0+bt_scanner.remote_device_count)) |
|
- | 351 | connect_mk("btspp://"+bt_scanner.remote_device_mac[keyCode-this.KEY_NUM0] + ":1"); |
|
197 | 352 | else |
|
198 | if ((mk==null)&&(keyCode >= this.KEY_NUM0) && (keyCode < this.KEY_NUM0+bt_scanner.remote_device_count)) |
353 | { |
199 | connect_mk("btspp://"+bt_scanner.remote_device_mac[keyCode-this.KEY_NUM0] + ":1"); |
354 | switch (keyCode) |
200 | else |
355 | { |
201 | { |
356 |