Extendes Version of TextLCD which scrolls oversized lines.
Dependents: RF22_MAX_test_Send
Extended version of TextLCD, which can scoll oversized lines. Uses a ticker!
Revision 5:e3b565c4190c, committed 2013-04-04
- Comitter:
- charly
- Date:
- Thu Apr 04 19:07:26 2013 +0000
- Parent:
- 4:92a07dbc9222
- Commit message:
- Disable Ticker while changing settings. realloc instead of malloc
Changed in this revision
TextLCDScroll.cpp | Show annotated file Show diff for this revision Revisions of this file |
TextLCDScroll.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r 92a07dbc9222 -r e3b565c4190c TextLCDScroll.cpp --- a/TextLCDScroll.cpp Tue Mar 12 20:00:04 2013 +0000 +++ b/TextLCDScroll.cpp Thu Apr 04 19:07:26 2013 +0000 @@ -12,7 +12,9 @@ //_mode = leftright; _mode = left; + //set Speed and start Ticker setSpeed(5); + cls(); // reduce interrupt level for the ticker timers. so other things (RF22 ) come first @@ -33,12 +35,16 @@ bool TextLCDScroll::setLine( int Line, char *str) { if (Line >= 0 && Line < rows()) { + //stop interrupts + tick.detach(); // free the old memory - if (line[Line] != NULL) { - free(line[Line]); - } + //if (line[Line] != NULL) { + // free(line[Line]); + //} // malloc new space for string - line[Line] = (char*)malloc((strlen(str)+1)*sizeof(char)); + //line[Line] = (char*)malloc((strlen(str)+1)*sizeof(char)); + //Realocate memory + line[Line] = (char*)realloc(line[Line], (strlen(str)+1)*sizeof(char)); //copy the string strcpy(line[Line], str); // be sure to refresh the display @@ -46,20 +52,26 @@ // start at beginning again _actPos[Line] = 0; _direction[Line] =1; + startTicker(); return(true); } else { return (false); } } +void TextLCDScroll::startTicker(){ + if (_mode == leftright) + tick.attach(this,&TextLCDScroll::ScrollRightLeft, 1.0/_speed); + else + tick.attach(this,&TextLCDScroll::ScrollLeft, 1.0/_speed); +} + bool TextLCDScroll::setSpeed( int speed) { if ((speed >= 0.1) && (speed <= 10)) { tick.detach(); - if (_mode == leftright) - tick.attach(this,&TextLCDScroll::ScrollRightLeft, 1.0/speed); - else - tick.attach(this,&TextLCDScroll::ScrollLeft, 1.0/speed); + _speed = speed; + startTicker(); return(true); } else { return(false);
diff -r 92a07dbc9222 -r e3b565c4190c TextLCDScroll.h --- a/TextLCDScroll.h Tue Mar 12 20:00:04 2013 +0000 +++ b/TextLCDScroll.h Thu Apr 04 19:07:26 2013 +0000 @@ -86,6 +86,7 @@ bool setScrollMode( ScrollModes mode); private: + void startTicker(); void ScrollRightLeft(); @@ -97,6 +98,7 @@ // these are changed in interrupt-routine! volatile int* _direction; volatile int* _actPos; + volatile int _speed; char* line[99];