Subversion Repositories Projects

Rev

Rev 269 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 269 Rev 382
Line 4... Line 4...
4
 *                      
4
 *                      
5
 * Author:        Marcus -LiGi- Bueschleb
5
 * Author:        Marcus -LiGi- Bueschleb
6
 *
6
 *
7
 *******************************************/
7
 *******************************************/
Line -... Line 8...
-
 
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.*;
Line 12... Line 14...
12
import java.io.*;
14
import java.io.*;
13
 
15
 
14
 
16
 
Line 15... Line -...
15
public class MKStatusVoice
-
 
16
    implements Runnable,PlayerListener
17
public class MKStatusVoice
17
{
18
    implements Runnable,PlayerListener
-
 
19
{
-
 
20
 
-
 
21
    DUBwiseCanvas canvas=null;
Line 18... Line 22...
18
 
22
    Player player;
19
    org.ligi.ufo.MKCommunicator mk=null;
23
 
20
    DUBwiseCanvas canvas=null;
24
    Player up_player;
Line 29... Line 33...
29
    public int delay=5;
33
    public int delay=5;
Line 30... Line 34...
30
 
34
 
31
    int act_player_state=PLAYERSTATE_IDLE;
35
    int act_player_state=PLAYERSTATE_IDLE;
Line 32... Line 36...
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
 
Line 38... Line 42...
38
        new Thread( this ).start(); // fire up main Thread 
42
        new Thread( this ).start(); // fire up main Thread 
39
    }
43
    }
Line 65... Line 69...
65
      }
69
      }
66
      player = null;
70
      player = null;
67
    }
71
    }
Line 68... Line 72...
68
 
72
 
69
 
73
 
-
 
74
    public Player init_player(String name)
70
    public void start_playing(String name)
75
    {
Line 71... Line 76...
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
            }
-
 
93
           
-
 
94
            _player.prefetch();
-
 
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
 
88
 
138
        try {
89
                        player.prefetch();
139
            act_player_state=PLAYERSTATE_PLAYING;
90
                        player.setLoopCount(1);
140
            player=init_player(name);
Line 91... Line 141...
91
                        player.start();
141
            player.start();    
92
        }
142
        }
Line 107... Line 157...
107
    }
157
    }
Line 108... Line 158...
108
 
158
 
109
    int info_from_debug_set=-1;
159
    int info_from_debug_set=-1;
Line -... Line 160...
-
 
160
    int volt_timeout=0;
-
 
161
 
110
    int volt_timeout=0;
162
    public int BASE_SLEEP=10;
Line -... Line 163...
-
 
163
 
-
 
164
    public int last_alt=-1;
-
 
165
 
-
 
166
 
111
 
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()
-
 
171
    {
115
    {
172
        while(true)
116
        while(true)
173
            {
-
 
174
                loop_cnt++;
Line 117... Line 175...
117
            {
175
                if ((canvas.mk!=null)&&(canvas.mk.connected)&&(canvas.settings.do_sound)&&(canvas.mk.UBatt()!=-1)&&(!canvas.mk.force_disconnect))
118
                if (mk.connected&&(canvas.settings.do_sound)&&(mk.UBatt()!=-1)&&(!mk.force_disconnect))
176
                    {
Line 119... Line 177...
119
                    {
177
                        volt_timeout--;
120
       
178
       
-
 
179
                        if (info_from_debug_set!=canvas.mk.stats.debug_data_count)
-
 
180
                            { // only when newdata
121
                        if (info_from_debug_set!=mk.stats.debug_data_count)
181
                               
122
                            { // only when newdata
182
                                if (canvas.settings.do_volts_sound&&(volt_timeout<0))
123
                               
183
                                    {
124
                                if (canvas.settings.do_volts_sound&&(volt_timeout--<0))
184
                                        volts_play_cnt++;
125
                                    {
185
 
Line 126... Line 186...
126
                                        volt_timeout=delay*10;
186
                                        volt_timeout=(delay*1000)/BASE_SLEEP;
127
                                        int ubatt=mk.UBatt();
187
                                        int ubatt=canvas.mk.UBatt();
Line 142... Line 202...
142
 
202
 
143
                               
203
                               
144
 
204
 
Line 145... Line 205...
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();
-
 
208
 
148
 
209
                               
149
                               
210
                                        if (last_alt>canvas.mk.Alt()+canvas.settings.altsteps)
150
                                        if (last_alt>mk.Alt()+canvas.settings.altsteps)
211
                                            {
151
                                            {
212
                                                //                                              start_playing("down");
Line 152... Line 213...
152
                                                start_playing("down");
213
                                                play_down();
153
                                                wait_for_end();
214
                                                wait_for_end();
-
 
215
                                                last_alt-=canvas.settings.altsteps;
154
                                                last_alt-=canvas.settings.altsteps;
216
                                            }
155
                                            }
217
                                        if (last_alt<canvas.mk.Alt()-canvas.settings.altsteps)
156
                                        if (last_alt<mk.Alt()-canvas.settings.altsteps)
218
                                           
157
                                           
219
                                            {
158
                                            {
220
                                                //start_playing("up");
Line 166... Line 228...
166
                            }
228
                            }
Line 167... Line 229...
167
       
229
       
Line 168... Line 230...
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
                   
Line 178... Line 240...
178
                }
240
                }
179
                catch (Exception e)  {   }
241
                catch (Exception e)  {   }
Line 180... Line 242...
180
               
242
               
-
 
243
            }