Sat Chat
Dependencies: 4DGL-uLCD-SE USBDevice max32630fthr
main.cpp@0:7f19ba74283d, 2017-10-09 (annotated)
- Committer:
- Phyu
- Date:
- Mon Oct 09 15:21:33 2017 +0000
- Revision:
- 0:7f19ba74283d
-
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Phyu | 0:7f19ba74283d | 1 | /* BLACK CODE INCLUDE START |
Phyu | 0:7f19ba74283d | 2 | External libraries are worrying! |
Phyu | 0:7f19ba74283d | 3 | Keep it simple and avoid anything non essential or obscure. |
Phyu | 0:7f19ba74283d | 4 | Consider copying functions from libraries into the code so |
Phyu | 0:7f19ba74283d | 5 | we have control. */ |
Phyu | 0:7f19ba74283d | 6 | #include "mbed.h" |
Phyu | 0:7f19ba74283d | 7 | #include "uLCD_4DGL.h" |
Phyu | 0:7f19ba74283d | 8 | #include "max32630fthr.h" |
Phyu | 0:7f19ba74283d | 9 | #include <stdbool.h> |
Phyu | 0:7f19ba74283d | 10 | #include <string> |
Phyu | 0:7f19ba74283d | 11 | //#include <Keypad.h> |
Phyu | 0:7f19ba74283d | 12 | /* BLACK CODE INCLUDE END */ |
Phyu | 0:7f19ba74283d | 13 | |
Phyu | 0:7f19ba74283d | 14 | /* BLACK CODE DEFINE START */ |
Phyu | 0:7f19ba74283d | 15 | #define ONN 0 |
Phyu | 0:7f19ba74283d | 16 | #define OFFF 1 |
Phyu | 0:7f19ba74283d | 17 | #define EXIT_SUCCESS 0 |
Phyu | 0:7f19ba74283d | 18 | #define EXIT_FAILURE 1 |
Phyu | 0:7f19ba74283d | 19 | /* BLACK CODE DEFINE END */ |
Phyu | 0:7f19ba74283d | 20 | |
Phyu | 0:7f19ba74283d | 21 | /* BLACK CODE GLOBAL VAR START */ |
Phyu | 0:7f19ba74283d | 22 | //const int GPS_TIMEOUT=180; //Wait three minutes maximum for GPS. |
Phyu | 0:7f19ba74283d | 23 | char gpsfix_last_utc_time[11] = {0}; |
Phyu | 0:7f19ba74283d | 24 | char gpsfix_last_utc_date[7] = {0}; |
Phyu | 0:7f19ba74283d | 25 | char gpsfix_longtitude[12] = {0}; |
Phyu | 0:7f19ba74283d | 26 | char gpsfix_latitude[12] = {0}; |
Phyu | 0:7f19ba74283d | 27 | char gpsfix_speed[8] = {0}; //Set but not used |
Phyu | 0:7f19ba74283d | 28 | char gpsfix_course[7] = {0}; //Set but not used |
Phyu | 0:7f19ba74283d | 29 | char gpsfix_variation[7] = {0}; //Set but not used |
Phyu | 0:7f19ba74283d | 30 | char gpsfix_mag_var_ew[1] = {0};//Set but not used |
Phyu | 0:7f19ba74283d | 31 | char gpsfix_ns = 0; |
Phyu | 0:7f19ba74283d | 32 | char gpsfix_ew = 0; |
Phyu | 0:7f19ba74283d | 33 | bool gps_data_present = false; //If this is false we can't even use stale GPS data. |
Phyu | 0:7f19ba74283d | 34 | /* BLACK CODE GLOBAL VAR END */ |
Phyu | 0:7f19ba74283d | 35 | |
Phyu | 0:7f19ba74283d | 36 | /* BLACK CODE PERIPHERAL INIT START */ |
Phyu | 0:7f19ba74283d | 37 | uLCD_4DGL uLCD(P3_1,P3_0,P5_2); |
Phyu | 0:7f19ba74283d | 38 | DigitalOut red_led(LED1,1); |
Phyu | 0:7f19ba74283d | 39 | DigitalOut green_led(LED2,1); |
Phyu | 0:7f19ba74283d | 40 | DigitalOut gps_led(LED3,1); //Blue |
Phyu | 0:7f19ba74283d | 41 | AnalogIn joyX (AIN_0); |
Phyu | 0:7f19ba74283d | 42 | AnalogIn joyY (AIN_1); |
Phyu | 0:7f19ba74283d | 43 | DigitalIn joyButton(P4_0); |
Phyu | 0:7f19ba74283d | 44 | //Buttons |
Phyu | 0:7f19ba74283d | 45 | DigitalIn redButton (P5_6,PullUp); |
Phyu | 0:7f19ba74283d | 46 | DigitalIn blackButton (P5_5,PullUp); |
Phyu | 0:7f19ba74283d | 47 | //Keypad |
Phyu | 0:7f19ba74283d | 48 | DigitalIn keypadLine2(P3_2); |
Phyu | 0:7f19ba74283d | 49 | DigitalIn keypadLine7(P5_0); |
Phyu | 0:7f19ba74283d | 50 | DigitalIn keypadLine6(P6_0); |
Phyu | 0:7f19ba74283d | 51 | DigitalIn keypadLine4(P3_4); |
Phyu | 0:7f19ba74283d | 52 | DigitalOut keypadLine3(P3_5); |
Phyu | 0:7f19ba74283d | 53 | DigitalOut keypadLine1(P3_3); |
Phyu | 0:7f19ba74283d | 54 | DigitalOut keypadLine5(P5_1); |
Phyu | 0:7f19ba74283d | 55 | Serial pc(USBTX, USBRX); |
Phyu | 0:7f19ba74283d | 56 | Serial gps(P5_3, P5_4, 9600); |
Phyu | 0:7f19ba74283d | 57 | I2C i2c(P5_7,P6_0); // SDA, SCL |
Phyu | 0:7f19ba74283d | 58 | /* BLACK CODE PERIPHERAL INIT END */ |
Phyu | 0:7f19ba74283d | 59 | |
Phyu | 0:7f19ba74283d | 60 | void home(); |
Phyu | 0:7f19ba74283d | 61 | void CompareKey(); |
Phyu | 0:7f19ba74283d | 62 | void Getmessage(); |
Phyu | 0:7f19ba74283d | 63 | void TrackingService(); |
Phyu | 0:7f19ba74283d | 64 | void Sos(); |
Phyu | 0:7f19ba74283d | 65 | char ChartoAlpha(char num); |
Phyu | 0:7f19ba74283d | 66 | void shortcut(); |
Phyu | 0:7f19ba74283d | 67 | void ReadMessage(); |
Phyu | 0:7f19ba74283d | 68 | void PrintChar(char key); |
Phyu | 0:7f19ba74283d | 69 | void tracking_power(bool state); |
Phyu | 0:7f19ba74283d | 70 | |
Phyu | 0:7f19ba74283d | 71 | |
Phyu | 0:7f19ba74283d | 72 | /*char getkey(void) |
Phyu | 0:7f19ba74283d | 73 | { |
Phyu | 0:7f19ba74283d | 74 | keypadLine3 = 0; |
Phyu | 0:7f19ba74283d | 75 | keypadLine1 = 1; |
Phyu | 0:7f19ba74283d | 76 | keypadLine5 = 1; |
Phyu | 0:7f19ba74283d | 77 | if (!keypadLine2) { |
Phyu | 0:7f19ba74283d | 78 | |
Phyu | 0:7f19ba74283d | 79 | wait(.5); |
Phyu | 0:7f19ba74283d | 80 | return '1'; |
Phyu | 0:7f19ba74283d | 81 | } |
Phyu | 0:7f19ba74283d | 82 | if (!keypadLine7) { |
Phyu | 0:7f19ba74283d | 83 | wait(.5); |
Phyu | 0:7f19ba74283d | 84 | return '4'; |
Phyu | 0:7f19ba74283d | 85 | } |
Phyu | 0:7f19ba74283d | 86 | if (!keypadLine6) { |
Phyu | 0:7f19ba74283d | 87 | wait(.5); |
Phyu | 0:7f19ba74283d | 88 | return '7'; |
Phyu | 0:7f19ba74283d | 89 | } |
Phyu | 0:7f19ba74283d | 90 | if (!keypadLine4) { |
Phyu | 0:7f19ba74283d | 91 | wait(.5); |
Phyu | 0:7f19ba74283d | 92 | return '*'; |
Phyu | 0:7f19ba74283d | 93 | } |
Phyu | 0:7f19ba74283d | 94 | keypadLine3 = 1; |
Phyu | 0:7f19ba74283d | 95 | keypadLine1 = 0; |
Phyu | 0:7f19ba74283d | 96 | if (!keypadLine2) { |
Phyu | 0:7f19ba74283d | 97 | wait(.5); |
Phyu | 0:7f19ba74283d | 98 | return '2'; |
Phyu | 0:7f19ba74283d | 99 | |
Phyu | 0:7f19ba74283d | 100 | } |
Phyu | 0:7f19ba74283d | 101 | if (!keypadLine7) { |
Phyu | 0:7f19ba74283d | 102 | wait(.5); |
Phyu | 0:7f19ba74283d | 103 | return '5'; |
Phyu | 0:7f19ba74283d | 104 | } |
Phyu | 0:7f19ba74283d | 105 | if (!keypadLine6) { |
Phyu | 0:7f19ba74283d | 106 | wait(.5); |
Phyu | 0:7f19ba74283d | 107 | return '8'; |
Phyu | 0:7f19ba74283d | 108 | } |
Phyu | 0:7f19ba74283d | 109 | if (!keypadLine4) { |
Phyu | 0:7f19ba74283d | 110 | wait(.5); |
Phyu | 0:7f19ba74283d | 111 | return '0'; |
Phyu | 0:7f19ba74283d | 112 | } |
Phyu | 0:7f19ba74283d | 113 | keypadLine1 = 1; |
Phyu | 0:7f19ba74283d | 114 | keypadLine5 = 0; |
Phyu | 0:7f19ba74283d | 115 | if (!keypadLine2) { |
Phyu | 0:7f19ba74283d | 116 | wait(.5); |
Phyu | 0:7f19ba74283d | 117 | return '3'; |
Phyu | 0:7f19ba74283d | 118 | } |
Phyu | 0:7f19ba74283d | 119 | if (!keypadLine7) { |
Phyu | 0:7f19ba74283d | 120 | wait(.5); |
Phyu | 0:7f19ba74283d | 121 | return '6'; |
Phyu | 0:7f19ba74283d | 122 | } |
Phyu | 0:7f19ba74283d | 123 | if (!keypadLine6) { |
Phyu | 0:7f19ba74283d | 124 | |
Phyu | 0:7f19ba74283d | 125 | wait(.5); |
Phyu | 0:7f19ba74283d | 126 | return '9'; |
Phyu | 0:7f19ba74283d | 127 | |
Phyu | 0:7f19ba74283d | 128 | } |
Phyu | 0:7f19ba74283d | 129 | if (!keypadLine4) { |
Phyu | 0:7f19ba74283d | 130 | wait(.5); |
Phyu | 0:7f19ba74283d | 131 | return '#'; |
Phyu | 0:7f19ba74283d | 132 | } |
Phyu | 0:7f19ba74283d | 133 | return NULL; |
Phyu | 0:7f19ba74283d | 134 | } |
Phyu | 0:7f19ba74283d | 135 | */ |
Phyu | 0:7f19ba74283d | 136 | |
Phyu | 0:7f19ba74283d | 137 | /*int i, k, pwcount=0; |
Phyu | 0:7f19ba74283d | 138 | char password[] = "999", entry[10]; |
Phyu | 0:7f19ba74283d | 139 | |
Phyu | 0:7f19ba74283d | 140 | char getkey() |
Phyu | 0:7f19ba74283d | 141 | { |
Phyu | 0:7f19ba74283d | 142 | |
Phyu | 0:7f19ba74283d | 143 | keypadLine3 = 0; |
Phyu | 0:7f19ba74283d | 144 | keypadLine1 = 1; |
Phyu | 0:7f19ba74283d | 145 | keypadLine5 = 1; |
Phyu | 0:7f19ba74283d | 146 | if (!keypadLine2) { |
Phyu | 0:7f19ba74283d | 147 | entry[pwcount] = '1'; |
Phyu | 0:7f19ba74283d | 148 | // pwcount++; |
Phyu | 0:7f19ba74283d | 149 | wait(.5); |
Phyu | 0:7f19ba74283d | 150 | |
Phyu | 0:7f19ba74283d | 151 | return '1' ; |
Phyu | 0:7f19ba74283d | 152 | } |
Phyu | 0:7f19ba74283d | 153 | if (!keypadLine7) { |
Phyu | 0:7f19ba74283d | 154 | entry[pwcount] = '4'; |
Phyu | 0:7f19ba74283d | 155 | // pwcount++; |
Phyu | 0:7f19ba74283d | 156 | wait(.5); |
Phyu | 0:7f19ba74283d | 157 | |
Phyu | 0:7f19ba74283d | 158 | return '4' ; |
Phyu | 0:7f19ba74283d | 159 | } |
Phyu | 0:7f19ba74283d | 160 | if (!keypadLine6) { |
Phyu | 0:7f19ba74283d | 161 | entry[pwcount] = '7'; |
Phyu | 0:7f19ba74283d | 162 | // pwcount++; |
Phyu | 0:7f19ba74283d | 163 | wait(.5); |
Phyu | 0:7f19ba74283d | 164 | return '7'; |
Phyu | 0:7f19ba74283d | 165 | } |
Phyu | 0:7f19ba74283d | 166 | if (!keypadLine4) { |
Phyu | 0:7f19ba74283d | 167 | entry[pwcount] = '*'; |
Phyu | 0:7f19ba74283d | 168 | // pwcount++; |
Phyu | 0:7f19ba74283d | 169 | wait(.5); |
Phyu | 0:7f19ba74283d | 170 | return '*'; |
Phyu | 0:7f19ba74283d | 171 | } |
Phyu | 0:7f19ba74283d | 172 | keypadLine3 = 1; |
Phyu | 0:7f19ba74283d | 173 | keypadLine1 = 0; |
Phyu | 0:7f19ba74283d | 174 | if (!keypadLine2) { |
Phyu | 0:7f19ba74283d | 175 | entry[pwcount] = '2'; |
Phyu | 0:7f19ba74283d | 176 | // pwcount++; |
Phyu | 0:7f19ba74283d | 177 | wait(.5); |
Phyu | 0:7f19ba74283d | 178 | |
Phyu | 0:7f19ba74283d | 179 | return '2' ; |
Phyu | 0:7f19ba74283d | 180 | } |
Phyu | 0:7f19ba74283d | 181 | if (!keypadLine7) { |
Phyu | 0:7f19ba74283d | 182 | entry[pwcount] = '5'; |
Phyu | 0:7f19ba74283d | 183 | // pwcount++; |
Phyu | 0:7f19ba74283d | 184 | wait(.5); |
Phyu | 0:7f19ba74283d | 185 | return '5'; |
Phyu | 0:7f19ba74283d | 186 | } |
Phyu | 0:7f19ba74283d | 187 | if (!keypadLine6) { |
Phyu | 0:7f19ba74283d | 188 | entry[pwcount] = '8'; |
Phyu | 0:7f19ba74283d | 189 | // pwcount++; |
Phyu | 0:7f19ba74283d | 190 | wait(.5); |
Phyu | 0:7f19ba74283d | 191 | return '8'; |
Phyu | 0:7f19ba74283d | 192 | } |
Phyu | 0:7f19ba74283d | 193 | if (!keypadLine4) { |
Phyu | 0:7f19ba74283d | 194 | entry[pwcount] = '0'; |
Phyu | 0:7f19ba74283d | 195 | // pwcount++; |
Phyu | 0:7f19ba74283d | 196 | wait(.5); |
Phyu | 0:7f19ba74283d | 197 | return '0'; |
Phyu | 0:7f19ba74283d | 198 | } |
Phyu | 0:7f19ba74283d | 199 | keypadLine1 = 1; |
Phyu | 0:7f19ba74283d | 200 | keypadLine5 = 0; |
Phyu | 0:7f19ba74283d | 201 | if (!keypadLine2) { |
Phyu | 0:7f19ba74283d | 202 | entry[pwcount] = '3'; |
Phyu | 0:7f19ba74283d | 203 | // pwcount++; |
Phyu | 0:7f19ba74283d | 204 | wait(.5); |
Phyu | 0:7f19ba74283d | 205 | |
Phyu | 0:7f19ba74283d | 206 | return '3' ; |
Phyu | 0:7f19ba74283d | 207 | } |
Phyu | 0:7f19ba74283d | 208 | if (!keypadLine7) { |
Phyu | 0:7f19ba74283d | 209 | entry[pwcount] = '6'; |
Phyu | 0:7f19ba74283d | 210 | // pwcount++; |
Phyu | 0:7f19ba74283d | 211 | wait(.5); |
Phyu | 0:7f19ba74283d | 212 | return '6'; |
Phyu | 0:7f19ba74283d | 213 | } |
Phyu | 0:7f19ba74283d | 214 | if (!keypadLine6) { |
Phyu | 0:7f19ba74283d | 215 | entry[pwcount] = '9'; |
Phyu | 0:7f19ba74283d | 216 | pwcount++; |
Phyu | 0:7f19ba74283d | 217 | uLCD.printf("%d",pwcount); |
Phyu | 0:7f19ba74283d | 218 | wait(.5); |
Phyu | 0:7f19ba74283d | 219 | return '9'; |
Phyu | 0:7f19ba74283d | 220 | } |
Phyu | 0:7f19ba74283d | 221 | if (!keypadLine4) { |
Phyu | 0:7f19ba74283d | 222 | entry[pwcount] = '#'; |
Phyu | 0:7f19ba74283d | 223 | pwcount++; |
Phyu | 0:7f19ba74283d | 224 | wait(.5); |
Phyu | 0:7f19ba74283d | 225 | return '#'; |
Phyu | 0:7f19ba74283d | 226 | } |
Phyu | 0:7f19ba74283d | 227 | if (blackButton == 0) |
Phyu | 0:7f19ba74283d | 228 | { |
Phyu | 0:7f19ba74283d | 229 | wait(.5); |
Phyu | 0:7f19ba74283d | 230 | pwcount=0; |
Phyu | 0:7f19ba74283d | 231 | for(k=0; k<=3; k++){ |
Phyu | 0:7f19ba74283d | 232 | if(password[k] != entry[k]){ |
Phyu | 0:7f19ba74283d | 233 | k=0; |
Phyu | 0:7f19ba74283d | 234 | uLCD.cls(); |
Phyu | 0:7f19ba74283d | 235 | uLCD.text_string("Wrong Number", 1, 4, FONT_7X8, GREEN); |
Phyu | 0:7f19ba74283d | 236 | uLCD.printf("%d",k); |
Phyu | 0:7f19ba74283d | 237 | wait(3); |
Phyu | 0:7f19ba74283d | 238 | uLCD.cls(); |
Phyu | 0:7f19ba74283d | 239 | Sos(); |
Phyu | 0:7f19ba74283d | 240 | break; |
Phyu | 0:7f19ba74283d | 241 | } |
Phyu | 0:7f19ba74283d | 242 | if(k==2){ |
Phyu | 0:7f19ba74283d | 243 | uLCD.cls(); |
Phyu | 0:7f19ba74283d | 244 | uLCD.text_string("Calling has\nreached!", 1, 4, FONT_7X8, GREEN); |
Phyu | 0:7f19ba74283d | 245 | uLCD.printf("%d",k); |
Phyu | 0:7f19ba74283d | 246 | wait(3); |
Phyu | 0:7f19ba74283d | 247 | uLCD.cls(); |
Phyu | 0:7f19ba74283d | 248 | home(); |
Phyu | 0:7f19ba74283d | 249 | break; |
Phyu | 0:7f19ba74283d | 250 | } |
Phyu | 0:7f19ba74283d | 251 | } |
Phyu | 0:7f19ba74283d | 252 | for(k=0; k<10; k++) |
Phyu | 0:7f19ba74283d | 253 | entry[k]=0; |
Phyu | 0:7f19ba74283d | 254 | } |
Phyu | 0:7f19ba74283d | 255 | return NULL; |
Phyu | 0:7f19ba74283d | 256 | } |
Phyu | 0:7f19ba74283d | 257 | */ |
Phyu | 0:7f19ba74283d | 258 | |
Phyu | 0:7f19ba74283d | 259 | int i, k, pw2 , j,pwcount=0; |
Phyu | 0:7f19ba74283d | 260 | char sos[] = "999", entry[10]; |
Phyu | 0:7f19ba74283d | 261 | char track2[] = "111", entry2[10]; bool track ; |
Phyu | 0:7f19ba74283d | 262 | char getkey() |
Phyu | 0:7f19ba74283d | 263 | { |
Phyu | 0:7f19ba74283d | 264 | |
Phyu | 0:7f19ba74283d | 265 | keypadLine3 = 0; |
Phyu | 0:7f19ba74283d | 266 | keypadLine1 = 1; |
Phyu | 0:7f19ba74283d | 267 | keypadLine5 = 1; |
Phyu | 0:7f19ba74283d | 268 | if (!keypadLine2) { |
Phyu | 0:7f19ba74283d | 269 | entry2[pw2] = '1'; |
Phyu | 0:7f19ba74283d | 270 | pw2++; |
Phyu | 0:7f19ba74283d | 271 | wait(.5); |
Phyu | 0:7f19ba74283d | 272 | return '1'; |
Phyu | 0:7f19ba74283d | 273 | } |
Phyu | 0:7f19ba74283d | 274 | if (!keypadLine7) { |
Phyu | 0:7f19ba74283d | 275 | entry[pwcount] = '4'; |
Phyu | 0:7f19ba74283d | 276 | |
Phyu | 0:7f19ba74283d | 277 | wait(.5); |
Phyu | 0:7f19ba74283d | 278 | |
Phyu | 0:7f19ba74283d | 279 | return '4' ; |
Phyu | 0:7f19ba74283d | 280 | } |
Phyu | 0:7f19ba74283d | 281 | if (!keypadLine6) { |
Phyu | 0:7f19ba74283d | 282 | entry[pwcount] = '7'; |
Phyu | 0:7f19ba74283d | 283 | |
Phyu | 0:7f19ba74283d | 284 | wait(.5); |
Phyu | 0:7f19ba74283d | 285 | return '7'; |
Phyu | 0:7f19ba74283d | 286 | } |
Phyu | 0:7f19ba74283d | 287 | if (!keypadLine4) { |
Phyu | 0:7f19ba74283d | 288 | entry[pwcount] = '*'; |
Phyu | 0:7f19ba74283d | 289 | |
Phyu | 0:7f19ba74283d | 290 | wait(.5); |
Phyu | 0:7f19ba74283d | 291 | pw2=0; |
Phyu | 0:7f19ba74283d | 292 | for(j=0; j<=3; j++){ |
Phyu | 0:7f19ba74283d | 293 | if(track2[j] != entry2[j]){ |
Phyu | 0:7f19ba74283d | 294 | uLCD.cls(); |
Phyu | 0:7f19ba74283d | 295 | uLCD.text_string("Invalid\nKeypressed\n", 1, 4, FONT_7X8, GREEN); |
Phyu | 0:7f19ba74283d | 296 | wait(3); |
Phyu | 0:7f19ba74283d | 297 | uLCD.cls(); |
Phyu | 0:7f19ba74283d | 298 | for(j=0; j<10; j++) |
Phyu | 0:7f19ba74283d | 299 | entry2[j]=0; |
Phyu | 0:7f19ba74283d | 300 | TrackingService(); |
Phyu | 0:7f19ba74283d | 301 | break; |
Phyu | 0:7f19ba74283d | 302 | } |
Phyu | 0:7f19ba74283d | 303 | if(j==2){ |
Phyu | 0:7f19ba74283d | 304 | uLCD.cls(); |
Phyu | 0:7f19ba74283d | 305 | track =! track ; |
Phyu | 0:7f19ba74283d | 306 | if ( track == ONN) |
Phyu | 0:7f19ba74283d | 307 | { |
Phyu | 0:7f19ba74283d | 308 | uLCD.text_string("Tracking has\nswitched On!", 1, 4, FONT_7X8, GREEN); |
Phyu | 0:7f19ba74283d | 309 | } |
Phyu | 0:7f19ba74283d | 310 | if ( track == OFFF ) |
Phyu | 0:7f19ba74283d | 311 | { |
Phyu | 0:7f19ba74283d | 312 | uLCD.text_string("Tracking has\nswitched OFF!", 1, 4, FONT_7X8, GREEN); |
Phyu | 0:7f19ba74283d | 313 | } |
Phyu | 0:7f19ba74283d | 314 | wait(3); |
Phyu | 0:7f19ba74283d | 315 | uLCD.cls(); |
Phyu | 0:7f19ba74283d | 316 | for(j=0; j<10; j++) |
Phyu | 0:7f19ba74283d | 317 | entry2[j]=0; |
Phyu | 0:7f19ba74283d | 318 | home(); |
Phyu | 0:7f19ba74283d | 319 | break; |
Phyu | 0:7f19ba74283d | 320 | } |
Phyu | 0:7f19ba74283d | 321 | |
Phyu | 0:7f19ba74283d | 322 | } |
Phyu | 0:7f19ba74283d | 323 | for(j=0; j<10; j++) |
Phyu | 0:7f19ba74283d | 324 | entry2[j]=0; |
Phyu | 0:7f19ba74283d | 325 | return '*'; |
Phyu | 0:7f19ba74283d | 326 | } |
Phyu | 0:7f19ba74283d | 327 | keypadLine3 = 1; |
Phyu | 0:7f19ba74283d | 328 | keypadLine1 = 0; |
Phyu | 0:7f19ba74283d | 329 | if (!keypadLine2) { |
Phyu | 0:7f19ba74283d | 330 | entry[pwcount] = '2'; |
Phyu | 0:7f19ba74283d | 331 | |
Phyu | 0:7f19ba74283d | 332 | wait(.5); |
Phyu | 0:7f19ba74283d | 333 | |
Phyu | 0:7f19ba74283d | 334 | return '2' ; |
Phyu | 0:7f19ba74283d | 335 | } |
Phyu | 0:7f19ba74283d | 336 | if (!keypadLine7) { |
Phyu | 0:7f19ba74283d | 337 | entry[pwcount] = '5'; |
Phyu | 0:7f19ba74283d | 338 | |
Phyu | 0:7f19ba74283d | 339 | wait(.5); |
Phyu | 0:7f19ba74283d | 340 | return '5'; |
Phyu | 0:7f19ba74283d | 341 | } |
Phyu | 0:7f19ba74283d | 342 | if (!keypadLine6) { |
Phyu | 0:7f19ba74283d | 343 | entry2[pwcount] = '8'; |
Phyu | 0:7f19ba74283d | 344 | pw2++; |
Phyu | 0:7f19ba74283d | 345 | wait(.5); |
Phyu | 0:7f19ba74283d | 346 | return '8'; |
Phyu | 0:7f19ba74283d | 347 | } |
Phyu | 0:7f19ba74283d | 348 | if (!keypadLine4) { |
Phyu | 0:7f19ba74283d | 349 | entry[pwcount] = '0'; |
Phyu | 0:7f19ba74283d | 350 | |
Phyu | 0:7f19ba74283d | 351 | wait(.5); |
Phyu | 0:7f19ba74283d | 352 | return '0'; |
Phyu | 0:7f19ba74283d | 353 | } |
Phyu | 0:7f19ba74283d | 354 | keypadLine1 = 1; |
Phyu | 0:7f19ba74283d | 355 | keypadLine5 = 0; |
Phyu | 0:7f19ba74283d | 356 | if (!keypadLine2) { |
Phyu | 0:7f19ba74283d | 357 | entry[pwcount] = '3'; |
Phyu | 0:7f19ba74283d | 358 | |
Phyu | 0:7f19ba74283d | 359 | wait(.5); |
Phyu | 0:7f19ba74283d | 360 | |
Phyu | 0:7f19ba74283d | 361 | return '3' ; |
Phyu | 0:7f19ba74283d | 362 | } |
Phyu | 0:7f19ba74283d | 363 | if (!keypadLine7) { |
Phyu | 0:7f19ba74283d | 364 | entry[pwcount] = '6'; |
Phyu | 0:7f19ba74283d | 365 | |
Phyu | 0:7f19ba74283d | 366 | wait(.5); |
Phyu | 0:7f19ba74283d | 367 | return '6'; |
Phyu | 0:7f19ba74283d | 368 | } |
Phyu | 0:7f19ba74283d | 369 | if (!keypadLine6) { |
Phyu | 0:7f19ba74283d | 370 | entry[pwcount] = '9'; |
Phyu | 0:7f19ba74283d | 371 | pwcount++; |
Phyu | 0:7f19ba74283d | 372 | |
Phyu | 0:7f19ba74283d | 373 | wait(.5); |
Phyu | 0:7f19ba74283d | 374 | return '9'; |
Phyu | 0:7f19ba74283d | 375 | } |
Phyu | 0:7f19ba74283d | 376 | if (!keypadLine4) { |
Phyu | 0:7f19ba74283d | 377 | entry[pwcount] = '#'; |
Phyu | 0:7f19ba74283d | 378 | |
Phyu | 0:7f19ba74283d | 379 | wait(.5); |
Phyu | 0:7f19ba74283d | 380 | |
Phyu | 0:7f19ba74283d | 381 | |
Phyu | 0:7f19ba74283d | 382 | return '#'; |
Phyu | 0:7f19ba74283d | 383 | } |
Phyu | 0:7f19ba74283d | 384 | if (blackButton == 0) |
Phyu | 0:7f19ba74283d | 385 | { |
Phyu | 0:7f19ba74283d | 386 | wait(.5); |
Phyu | 0:7f19ba74283d | 387 | pwcount=0; |
Phyu | 0:7f19ba74283d | 388 | for(k=0; k<=3; k++){ |
Phyu | 0:7f19ba74283d | 389 | if(sos[k] != entry[k]){ |
Phyu | 0:7f19ba74283d | 390 | uLCD.cls(); |
Phyu | 0:7f19ba74283d | 391 | uLCD.text_string("Wrong Number", 1, 4, FONT_7X8, GREEN); |
Phyu | 0:7f19ba74283d | 392 | wait(3); |
Phyu | 0:7f19ba74283d | 393 | uLCD.cls(); |
Phyu | 0:7f19ba74283d | 394 | for(k=0; k<10; k++) |
Phyu | 0:7f19ba74283d | 395 | entry[k]=0; |
Phyu | 0:7f19ba74283d | 396 | Sos(); |
Phyu | 0:7f19ba74283d | 397 | break; |
Phyu | 0:7f19ba74283d | 398 | } |
Phyu | 0:7f19ba74283d | 399 | if(k==2){ |
Phyu | 0:7f19ba74283d | 400 | uLCD.cls(); |
Phyu | 0:7f19ba74283d | 401 | uLCD.text_string("SOS calling has\nreached!", 1, 4, FONT_7X8, GREEN); |
Phyu | 0:7f19ba74283d | 402 | wait(3); |
Phyu | 0:7f19ba74283d | 403 | uLCD.cls(); |
Phyu | 0:7f19ba74283d | 404 | for(k=0; k<10; k++) |
Phyu | 0:7f19ba74283d | 405 | entry[k]=0; |
Phyu | 0:7f19ba74283d | 406 | home(); |
Phyu | 0:7f19ba74283d | 407 | break; |
Phyu | 0:7f19ba74283d | 408 | } |
Phyu | 0:7f19ba74283d | 409 | |
Phyu | 0:7f19ba74283d | 410 | } |
Phyu | 0:7f19ba74283d | 411 | for(k=0; k<10; k++) |
Phyu | 0:7f19ba74283d | 412 | entry[k]=0; |
Phyu | 0:7f19ba74283d | 413 | } |
Phyu | 0:7f19ba74283d | 414 | |
Phyu | 0:7f19ba74283d | 415 | return NULL; |
Phyu | 0:7f19ba74283d | 416 | } |
Phyu | 0:7f19ba74283d | 417 | |
Phyu | 0:7f19ba74283d | 418 | |
Phyu | 0:7f19ba74283d | 419 | void ReadMessage() |
Phyu | 0:7f19ba74283d | 420 | { |
Phyu | 0:7f19ba74283d | 421 | |
Phyu | 0:7f19ba74283d | 422 | uLCD.printf("\n1.Hey I have been busy..... "); |
Phyu | 0:7f19ba74283d | 423 | uLCD.printf("\n2.Hi Sir,we would like..... "); |
Phyu | 0:7f19ba74283d | 424 | uLCD.printf("\n3.Darling,Be safe.C you..... "); |
Phyu | 0:7f19ba74283d | 425 | while ( true) |
Phyu | 0:7f19ba74283d | 426 | { char cut = getkey(); |
Phyu | 0:7f19ba74283d | 427 | switch ( cut ) |
Phyu | 0:7f19ba74283d | 428 | { |
Phyu | 0:7f19ba74283d | 429 | case '1' : uLCD.cls(); |
Phyu | 0:7f19ba74283d | 430 | uLCD.text_string("Hey I have been\nbusy these weeks\nSorry I cannot meet\nwith you.see you\nwhen you'r back!", 1, 4, FONT_7X8, GREEN); |
Phyu | 0:7f19ba74283d | 431 | wait (5); |
Phyu | 0:7f19ba74283d | 432 | uLCD.cls(); |
Phyu | 0:7f19ba74283d | 433 | ReadMessage(); |
Phyu | 0:7f19ba74283d | 434 | break; |
Phyu | 0:7f19ba74283d | 435 | |
Phyu | 0:7f19ba74283d | 436 | case '2' : uLCD.cls(); |
Phyu | 0:7f19ba74283d | 437 | uLCD.text_string("Hi Sir.\nwe would like\nto confirm for\nyour booking\non 2nd Nov 2017", 1, 4, FONT_7X8, GREEN); |
Phyu | 0:7f19ba74283d | 438 | wait (5); |
Phyu | 0:7f19ba74283d | 439 | uLCD.cls(); |
Phyu | 0:7f19ba74283d | 440 | ReadMessage(); |
Phyu | 0:7f19ba74283d | 441 | break; |
Phyu | 0:7f19ba74283d | 442 | case '3' : uLCD.cls(); |
Phyu | 0:7f19ba74283d | 443 | uLCD.text_string("Darling,\nBe safe.\nWe will join you\non 2nd Nov", 1, 4, FONT_7X8, GREEN); |
Phyu | 0:7f19ba74283d | 444 | wait (5); |
Phyu | 0:7f19ba74283d | 445 | uLCD.cls(); |
Phyu | 0:7f19ba74283d | 446 | ReadMessage(); |
Phyu | 0:7f19ba74283d | 447 | break; |
Phyu | 0:7f19ba74283d | 448 | |
Phyu | 0:7f19ba74283d | 449 | |
Phyu | 0:7f19ba74283d | 450 | case '#' : |
Phyu | 0:7f19ba74283d | 451 | uLCD.cls(); |
Phyu | 0:7f19ba74283d | 452 | home(); |
Phyu | 0:7f19ba74283d | 453 | break; |
Phyu | 0:7f19ba74283d | 454 | |
Phyu | 0:7f19ba74283d | 455 | |
Phyu | 0:7f19ba74283d | 456 | case '0' : |
Phyu | 0:7f19ba74283d | 457 | uLCD.cls(); |
Phyu | 0:7f19ba74283d | 458 | Getmessage(); |
Phyu | 0:7f19ba74283d | 459 | break; |
Phyu | 0:7f19ba74283d | 460 | |
Phyu | 0:7f19ba74283d | 461 | |
Phyu | 0:7f19ba74283d | 462 | } |
Phyu | 0:7f19ba74283d | 463 | } |
Phyu | 0:7f19ba74283d | 464 | } |
Phyu | 0:7f19ba74283d | 465 | |
Phyu | 0:7f19ba74283d | 466 | |
Phyu | 0:7f19ba74283d | 467 | |
Phyu | 0:7f19ba74283d | 468 | char ChartoAlpha(char num) |
Phyu | 0:7f19ba74283d | 469 | { |
Phyu | 0:7f19ba74283d | 470 | |
Phyu | 0:7f19ba74283d | 471 | if ( num == '2') |
Phyu | 0:7f19ba74283d | 472 | { |
Phyu | 0:7f19ba74283d | 473 | |
Phyu | 0:7f19ba74283d | 474 | uLCD.putc('A'); |
Phyu | 0:7f19ba74283d | 475 | |
Phyu | 0:7f19ba74283d | 476 | } |
Phyu | 0:7f19ba74283d | 477 | if ( num == '2' && num == '2' ) |
Phyu | 0:7f19ba74283d | 478 | { |
Phyu | 0:7f19ba74283d | 479 | |
Phyu | 0:7f19ba74283d | 480 | uLCD.putc('B'); |
Phyu | 0:7f19ba74283d | 481 | |
Phyu | 0:7f19ba74283d | 482 | } |
Phyu | 0:7f19ba74283d | 483 | if ( num == '2' && num == '2' && num == '2' ) |
Phyu | 0:7f19ba74283d | 484 | { |
Phyu | 0:7f19ba74283d | 485 | wait(.5); |
Phyu | 0:7f19ba74283d | 486 | uLCD.putc('C'); |
Phyu | 0:7f19ba74283d | 487 | |
Phyu | 0:7f19ba74283d | 488 | } |
Phyu | 0:7f19ba74283d | 489 | if ( num == '0' ) |
Phyu | 0:7f19ba74283d | 490 | { wait(.2); |
Phyu | 0:7f19ba74283d | 491 | uLCD.putc(' '); |
Phyu | 0:7f19ba74283d | 492 | } |
Phyu | 0:7f19ba74283d | 493 | if ( num == '3' ) |
Phyu | 0:7f19ba74283d | 494 | { wait(.2); |
Phyu | 0:7f19ba74283d | 495 | uLCD.putc('D'); |
Phyu | 0:7f19ba74283d | 496 | } |
Phyu | 0:7f19ba74283d | 497 | |
Phyu | 0:7f19ba74283d | 498 | if ( num == '4' ) |
Phyu | 0:7f19ba74283d | 499 | { wait(.2); |
Phyu | 0:7f19ba74283d | 500 | uLCD.putc('G'); |
Phyu | 0:7f19ba74283d | 501 | } |
Phyu | 0:7f19ba74283d | 502 | if ( num == '5' ) |
Phyu | 0:7f19ba74283d | 503 | { wait(.2); |
Phyu | 0:7f19ba74283d | 504 | uLCD.putc('J'); |
Phyu | 0:7f19ba74283d | 505 | } |
Phyu | 0:7f19ba74283d | 506 | if ( num == '6' ) |
Phyu | 0:7f19ba74283d | 507 | { wait(.2); |
Phyu | 0:7f19ba74283d | 508 | uLCD.putc('M'); |
Phyu | 0:7f19ba74283d | 509 | } |
Phyu | 0:7f19ba74283d | 510 | if ( num == '7' ) |
Phyu | 0:7f19ba74283d | 511 | { wait(.2); |
Phyu | 0:7f19ba74283d | 512 | uLCD.putc('P'); |
Phyu | 0:7f19ba74283d | 513 | } |
Phyu | 0:7f19ba74283d | 514 | if ( num == '8' ) |
Phyu | 0:7f19ba74283d | 515 | { wait(.2); |
Phyu | 0:7f19ba74283d | 516 | uLCD.putc('T'); |
Phyu | 0:7f19ba74283d | 517 | } |
Phyu | 0:7f19ba74283d | 518 | if ( num == '9' ) |
Phyu | 0:7f19ba74283d | 519 | { wait(.2); |
Phyu | 0:7f19ba74283d | 520 | uLCD.putc('W'); |
Phyu | 0:7f19ba74283d | 521 | } |
Phyu | 0:7f19ba74283d | 522 | if (blackButton == 0) |
Phyu | 0:7f19ba74283d | 523 | { |
Phyu | 0:7f19ba74283d | 524 | uLCD.cls(); |
Phyu | 0:7f19ba74283d | 525 | uLCD.text_string("Your message\nhas been\nsucessfully sent!", 1, 4, FONT_7X8, GREEN); |
Phyu | 0:7f19ba74283d | 526 | wait(2); |
Phyu | 0:7f19ba74283d | 527 | uLCD.cls(); |
Phyu | 0:7f19ba74283d | 528 | home(); |
Phyu | 0:7f19ba74283d | 529 | } |
Phyu | 0:7f19ba74283d | 530 | if ( num == '#') |
Phyu | 0:7f19ba74283d | 531 | { |
Phyu | 0:7f19ba74283d | 532 | uLCD.cls(); |
Phyu | 0:7f19ba74283d | 533 | home(); |
Phyu | 0:7f19ba74283d | 534 | } |
Phyu | 0:7f19ba74283d | 535 | |
Phyu | 0:7f19ba74283d | 536 | } |
Phyu | 0:7f19ba74283d | 537 | |
Phyu | 0:7f19ba74283d | 538 | void shortcut() |
Phyu | 0:7f19ba74283d | 539 | { |
Phyu | 0:7f19ba74283d | 540 | uLCD.printf("\n Press 1 to call help!"); |
Phyu | 0:7f19ba74283d | 541 | uLCD.printf("\n Press 2 to say you are safe!"); |
Phyu | 0:7f19ba74283d | 542 | uLCD.printf("\n Press 3 to request for your GPS co-ordinates!"); |
Phyu | 0:7f19ba74283d | 543 | |
Phyu | 0:7f19ba74283d | 544 | while ( true) |
Phyu | 0:7f19ba74283d | 545 | { char cut = getkey(); |
Phyu | 0:7f19ba74283d | 546 | switch ( cut ) |
Phyu | 0:7f19ba74283d | 547 | { |
Phyu | 0:7f19ba74283d | 548 | case '1' : uLCD.cls(); |
Phyu | 0:7f19ba74283d | 549 | uLCD.text_string("Calling Help\nIt will\narrive in 30-45mins!", 1, 4, FONT_7X8, GREEN); |
Phyu | 0:7f19ba74283d | 550 | wait (5); |
Phyu | 0:7f19ba74283d | 551 | uLCD.cls(); |
Phyu | 0:7f19ba74283d | 552 | shortcut(); |
Phyu | 0:7f19ba74283d | 553 | break; |
Phyu | 0:7f19ba74283d | 554 | |
Phyu | 0:7f19ba74283d | 555 | case '2' : uLCD.cls(); |
Phyu | 0:7f19ba74283d | 556 | uLCD.text_string("Thank you.\nIf you need\nany help,\nPress *999 for \nSOS!", 1, 4, FONT_7X8, GREEN); |
Phyu | 0:7f19ba74283d | 557 | wait (5); |
Phyu | 0:7f19ba74283d | 558 | uLCD.cls(); |
Phyu | 0:7f19ba74283d | 559 | shortcut(); |
Phyu | 0:7f19ba74283d | 560 | break; |
Phyu | 0:7f19ba74283d | 561 | |
Phyu | 0:7f19ba74283d | 562 | |
Phyu | 0:7f19ba74283d | 563 | case '#' : |
Phyu | 0:7f19ba74283d | 564 | uLCD.cls(); |
Phyu | 0:7f19ba74283d | 565 | home(); |
Phyu | 0:7f19ba74283d | 566 | break; |
Phyu | 0:7f19ba74283d | 567 | |
Phyu | 0:7f19ba74283d | 568 | |
Phyu | 0:7f19ba74283d | 569 | case '0' : |
Phyu | 0:7f19ba74283d | 570 | uLCD.cls(); |
Phyu | 0:7f19ba74283d | 571 | Getmessage(); |
Phyu | 0:7f19ba74283d | 572 | break; |
Phyu | 0:7f19ba74283d | 573 | |
Phyu | 0:7f19ba74283d | 574 | |
Phyu | 0:7f19ba74283d | 575 | } |
Phyu | 0:7f19ba74283d | 576 | } |
Phyu | 0:7f19ba74283d | 577 | } |
Phyu | 0:7f19ba74283d | 578 | |
Phyu | 0:7f19ba74283d | 579 | void Getmessage() |
Phyu | 0:7f19ba74283d | 580 | { |
Phyu | 0:7f19ba74283d | 581 | uLCD.printf("\n1.Type message"); |
Phyu | 0:7f19ba74283d | 582 | uLCD.printf("\n2.Short-cut message"); |
Phyu | 0:7f19ba74283d | 583 | uLCD.printf("\n3.Read message"); |
Phyu | 0:7f19ba74283d | 584 | uLCD.printf("\n4.Delete message"); |
Phyu | 0:7f19ba74283d | 585 | |
Phyu | 0:7f19ba74283d | 586 | char key = getkey(); |
Phyu | 0:7f19ba74283d | 587 | |
Phyu | 0:7f19ba74283d | 588 | uLCD.printf("\n\n Press # to go back to home page"); |
Phyu | 0:7f19ba74283d | 589 | while ( true) |
Phyu | 0:7f19ba74283d | 590 | { |
Phyu | 0:7f19ba74283d | 591 | char keyy = getkey(); |
Phyu | 0:7f19ba74283d | 592 | |
Phyu | 0:7f19ba74283d | 593 | if ( keyy == '#' ) |
Phyu | 0:7f19ba74283d | 594 | { uLCD.cls(); |
Phyu | 0:7f19ba74283d | 595 | home(); } |
Phyu | 0:7f19ba74283d | 596 | |
Phyu | 0:7f19ba74283d | 597 | if ( keyy == '0' ) |
Phyu | 0:7f19ba74283d | 598 | { uLCD.cls(); |
Phyu | 0:7f19ba74283d | 599 | Getmessage(); } |
Phyu | 0:7f19ba74283d | 600 | |
Phyu | 0:7f19ba74283d | 601 | if ( keyy == '1' ) |
Phyu | 0:7f19ba74283d | 602 | { |
Phyu | 0:7f19ba74283d | 603 | uLCD.cls(); |
Phyu | 0:7f19ba74283d | 604 | uLCD.printf("\n Type your message and Press Black button to send.\n"); |
Phyu | 0:7f19ba74283d | 605 | while (true) |
Phyu | 0:7f19ba74283d | 606 | { char num = getkey(); |
Phyu | 0:7f19ba74283d | 607 | |
Phyu | 0:7f19ba74283d | 608 | char alpah = ChartoAlpha(num); |
Phyu | 0:7f19ba74283d | 609 | |
Phyu | 0:7f19ba74283d | 610 | } |
Phyu | 0:7f19ba74283d | 611 | } |
Phyu | 0:7f19ba74283d | 612 | if ( keyy == '2' ) |
Phyu | 0:7f19ba74283d | 613 | { uLCD.cls(); |
Phyu | 0:7f19ba74283d | 614 | shortcut(); |
Phyu | 0:7f19ba74283d | 615 | } |
Phyu | 0:7f19ba74283d | 616 | |
Phyu | 0:7f19ba74283d | 617 | if ( keyy == '3' ) |
Phyu | 0:7f19ba74283d | 618 | { uLCD.cls(); |
Phyu | 0:7f19ba74283d | 619 | ReadMessage(); |
Phyu | 0:7f19ba74283d | 620 | } |
Phyu | 0:7f19ba74283d | 621 | if ( keyy == '4' ) |
Phyu | 0:7f19ba74283d | 622 | { uLCD.cls(); |
Phyu | 0:7f19ba74283d | 623 | uLCD.printf("\n Select to delete message: "); |
Phyu | 0:7f19ba74283d | 624 | } |
Phyu | 0:7f19ba74283d | 625 | |
Phyu | 0:7f19ba74283d | 626 | |
Phyu | 0:7f19ba74283d | 627 | } |
Phyu | 0:7f19ba74283d | 628 | |
Phyu | 0:7f19ba74283d | 629 | } |
Phyu | 0:7f19ba74283d | 630 | |
Phyu | 0:7f19ba74283d | 631 | |
Phyu | 0:7f19ba74283d | 632 | |
Phyu | 0:7f19ba74283d | 633 | |
Phyu | 0:7f19ba74283d | 634 | void TrackingService() |
Phyu | 0:7f19ba74283d | 635 | { |
Phyu | 0:7f19ba74283d | 636 | if ( track == ONN ) |
Phyu | 0:7f19ba74283d | 637 | { |
Phyu | 0:7f19ba74283d | 638 | uLCD.printf("Tracking Service is On!Press 111 and * to turn off!"); |
Phyu | 0:7f19ba74283d | 639 | uLCD.printf("\n\n Press # to go back to home page"); |
Phyu | 0:7f19ba74283d | 640 | } |
Phyu | 0:7f19ba74283d | 641 | if ( track == OFFF ) |
Phyu | 0:7f19ba74283d | 642 | { |
Phyu | 0:7f19ba74283d | 643 | uLCD.printf("Tracking Service is Off!Press 111 and * to turn on!"); |
Phyu | 0:7f19ba74283d | 644 | uLCD.printf("\n\n Press # to go back to home page"); |
Phyu | 0:7f19ba74283d | 645 | } |
Phyu | 0:7f19ba74283d | 646 | |
Phyu | 0:7f19ba74283d | 647 | |
Phyu | 0:7f19ba74283d | 648 | |
Phyu | 0:7f19ba74283d | 649 | while ( true) |
Phyu | 0:7f19ba74283d | 650 | { |
Phyu | 0:7f19ba74283d | 651 | char keyy = getkey(); |
Phyu | 0:7f19ba74283d | 652 | uLCD.putc(keyy); |
Phyu | 0:7f19ba74283d | 653 | if ( keyy == '#' ) |
Phyu | 0:7f19ba74283d | 654 | { uLCD.cls(); |
Phyu | 0:7f19ba74283d | 655 | home(); } |
Phyu | 0:7f19ba74283d | 656 | } |
Phyu | 0:7f19ba74283d | 657 | |
Phyu | 0:7f19ba74283d | 658 | } |
Phyu | 0:7f19ba74283d | 659 | |
Phyu | 0:7f19ba74283d | 660 | void Sos() |
Phyu | 0:7f19ba74283d | 661 | { |
Phyu | 0:7f19ba74283d | 662 | k = 0 ; |
Phyu | 0:7f19ba74283d | 663 | uLCD.printf("\n Press 999 and black button for SOS service! "); |
Phyu | 0:7f19ba74283d | 664 | |
Phyu | 0:7f19ba74283d | 665 | uLCD.printf("\n\n Press # to go back to home page\n\n"); |
Phyu | 0:7f19ba74283d | 666 | while (true) |
Phyu | 0:7f19ba74283d | 667 | { |
Phyu | 0:7f19ba74283d | 668 | char key = getkey(); |
Phyu | 0:7f19ba74283d | 669 | uLCD.putc(key); |
Phyu | 0:7f19ba74283d | 670 | |
Phyu | 0:7f19ba74283d | 671 | if ( key == '#' ) |
Phyu | 0:7f19ba74283d | 672 | { uLCD.cls(); |
Phyu | 0:7f19ba74283d | 673 | home(); } |
Phyu | 0:7f19ba74283d | 674 | |
Phyu | 0:7f19ba74283d | 675 | } |
Phyu | 0:7f19ba74283d | 676 | |
Phyu | 0:7f19ba74283d | 677 | } |
Phyu | 0:7f19ba74283d | 678 | |
Phyu | 0:7f19ba74283d | 679 | void GPS() |
Phyu | 0:7f19ba74283d | 680 | { |
Phyu | 0:7f19ba74283d | 681 | uLCD.printf("\nYour co-ordinates now is X=%i Y=%i ", int(joyX.read_u16()), int(joyY.read_u16())); |
Phyu | 0:7f19ba74283d | 682 | |
Phyu | 0:7f19ba74283d | 683 | |
Phyu | 0:7f19ba74283d | 684 | uLCD.printf("\n\n Press # to go back to home page"); |
Phyu | 0:7f19ba74283d | 685 | while ( true) |
Phyu | 0:7f19ba74283d | 686 | { |
Phyu | 0:7f19ba74283d | 687 | char keyy = getkey(); |
Phyu | 0:7f19ba74283d | 688 | |
Phyu | 0:7f19ba74283d | 689 | if ( keyy == '#' ) |
Phyu | 0:7f19ba74283d | 690 | { uLCD.cls(); |
Phyu | 0:7f19ba74283d | 691 | home(); } |
Phyu | 0:7f19ba74283d | 692 | } |
Phyu | 0:7f19ba74283d | 693 | } |
Phyu | 0:7f19ba74283d | 694 | |
Phyu | 0:7f19ba74283d | 695 | void Onoff() |
Phyu | 0:7f19ba74283d | 696 | { |
Phyu | 0:7f19ba74283d | 697 | uLCD.printf("\nPress Red Button to power off device"); |
Phyu | 0:7f19ba74283d | 698 | |
Phyu | 0:7f19ba74283d | 699 | |
Phyu | 0:7f19ba74283d | 700 | uLCD.printf("\n\n Press # to go back to home page"); |
Phyu | 0:7f19ba74283d | 701 | while ( true) |
Phyu | 0:7f19ba74283d | 702 | { |
Phyu | 0:7f19ba74283d | 703 | char keyy = getkey(); |
Phyu | 0:7f19ba74283d | 704 | if (redButton == 0) |
Phyu | 0:7f19ba74283d | 705 | { uLCD.cls(); |
Phyu | 0:7f19ba74283d | 706 | uLCD.text_string("Shutting\nDown.......", 1, 4, FONT_7X8, GREEN); |
Phyu | 0:7f19ba74283d | 707 | wait(3 ); |
Phyu | 0:7f19ba74283d | 708 | uLCD.reset(); |
Phyu | 0:7f19ba74283d | 709 | |
Phyu | 0:7f19ba74283d | 710 | } |
Phyu | 0:7f19ba74283d | 711 | |
Phyu | 0:7f19ba74283d | 712 | if ( keyy == '#' ) |
Phyu | 0:7f19ba74283d | 713 | { uLCD.cls(); |
Phyu | 0:7f19ba74283d | 714 | home(); } |
Phyu | 0:7f19ba74283d | 715 | |
Phyu | 0:7f19ba74283d | 716 | |
Phyu | 0:7f19ba74283d | 717 | } |
Phyu | 0:7f19ba74283d | 718 | } |
Phyu | 0:7f19ba74283d | 719 | |
Phyu | 0:7f19ba74283d | 720 | |
Phyu | 0:7f19ba74283d | 721 | void home() |
Phyu | 0:7f19ba74283d | 722 | { |
Phyu | 0:7f19ba74283d | 723 | |
Phyu | 0:7f19ba74283d | 724 | uLCD.printf("\nHello\nWelcome to SatChat.\n"); //Default Green on black text |
Phyu | 0:7f19ba74283d | 725 | uLCD.printf("\n1.Message"); |
Phyu | 0:7f19ba74283d | 726 | uLCD.printf("\n2.Call for help(#999)"); |
Phyu | 0:7f19ba74283d | 727 | uLCD.printf("\n3.Tracking Service"); |
Phyu | 0:7f19ba74283d | 728 | uLCD.printf("\n4.Request GPS co-ordinates"); |
Phyu | 0:7f19ba74283d | 729 | uLCD.printf("\n5.Power on/off"); |
Phyu | 0:7f19ba74283d | 730 | |
Phyu | 0:7f19ba74283d | 731 | |
Phyu | 0:7f19ba74283d | 732 | while(true) |
Phyu | 0:7f19ba74283d | 733 | { |
Phyu | 0:7f19ba74283d | 734 | |
Phyu | 0:7f19ba74283d | 735 | gps_led= !gps_led ; |
Phyu | 0:7f19ba74283d | 736 | //uLCD.printf("\nJoystick: X=%i Y=%i ", int(joyX.read_u16()), int(joyY.read_u16())); |
Phyu | 0:7f19ba74283d | 737 | if (joyButton==0){ |
Phyu | 0:7f19ba74283d | 738 | uLCD.printf("Joystick Button pressed"); |
Phyu | 0:7f19ba74283d | 739 | } |
Phyu | 0:7f19ba74283d | 740 | |
Phyu | 0:7f19ba74283d | 741 | char keypressed = getkey(); |
Phyu | 0:7f19ba74283d | 742 | if (keypressed == '1') |
Phyu | 0:7f19ba74283d | 743 | { |
Phyu | 0:7f19ba74283d | 744 | uLCD.cls(); |
Phyu | 0:7f19ba74283d | 745 | Getmessage(); |
Phyu | 0:7f19ba74283d | 746 | } |
Phyu | 0:7f19ba74283d | 747 | if (keypressed == '2') |
Phyu | 0:7f19ba74283d | 748 | { |
Phyu | 0:7f19ba74283d | 749 | uLCD.cls(); |
Phyu | 0:7f19ba74283d | 750 | Sos(); |
Phyu | 0:7f19ba74283d | 751 | } |
Phyu | 0:7f19ba74283d | 752 | if (keypressed == '3') |
Phyu | 0:7f19ba74283d | 753 | { |
Phyu | 0:7f19ba74283d | 754 | uLCD.cls(); |
Phyu | 0:7f19ba74283d | 755 | |
Phyu | 0:7f19ba74283d | 756 | TrackingService(); |
Phyu | 0:7f19ba74283d | 757 | |
Phyu | 0:7f19ba74283d | 758 | } |
Phyu | 0:7f19ba74283d | 759 | |
Phyu | 0:7f19ba74283d | 760 | if (keypressed == '4') |
Phyu | 0:7f19ba74283d | 761 | { |
Phyu | 0:7f19ba74283d | 762 | uLCD.cls(); |
Phyu | 0:7f19ba74283d | 763 | GPS(); |
Phyu | 0:7f19ba74283d | 764 | } |
Phyu | 0:7f19ba74283d | 765 | if (keypressed == '5') |
Phyu | 0:7f19ba74283d | 766 | { |
Phyu | 0:7f19ba74283d | 767 | uLCD.cls(); |
Phyu | 0:7f19ba74283d | 768 | Onoff(); |
Phyu | 0:7f19ba74283d | 769 | } |
Phyu | 0:7f19ba74283d | 770 | if (redButton == 0) |
Phyu | 0:7f19ba74283d | 771 | { uLCD.cls(); |
Phyu | 0:7f19ba74283d | 772 | uLCD.text_string("Shutting\nDown.......", 1, 4, FONT_7X8, GREEN); |
Phyu | 0:7f19ba74283d | 773 | wait(3 ); |
Phyu | 0:7f19ba74283d | 774 | uLCD.reset(); |
Phyu | 0:7f19ba74283d | 775 | |
Phyu | 0:7f19ba74283d | 776 | } |
Phyu | 0:7f19ba74283d | 777 | if (blackButton == 0){ |
Phyu | 0:7f19ba74283d | 778 | uLCD.printf(",Black button pressed"); |
Phyu | 0:7f19ba74283d | 779 | uLCD.cls(); |
Phyu | 0:7f19ba74283d | 780 | |
Phyu | 0:7f19ba74283d | 781 | } |
Phyu | 0:7f19ba74283d | 782 | } |
Phyu | 0:7f19ba74283d | 783 | } |
Phyu | 0:7f19ba74283d | 784 | /* |
Phyu | 0:7f19ba74283d | 785 | void tracking_power(bool state) |
Phyu | 0:7f19ba74283d | 786 | /* BLACK CODE |
Phyu | 0:7f19ba74283d | 787 | MAX32630FTHR routine to control the output of the 3v3 line. |
Phyu | 0:7f19ba74283d | 788 | This is achieved by issuing commands to the MAX14690 controller. |
Phyu | 0:7f19ba74283d | 789 | In this case when the GPS is shutdown we clear any serial |
Phyu | 0:7f19ba74283d | 790 | data to avoid issues with mbeds buggy serial code */ |
Phyu | 0:7f19ba74283d | 791 | /*{ |
Phyu | 0:7f19ba74283d | 792 | /* char data[2]; |
Phyu | 0:7f19ba74283d | 793 | data[0] = 0x16; //MAX14690 LDO3cfg register |
Phyu | 0:7f19ba74283d | 794 | uLCD.printf("Tracing Service is:"); |
Phyu | 0:7f19ba74283d | 795 | if (state == ONN) { |
Phyu | 0:7f19ba74283d | 796 | data[1] = 0xE2; //Enable LDO3 |
Phyu | 0:7f19ba74283d | 797 | i2c.write( 0x50, data, 2 ); |
Phyu | 0:7f19ba74283d | 798 | gps_led= ONN; |
Phyu | 0:7f19ba74283d | 799 | uLCD.printf("ON\n\r"); |
Phyu | 0:7f19ba74283d | 800 | } else { |
Phyu | 0:7f19ba74283d | 801 | data[1] = 0xE0; //Disable LDO3 |
Phyu | 0:7f19ba74283d | 802 | i2c.write( 0x50, data, 2 ); |
Phyu | 0:7f19ba74283d | 803 | gps_led=OFFF; |
Phyu | 0:7f19ba74283d | 804 | while (gps.readable()) { |
Phyu | 0:7f19ba74283d | 805 | char dummy = gps.getc(); //Empty serial buffer because overflows reveal MBED bugs :-( |
Phyu | 0:7f19ba74283d | 806 | } |
Phyu | 0:7f19ba74283d | 807 | uLCD.printf("OFF\n\r"); |
Phyu | 0:7f19ba74283d | 808 | } |
Phyu | 0:7f19ba74283d | 809 | } |
Phyu | 0:7f19ba74283d | 810 | |
Phyu | 0:7f19ba74283d | 811 | int get_epoch_from_last_gps_time(void) |
Phyu | 0:7f19ba74283d | 812 | /* BLACK CODE |
Phyu | 0:7f19ba74283d | 813 | Given appropriate global char arrays of time and date information, |
Phyu | 0:7f19ba74283d | 814 | return a unix time epoch. |
Phyu | 0:7f19ba74283d | 815 | */ |
Phyu | 0:7f19ba74283d | 816 | /*{ |
Phyu | 0:7f19ba74283d | 817 | struct tm t; |
Phyu | 0:7f19ba74283d | 818 | time_t epoch; |
Phyu | 0:7f19ba74283d | 819 | char two_char_str[3] = {0}; |
Phyu | 0:7f19ba74283d | 820 | memcpy(two_char_str, gpsfix_last_utc_date+4, 2); |
Phyu | 0:7f19ba74283d | 821 | t.tm_year = atoi(two_char_str)+100; //Years since 1900 |
Phyu | 0:7f19ba74283d | 822 | memcpy(two_char_str, gpsfix_last_utc_date+2, 2); |
Phyu | 0:7f19ba74283d | 823 | t.tm_mon = atoi(two_char_str)-1; // Month, 0 - jan gpsfix_last_utc_date |
Phyu | 0:7f19ba74283d | 824 | memcpy(two_char_str, gpsfix_last_utc_date, 2); |
Phyu | 0:7f19ba74283d | 825 | t.tm_mday = atoi(two_char_str); // Day of the month gpsfix_last_utc_date |
Phyu | 0:7f19ba74283d | 826 | memcpy(two_char_str, gpsfix_last_utc_time, 2); |
Phyu | 0:7f19ba74283d | 827 | t.tm_hour = atoi(two_char_str); |
Phyu | 0:7f19ba74283d | 828 | memcpy(two_char_str, gpsfix_last_utc_time+2, 2); |
Phyu | 0:7f19ba74283d | 829 | t.tm_min = atoi(two_char_str); |
Phyu | 0:7f19ba74283d | 830 | memcpy(two_char_str, gpsfix_last_utc_time+4, 2); |
Phyu | 0:7f19ba74283d | 831 | t.tm_sec = atoi(two_char_str); |
Phyu | 0:7f19ba74283d | 832 | t.tm_isdst = 0; // Is DST on? 1 = yes, 0 = no, -1 = unknown |
Phyu | 0:7f19ba74283d | 833 | epoch = mktime(&t); |
Phyu | 0:7f19ba74283d | 834 | return epoch; |
Phyu | 0:7f19ba74283d | 835 | //BLACK CODE |
Phyu | 0:7f19ba74283d | 836 | } |
Phyu | 0:7f19ba74283d | 837 | |
Phyu | 0:7f19ba74283d | 838 | /*int gps_update(void) |
Phyu | 0:7f19ba74283d | 839 | /* BLACK CODE |
Phyu | 0:7f19ba74283d | 840 | gps_update |
Phyu | 0:7f19ba74283d | 841 | Reads NMEA data from a serial interface defined as "gps". |
Phyu | 0:7f19ba74283d | 842 | The function waits for a valid $GPRMC sentence. It then decodes the sentence and populates the |
Phyu | 0:7f19ba74283d | 843 | following global variables which are assumed to exist. |
Phyu | 0:7f19ba74283d | 844 | |
Phyu | 0:7f19ba74283d | 845 | gpsfix_last_utc_time[11] = {0}; char gpsfix_last_utc_date[7] = {0};char gpsfix_longtitude[12] = {0}; |
Phyu | 0:7f19ba74283d | 846 | char gpsfix_latitude[12] = {0}; char gpsfix_speed[8] = {0}; char gpsfix_course[7] = {0}; |
Phyu | 0:7f19ba74283d | 847 | char gpsfix_variation[7] = {0}; char gpsfix_mag_var_ew[1] = {0}; char gpsfix_ns = 0; char gpsfix_ew = 0; |
Phyu | 0:7f19ba74283d | 848 | |
Phyu | 0:7f19ba74283d | 849 | The following are also assumed to be part of the global declarations. |
Phyu | 0:7f19ba74283d | 850 | #define EXIT_SUCCESS 0 |
Phyu | 0:7f19ba74283d | 851 | #define EXIT_FAILURE 1 |
Phyu | 0:7f19ba74283d | 852 | const int GPS_TIMEOUT=180; |
Phyu | 0:7f19ba74283d | 853 | a gps_power() function that controls power to the GPS unit. |
Phyu | 0:7f19ba74283d | 854 | |
Phyu | 0:7f19ba74283d | 855 | If the function is successful it returns a 0. If a valid fix is not obtined within the GPS_TIMEOUT |
Phyu | 0:7f19ba74283d | 856 | period a 1 is returned. |
Phyu | 0:7f19ba74283d | 857 | |
Phyu | 0:7f19ba74283d | 858 | The code has been tested with a uBlox 6M but other GPS units may work. |
Phyu | 0:7f19ba74283d | 859 | The code is deliberately blocking as the mbed OS seems to crash on serial interrupts and buffer overflow. |
Phyu | 0:7f19ba74283d | 860 | The serial port is continuously read while waiting for a fix. Once a fix is obtained or a timeout occurs |
Phyu | 0:7f19ba74283d | 861 | the GPS is powered down and remaining data read out of the buffer. |
Phyu | 0:7f19ba74283d | 862 | */ |
Phyu | 0:7f19ba74283d | 863 | /*{ |
Phyu | 0:7f19ba74283d | 864 | gps_power(ONN); |
Phyu | 0:7f19ba74283d | 865 | time_t gps_on_time = time(NULL); //Start time for GPS timeout calculation. |
Phyu | 0:7f19ba74283d | 866 | bool wait_for_fix = true; //Set this to false once a fix is obtained. |
Phyu | 0:7f19ba74283d | 867 | while (wait_for_fix) { //Keep monitoring the GPS until we get a fix. |
Phyu | 0:7f19ba74283d | 868 | if ((time(NULL) - gps_on_time) > GPS_TIMEOUT) { |
Phyu | 0:7f19ba74283d | 869 | gps_power(OFFF); |
Phyu | 0:7f19ba74283d | 870 | return EXIT_FAILURE; //Return an error if the GPS takes too long for a fix. |
Phyu | 0:7f19ba74283d | 871 | } |
Phyu | 0:7f19ba74283d | 872 | int checksum = 0; |
Phyu | 0:7f19ba74283d | 873 | char nmea_sentence[83] = {0}; //NMEA length max is 82 + 1 terminator. Fill with NULL terminators to save doing it later. |
Phyu | 0:7f19ba74283d | 874 | while (gps.getc()!='$'); //wait for start of sentence |
Phyu | 0:7f19ba74283d | 875 | int nmea_index = 0; |
Phyu | 0:7f19ba74283d | 876 | nmea_sentence[nmea_index] = '$'; //Manually insert the '$' because we don't want it included in the checksum loop |
Phyu | 0:7f19ba74283d | 877 | char nmea_char = gps.getc(); //get sentence first char from GPS |
Phyu | 0:7f19ba74283d | 878 | while (nmea_char != '*') { //Loop, building sentence and calc'ing CS until a * is seen |
Phyu | 0:7f19ba74283d | 879 | checksum ^= nmea_char; //Calc checksum as we read sentence |
Phyu | 0:7f19ba74283d | 880 | if ((nmea_sentence[nmea_index] == ',')&&(nmea_char == ',')) { |
Phyu | 0:7f19ba74283d | 881 | nmea_sentence[++nmea_index] = ' '; //Pad consecutive comma with a space to make it possible to use strtok with empty values |
Phyu | 0:7f19ba74283d | 882 | } |
Phyu | 0:7f19ba74283d | 883 | nmea_sentence[++nmea_index] = nmea_char; //build the sentence with the next character |
Phyu | 0:7f19ba74283d | 884 | if (nmea_index > 81) { |
Phyu | 0:7f19ba74283d | 885 | nmea_index=81; //Don't overflow sentence buffer |
Phyu | 0:7f19ba74283d | 886 | } |
Phyu | 0:7f19ba74283d | 887 | nmea_char = gps.getc(); //get next char from GPS |
Phyu | 0:7f19ba74283d | 888 | } |
Phyu | 0:7f19ba74283d | 889 | //Last character was the '*' so next two are CS |
Phyu | 0:7f19ba74283d | 890 | char hex_checksum[3] = {0}; |
Phyu | 0:7f19ba74283d | 891 | hex_checksum[0] = gps.getc(); |
Phyu | 0:7f19ba74283d | 892 | hex_checksum[1] = gps.getc(); |
Phyu | 0:7f19ba74283d | 893 | if (checksum == (int)strtol(hex_checksum, NULL, 16) ) { //Compare calc and read checksums. |
Phyu | 0:7f19ba74283d | 894 | //Valid sentence so check if it's a GPRMC |
Phyu | 0:7f19ba74283d | 895 | const char gprmc[7] = "$GPRMC"; |
Phyu | 0:7f19ba74283d | 896 | char *token; |
Phyu | 0:7f19ba74283d | 897 | token = strtok(nmea_sentence, ","); |
Phyu | 0:7f19ba74283d | 898 | if (strcmp(token,gprmc) == 0) { //GPRMC |
Phyu | 0:7f19ba74283d | 899 | pc.printf( " %s\n\r", token ); //Get the time |
Phyu | 0:7f19ba74283d | 900 | if (token != NULL) { |
Phyu | 0:7f19ba74283d | 901 | token = strtok(NULL, ","); |
Phyu | 0:7f19ba74283d | 902 | if (*token != 32) { //If there is a time present (anything but a space), record it. |
Phyu | 0:7f19ba74283d | 903 | //pc.printf("Time: %s\n\r",token); |
Phyu | 0:7f19ba74283d | 904 | gps_led =! gps_led; //Flash blue LED |
Phyu | 0:7f19ba74283d | 905 | memcpy(gpsfix_last_utc_time, token, sizeof gpsfix_last_utc_time - 1); |
Phyu | 0:7f19ba74283d | 906 | } |
Phyu | 0:7f19ba74283d | 907 | } |
Phyu | 0:7f19ba74283d | 908 | if (token != NULL) { |
Phyu | 0:7f19ba74283d | 909 | token = strtok(NULL, ","); |
Phyu | 0:7f19ba74283d | 910 | if (*token == 'V') { |
Phyu | 0:7f19ba74283d | 911 | pc.printf("VOID"); |
Phyu | 0:7f19ba74283d | 912 | } |
Phyu | 0:7f19ba74283d | 913 | } |
Phyu | 0:7f19ba74283d | 914 | if (*token == 'A') { //Is this an 'A'ctive (valid) fix? |
Phyu | 0:7f19ba74283d | 915 | pc.printf("Got a fix\n\r"); |
Phyu | 0:7f19ba74283d | 916 | gps_power(OFF); //Yes - No need for GPS now |
Phyu | 0:7f19ba74283d | 917 | wait_for_fix = false; //Stop looping now we have a fix. |
Phyu | 0:7f19ba74283d | 918 | if (token != NULL) { |
Phyu | 0:7f19ba74283d | 919 | token = strtok(NULL, ","); |
Phyu | 0:7f19ba74283d | 920 | pc.printf("Latitude: %s\n\r",token); |
Phyu | 0:7f19ba74283d | 921 | memcpy(gpsfix_latitude, token, sizeof gpsfix_latitude - 1); |
Phyu | 0:7f19ba74283d | 922 | } |
Phyu | 0:7f19ba74283d | 923 | if (token != NULL) { |
Phyu | 0:7f19ba74283d | 924 | token = strtok(NULL, ","); |
Phyu | 0:7f19ba74283d | 925 | pc.printf("North/South: %s\n\r",token); |
Phyu | 0:7f19ba74283d | 926 | gpsfix_ns = *token; |
Phyu | 0:7f19ba74283d | 927 | } |
Phyu | 0:7f19ba74283d | 928 | if (token != NULL) { |
Phyu | 0:7f19ba74283d | 929 | token = strtok(NULL, ","); |
Phyu | 0:7f19ba74283d | 930 | pc.printf("Longitude: %s\n\r",token); |
Phyu | 0:7f19ba74283d | 931 | memcpy(gpsfix_longtitude, token, sizeof gpsfix_longtitude - 1); |
Phyu | 0:7f19ba74283d | 932 | } |
Phyu | 0:7f19ba74283d | 933 | if (token != NULL) { |
Phyu | 0:7f19ba74283d | 934 | token = strtok(NULL, ","); |
Phyu | 0:7f19ba74283d | 935 | pc.printf("East/West: %s\n\r",token); |
Phyu | 0:7f19ba74283d | 936 | gpsfix_ew = *token; |
Phyu | 0:7f19ba74283d | 937 | } |
Phyu | 0:7f19ba74283d | 938 | if (token != NULL) { |
Phyu | 0:7f19ba74283d | 939 | token = strtok(NULL, ","); |
Phyu | 0:7f19ba74283d | 940 | //pc.printf("Speed in knots: %s\n\r",token); |
Phyu | 0:7f19ba74283d | 941 | } |
Phyu | 0:7f19ba74283d | 942 | if (token != NULL) { |
Phyu | 0:7f19ba74283d | 943 | token = strtok(NULL, ","); |
Phyu | 0:7f19ba74283d | 944 | //pc.printf("True course: %s\n\r",token); |
Phyu | 0:7f19ba74283d | 945 | } |
Phyu | 0:7f19ba74283d | 946 | if (token != NULL) { |
Phyu | 0:7f19ba74283d | 947 | token = strtok(NULL, ","); |
Phyu | 0:7f19ba74283d | 948 | pc.printf("Date: %s\n\r",token); |
Phyu | 0:7f19ba74283d | 949 | memcpy(gpsfix_last_utc_date, token, sizeof gpsfix_last_utc_date - 1); |
Phyu | 0:7f19ba74283d | 950 | } |
Phyu | 0:7f19ba74283d | 951 | if (token != NULL) { |
Phyu | 0:7f19ba74283d | 952 | token = strtok(NULL, ","); |
Phyu | 0:7f19ba74283d | 953 | //pc.printf("Variation: %s\n\r",token); |
Phyu | 0:7f19ba74283d | 954 | } |
Phyu | 0:7f19ba74283d | 955 | if (token != NULL) { |
Phyu | 0:7f19ba74283d | 956 | token = strtok(NULL, ","); |
Phyu | 0:7f19ba74283d | 957 | //pc.printf("Variation East/West: %s\n\r",token); |
Phyu | 0:7f19ba74283d | 958 | } |
Phyu | 0:7f19ba74283d | 959 | } |
Phyu | 0:7f19ba74283d | 960 | } |
Phyu | 0:7f19ba74283d | 961 | } |
Phyu | 0:7f19ba74283d | 962 | } |
Phyu | 0:7f19ba74283d | 963 | return EXIT_SUCCESS; |
Phyu | 0:7f19ba74283d | 964 | //BLACK CODE |
Phyu | 0:7f19ba74283d | 965 | }*/ |
Phyu | 0:7f19ba74283d | 966 | |
Phyu | 0:7f19ba74283d | 967 | main() |
Phyu | 0:7f19ba74283d | 968 | { /*Set the power button behaviour. |
Phyu | 0:7f19ba74283d | 969 | char data[2]; |
Phyu | 0:7f19ba74283d | 970 | data[0] = 0x1A; //MAX14690 BootCfg register |
Phyu | 0:7f19ba74283d | 971 | data[1] = 0x30; //Always-On Mode, off state via PWR_OFF_CMD |
Phyu | 0:7f19ba74283d | 972 | i2c.write( 0x50, data, 2 ); |
Phyu | 0:7f19ba74283d | 973 | */ |
Phyu | 0:7f19ba74283d | 974 | |
Phyu | 0:7f19ba74283d | 975 | char data[2]; |
Phyu | 0:7f19ba74283d | 976 | data[0] = 0x17; //MAX14690 LDO3Vset register |
Phyu | 0:7f19ba74283d | 977 | data[1] = 0x19; //3.3V |
Phyu | 0:7f19ba74283d | 978 | i2c.write( 0x50, data, 2 ); |
Phyu | 0:7f19ba74283d | 979 | //tracking_power(OFFF); |
Phyu | 0:7f19ba74283d | 980 | |
Phyu | 0:7f19ba74283d | 981 | |
Phyu | 0:7f19ba74283d | 982 | uLCD.printf("\nTracking Service is On!"); |
Phyu | 0:7f19ba74283d | 983 | uLCD.printf("\n\nThis Unit require your GPS fix at every interval"); |
Phyu | 0:7f19ba74283d | 984 | uLCD.printf("\n\nPlesae enter your desirable interval for us to check on you"); |
Phyu | 0:7f19ba74283d | 985 | |
Phyu | 0:7f19ba74283d | 986 | wait(3); |
Phyu | 0:7f19ba74283d | 987 | |
Phyu | 0:7f19ba74283d | 988 | while ( true) |
Phyu | 0:7f19ba74283d | 989 | { char mins = getkey(); |
Phyu | 0:7f19ba74283d | 990 | int min = mins; |
Phyu | 0:7f19ba74283d | 991 | if ( mins ) |
Phyu | 0:7f19ba74283d | 992 | { uLCD.cls(); |
Phyu | 0:7f19ba74283d | 993 | uLCD.printf("\n You have entered %c mins for the interval",mins); |
Phyu | 0:7f19ba74283d | 994 | } |
Phyu | 0:7f19ba74283d | 995 | if (redButton == 0) |
Phyu | 0:7f19ba74283d | 996 | { uLCD.cls(); |
Phyu | 0:7f19ba74283d | 997 | uLCD.text_string("Shutting\nDown.......", 1, 4, FONT_7X8, GREEN); |
Phyu | 0:7f19ba74283d | 998 | wait(3 ); |
Phyu | 0:7f19ba74283d | 999 | uLCD.reset(); |
Phyu | 0:7f19ba74283d | 1000 | |
Phyu | 0:7f19ba74283d | 1001 | } |
Phyu | 0:7f19ba74283d | 1002 | uLCD.cls(); |
Phyu | 0:7f19ba74283d | 1003 | home(); |
Phyu | 0:7f19ba74283d | 1004 | } |
Phyu | 0:7f19ba74283d | 1005 | |
Phyu | 0:7f19ba74283d | 1006 | |
Phyu | 0:7f19ba74283d | 1007 | |
Phyu | 0:7f19ba74283d | 1008 | |
Phyu | 0:7f19ba74283d | 1009 | |
Phyu | 0:7f19ba74283d | 1010 | //wait(5); |
Phyu | 0:7f19ba74283d | 1011 | //uLCD.cls(); |
Phyu | 0:7f19ba74283d | 1012 | |
Phyu | 0:7f19ba74283d | 1013 | //uLCD.printf("Tracking Service is On!Press 111 to turn off!"); |
Phyu | 0:7f19ba74283d | 1014 | |
Phyu | 0:7f19ba74283d | 1015 | // gps_led= !gps_led ; |
Phyu | 0:7f19ba74283d | 1016 | |
Phyu | 0:7f19ba74283d | 1017 | |
Phyu | 0:7f19ba74283d | 1018 | |
Phyu | 0:7f19ba74283d | 1019 | |
Phyu | 0:7f19ba74283d | 1020 | |
Phyu | 0:7f19ba74283d | 1021 | |
Phyu | 0:7f19ba74283d | 1022 | |
Phyu | 0:7f19ba74283d | 1023 | |
Phyu | 0:7f19ba74283d | 1024 | |
Phyu | 0:7f19ba74283d | 1025 | //Set the voltage to 3v3 for the GPS. |
Phyu | 0:7f19ba74283d | 1026 | /* char data[2]; |
Phyu | 0:7f19ba74283d | 1027 | data[0] = 0x17; //MAX14690 LDO3Vset register |
Phyu | 0:7f19ba74283d | 1028 | data[1] = 0x19; //3.3V |
Phyu | 0:7f19ba74283d | 1029 | i2c.write( 0x50, data, 2 ); |
Phyu | 0:7f19ba74283d | 1030 | gps_power(OFF);*/ |
Phyu | 0:7f19ba74283d | 1031 | |
Phyu | 0:7f19ba74283d | 1032 | /* while (1) { |
Phyu | 0:7f19ba74283d | 1033 | |
Phyu | 0:7f19ba74283d | 1034 | if (gps_update()==EXIT_SUCCESS) { |
Phyu | 0:7f19ba74283d | 1035 | gps_data_present = true; |
Phyu | 0:7f19ba74283d | 1036 | int gps_epoch = get_epoch_from_last_gps_time(); |
Phyu | 0:7f19ba74283d | 1037 | set_time(gps_epoch); |
Phyu | 0:7f19ba74283d | 1038 | pc.printf("Got a GPS fix and time.\n\r"); |
Phyu | 0:7f19ba74283d | 1039 | } else { |
Phyu | 0:7f19ba74283d | 1040 | pc.printf("GPS timed out and we have no existing fix.\n\r"); |
Phyu | 0:7f19ba74283d | 1041 | pc.printf("We can send an Iridium packet but coordinates are rough.\n\r"); |
Phyu | 0:7f19ba74283d | 1042 | } |
Phyu | 0:7f19ba74283d | 1043 | time_t seconds = time(NULL); |
Phyu | 0:7f19ba74283d | 1044 | //printf("Time as a basic string = %s", ctime(&seconds)); |
Phyu | 0:7f19ba74283d | 1045 | wait(60); |
Phyu | 0:7f19ba74283d | 1046 | seconds = time(NULL); |
Phyu | 0:7f19ba74283d | 1047 | |
Phyu | 0:7f19ba74283d | 1048 | wait(33); |
Phyu | 0:7f19ba74283d | 1049 | seconds = time(NULL); |
Phyu | 0:7f19ba74283d | 1050 | printf("Time as a basic string = %s", ctime(&seconds)); |
Phyu | 0:7f19ba74283d | 1051 | wait(60); |
Phyu | 0:7f19ba74283d | 1052 | } */ |
Phyu | 0:7f19ba74283d | 1053 | } |
Phyu | 0:7f19ba74283d | 1054 | |
Phyu | 0:7f19ba74283d | 1055 | |
Phyu | 0:7f19ba74283d | 1056 | |
Phyu | 0:7f19ba74283d | 1057 | |
Phyu | 0:7f19ba74283d | 1058 | |
Phyu | 0:7f19ba74283d | 1059 | |
Phyu | 0:7f19ba74283d | 1060 | |
Phyu | 0:7f19ba74283d | 1061 | |
Phyu | 0:7f19ba74283d | 1062 |