SMS message display on LED Matrix board with printer option
Dependencies: AdafruitThermalPrinter HT1632_LedMatrix VodafoneUSBModem mbed-rtos mbed
Diff: main.cpp
- Revision:
- 4:a364da55b42e
- Parent:
- 3:59038ad536ac
- Child:
- 5:a2c0e95f9a0b
--- a/main.cpp Tue Feb 26 16:53:02 2013 +0000 +++ b/main.cpp Fri Mar 08 21:38:54 2013 +0000 @@ -93,13 +93,13 @@ #endif // Message buffers. New message waiting to be displayed and current message being displayed -#define MAX_NUM_MSGS 10 +//#define MAX_NUM_MSGS 10 static char cmdBuf[12]; static char newMsgBuf[MAX_MSG_LENGTH]; -static char msgBuf[MAX_NUM_MSGS][MAX_MSG_LENGTH]; -static int currentMsg = 0; -static int numberOfMsgs = 0; -static boolean getNextMessage = true; +static char msgBuf[MAX_MSG_LENGTH]; +//static int currentMsg = 0; +//static int numberOfMsgs = 0; +static bool getNextMessage = true; #ifdef USE_LED static char ownNumber[20]; @@ -144,7 +144,8 @@ #ifdef USE_LED // Load a new message -void addNewMessage( char *newMsgStart ) + +void setNewMessage( char *newMsgStart ) { strncpy( newMsgBuf, newMsgStart, MAX_MSG_LENGTH ); resetMessage = true; @@ -153,19 +154,9 @@ void resetMessageBuffers( ) { - for( int i=0; i<MAX_NUM_MSGS; i++ ) { - strcpy( &msgBuf[i][0], " " ); - } - currentMsg = 0; - numberOfMsgs = 0; + strcpy( msgBuf, " " ); + newMsgBuf[0] = '\0'; } - -void checkAndSetNextMessage() -{ - numberOfMsgs++; - -} - #endif void sendUSSDCommand( VodafoneUSBModem *_modem, char *ussdCommand, bool setScrolling ) @@ -283,7 +274,7 @@ sprintf(newMsgBuf, "Link State: %s on %s ", linkStateStr[pRegistrationState], bearerStr[pBearer] ); #ifdef USE_LED - addNewMessage( newMsgBuf ); + setNewMessage( newMsgBuf ); #endif #ifdef USE_PRINTER timestampMessage( newMsgBuf ); @@ -295,7 +286,7 @@ getOwnNumber( &modem, ownNumber ); #ifdef USE_LED sprintf(newMsgBuf, "Own number %s", ownNumber ); - timestampMessage( newMsgBuf ); + setNewMessage( newMsgBuf ); #endif #ifdef USE_PRINTER @@ -310,7 +301,7 @@ #ifdef USE_LED //strcpy( &msgBuf[currentMsg][0], INFO_MSG ); sprintf(newMsgBuf, "%s %s ", INFO_MSG, ownNumber ); - addNewMessage( newMsgBuf ); + setNewMessage( newMsgBuf ); led.displayOn(); #endif @@ -353,15 +344,15 @@ resetMessage = true; } else if ( strncmp( cmdBuf, "INFO", 4 ) == 0 ) { sprintf(newMsgBuf, "%s %s ", INFO_MSG, ownNumber ); - addNewMessage( newMsgBuf ); + setNewMessage( newMsgBuf ); #endif // } else if ( strncmp( cmdBuf, "DEMO", 4 ) == 0 ) { // matrixDemo(); // sprintf(newMsgBuf, "%s %s ", INFO_MSG, ownNumber ); -// addNewMessage( newMsgBuf ); +// setNewMessage( newMsgBuf ); #ifdef USE_LED } else if ( strncmp( cmdBuf, "CLEAR", 5 ) == 0 ) { - addNewMessage( " " ); + setNewMessage( " " ); #endif } } @@ -377,11 +368,11 @@ { int y,xmax,ymax; led.getXYMax(&xmax,&ymax); - boolean msgFinished = false; + bool msgFinished = true; while(true) { // shift the whole screen 6 times, one column at a time; making 1 character - if( strlen( &msgBuf[currentMsg][0] ) > 10 ) { + if( strlen( &msgBuf[0] ) > 10 ) { for (int x=0; x < 6; x++) { led.scrollLeft(1, 1); msgx--; @@ -392,10 +383,10 @@ // fit as much as we can on the available display space - while (!led.putChar(msgx,0,msgBuf[currentMsg][crtPos])) { // zero return if it all fitted + while (!led.putChar(msgx,0,msgBuf[crtPos])) { // zero return if it all fitted led.getXY(&msgx,&y); crtPos++; // we got all of the character on!! - if (crtPos >= strlen(&msgBuf[currentMsg][0])) { + if (crtPos >= strlen(msgBuf)) { crtPos = 0; } } @@ -412,11 +403,11 @@ msgx = 1; msgFinished = false; - strncpy( &msgBuf[currentMsg][0], newMsgBuf, MAX_MSG_LENGTH ); - if( strlen( &msgBuf[currentMsg][0] ) > 10 ) { - strcat( &msgBuf[currentMsg][0], " "); + strncpy( msgBuf, newMsgBuf, MAX_MSG_LENGTH ); + if( strlen( msgBuf ) > 10 ) { + strcat( msgBuf, " "); } else { - led.putString(0,0, &msgBuf[currentMsg][0]); + led.putString(0,0, msgBuf); } resetMessage = false; }