Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
181 | 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 | *********************************************************************************************************************************/ |
||
11 | |||
12 | import javax.microedition.lcdui.*; |
||
13 | |||
14 | public class MKMiniCanvas |
||
15 | extends Canvas |
||
16 | implements Runnable |
||
17 | { |
||
18 | |||
19 | |||
20 | |||
21 | int vibrating=0; |
||
22 | |||
23 | //BTAbstractor bt; |
||
24 | |||
25 | BTSearcher bt_scanner; |
||
26 | MKCommunicator mk=null; |
||
27 | MKStatistics mk_stat=null; |
||
28 | |||
29 | // data Section |
||
30 | |||
31 | public String err=""; |
||
32 | |||
33 | |||
34 | public MKMiniCanvas() |
||
35 | { |
||
36 | |||
37 | bt_scanner = new BTSearcher(); |
||
38 | //////////////////////////////////////////////////////////////////////////////mk = new MKCommunicator("btspp://000BCE016B5B:1"); |
||
39 | |||
40 | new Thread(this).start(); |
||
41 | } |
||
42 | |||
43 | |||
44 | |||
45 | /********************************************************** Thread ***********************************************************/ |
||
46 | // ticking runnable Section |
||
47 | public void run() |
||
48 | { |
||
49 | |||
50 | while(true) |
||
51 | { |
||
52 | long loopStartTime = System.currentTimeMillis(); |
||
53 | long sleeptime=0; |
||
54 | // ticked thing |
||
55 | |||
56 | com.nokia.mid.ui.DeviceControl.setLights(0,100); |
||
57 | //bt.tick(); |
||
58 | // every state has sth to do in tick section |
||
59 | |||
60 | |||
61 | // System.gc(); |
||
62 | repaint(); |
||
63 | serviceRepaints(); |
||
64 | |||
65 | |||
66 | sleeptime=1000/ 15 - (int) (System.currentTimeMillis()- loopStartTime); |
||
67 | |||
68 | |||
69 | if (sleeptime<0) |
||
70 | sleeptime=100; // everyone has fi sleep |
||
71 | |||
72 | try { Thread.sleep(sleeptime); } |
||
73 | catch (Exception e) |
||
74 | { |
||
75 | err="Problem Sleeping "; |
||
76 | } |
||
77 | |||
78 | } |
||
79 | } |
||
80 | |||
81 | |||
82 | |||
83 | |||
84 | |||
85 | // drawing section |
||
86 | public void paint(Graphics g) { |
||
87 | g.setColor(0xFFFFFF); |
||
88 | g.fillRect(0,0,this.getWidth(),this.getHeight()); |
||
89 | g.setColor(0x000000); |
||
90 | |||
91 | if (mk==null) |
||
92 | { |
||
93 | if (bt_scanner.searching) |
||
94 | g.drawString("scanning for BT-Devices",0,0,Graphics.TOP | Graphics.LEFT); |
||
95 | else |
||
96 | { |
||
97 | g.drawString("Press key 0-"+(bt_scanner.remote_device_count-1) + " to continue" ,0,0,Graphics.TOP | Graphics.LEFT); |
||
98 | for (int i=0;i<bt_scanner.remote_device_count;i++) |
||
99 | g.drawString("#"+i+">" + bt_scanner.remote_device_name[i]+"("+bt_scanner.remote_device_mac[i]+")",0,15+15*i,Graphics.TOP | Graphics.LEFT); |
||
100 | |||
101 | } |
||
102 | } |
||
103 | else // MK is connected |
||
104 | { |
||
105 | int y_off=0; |
||
106 | int spacer=15; |
||
107 | g.drawString("#"+mk.data_count + "from:" + mk.mk_url,0,y_off,Graphics.TOP | Graphics.LEFT); |
||
108 | y_off+=spacer; |
||
109 | g.drawString("v"+mk.version_major+"."+mk.version_minor,0,y_off,Graphics.TOP | Graphics.LEFT); |
||
110 | y_off+=spacer; |
||
111 | |||
112 | try { |
||
113 | g.drawString("motor1:"+mk.debug_data.analog[12],0,y_off,Graphics.TOP | Graphics.LEFT); |
||
114 | y_off+=spacer; |
||
115 | g.drawString("motor2:"+mk.debug_data.analog[13],0,y_off,Graphics.TOP | Graphics.LEFT); |
||
116 | y_off+=spacer; |
||
117 | g.drawString("motor3:"+mk.debug_data.analog[14],0,y_off,Graphics.TOP | Graphics.LEFT); |
||
118 | y_off+=spacer; |
||
119 | g.drawString("motor4:"+mk.debug_data.analog[15],0,y_off,Graphics.TOP | Graphics.LEFT); |
||
120 | y_off+=spacer; |
||
121 | |||
122 | } |
||
123 | catch (Exception e) { } |
||
124 | if (mk.connected) |
||
125 | { |
||
126 | g.drawString("time conn:" +((System.currentTimeMillis()- mk.connection_start_time)/1000)+"s" ,0,y_off,Graphics.TOP | Graphics.LEFT); |
||
127 | y_off+=spacer; |
||
128 | g.drawString("time motor>15:" +(mk_stat.motor_on_time/1000) +"s" ,0,y_off,Graphics.TOP | Graphics.LEFT); |
||
129 | } |
||
130 | |||
131 | } |
||
132 | |||
133 | } |
||
134 | |||
135 | /*********************************************** input Section **********************************************/ |
||
136 | // keys |
||
137 | public void keyPressed(int keyCode) |
||
138 | { |
||
139 | |||
140 | if ((mk==null)&&(keyCode >= this.KEY_NUM0) && (keyCode < this.KEY_NUM0+bt_scanner.remote_device_count)) |
||
141 | { |
||
142 | mk = new MKCommunicator("btspp://"+bt_scanner.remote_device_mac[keyCode-this.KEY_NUM0] + ":1"); |
||
143 | mk_stat= new MKStatistics(mk); |
||
144 | } |
||
145 | return; |
||
146 | } |
||
147 | |||
148 | |||
149 | |||
150 | |||
151 | |||
152 | |||
153 | |||
154 | |||
155 | } |
||
156 | |||
157 |