Lib_siemens.java
  1 /*
  2  * Lib_siemens.java
  3  *
  4  */
  5 
  6 /*
  7 import java.io.IOException;
  8  
  9 import com.siemens.mp.game.Vibrator;
 10 import com.siemens.mp.game.Sound;
 11 import com.siemens.mp.media.Manager;
 12 import com.siemens.mp.media.MediaException;
 13 import com.siemens.mp.game.Light;
 14 import com.siemens.mp.gsm.Call;
 15 import com.siemens.mp.NotAllowedException;
 16 import com.siemens.mp.gsm.SMS;
 17  */
 18 
 19 /**
 20  * Lib_siemens for MIDletPascal.
 21  * To compile this class, you also need MIDP 1.0 and Siemens extension APIs.
 22  * And to use, of course, MIDletPascal (http://www.midletpascal.com)
 23  *
 24  * The listed functions are available on all java-able Siemens phones.
 25  *
 26  * web: http://inf.nyme.hu/~kusicsk/
 27  * e-mail: znos@freemail.hu
 28  *
 29  * @author Krisztian Kusics (a. ZnOS)
 30  */
 31 public class Lib_siemens {
 32     
 33     //==========================================================================
 34     // Vibrator
 35     //==========================================================================
 36     
 37     /**
 38      * Activates vibrator.
 39      */
 40     public static void startvibrator() {
 41         com.siemens.mp.game.Vibrator.startVibrator();
 42     }
 43     
 44     /**
 45      * Deactivates vibrator.
 46      */
 47     public static void stopvibrator() {
 48         com.siemens.mp.game.Vibrator.stopVibrator();
 49     }
 50     
 51     /**
 52      * Activates the vibrator for a given time in milliseconds.
 53      * @param duration duration of the vibrator activation period, in milliseconds.
 54      */
 55     public static void triggervibrator(int duration) {
 56         com.siemens.mp.game.Vibrator.triggerVibrator(duration);
 57     }
 58     
 59     //==========================================================================
 60     // Sound
 61     //==========================================================================
 62     
 63     /**
 64      * Plays a tone.
 65      * @param tone_freq the frequency of this tone [Hz]
 66      * @param tone_time the duration of this tone [ms]
 67      */
 68     public static void playtone(int tone_freq, int tone_time) {
 69         com.siemens.mp.game.Sound.playTone(tone_freq, tone_time);
 70     }
 71     
 72     /**
 73      * Play back a tone as specified by a note and its duration. A note is given
 74      * in the range of 0 to 127. The frequency of the note can be calculated from
 75      * the following formula:
 76      *
 77      *    SEMITONE_CONST = 17.31234049066755 = 1/(ln(2^(1/12)))
 78      *    note = ln(freq/8.176)*SEMITONE_CONST
 79      *
 80      *    The musical note A = MIDI note 69 (0x45) = 440 Hz.
 81      *
 82      * This call is a non-blocking call. Notice that this method may utilize CPU
 83      * resources significantly on devices that don"t have hardware support for
 84      * tone generation.
 85      * @param note Defines the tone of the note as specified by the above formula.
 86      * @param duration The duration of the tone in milli-seconds. Duration must
 87      * be non-negative.
 88      * @param volume Audio volume range from 0 to 100. 100 represents the maximum
 89      * volume at the current hardware level. Setting the volume to a value less
 90      * than 0 will set the volume to 0. Setting the volume to greater than 100
 91      * will set the volume to 100.
 92      */
 93     public static void playmiditone(int note, int duration, int volume) {
 94         try {
 95             com.siemens.mp.media.Manager.playTone(note, duration, volume);
 96         } catch(IllegalArgumentException iae) {
 97             // if the given note or duration is out of range.
 98         } catch(com.siemens.mp.media.MediaException me) {
 99             // if the tone cannot be played due to a device-related problem.
100         }
101     }
102     
103     //==========================================================================
104     // LCD backlight
105     //==========================================================================
106     
107     /**
108      * Activates the LCD backlight.
109      */
110     public static void setlighton() {
111         com.siemens.mp.game.Light.setLightOn();
112     }
113     
114     /**
115      * Deactivates LCD backlight.
116      */
117     public static void setlightoff() {
118         com.siemens.mp.game.Light.setLightOff();
119     }
120     
121     //==========================================================================
122     // Making an outgoing call
123     //==========================================================================
124     
125     /**
126      * Starts a phone call.
127      * IMPORTANT NOTE: The java application will terminate upon performing this method call.
128      * @param number a phone number to dial. (International format)
129      */
130     public static void dial(String number) {
131         try {
132             com.siemens.mp.gsm.Call.start(number);
133         } catch(IllegalArgumentException iae) {
134             // if a phone number is entered in the wrong format or is missing in method call
135         } catch(com.siemens.mp.NotAllowedException nae) {
136             // if the call is not allowed (by the user)
137         }
138     }
139     
140     //==========================================================================
141     // Sending SMS
142     //==========================================================================
143     
144     /**
145      * Sends an sms to the specified number. The user will be prompted whether
146      * an SMS is allowed to be send each time the method is called.
147      * For further information regarding the mapping of Unicode into standard GSM char
148      * (7 bit) see the <A href="http://unicode.org/Public/MAPPINGS/ETSI/GSM0338.TXT">
149      * ETSI mapping specifications</A>.
150      * @param number phone number to send SMS to. (International format)
151      * @param data SMS text
152      * @return number of characters actually send
153      */
154     public static int sendsms(String number, String data) {
155         int numOfCharsSent = 0;
156         
157         try {
158             numOfCharsSent = com.siemens.mp.gsm.SMS.send(number, data);
159         } catch(IllegalArgumentException iae) {
160             // the phone number or the text message is missing in method call, or format of the number is incorrect
161         } catch(com.siemens.mp.NotAllowedException nae) {
162             // if the transfer is not allowed.
163         } catch(java.io.IOException ioe) {
164             // if the network is not available
165         }
166         
167         return numOfCharsSent;
168     }
169     
170 }
171