SMS message display on LED Matrix board with printer option
Dependencies: AdafruitThermalPrinter HT1632_LedMatrix VodafoneUSBModem mbed-rtos mbed
main.cpp@1:243371cb92c8, 2013-01-30 (annotated)
- Committer:
- SomeRandomBloke
- Date:
- Wed Jan 30 16:58:33 2013 +0000
- Revision:
- 1:243371cb92c8
- Parent:
- 0:9d29b886d41b
- Child:
- 2:787cbb491f8f
library updates and attempt to acquire own number
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
SomeRandomBloke | 0:9d29b886d41b | 1 | /** |
SomeRandomBloke | 0:9d29b886d41b | 2 | * Mbed SMS to Printer and LED Matrix Displays |
SomeRandomBloke | 0:9d29b886d41b | 3 | * Based on SMS example from VodafoneUSBModem library and |
SomeRandomBloke | 0:9d29b886d41b | 4 | * 3GReceiptPrinter app from Ashley Mills. |
SomeRandomBloke | 0:9d29b886d41b | 5 | * |
SomeRandomBloke | 0:9d29b886d41b | 6 | * Requires libraries: |
SomeRandomBloke | 0:9d29b886d41b | 7 | * AdafruitThermalPrinter - Port of Arduino library by Ashley Mills |
SomeRandomBloke | 0:9d29b886d41b | 8 | * VodafoneUSBModem - Driver for Vodafone K3370 Mobile Broadband dongle |
SomeRandomBloke | 0:9d29b886d41b | 9 | * HT1632_LedMatrix - LED Matrix library by Andrew Lindsay, port of Arduino library by Andrew Lindsay |
SomeRandomBloke | 0:9d29b886d41b | 10 | * |
SomeRandomBloke | 0:9d29b886d41b | 11 | * @author Andrew Lindsay |
SomeRandomBloke | 0:9d29b886d41b | 12 | * |
SomeRandomBloke | 0:9d29b886d41b | 13 | * @section LICENSE |
SomeRandomBloke | 0:9d29b886d41b | 14 | * |
SomeRandomBloke | 0:9d29b886d41b | 15 | * Copyright (c) 2012 Andrew Lindsay (andrew [at] thiseldo [dot] co [dot] uk) |
SomeRandomBloke | 0:9d29b886d41b | 16 | * |
SomeRandomBloke | 0:9d29b886d41b | 17 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
SomeRandomBloke | 0:9d29b886d41b | 18 | * of this software and associated documentation files (the "Software"), to deal |
SomeRandomBloke | 0:9d29b886d41b | 19 | * in the Software without restriction, including without limitation the rights |
SomeRandomBloke | 0:9d29b886d41b | 20 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
SomeRandomBloke | 0:9d29b886d41b | 21 | * copies of the Software, and to permit persons to whom the Software is |
SomeRandomBloke | 0:9d29b886d41b | 22 | * furnished to do so, subject to the following conditions: |
SomeRandomBloke | 0:9d29b886d41b | 23 | |
SomeRandomBloke | 0:9d29b886d41b | 24 | * The above copyright notice and this permission notice shall be included in |
SomeRandomBloke | 0:9d29b886d41b | 25 | * all copies or substantial portions of the Software. |
SomeRandomBloke | 0:9d29b886d41b | 26 | * |
SomeRandomBloke | 0:9d29b886d41b | 27 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
SomeRandomBloke | 0:9d29b886d41b | 28 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
SomeRandomBloke | 0:9d29b886d41b | 29 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
SomeRandomBloke | 0:9d29b886d41b | 30 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
SomeRandomBloke | 0:9d29b886d41b | 31 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
SomeRandomBloke | 0:9d29b886d41b | 32 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
SomeRandomBloke | 0:9d29b886d41b | 33 | * THE SOFTWARE. |
SomeRandomBloke | 0:9d29b886d41b | 34 | * |
SomeRandomBloke | 0:9d29b886d41b | 35 | * @section DESCRIPTION |
SomeRandomBloke | 0:9d29b886d41b | 36 | * Display received SMS on scrolling LED matrix with optional output to thermal printer. |
SomeRandomBloke | 0:9d29b886d41b | 37 | * |
SomeRandomBloke | 0:9d29b886d41b | 38 | * TODO: Still have issue with restarts when using printer. |
SomeRandomBloke | 0:9d29b886d41b | 39 | * mbed-rtos and serial problem? |
SomeRandomBloke | 0:9d29b886d41b | 40 | * |
SomeRandomBloke | 0:9d29b886d41b | 41 | */ |
SomeRandomBloke | 0:9d29b886d41b | 42 | |
SomeRandomBloke | 0:9d29b886d41b | 43 | #define USE_LED |
SomeRandomBloke | 0:9d29b886d41b | 44 | #define USE_PRINTER |
SomeRandomBloke | 0:9d29b886d41b | 45 | |
SomeRandomBloke | 0:9d29b886d41b | 46 | #include <ctype.h> |
SomeRandomBloke | 0:9d29b886d41b | 47 | |
SomeRandomBloke | 0:9d29b886d41b | 48 | #include "mbed.h" |
SomeRandomBloke | 0:9d29b886d41b | 49 | #include "VodafoneUSBModem.h" |
SomeRandomBloke | 0:9d29b886d41b | 50 | //#include <LinkMonitor.h> |
SomeRandomBloke | 0:9d29b886d41b | 51 | |
SomeRandomBloke | 0:9d29b886d41b | 52 | #ifdef USE_LED |
SomeRandomBloke | 0:9d29b886d41b | 53 | #include "HT1632_LedMatrix.h" |
SomeRandomBloke | 0:9d29b886d41b | 54 | #endif |
SomeRandomBloke | 0:9d29b886d41b | 55 | #ifdef USE_PRINTER |
SomeRandomBloke | 0:9d29b886d41b | 56 | #include "AdafruitThermal.h" |
SomeRandomBloke | 0:9d29b886d41b | 57 | #endif |
SomeRandomBloke | 0:9d29b886d41b | 58 | |
SomeRandomBloke | 0:9d29b886d41b | 59 | #define DEBUG 1 |
SomeRandomBloke | 0:9d29b886d41b | 60 | |
SomeRandomBloke | 0:9d29b886d41b | 61 | #ifdef USE_LED |
SomeRandomBloke | 0:9d29b886d41b | 62 | // Cound try to get own number usine USSD request |
SomeRandomBloke | 1:243371cb92c8 | 63 | #define INFO_MSG " Send a message to " |
SomeRandomBloke | 1:243371cb92c8 | 64 | //#define INFO_MSG " Send a message to 07765946942 " |
SomeRandomBloke | 0:9d29b886d41b | 65 | #endif |
SomeRandomBloke | 0:9d29b886d41b | 66 | |
SomeRandomBloke | 0:9d29b886d41b | 67 | // Vodafone USSD commands |
SomeRandomBloke | 0:9d29b886d41b | 68 | #define USSD_COMMAND_OWN_NUMBER "*#100#" |
SomeRandomBloke | 0:9d29b886d41b | 69 | #define USSD_COMMAND_BALANCE "*#134#" |
SomeRandomBloke | 0:9d29b886d41b | 70 | #define USSD_COMMAND_TIME "*#103#" |
SomeRandomBloke | 0:9d29b886d41b | 71 | |
SomeRandomBloke | 0:9d29b886d41b | 72 | |
SomeRandomBloke | 0:9d29b886d41b | 73 | #ifdef DEBUG |
SomeRandomBloke | 0:9d29b886d41b | 74 | Serial debug_pc(USBTX, USBRX); // tx, rx |
SomeRandomBloke | 0:9d29b886d41b | 75 | #endif |
SomeRandomBloke | 0:9d29b886d41b | 76 | |
SomeRandomBloke | 0:9d29b886d41b | 77 | #ifdef USE_PRINTER |
SomeRandomBloke | 0:9d29b886d41b | 78 | AdafruitThermal printer(p28,p27); // setup printer |
SomeRandomBloke | 0:9d29b886d41b | 79 | #endif |
SomeRandomBloke | 0:9d29b886d41b | 80 | // Define a maximum size for storage arrays, is 160 (SMS size) + a bit more. |
SomeRandomBloke | 0:9d29b886d41b | 81 | #define MAX_MSG_LENGTH 192 |
SomeRandomBloke | 0:9d29b886d41b | 82 | |
SomeRandomBloke | 0:9d29b886d41b | 83 | // Month list used in converting to integer for set_time |
SomeRandomBloke | 0:9d29b886d41b | 84 | char months[12][4] = {"JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC" }; |
SomeRandomBloke | 0:9d29b886d41b | 85 | |
SomeRandomBloke | 0:9d29b886d41b | 86 | #ifdef USE_LED |
SomeRandomBloke | 0:9d29b886d41b | 87 | |
SomeRandomBloke | 0:9d29b886d41b | 88 | #define LED_MAX_DISPLAY_X 4 |
SomeRandomBloke | 0:9d29b886d41b | 89 | #define LED_MAX_DISPLAY_Y 1 |
SomeRandomBloke | 0:9d29b886d41b | 90 | |
SomeRandomBloke | 0:9d29b886d41b | 91 | // create object to control the LED Matrix |
SomeRandomBloke | 0:9d29b886d41b | 92 | HT1632_LedMatrix led = HT1632_LedMatrix(); |
SomeRandomBloke | 0:9d29b886d41b | 93 | #define DISPDELAY 90 |
SomeRandomBloke | 0:9d29b886d41b | 94 | #endif |
SomeRandomBloke | 0:9d29b886d41b | 95 | |
SomeRandomBloke | 0:9d29b886d41b | 96 | // Message buffers. New message waiting to be displayed and current message being displayed |
SomeRandomBloke | 0:9d29b886d41b | 97 | static char cmdBuf[12]; |
SomeRandomBloke | 0:9d29b886d41b | 98 | static char newMsgBuf[MAX_MSG_LENGTH]; |
SomeRandomBloke | 0:9d29b886d41b | 99 | static char msgBuf[MAX_MSG_LENGTH]; |
SomeRandomBloke | 0:9d29b886d41b | 100 | |
SomeRandomBloke | 0:9d29b886d41b | 101 | #ifdef USE_LED |
SomeRandomBloke | 1:243371cb92c8 | 102 | static char ownNumber[20]; |
SomeRandomBloke | 1:243371cb92c8 | 103 | |
SomeRandomBloke | 0:9d29b886d41b | 104 | int crtPos = 0; |
SomeRandomBloke | 0:9d29b886d41b | 105 | int msgx = 1; // position on message screen of current character, set to 1 to allow for first scroll |
SomeRandomBloke | 0:9d29b886d41b | 106 | bool resetMessage = false; |
SomeRandomBloke | 0:9d29b886d41b | 107 | |
SomeRandomBloke | 0:9d29b886d41b | 108 | void matrixDemo( void ); |
SomeRandomBloke | 0:9d29b886d41b | 109 | #endif |
SomeRandomBloke | 0:9d29b886d41b | 110 | |
SomeRandomBloke | 0:9d29b886d41b | 111 | // Define the onboard LEDs to use as status indicators |
SomeRandomBloke | 0:9d29b886d41b | 112 | DigitalOut led1(LED1); // Activity |
SomeRandomBloke | 0:9d29b886d41b | 113 | DigitalOut led2(LED2); // Activity, alternates with led2 |
SomeRandomBloke | 0:9d29b886d41b | 114 | DigitalOut led3(LED3); // SMS received, turns off after processed |
SomeRandomBloke | 0:9d29b886d41b | 115 | DigitalOut led4(LED4); // USSD requested |
SomeRandomBloke | 0:9d29b886d41b | 116 | |
SomeRandomBloke | 0:9d29b886d41b | 117 | int threadRestartCount = 0; |
SomeRandomBloke | 0:9d29b886d41b | 118 | |
SomeRandomBloke | 0:9d29b886d41b | 119 | // Convert string buffer to upper case, is destructive. Buffer will be changed. |
SomeRandomBloke | 0:9d29b886d41b | 120 | char* stoupper( char* s ) |
SomeRandomBloke | 0:9d29b886d41b | 121 | { |
SomeRandomBloke | 0:9d29b886d41b | 122 | char* p = s; |
SomeRandomBloke | 0:9d29b886d41b | 123 | while (*p = toupper( *p )) p++; |
SomeRandomBloke | 0:9d29b886d41b | 124 | return s; |
SomeRandomBloke | 0:9d29b886d41b | 125 | } |
SomeRandomBloke | 0:9d29b886d41b | 126 | |
SomeRandomBloke | 0:9d29b886d41b | 127 | |
SomeRandomBloke | 0:9d29b886d41b | 128 | #ifdef USE_PRINTER |
SomeRandomBloke | 0:9d29b886d41b | 129 | void timestampMessage( char *msg ) |
SomeRandomBloke | 0:9d29b886d41b | 130 | { |
SomeRandomBloke | 0:9d29b886d41b | 131 | char timebuf[50]; |
SomeRandomBloke | 0:9d29b886d41b | 132 | // Print date/time, then message |
SomeRandomBloke | 0:9d29b886d41b | 133 | time_t seconds = time(NULL); |
SomeRandomBloke | 0:9d29b886d41b | 134 | strftime(timebuf, 50, "%d/%m/%Y %X\n", localtime(&seconds)); |
SomeRandomBloke | 0:9d29b886d41b | 135 | printer.print(timebuf); |
SomeRandomBloke | 0:9d29b886d41b | 136 | printer.print(msg); |
SomeRandomBloke | 0:9d29b886d41b | 137 | // linefeed a couple of times |
SomeRandomBloke | 0:9d29b886d41b | 138 | printer.feed(3); |
SomeRandomBloke | 0:9d29b886d41b | 139 | } |
SomeRandomBloke | 0:9d29b886d41b | 140 | #endif |
SomeRandomBloke | 0:9d29b886d41b | 141 | |
SomeRandomBloke | 0:9d29b886d41b | 142 | #ifdef USE_LED |
SomeRandomBloke | 0:9d29b886d41b | 143 | // Load a new message |
SomeRandomBloke | 0:9d29b886d41b | 144 | void setNewMessage( char *newMsgStart ) |
SomeRandomBloke | 0:9d29b886d41b | 145 | { |
SomeRandomBloke | 0:9d29b886d41b | 146 | strncpy( newMsgBuf, newMsgStart, MAX_MSG_LENGTH ); |
SomeRandomBloke | 0:9d29b886d41b | 147 | resetMessage = true; |
SomeRandomBloke | 0:9d29b886d41b | 148 | } |
SomeRandomBloke | 0:9d29b886d41b | 149 | #endif |
SomeRandomBloke | 0:9d29b886d41b | 150 | |
SomeRandomBloke | 0:9d29b886d41b | 151 | void sendUSSDCommand( VodafoneUSBModem *_modem, char *ussdCommand, bool setScrolling ) |
SomeRandomBloke | 0:9d29b886d41b | 152 | { |
SomeRandomBloke | 0:9d29b886d41b | 153 | led4 = 1; |
SomeRandomBloke | 0:9d29b886d41b | 154 | #ifdef DEBUG |
SomeRandomBloke | 0:9d29b886d41b | 155 | debug_pc.printf("Sending %s on USSD channel\n", ussdCommand); |
SomeRandomBloke | 0:9d29b886d41b | 156 | #endif |
SomeRandomBloke | 0:9d29b886d41b | 157 | int ret = _modem->sendUSSD(ussdCommand, newMsgBuf, MAX_MSG_LENGTH); |
SomeRandomBloke | 0:9d29b886d41b | 158 | // Check for correct response |
SomeRandomBloke | 0:9d29b886d41b | 159 | if(ret) { |
SomeRandomBloke | 0:9d29b886d41b | 160 | // Non 0 value indicates an error?? |
SomeRandomBloke | 0:9d29b886d41b | 161 | #ifdef DEBUG |
SomeRandomBloke | 0:9d29b886d41b | 162 | debug_pc.printf("Send USSD command returned %d\n", ret); |
SomeRandomBloke | 0:9d29b886d41b | 163 | #endif |
SomeRandomBloke | 0:9d29b886d41b | 164 | led4 = 0; |
SomeRandomBloke | 0:9d29b886d41b | 165 | return; |
SomeRandomBloke | 0:9d29b886d41b | 166 | } |
SomeRandomBloke | 0:9d29b886d41b | 167 | |
SomeRandomBloke | 0:9d29b886d41b | 168 | // Should only display message if one has been received. |
SomeRandomBloke | 0:9d29b886d41b | 169 | #ifdef DEBUG |
SomeRandomBloke | 0:9d29b886d41b | 170 | debug_pc.printf("Result of command: %s\n", newMsgBuf); |
SomeRandomBloke | 0:9d29b886d41b | 171 | #endif |
SomeRandomBloke | 0:9d29b886d41b | 172 | |
SomeRandomBloke | 0:9d29b886d41b | 173 | led4 = 0; |
SomeRandomBloke | 0:9d29b886d41b | 174 | |
SomeRandomBloke | 0:9d29b886d41b | 175 | #ifdef USE_LED |
SomeRandomBloke | 0:9d29b886d41b | 176 | resetMessage = setScrolling; |
SomeRandomBloke | 0:9d29b886d41b | 177 | #endif |
SomeRandomBloke | 0:9d29b886d41b | 178 | } |
SomeRandomBloke | 0:9d29b886d41b | 179 | |
SomeRandomBloke | 0:9d29b886d41b | 180 | void setTime(VodafoneUSBModem *_modem ) |
SomeRandomBloke | 0:9d29b886d41b | 181 | { |
SomeRandomBloke | 0:9d29b886d41b | 182 | char numBuf[10]; |
SomeRandomBloke | 0:9d29b886d41b | 183 | // Set RTC using received message, format is DD-MMM-YYYY HH:MM |
SomeRandomBloke | 0:9d29b886d41b | 184 | // Month is in text name, e.g. NOV, time is using 24 hour clock. |
SomeRandomBloke | 0:9d29b886d41b | 185 | struct tm t; |
SomeRandomBloke | 0:9d29b886d41b | 186 | int retryCount = 3; |
SomeRandomBloke | 0:9d29b886d41b | 187 | |
SomeRandomBloke | 0:9d29b886d41b | 188 | while( retryCount ) { |
SomeRandomBloke | 0:9d29b886d41b | 189 | sendUSSDCommand( _modem, USSD_COMMAND_TIME, false ); |
SomeRandomBloke | 0:9d29b886d41b | 190 | |
SomeRandomBloke | 0:9d29b886d41b | 191 | #ifdef DEBUG |
SomeRandomBloke | 0:9d29b886d41b | 192 | debug_pc.printf("Time received is %s\n", newMsgBuf); |
SomeRandomBloke | 0:9d29b886d41b | 193 | #endif |
SomeRandomBloke | 0:9d29b886d41b | 194 | |
SomeRandomBloke | 0:9d29b886d41b | 195 | t.tm_sec = 0; // 0-59 |
SomeRandomBloke | 0:9d29b886d41b | 196 | strncpy(numBuf, &newMsgBuf[15], 2 ); |
SomeRandomBloke | 0:9d29b886d41b | 197 | t.tm_min = atoi(numBuf); // 0-59 |
SomeRandomBloke | 0:9d29b886d41b | 198 | strncpy(numBuf, &newMsgBuf[12], 2 ); |
SomeRandomBloke | 0:9d29b886d41b | 199 | t.tm_hour = atoi(numBuf); // 0-23 |
SomeRandomBloke | 0:9d29b886d41b | 200 | strncpy(numBuf, &newMsgBuf[0], 2 ); |
SomeRandomBloke | 0:9d29b886d41b | 201 | t.tm_mday = atoi(numBuf); // 1-31 |
SomeRandomBloke | 0:9d29b886d41b | 202 | strncpy(numBuf, &newMsgBuf[3], 3 ); |
SomeRandomBloke | 0:9d29b886d41b | 203 | t.tm_mon = 0; // 0-11 |
SomeRandomBloke | 0:9d29b886d41b | 204 | for( int i=0; i<12; i++ ) { |
SomeRandomBloke | 0:9d29b886d41b | 205 | if( strncmp( months[i], numBuf, 3 ) == 0 ) { |
SomeRandomBloke | 0:9d29b886d41b | 206 | t.tm_mon = i; // 0-11 |
SomeRandomBloke | 0:9d29b886d41b | 207 | break; |
SomeRandomBloke | 0:9d29b886d41b | 208 | } |
SomeRandomBloke | 0:9d29b886d41b | 209 | } |
SomeRandomBloke | 0:9d29b886d41b | 210 | strncpy(numBuf, &newMsgBuf[9], 2 ); |
SomeRandomBloke | 0:9d29b886d41b | 211 | t.tm_year = 100 + atoi( numBuf ); // year since 1900 |
SomeRandomBloke | 0:9d29b886d41b | 212 | |
SomeRandomBloke | 0:9d29b886d41b | 213 | if( t.tm_year >110 ) { |
SomeRandomBloke | 0:9d29b886d41b | 214 | // convert to timestamp and display |
SomeRandomBloke | 0:9d29b886d41b | 215 | time_t seconds = mktime(&t); |
SomeRandomBloke | 0:9d29b886d41b | 216 | set_time( seconds ); |
SomeRandomBloke | 0:9d29b886d41b | 217 | retryCount = 0; // No more retries, terminate while |
SomeRandomBloke | 0:9d29b886d41b | 218 | } else { |
SomeRandomBloke | 0:9d29b886d41b | 219 | // Failed to set time, decrement tries |
SomeRandomBloke | 0:9d29b886d41b | 220 | retryCount--; |
SomeRandomBloke | 0:9d29b886d41b | 221 | } |
SomeRandomBloke | 0:9d29b886d41b | 222 | } |
SomeRandomBloke | 0:9d29b886d41b | 223 | } |
SomeRandomBloke | 0:9d29b886d41b | 224 | |
SomeRandomBloke | 1:243371cb92c8 | 225 | #ifdef USE_LED |
SomeRandomBloke | 1:243371cb92c8 | 226 | void getOwnNumber(VodafoneUSBModem *_modem, char *numPtr ) |
SomeRandomBloke | 1:243371cb92c8 | 227 | { |
SomeRandomBloke | 1:243371cb92c8 | 228 | char numBuf[10]; |
SomeRandomBloke | 1:243371cb92c8 | 229 | // Set RTC using received message, format is DD-MMM-YYYY HH:MM |
SomeRandomBloke | 1:243371cb92c8 | 230 | // Month is in text name, e.g. NOV, time is using 24 hour clock. |
SomeRandomBloke | 1:243371cb92c8 | 231 | struct tm t; |
SomeRandomBloke | 1:243371cb92c8 | 232 | int retryCount = 3; |
SomeRandomBloke | 1:243371cb92c8 | 233 | |
SomeRandomBloke | 1:243371cb92c8 | 234 | while( retryCount ) { |
SomeRandomBloke | 1:243371cb92c8 | 235 | sendUSSDCommand( _modem, USSD_COMMAND_OWN_NUMBER, false ); |
SomeRandomBloke | 1:243371cb92c8 | 236 | |
SomeRandomBloke | 1:243371cb92c8 | 237 | #ifdef DEBUG |
SomeRandomBloke | 1:243371cb92c8 | 238 | debug_pc.printf("Own Number received %s\n", newMsgBuf); |
SomeRandomBloke | 1:243371cb92c8 | 239 | #endif |
SomeRandomBloke | 1:243371cb92c8 | 240 | |
SomeRandomBloke | 1:243371cb92c8 | 241 | // Save number in array pointed to be numPtr |
SomeRandomBloke | 1:243371cb92c8 | 242 | |
SomeRandomBloke | 1:243371cb92c8 | 243 | // Terminator |
SomeRandomBloke | 1:243371cb92c8 | 244 | *numPtr = '\0'; |
SomeRandomBloke | 1:243371cb92c8 | 245 | |
SomeRandomBloke | 1:243371cb92c8 | 246 | /* |
SomeRandomBloke | 1:243371cb92c8 | 247 | |
SomeRandomBloke | 1:243371cb92c8 | 248 | |
SomeRandomBloke | 1:243371cb92c8 | 249 | t.tm_sec = 0; // 0-59 |
SomeRandomBloke | 1:243371cb92c8 | 250 | strncpy(numBuf, &newMsgBuf[15], 2 ); |
SomeRandomBloke | 1:243371cb92c8 | 251 | t.tm_min = atoi(numBuf); // 0-59 |
SomeRandomBloke | 1:243371cb92c8 | 252 | strncpy(numBuf, &newMsgBuf[12], 2 ); |
SomeRandomBloke | 1:243371cb92c8 | 253 | t.tm_hour = atoi(numBuf); // 0-23 |
SomeRandomBloke | 1:243371cb92c8 | 254 | strncpy(numBuf, &newMsgBuf[0], 2 ); |
SomeRandomBloke | 1:243371cb92c8 | 255 | t.tm_mday = atoi(numBuf); // 1-31 |
SomeRandomBloke | 1:243371cb92c8 | 256 | strncpy(numBuf, &newMsgBuf[3], 3 ); |
SomeRandomBloke | 1:243371cb92c8 | 257 | t.tm_mon = 0; // 0-11 |
SomeRandomBloke | 1:243371cb92c8 | 258 | for( int i=0; i<12; i++ ) { |
SomeRandomBloke | 1:243371cb92c8 | 259 | if( strncmp( months[i], numBuf, 3 ) == 0 ) { |
SomeRandomBloke | 1:243371cb92c8 | 260 | t.tm_mon = i; // 0-11 |
SomeRandomBloke | 1:243371cb92c8 | 261 | break; |
SomeRandomBloke | 1:243371cb92c8 | 262 | } |
SomeRandomBloke | 1:243371cb92c8 | 263 | } |
SomeRandomBloke | 1:243371cb92c8 | 264 | strncpy(numBuf, &newMsgBuf[9], 2 ); |
SomeRandomBloke | 1:243371cb92c8 | 265 | t.tm_year = 100 + atoi( numBuf ); // year since 1900 |
SomeRandomBloke | 1:243371cb92c8 | 266 | |
SomeRandomBloke | 1:243371cb92c8 | 267 | if( t.tm_year >110 ) { |
SomeRandomBloke | 1:243371cb92c8 | 268 | // convert to timestamp and display |
SomeRandomBloke | 1:243371cb92c8 | 269 | time_t seconds = mktime(&t); |
SomeRandomBloke | 1:243371cb92c8 | 270 | set_time( seconds ); |
SomeRandomBloke | 1:243371cb92c8 | 271 | retryCount = 0; // No more retries, terminate while |
SomeRandomBloke | 1:243371cb92c8 | 272 | } else { |
SomeRandomBloke | 1:243371cb92c8 | 273 | // Failed to set time, decrement tries |
SomeRandomBloke | 1:243371cb92c8 | 274 | retryCount--; |
SomeRandomBloke | 1:243371cb92c8 | 275 | } |
SomeRandomBloke | 1:243371cb92c8 | 276 | */ |
SomeRandomBloke | 1:243371cb92c8 | 277 | } |
SomeRandomBloke | 1:243371cb92c8 | 278 | } |
SomeRandomBloke | 1:243371cb92c8 | 279 | #endif |
SomeRandomBloke | 1:243371cb92c8 | 280 | |
SomeRandomBloke | 0:9d29b886d41b | 281 | |
SomeRandomBloke | 0:9d29b886d41b | 282 | void receiveSMS(void const*) |
SomeRandomBloke | 0:9d29b886d41b | 283 | { |
SomeRandomBloke | 0:9d29b886d41b | 284 | VodafoneUSBModem modem; |
SomeRandomBloke | 0:9d29b886d41b | 285 | time_t seconds = time(NULL); |
SomeRandomBloke | 0:9d29b886d41b | 286 | |
SomeRandomBloke | 0:9d29b886d41b | 287 | threadRestartCount++; |
SomeRandomBloke | 0:9d29b886d41b | 288 | |
SomeRandomBloke | 0:9d29b886d41b | 289 | // int pRssi = 0; |
SomeRandomBloke | 0:9d29b886d41b | 290 | // setNewMessage( "Starting" ); |
SomeRandomBloke | 0:9d29b886d41b | 291 | |
SomeRandomBloke | 0:9d29b886d41b | 292 | |
SomeRandomBloke | 0:9d29b886d41b | 293 | // LinkMonitor::REGISTRATION_STATE pRegistrationState; |
SomeRandomBloke | 0:9d29b886d41b | 294 | // LinkMonitor::BEARER pBearer; |
SomeRandomBloke | 0:9d29b886d41b | 295 | |
SomeRandomBloke | 0:9d29b886d41b | 296 | // modem.getLinkState( &pRssi,&pRegistrationState, &pBearer); |
SomeRandomBloke | 0:9d29b886d41b | 297 | #ifdef DEBUG |
SomeRandomBloke | 0:9d29b886d41b | 298 | // debug_pc.printf("Link state Rssi: %d, Registration state %x Bearer %x\n",pRssi,pRegistrationState, pBearer); |
SomeRandomBloke | 0:9d29b886d41b | 299 | #endif |
SomeRandomBloke | 0:9d29b886d41b | 300 | |
SomeRandomBloke | 1:243371cb92c8 | 301 | #ifdef USE_LED |
SomeRandomBloke | 1:243371cb92c8 | 302 | // Get own number fromt he network |
SomeRandomBloke | 1:243371cb92c8 | 303 | getOwnNumber( &modem, ownNumber ); |
SomeRandomBloke | 1:243371cb92c8 | 304 | #endif |
SomeRandomBloke | 1:243371cb92c8 | 305 | |
SomeRandomBloke | 0:9d29b886d41b | 306 | // sprintf(msgBuf, "Link state Rssi: %d, Registration state %x Bearer %x ",pRssi,pRegistrationState, pBearer); |
SomeRandomBloke | 0:9d29b886d41b | 307 | #ifdef USE_PRINTER |
SomeRandomBloke | 0:9d29b886d41b | 308 | // Check if time already set, if not then get it. Use year = 0 as test |
SomeRandomBloke | 0:9d29b886d41b | 309 | struct tm *t = localtime(&seconds); |
SomeRandomBloke | 0:9d29b886d41b | 310 | if( t->tm_year == 0 ) { |
SomeRandomBloke | 0:9d29b886d41b | 311 | setTime( &modem ); |
SomeRandomBloke | 0:9d29b886d41b | 312 | } |
SomeRandomBloke | 0:9d29b886d41b | 313 | |
SomeRandomBloke | 0:9d29b886d41b | 314 | sprintf(newMsgBuf, "Thread Start %d\r\n", threadRestartCount ); |
SomeRandomBloke | 0:9d29b886d41b | 315 | timestampMessage( newMsgBuf ); |
SomeRandomBloke | 0:9d29b886d41b | 316 | #endif |
SomeRandomBloke | 0:9d29b886d41b | 317 | #ifdef USE_LED |
SomeRandomBloke | 0:9d29b886d41b | 318 | //strcpy( msgBuf, INFO_MSG ); |
SomeRandomBloke | 1:243371cb92c8 | 319 | sprintf(newMsgBuf, "%s %s ", INFO_MSG, ownNumber ); |
SomeRandomBloke | 1:243371cb92c8 | 320 | setNewMessage( newMsgBuf ); |
SomeRandomBloke | 0:9d29b886d41b | 321 | |
SomeRandomBloke | 0:9d29b886d41b | 322 | led.displayOn(); |
SomeRandomBloke | 0:9d29b886d41b | 323 | #endif |
SomeRandomBloke | 0:9d29b886d41b | 324 | char num[17]; |
SomeRandomBloke | 0:9d29b886d41b | 325 | size_t smsCount; |
SomeRandomBloke | 0:9d29b886d41b | 326 | |
SomeRandomBloke | 0:9d29b886d41b | 327 | while(true) { |
SomeRandomBloke | 0:9d29b886d41b | 328 | if( modem.getSMCount(&smsCount) ==OK ) { |
SomeRandomBloke | 0:9d29b886d41b | 329 | if( smsCount > 0) { |
SomeRandomBloke | 0:9d29b886d41b | 330 | led3 = 1; |
SomeRandomBloke | 0:9d29b886d41b | 331 | #ifdef DEBUG |
SomeRandomBloke | 0:9d29b886d41b | 332 | debug_pc.printf("%d SMS to read\n", smsCount); |
SomeRandomBloke | 0:9d29b886d41b | 333 | #endif |
SomeRandomBloke | 0:9d29b886d41b | 334 | if( modem.getSM(num, newMsgBuf, MAX_MSG_LENGTH) == OK ) { |
SomeRandomBloke | 0:9d29b886d41b | 335 | |
SomeRandomBloke | 0:9d29b886d41b | 336 | #ifdef DEBUG |
SomeRandomBloke | 0:9d29b886d41b | 337 | debug_pc.printf("%s : %s\n", num, newMsgBuf); |
SomeRandomBloke | 0:9d29b886d41b | 338 | #endif |
SomeRandomBloke | 0:9d29b886d41b | 339 | #ifdef USE_PRINTER |
SomeRandomBloke | 0:9d29b886d41b | 340 | // Print date/time, then message |
SomeRandomBloke | 0:9d29b886d41b | 341 | timestampMessage( newMsgBuf ); |
SomeRandomBloke | 0:9d29b886d41b | 342 | #endif |
SomeRandomBloke | 0:9d29b886d41b | 343 | #ifdef USE_LED |
SomeRandomBloke | 0:9d29b886d41b | 344 | resetMessage = true; |
SomeRandomBloke | 0:9d29b886d41b | 345 | #endif |
SomeRandomBloke | 0:9d29b886d41b | 346 | strncpy( cmdBuf, newMsgBuf, 10 ); |
SomeRandomBloke | 0:9d29b886d41b | 347 | stoupper( cmdBuf ); // This is a destructive function, original characters are uppercased |
SomeRandomBloke | 0:9d29b886d41b | 348 | if( strncmp( cmdBuf, "BALANCE", 7 ) == 0 ) { |
SomeRandomBloke | 0:9d29b886d41b | 349 | sendUSSDCommand( &modem, USSD_COMMAND_BALANCE, true ); |
SomeRandomBloke | 0:9d29b886d41b | 350 | #ifdef USE_PRINTER |
SomeRandomBloke | 0:9d29b886d41b | 351 | timestampMessage( newMsgBuf ); |
SomeRandomBloke | 0:9d29b886d41b | 352 | #endif |
SomeRandomBloke | 0:9d29b886d41b | 353 | #ifdef USE_LED |
SomeRandomBloke | 0:9d29b886d41b | 354 | resetMessage = true; |
SomeRandomBloke | 0:9d29b886d41b | 355 | } else if ( strncmp( cmdBuf, "INFO", 4 ) == 0 ) { |
SomeRandomBloke | 1:243371cb92c8 | 356 | // setNewMessage( INFO_MSG ); |
SomeRandomBloke | 1:243371cb92c8 | 357 | sprintf(newMsgBuf, "%s %s ", INFO_MSG, ownNumber ); |
SomeRandomBloke | 1:243371cb92c8 | 358 | setNewMessage( newMsgBuf ); |
SomeRandomBloke | 0:9d29b886d41b | 359 | #endif |
SomeRandomBloke | 0:9d29b886d41b | 360 | // } else if ( strncmp( cmdBuf, "DEMO", 4 ) == 0 ) { |
SomeRandomBloke | 1:243371cb92c8 | 361 | // matrixDemo(); |
SomeRandomBloke | 1:243371cb92c8 | 362 | // sprintf(newMsgBuf, "%s %s ", INFO_MSG, ownNumber ); |
SomeRandomBloke | 1:243371cb92c8 | 363 | // setNewMessage( newMsgBuf ); |
SomeRandomBloke | 0:9d29b886d41b | 364 | #ifdef USE_LED |
SomeRandomBloke | 0:9d29b886d41b | 365 | } else if ( strncmp( cmdBuf, "CLEAR", 5 ) == 0 ) { |
SomeRandomBloke | 0:9d29b886d41b | 366 | setNewMessage( " " ); |
SomeRandomBloke | 0:9d29b886d41b | 367 | #endif |
SomeRandomBloke | 0:9d29b886d41b | 368 | } |
SomeRandomBloke | 0:9d29b886d41b | 369 | } |
SomeRandomBloke | 0:9d29b886d41b | 370 | } |
SomeRandomBloke | 0:9d29b886d41b | 371 | } |
SomeRandomBloke | 0:9d29b886d41b | 372 | Thread::wait(3000); |
SomeRandomBloke | 0:9d29b886d41b | 373 | led3 = 0; |
SomeRandomBloke | 0:9d29b886d41b | 374 | } |
SomeRandomBloke | 0:9d29b886d41b | 375 | } |
SomeRandomBloke | 0:9d29b886d41b | 376 | |
SomeRandomBloke | 0:9d29b886d41b | 377 | #ifdef USE_LED |
SomeRandomBloke | 0:9d29b886d41b | 378 | void displayScrollingLine(void const*) |
SomeRandomBloke | 0:9d29b886d41b | 379 | { |
SomeRandomBloke | 0:9d29b886d41b | 380 | int y,xmax,ymax; |
SomeRandomBloke | 0:9d29b886d41b | 381 | led.getXYMax(&xmax,&ymax); |
SomeRandomBloke | 0:9d29b886d41b | 382 | |
SomeRandomBloke | 0:9d29b886d41b | 383 | while(true) { |
SomeRandomBloke | 0:9d29b886d41b | 384 | // shift the whole screen 6 times, one column at a time; making 1 character |
SomeRandomBloke | 0:9d29b886d41b | 385 | if( strlen( msgBuf ) > 10 ) { |
SomeRandomBloke | 0:9d29b886d41b | 386 | for (int x=0; x < 6; x++) { |
SomeRandomBloke | 0:9d29b886d41b | 387 | led.scrollLeft(1, 1); |
SomeRandomBloke | 0:9d29b886d41b | 388 | msgx--; |
SomeRandomBloke | 0:9d29b886d41b | 389 | // fit as much as we can on the available display space |
SomeRandomBloke | 0:9d29b886d41b | 390 | |
SomeRandomBloke | 0:9d29b886d41b | 391 | while (!led.putChar(msgx,0,msgBuf[crtPos])) { // zero return if it all fitted |
SomeRandomBloke | 0:9d29b886d41b | 392 | led.getXY(&msgx,&y); |
SomeRandomBloke | 0:9d29b886d41b | 393 | crtPos++; // we got all of the character on!! |
SomeRandomBloke | 0:9d29b886d41b | 394 | if (crtPos >= strlen(msgBuf)) { |
SomeRandomBloke | 0:9d29b886d41b | 395 | crtPos = 0; |
SomeRandomBloke | 0:9d29b886d41b | 396 | } |
SomeRandomBloke | 0:9d29b886d41b | 397 | } |
SomeRandomBloke | 0:9d29b886d41b | 398 | led.putShadowRam(); |
SomeRandomBloke | 0:9d29b886d41b | 399 | Thread::wait(DISPDELAY); |
SomeRandomBloke | 0:9d29b886d41b | 400 | } |
SomeRandomBloke | 0:9d29b886d41b | 401 | } |
SomeRandomBloke | 0:9d29b886d41b | 402 | // Look for a new message being available |
SomeRandomBloke | 0:9d29b886d41b | 403 | // TODO add minimum interval between message changes, e.g. 60s |
SomeRandomBloke | 0:9d29b886d41b | 404 | if( resetMessage ) { |
SomeRandomBloke | 0:9d29b886d41b | 405 | led.clear(); |
SomeRandomBloke | 0:9d29b886d41b | 406 | crtPos = 0; |
SomeRandomBloke | 0:9d29b886d41b | 407 | msgx = 1; |
SomeRandomBloke | 0:9d29b886d41b | 408 | strncpy( msgBuf, newMsgBuf, MAX_MSG_LENGTH ); |
SomeRandomBloke | 0:9d29b886d41b | 409 | if( strlen( msgBuf ) > 10 ) { |
SomeRandomBloke | 0:9d29b886d41b | 410 | strcat( msgBuf, " "); |
SomeRandomBloke | 0:9d29b886d41b | 411 | } else { |
SomeRandomBloke | 0:9d29b886d41b | 412 | led.putString(0,0, msgBuf); |
SomeRandomBloke | 0:9d29b886d41b | 413 | } |
SomeRandomBloke | 0:9d29b886d41b | 414 | resetMessage = false; |
SomeRandomBloke | 0:9d29b886d41b | 415 | } |
SomeRandomBloke | 0:9d29b886d41b | 416 | } |
SomeRandomBloke | 0:9d29b886d41b | 417 | } |
SomeRandomBloke | 0:9d29b886d41b | 418 | |
SomeRandomBloke | 0:9d29b886d41b | 419 | |
SomeRandomBloke | 0:9d29b886d41b | 420 | void matrixDemo( void ) |
SomeRandomBloke | 0:9d29b886d41b | 421 | { |
SomeRandomBloke | 0:9d29b886d41b | 422 | int xmax,ymax; |
SomeRandomBloke | 0:9d29b886d41b | 423 | led.getXYMax(&xmax,&ymax); |
SomeRandomBloke | 0:9d29b886d41b | 424 | led.clear(); |
SomeRandomBloke | 0:9d29b886d41b | 425 | for( int n=0; n<3; n++ ) { |
SomeRandomBloke | 0:9d29b886d41b | 426 | for( int i=0; i<8; i++ ) { |
SomeRandomBloke | 0:9d29b886d41b | 427 | led.drawRectangle(i,i,xmax-i,ymax-i, 1); |
SomeRandomBloke | 0:9d29b886d41b | 428 | wait(0.05); |
SomeRandomBloke | 0:9d29b886d41b | 429 | } |
SomeRandomBloke | 0:9d29b886d41b | 430 | for( int i=7; i>=0; i-- ) { |
SomeRandomBloke | 0:9d29b886d41b | 431 | led.drawRectangle(i,i,xmax-i,ymax-i, 0); |
SomeRandomBloke | 0:9d29b886d41b | 432 | wait(0.05); |
SomeRandomBloke | 0:9d29b886d41b | 433 | } |
SomeRandomBloke | 0:9d29b886d41b | 434 | } |
SomeRandomBloke | 0:9d29b886d41b | 435 | led.clear(); |
SomeRandomBloke | 0:9d29b886d41b | 436 | for( int n=0; n<3; n++ ) { |
SomeRandomBloke | 0:9d29b886d41b | 437 | for(int i=0; i<(xmax/2); i++) { |
SomeRandomBloke | 0:9d29b886d41b | 438 | led.drawCircle((xmax/2), 7, i, 1 ); |
SomeRandomBloke | 0:9d29b886d41b | 439 | wait( 0.05 ); |
SomeRandomBloke | 0:9d29b886d41b | 440 | } |
SomeRandomBloke | 0:9d29b886d41b | 441 | for(int i=(xmax/2); i>=0; i--) { |
SomeRandomBloke | 0:9d29b886d41b | 442 | led.drawCircle((xmax/2), 7, i, 0 ); |
SomeRandomBloke | 0:9d29b886d41b | 443 | wait( 0.05 ); |
SomeRandomBloke | 0:9d29b886d41b | 444 | } |
SomeRandomBloke | 0:9d29b886d41b | 445 | } |
SomeRandomBloke | 0:9d29b886d41b | 446 | wait(2); |
SomeRandomBloke | 0:9d29b886d41b | 447 | |
SomeRandomBloke | 0:9d29b886d41b | 448 | led.clear(); |
SomeRandomBloke | 0:9d29b886d41b | 449 | led.init(2,1); // Use displays 1 and 2 as 64x8 display |
SomeRandomBloke | 0:9d29b886d41b | 450 | } |
SomeRandomBloke | 0:9d29b886d41b | 451 | |
SomeRandomBloke | 0:9d29b886d41b | 452 | |
SomeRandomBloke | 0:9d29b886d41b | 453 | void showTime() |
SomeRandomBloke | 0:9d29b886d41b | 454 | { |
SomeRandomBloke | 0:9d29b886d41b | 455 | time_t seconds = time(NULL); |
SomeRandomBloke | 0:9d29b886d41b | 456 | char timebuf[20]; |
SomeRandomBloke | 0:9d29b886d41b | 457 | strftime(timebuf, 20, "%X ", localtime(&seconds)); |
SomeRandomBloke | 0:9d29b886d41b | 458 | led.putString(12,8, timebuf ); |
SomeRandomBloke | 0:9d29b886d41b | 459 | } |
SomeRandomBloke | 0:9d29b886d41b | 460 | |
SomeRandomBloke | 0:9d29b886d41b | 461 | void showDate() |
SomeRandomBloke | 0:9d29b886d41b | 462 | { |
SomeRandomBloke | 0:9d29b886d41b | 463 | time_t seconds = time(NULL); |
SomeRandomBloke | 0:9d29b886d41b | 464 | char timebuf[20]; |
SomeRandomBloke | 0:9d29b886d41b | 465 | strftime(timebuf, 20, "%d/%m/%Y ", localtime(&seconds)); |
SomeRandomBloke | 0:9d29b886d41b | 466 | led.putString(4,8, timebuf ); |
SomeRandomBloke | 0:9d29b886d41b | 467 | } |
SomeRandomBloke | 0:9d29b886d41b | 468 | #endif |
SomeRandomBloke | 0:9d29b886d41b | 469 | |
SomeRandomBloke | 0:9d29b886d41b | 470 | |
SomeRandomBloke | 0:9d29b886d41b | 471 | int main() |
SomeRandomBloke | 0:9d29b886d41b | 472 | { |
SomeRandomBloke | 0:9d29b886d41b | 473 | #ifdef DEBUG |
SomeRandomBloke | 0:9d29b886d41b | 474 | debug_pc.baud(57600); |
SomeRandomBloke | 0:9d29b886d41b | 475 | #ifdef USE_LED |
SomeRandomBloke | 0:9d29b886d41b | 476 | debug_pc.printf("SMS to LED Matrix display\n"); |
SomeRandomBloke | 0:9d29b886d41b | 477 | #endif |
SomeRandomBloke | 0:9d29b886d41b | 478 | #ifdef USE_PRINTER |
SomeRandomBloke | 0:9d29b886d41b | 479 | printer.begin(); |
SomeRandomBloke | 0:9d29b886d41b | 480 | debug_pc.printf("SMS To Printer\n"); |
SomeRandomBloke | 0:9d29b886d41b | 481 | timestampMessage("SMS To Printer Starting"); |
SomeRandomBloke | 0:9d29b886d41b | 482 | #endif |
SomeRandomBloke | 0:9d29b886d41b | 483 | #endif |
SomeRandomBloke | 0:9d29b886d41b | 484 | #ifdef USE_LED |
SomeRandomBloke | 0:9d29b886d41b | 485 | int displayCount = 10; |
SomeRandomBloke | 0:9d29b886d41b | 486 | bool displayTime = true; |
SomeRandomBloke | 0:9d29b886d41b | 487 | |
SomeRandomBloke | 0:9d29b886d41b | 488 | led.init(LED_MAX_DISPLAY_X,LED_MAX_DISPLAY_Y); // Use displays 1 and 2 as 64x8 display |
SomeRandomBloke | 0:9d29b886d41b | 489 | led.clear(); |
SomeRandomBloke | 0:9d29b886d41b | 490 | led.setBrightness(2); |
SomeRandomBloke | 0:9d29b886d41b | 491 | //led.displayOff(); // Turn off display for now until receiver tast has started |
SomeRandomBloke | 0:9d29b886d41b | 492 | bool twoLineDisplay = (LED_MAX_DISPLAY_X > 1); |
SomeRandomBloke | 0:9d29b886d41b | 493 | led.putString( 0, 0, "SMS to LED Display" ); |
SomeRandomBloke | 0:9d29b886d41b | 494 | |
SomeRandomBloke | 0:9d29b886d41b | 495 | Thread::wait(3000); // Wait for display to initialise after power up |
SomeRandomBloke | 0:9d29b886d41b | 496 | #endif |
SomeRandomBloke | 0:9d29b886d41b | 497 | |
SomeRandomBloke | 0:9d29b886d41b | 498 | // Set initial blank message |
SomeRandomBloke | 0:9d29b886d41b | 499 | strcpy( msgBuf, " " ); |
SomeRandomBloke | 0:9d29b886d41b | 500 | |
SomeRandomBloke | 0:9d29b886d41b | 501 | Thread receiveTask(receiveSMS, NULL, osPriorityNormal, 1024 * 8); // try 6 next |
SomeRandomBloke | 0:9d29b886d41b | 502 | #ifdef USE_LED |
SomeRandomBloke | 0:9d29b886d41b | 503 | Thread displayTask(displayScrollingLine, NULL, osPriorityNormal, 1024 * 4); |
SomeRandomBloke | 0:9d29b886d41b | 504 | #endif |
SomeRandomBloke | 0:9d29b886d41b | 505 | |
SomeRandomBloke | 0:9d29b886d41b | 506 | // Show we are still working by alternitively flashing LED1 adn LED2, once a second |
SomeRandomBloke | 0:9d29b886d41b | 507 | led1 = 0; // Working |
SomeRandomBloke | 0:9d29b886d41b | 508 | led2 = 1; // Alternate with led1 |
SomeRandomBloke | 0:9d29b886d41b | 509 | led3 = 0; // Received and processign SMS |
SomeRandomBloke | 0:9d29b886d41b | 510 | led4 = 0; // Processing USSD message queue |
SomeRandomBloke | 0:9d29b886d41b | 511 | while(1) { |
SomeRandomBloke | 0:9d29b886d41b | 512 | #ifdef USE_LED |
SomeRandomBloke | 0:9d29b886d41b | 513 | // Only display date/time is we have a 2 row display |
SomeRandomBloke | 0:9d29b886d41b | 514 | if( twoLineDisplay ) { |
SomeRandomBloke | 0:9d29b886d41b | 515 | if( --displayCount <= 0 ) { |
SomeRandomBloke | 0:9d29b886d41b | 516 | displayTime = !displayTime; |
SomeRandomBloke | 0:9d29b886d41b | 517 | displayCount = 10; |
SomeRandomBloke | 0:9d29b886d41b | 518 | led.putString(0,8, " " ); |
SomeRandomBloke | 0:9d29b886d41b | 519 | } |
SomeRandomBloke | 0:9d29b886d41b | 520 | if( displayTime ) { |
SomeRandomBloke | 0:9d29b886d41b | 521 | showTime(); |
SomeRandomBloke | 0:9d29b886d41b | 522 | } else { |
SomeRandomBloke | 0:9d29b886d41b | 523 | showDate(); |
SomeRandomBloke | 0:9d29b886d41b | 524 | } |
SomeRandomBloke | 0:9d29b886d41b | 525 | } |
SomeRandomBloke | 0:9d29b886d41b | 526 | #endif |
SomeRandomBloke | 0:9d29b886d41b | 527 | led1=!led1; |
SomeRandomBloke | 0:9d29b886d41b | 528 | led2=!led2; |
SomeRandomBloke | 0:9d29b886d41b | 529 | Thread::wait(1000); |
SomeRandomBloke | 0:9d29b886d41b | 530 | } |
SomeRandomBloke | 0:9d29b886d41b | 531 | |
SomeRandomBloke | 0:9d29b886d41b | 532 | return 0; |
SomeRandomBloke | 0:9d29b886d41b | 533 | } |