Rev 269 | Rev 493 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 269 | Rev 382 | ||
---|---|---|---|
1 | /****************************************** |
1 | /****************************************** |
2 | * |
2 | * |
3 | * Voice output for MK |
3 | * Voice output for MK |
4 | * |
4 | * |
5 | * Author: Marcus -LiGi- Bueschleb |
5 | * Author: Marcus -LiGi- Bueschleb |
6 | * |
6 | * |
7 | *******************************************/ |
7 | *******************************************/ |
- | 8 | ||
- | 9 | //public class MKStatusVoice {} |
|
8 | 10 | ||
9 | import javax.microedition.media.*; |
11 | import javax.microedition.media.*; |
10 | import javax.microedition.media.control.*; |
12 | import javax.microedition.media.control.*; |
11 | import java.util.*; |
13 | import java.util.*; |
12 | import java.io.*; |
14 | import java.io.*; |
13 | 15 | ||
14 | 16 | ||
15 | public class MKStatusVoice |
17 | public class MKStatusVoice |
16 | implements Runnable,PlayerListener |
18 | implements Runnable,PlayerListener |
17 | { |
19 | { |
18 | - | ||
19 | org.ligi.ufo.MKCommunicator mk=null; |
20 | |
20 | DUBwiseCanvas canvas=null; |
21 | DUBwiseCanvas canvas=null; |
- | 22 | Player player; |
|
- | 23 | ||
- | 24 | Player up_player; |
|
21 | Player player; |
25 | Player down_player; |
22 | 26 | ||
23 | public final int PLAYERSTATE_IDLE=0; |
27 | public final int PLAYERSTATE_IDLE=0; |
24 | public final int PLAYERSTATE_PLAYING=1; |
28 | public final int PLAYERSTATE_PLAYING=1; |
25 | public final int PLAYERSTATE_FIN=2; |
29 | public final int PLAYERSTATE_FIN=2; |
26 | 30 | ||
27 | 31 | ||
28 | public int volume=100; |
32 | public int volume=100; |
29 | public int delay=5; |
33 | public int delay=5; |
30 | 34 | ||
31 | int act_player_state=PLAYERSTATE_IDLE; |
35 | int act_player_state=PLAYERSTATE_IDLE; |
32 | VolumeControl vc; |
36 | VolumeControl vc; |
33 | 37 | ||
34 | public MKStatusVoice(org.ligi.ufo.MKCommunicator _mk,DUBwiseCanvas _canvas) |
38 | public MKStatusVoice(DUBwiseCanvas _canvas) |
35 | { |
39 | { |
36 | canvas=_canvas; |
40 | canvas=_canvas; |
37 | mk=_mk; |
41 | |
38 | new Thread( this ).start(); // fire up main Thread |
42 | new Thread( this ).start(); // fire up main Thread |
39 | } |
43 | } |
40 | 44 | ||
41 | public void playerUpdate(Player player, String event, Object data) |
45 | public void playerUpdate(Player player, String event, Object data) |
42 | { |
46 | { |
43 | if(event == PlayerListener.END_OF_MEDIA) { |
47 | if(event == PlayerListener.END_OF_MEDIA) { |
44 | try { |
48 | try { |
45 | defplayer(); |
49 | defplayer(); |
46 | } |
50 | } |
47 | catch(MediaException me) { } |
51 | catch(MediaException me) { } |
48 | act_player_state=PLAYERSTATE_FIN; |
52 | act_player_state=PLAYERSTATE_FIN; |
49 | player=null; |
53 | player=null; |
50 | 54 | ||
51 | } |
55 | } |
52 | } |
56 | } |
53 | 57 | ||
54 | void defplayer() throws MediaException { |
58 | void defplayer() throws MediaException { |
55 | if (player != null) { |
59 | if (player != null) { |
56 | if(player.getState() == Player.STARTED) { |
60 | if(player.getState() == Player.STARTED) { |
57 | player.stop(); |
61 | player.stop(); |
58 | } |
62 | } |
59 | if(player.getState() == Player.PREFETCHED) { |
63 | if(player.getState() == Player.PREFETCHED) { |
60 | player.deallocate(); |
64 | player.deallocate(); |
61 | } |
65 | } |
62 | if(player.getState() == Player.REALIZED || player.getState() == Player.UNREALIZED) { |
66 | if(player.getState() == Player.REALIZED || player.getState() == Player.UNREALIZED) { |
63 | player.close(); |
67 | player.close(); |
64 | } |
68 | } |
65 | } |
69 | } |
66 | player = null; |
70 | player = null; |
67 | } |
71 | } |
68 | 72 | ||
69 | 73 | ||
70 | public void start_playing(String name) |
74 | public Player init_player(String name) |
- | 75 | { |
|
71 | { |
76 | Player _player=null; |
72 | try { |
77 | try { |
73 | 78 | ||
74 | try { |
79 | try { |
75 | player = Manager.createPlayer(getClass().getResourceAsStream(name+".mp3"), "audio/mp3"); |
80 | _player = Manager.createPlayer(getClass().getResourceAsStream(name+".mp3"), "audio/mp3"); |
76 | } |
81 | } |
77 | catch (Exception e) { |
82 | catch (Exception e) { |
78 | player = Manager.createPlayer(getClass().getResourceAsStream(name+".wav"), "audio/x-wav"); |
83 | _player = Manager.createPlayer(getClass().getResourceAsStream(name+".wav"), "audio/x-wav"); |
79 | } |
84 | } |
80 | player.addPlayerListener(this); |
85 | _player.addPlayerListener(this); |
81 | player.realize(); |
86 | _player.realize(); |
82 | act_player_state=PLAYERSTATE_PLAYING; |
- | |
- | 87 | ||
83 | 88 | ||
84 | vc = (VolumeControl) player.getControl("VolumeControl"); |
89 | vc = (VolumeControl) _player.getControl("VolumeControl"); |
85 | if(vc != null) { |
90 | if(vc != null) { |
86 | vc.setLevel(volume); |
91 | vc.setLevel(volume); |
87 | } |
92 | } |
88 | 93 | ||
89 | player.prefetch(); |
94 | _player.prefetch(); |
90 | player.setLoopCount(1); |
95 | _player.setLoopCount(1); |
- | 96 | _player.start(); |
|
- | 97 | } |
|
- | 98 | catch (Exception e) { |
|
- | 99 | ||
- | 100 | } |
|
- | 101 | return _player; |
|
- | 102 | ||
- | 103 | } |
|
- | 104 | ||
- | 105 | public void play_up() |
|
- | 106 | { |
|
- | 107 | ||
- | 108 | try { |
|
- | 109 | act_player_state=PLAYERSTATE_PLAYING; |
|
- | 110 | if (up_player==null) |
|
- | 111 | up_player=init_player("up"); |
|
- | 112 | ||
- | 113 | ||
- | 114 | up_player.start(); |
|
- | 115 | } |
|
- | 116 | catch (Exception e) { |
|
- | 117 | ||
- | 118 | } |
|
- | 119 | } |
|
- | 120 | ||
- | 121 | ||
- | 122 | public void play_down() |
|
- | 123 | { |
|
- | 124 | ||
- | 125 | try { |
|
- | 126 | act_player_state=PLAYERSTATE_PLAYING; |
|
- | 127 | if (down_player==null) |
|
- | 128 | down_player=init_player("down"); |
|
- | 129 | down_player.start(); |
|
- | 130 | } |
|
- | 131 | catch (Exception e) { |
|
- | 132 | ||
- | 133 | } |
|
- | 134 | } |
|
- | 135 | public void start_playing(String name) |
|
- | 136 | { |
|
- | 137 | ||
- | 138 | try { |
|
- | 139 | act_player_state=PLAYERSTATE_PLAYING; |
|
- | 140 | player=init_player(name); |
|
91 | player.start(); |
141 | player.start(); |
92 | } |
142 | } |
93 | catch (Exception e) { |
143 | catch (Exception e) { |
94 | 144 | ||
95 | } |
145 | } |
96 | } |
146 | } |
97 | 147 | ||
98 | public void wait_for_end() |
148 | public void wait_for_end() |
99 | { |
149 | { |
100 | while (act_player_state!=PLAYERSTATE_FIN) |
150 | while (act_player_state!=PLAYERSTATE_FIN) |
101 | { |
151 | { |
102 | try { Thread.sleep(5); } |
152 | try { Thread.sleep(5); } |
103 | catch (Exception e) { } |
153 | catch (Exception e) { } |
104 | } |
154 | } |
105 | 155 | ||
106 | 156 | ||
107 | } |
157 | } |
108 | 158 | ||
109 | int info_from_debug_set=-1; |
159 | int info_from_debug_set=-1; |
110 | int volt_timeout=0; |
160 | int volt_timeout=0; |
- | 161 | ||
- | 162 | public int BASE_SLEEP=10; |
|
111 | 163 | ||
- | 164 | public int last_alt=-1; |
|
- | 165 | ||
- | 166 | ||
- | 167 | public int loop_cnt; |
|
112 | public int last_alt=-1; |
168 | public int volts_play_cnt; |
113 | 169 | ||
114 | public void run() |
170 | public void run() |
115 | { |
171 | { |
116 | while(true) |
172 | while(true) |
117 | { |
173 | { |
- | 174 | loop_cnt++; |
|
118 | if (mk.connected&&(canvas.settings.do_sound)&&(mk.UBatt()!=-1)&&(!mk.force_disconnect)) |
175 | if ((canvas.mk!=null)&&(canvas.mk.connected)&&(canvas.settings.do_sound)&&(canvas.mk.UBatt()!=-1)&&(!canvas.mk.force_disconnect)) |
119 | { |
176 | { |
- | 177 | volt_timeout--; |
|
120 | 178 | ||
121 | if (info_from_debug_set!=mk.stats.debug_data_count) |
179 | if (info_from_debug_set!=canvas.mk.stats.debug_data_count) |
122 | { // only when newdata |
180 | { // only when newdata |
123 | 181 | ||
- | 182 | if (canvas.settings.do_volts_sound&&(volt_timeout<0)) |
|
- | 183 | { |
|
124 | if (canvas.settings.do_volts_sound&&(volt_timeout--<0)) |
184 | volts_play_cnt++; |
125 | { |
185 | |
126 | volt_timeout=delay*10; |
186 | volt_timeout=(delay*1000)/BASE_SLEEP; |
127 | int ubatt=mk.UBatt(); |
187 | int ubatt=canvas.mk.UBatt(); |
128 | info_from_debug_set=mk.stats.debug_data_count; |
188 | info_from_debug_set=canvas.mk.stats.debug_data_count; |
129 | start_playing(""+(ubatt/10)); |
189 | start_playing(""+(ubatt/10)); |
130 | wait_for_end(); |
190 | wait_for_end(); |
131 | 191 | ||
132 | if((ubatt%10)!=0) |
192 | if((ubatt%10)!=0) |
133 | { |
193 | { |
134 | start_playing("komma"); |
194 | start_playing("komma"); |
135 | wait_for_end(); |
195 | wait_for_end(); |
136 | start_playing(""+(ubatt%10)); |
196 | start_playing(""+(ubatt%10)); |
137 | wait_for_end(); |
197 | wait_for_end(); |
138 | } |
198 | } |
139 | start_playing("volt"); |
199 | start_playing("volt"); |
140 | wait_for_end(); |
200 | wait_for_end(); |
141 | } |
201 | } |
142 | 202 | ||
143 | 203 | ||
144 | 204 | ||
145 | if (canvas.settings.do_altimeter_sound) |
205 | if (canvas.settings.do_altimeter_sound) |
146 | { |
206 | { |
147 | if (last_alt==-1) last_alt=mk.Alt(); |
207 | if (last_alt==-1) last_alt=canvas.mk.Alt(); |
148 | 208 | ||
149 | 209 | ||
150 | if (last_alt>mk.Alt()+canvas.settings.altsteps) |
210 | if (last_alt>canvas.mk.Alt()+canvas.settings.altsteps) |
- | 211 | { |
|
151 | { |
212 | // start_playing("down"); |
152 | start_playing("down"); |
213 | play_down(); |
153 | wait_for_end(); |
214 | wait_for_end(); |
154 | last_alt-=canvas.settings.altsteps; |
215 | last_alt-=canvas.settings.altsteps; |
155 | } |
216 | } |
156 | if (last_alt<mk.Alt()-canvas.settings.altsteps) |
217 | if (last_alt<canvas.mk.Alt()-canvas.settings.altsteps) |
157 | 218 | ||
158 | { |
219 | { |
- | 220 | //start_playing("up"); |
|
159 | start_playing("up"); |
221 | play_up(); |
160 | wait_for_end(); |
222 | wait_for_end(); |
161 | last_alt+=canvas.settings.altsteps; |
223 | last_alt+=canvas.settings.altsteps; |
162 | } |
224 | } |
163 | } |
225 | } |
164 | else |
226 | else |
165 | last_alt=-1; |
227 | last_alt=-1; |
166 | } |
228 | } |
167 | 229 | ||
168 | } |
230 | } |
169 | 231 | ||
170 | try { |
232 | try { |
171 | Thread.sleep(100); |
233 | Thread.sleep(BASE_SLEEP); |
172 | /* |
234 | |
173 | if (delay<1) |
235 | //if (delay<1) |
174 | Thread.sleep(1000); |
236 | // Thread.sleep(1000); |
175 | else |
237 | //else |
176 | Thread.sleep(delay*1000); |
238 | // Thread.sleep(delay*1000); |
177 | */ |
239 | |
178 | } |
240 | } |
179 | catch (Exception e) { } |
241 | catch (Exception e) { } |
180 | 242 | ||
181 | } |
243 | } |
182 | } |
244 | } |
183 | 245 | ||
184 | 246 | ||
185 | 247 | ||
186 | } |
248 | } |
- | 249 | ||
187 | 250 |