Rev 229 | Rev 269 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 229 | Rev 265 | ||
---|---|---|---|
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 | 8 | ||
9 | import javax.microedition.media.*; |
9 | import javax.microedition.media.*; |
10 | import javax.microedition.media.control.*; |
10 | import javax.microedition.media.control.*; |
11 | import java.util.*; |
11 | import java.util.*; |
12 | import java.io.*; |
12 | import java.io.*; |
13 | 13 | ||
14 | 14 | ||
15 | public class MKStatusVoice |
15 | public class MKStatusVoice |
16 | implements Runnable,PlayerListener |
16 | implements Runnable,PlayerListener |
17 | { |
17 | { |
18 | 18 | ||
19 | org.ligi.ufo.MKCommunicator mk=null; |
19 | org.ligi.ufo.MKCommunicator mk=null; |
20 | DUBwiseCanvas canvas=null; |
20 | DUBwiseCanvas canvas=null; |
21 | Player player; |
21 | Player player; |
22 | 22 | ||
23 | public final int PLAYERSTATE_IDLE=0; |
23 | public final int PLAYERSTATE_IDLE=0; |
24 | public final int PLAYERSTATE_PLAYING=1; |
24 | public final int PLAYERSTATE_PLAYING=1; |
25 | public final int PLAYERSTATE_FIN=2; |
25 | public final int PLAYERSTATE_FIN=2; |
26 | 26 | ||
27 | 27 | ||
28 | public int volume=100; |
28 | public int volume=100; |
29 | public int delay=5; |
29 | public int delay=5; |
30 | 30 | ||
31 | int act_player_state=PLAYERSTATE_IDLE; |
31 | int act_player_state=PLAYERSTATE_IDLE; |
32 | VolumeControl vc; |
32 | VolumeControl vc; |
33 | 33 | ||
34 | public MKStatusVoice(org.ligi.ufo.MKCommunicator _mk,DUBwiseCanvas _canvas) |
34 | public MKStatusVoice(org.ligi.ufo.MKCommunicator _mk,DUBwiseCanvas _canvas) |
35 | { |
35 | { |
36 | canvas=_canvas; |
36 | canvas=_canvas; |
37 | mk=_mk; |
37 | mk=_mk; |
38 | new Thread( this ).start(); // fire up main Thread |
38 | new Thread( this ).start(); // fire up main Thread |
39 | } |
39 | } |
40 | 40 | ||
41 | public void playerUpdate(Player player, String event, Object data) |
41 | public void playerUpdate(Player player, String event, Object data) |
42 | { |
42 | { |
43 | if(event == PlayerListener.END_OF_MEDIA) { |
43 | if(event == PlayerListener.END_OF_MEDIA) { |
44 | try { |
44 | try { |
45 | defplayer(); |
45 | defplayer(); |
46 | } |
46 | } |
47 | catch(MediaException me) { } |
47 | catch(MediaException me) { } |
48 | act_player_state=PLAYERSTATE_FIN; |
48 | act_player_state=PLAYERSTATE_FIN; |
49 | player=null; |
49 | player=null; |
50 | 50 | ||
51 | } |
51 | } |
52 | } |
52 | } |
53 | 53 | ||
54 | void defplayer() throws MediaException { |
54 | void defplayer() throws MediaException { |
55 | if (player != null) { |
55 | if (player != null) { |
56 | if(player.getState() == Player.STARTED) { |
56 | if(player.getState() == Player.STARTED) { |
57 | player.stop(); |
57 | player.stop(); |
58 | } |
58 | } |
59 | if(player.getState() == Player.PREFETCHED) { |
59 | if(player.getState() == Player.PREFETCHED) { |
60 | player.deallocate(); |
60 | player.deallocate(); |
61 | } |
61 | } |
62 | if(player.getState() == Player.REALIZED || player.getState() == Player.UNREALIZED) { |
62 | if(player.getState() == Player.REALIZED || player.getState() == Player.UNREALIZED) { |
63 | player.close(); |
63 | player.close(); |
64 | } |
64 | } |
65 | } |
65 | } |
66 | player = null; |
66 | player = null; |
67 | } |
67 | } |
68 | 68 | ||
69 | 69 | ||
70 | public void start_playing(String name) |
70 | public void start_playing(String name) |
71 | { |
71 | { |
72 | try { |
72 | try { |
73 | 73 | ||
74 | try { |
74 | try { |
75 | player = Manager.createPlayer(getClass().getResourceAsStream(name+".mp3"), "audio/mp3"); |
75 | player = Manager.createPlayer(getClass().getResourceAsStream(name+".mp3"), "audio/mp3"); |
76 | } |
76 | } |
77 | catch (Exception e) { |
77 | catch (Exception e) { |
78 | player = Manager.createPlayer(getClass().getResourceAsStream(name+".wav"), "audio/x-wav"); |
78 | player = Manager.createPlayer(getClass().getResourceAsStream(name+".wav"), "audio/x-wav"); |
79 | } |
79 | } |
80 | player.addPlayerListener(this); |
80 | player.addPlayerListener(this); |
81 | player.realize(); |
81 | player.realize(); |
82 | act_player_state=PLAYERSTATE_PLAYING; |
82 | act_player_state=PLAYERSTATE_PLAYING; |
83 | 83 | ||
84 | vc = (VolumeControl) player.getControl("VolumeControl"); |
84 | vc = (VolumeControl) player.getControl("VolumeControl"); |
85 | if(vc != null) { |
85 | if(vc != null) { |
86 | vc.setLevel(volume); |
86 | vc.setLevel(volume); |
87 | } |
87 | } |
88 | 88 | ||
89 | player.prefetch(); |
89 | player.prefetch(); |
90 | player.setLoopCount(1); |
90 | player.setLoopCount(1); |
91 | player.start(); |
91 | player.start(); |
92 | } |
92 | } |
93 | catch (Exception e) { |
93 | catch (Exception e) { |
94 | 94 | ||
95 | } |
95 | } |
96 | } |
96 | } |
97 | 97 | ||
98 | public void wait_for_end() |
98 | public void wait_for_end() |
99 | { |
99 | { |
100 | while (act_player_state!=PLAYERSTATE_FIN) |
100 | while (act_player_state!=PLAYERSTATE_FIN) |
101 | { |
101 | { |
102 | try { Thread.sleep(5); } |
102 | try { Thread.sleep(5); } |
103 | catch (Exception e) { } |
103 | catch (Exception e) { } |
104 | } |
104 | } |
105 | 105 | ||
106 | 106 | ||
107 | } |
107 | } |
108 | 108 | ||
109 | int info_from_debug_set=-1; |
109 | int info_from_debug_set=-1; |
- | 110 | int volt_timeout=0; |
|
- | 111 | ||
- | 112 | public int last_alt=-1; |
|
- | 113 | ||
110 | public void run() |
114 | public void run() |
111 | { |
115 | { |
112 | while(true) |
116 | while(true) |
113 | { |
117 | { |
114 | if (mk.connected&&(canvas.settings.do_sound)&&(mk.debug_data.UBatt()!=-1)&&(!mk.force_disconnect)) |
118 | if (mk.connected&&(canvas.settings.do_sound)&&(mk.UBatt()!=-1)&&(!mk.force_disconnect)) |
115 | { |
119 | { |
116 | int ubatt=mk.debug_data.UBatt(); |
- | |
117 | 120 | ||
118 | if (info_from_debug_set!=mk.stats.debug_data_count) |
121 | if (info_from_debug_set!=mk.stats.debug_data_count) |
119 | { |
- | |
120 | info_from_debug_set=mk.stats.debug_data_count; |
- | |
121 | start_playing(""+(ubatt/10)); |
- | |
122 | wait_for_end(); |
122 | { // only when newdata |
123 | 123 | ||
124 | if((ubatt%10)!=0) |
124 | if (canvas.settings.do_volts_sound&&(volt_timeout--<0)) |
- | 125 | { |
|
- | 126 | volt_timeout=delay*10; |
|
- | 127 | int ubatt=mk.UBatt(); |
|
125 | { |
128 | info_from_debug_set=mk.stats.debug_data_count; |
126 | start_playing("komma"); |
129 | start_playing(""+(ubatt/10)); |
- | 130 | wait_for_end(); |
|
- | 131 | ||
- | 132 | if((ubatt%10)!=0) |
|
- | 133 | { |
|
- | 134 | start_playing("komma"); |
|
127 | wait_for_end(); |
135 | wait_for_end(); |
- | 136 | start_playing(""+(ubatt%10)); |
|
- | 137 | wait_for_end(); |
|
- | 138 | } |
|
128 | start_playing(""+(ubatt%10)); |
139 | start_playing("volt"); |
129 | wait_for_end(); |
140 | wait_for_end(); |
- | 141 | } |
|
- | 142 | ||
- | 143 | ||
- | 144 | ||
- | 145 | if (canvas.settings.do_altimeter_sound) |
|
- | 146 | { |
|
- | 147 | if (last_alt==-1) last_alt=mk.Alt(); |
|
- | 148 | int alt_diff=10; |
|
- | 149 | ||
- | 150 | if (last_alt>mk.Alt()+alt_diff) |
|
130 | } |
151 | { |
- | 152 | start_playing("down"); |
|
- | 153 | wait_for_end(); |
|
- | 154 | last_alt-=alt_diff; |
|
- | 155 | } |
|
- | 156 | if (last_alt<mk.Alt()-alt_diff) |
|
- | 157 | ||
- | 158 | { |
|
- | 159 | start_playing("up"); |
|
- | 160 | wait_for_end(); |
|
- | 161 | last_alt+=alt_diff; |
|
- | 162 | } |
|
- | 163 | } |
|
- | 164 | else |
|
131 | start_playing("volt"); |
165 | last_alt=-1; |
132 | } |
166 | } |
133 | 167 | ||
134 | } |
168 | } |
135 | 169 | ||
- | 170 | try { |
|
- | 171 | Thread.sleep(100); |
|
136 | try { |
172 | /* |
137 | if (delay<1) |
173 | if (delay<1) |
138 | Thread.sleep(1000); |
174 | Thread.sleep(1000); |
139 | else |
175 | else |
140 | Thread.sleep(delay*1000); |
176 | Thread.sleep(delay*1000); |
- | 177 | */ |
|
141 | } |
178 | } |
142 | catch (Exception e) { } |
179 | catch (Exception e) { } |
143 | 180 | ||
144 | } |
181 | } |
145 | } |
182 | } |
146 | 183 | ||
147 | 184 | ||
148 | 185 | ||
149 | } |
186 | } |
150 | 187 |