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 2:66723c542cef, committed 2012-04-24
- Comitter:
- charly
- Date:
- Tue Apr 24 06:18:21 2012 +0000
- Parent:
- 1:d7cc0e2a55ba
- Child:
- 3:1d7a7a249647
- Commit message:
- reduced priority of ticker-Interrupt, so other things come first (needed for RF22)
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 |
--- a/TextLCDScroll.cpp Tue Mar 27 20:30:27 2012 +0000
+++ b/TextLCDScroll.cpp Tue Apr 24 06:18:21 2012 +0000
@@ -4,103 +4,106 @@
#include <string>
using namespace std;
- TextLCDScroll::TextLCDScroll(PinName rs, PinName e, PinName d4, PinName d5,
- PinName d6, PinName d7, TextLCD::LCDType type): TextLCD(rs,e,d4,d5,d6,d7,type) {
+TextLCDScroll::TextLCDScroll(PinName rs, PinName e, PinName d4, PinName d5,
+ PinName d6, PinName d7, TextLCD::LCDType type): TextLCD(rs,e,d4,d5,d6,d7,type) {
- _direction = new int[rows()];
- _actPos = new int[rows()];
- _stringArray = new string[rows()];
- for (int i=0; i<rows(); i++) {
- _direction[i]=1;
- _actPos[i] = 0;
- _stringArray[i] = "";
- }
- _spaces = string(columns(),' ');
- //_mode = leftright;
- _mode = left;
+ _direction = new int[rows()];
+ _actPos = new int[rows()];
+ _stringArray = new string[rows()];
+ for (int i=0; i<rows(); i++) {
+ _direction[i]=1;
+ _actPos[i] = 0;
+ _stringArray[i] = "";
+ }
+ _spaces = string(columns(),' ');
+ //_mode = leftright;
+ _mode = left;
- setSpeed(5);
+ setSpeed(5);
- }
+ // reduce interrupt level for the ticker timers. so other things (RF22 ) come first
+ NVIC_SetPriority(TIMER3_IRQn, 10);
+
+}
- bool TextLCDScroll::setLine( int Line, string str) {
- if (Line >= 0 && Line < rows()) {
- if ((str.length() > columns()) && (_mode == left))
- _stringArray[Line] = _spaces + str + _spaces;
- else
- _stringArray[Line] = str;
+bool TextLCDScroll::setLine( int Line, string str) {
+ if (Line >= 0 && Line < rows()) {
+ if ((str.length() > columns()) && (_mode == left))
+ _stringArray[Line] = _spaces + str + _spaces;
+ else
+ _stringArray[Line] = str;
+
+ // be sure to refresh the display
+ cls();
+ // start at beginning again
+ _actPos[Line] = 0;
+ _direction[Line] =1;
+ return(true);
+ } else {
+ return (false);
+ }
+}
- // be sure to refresh the display
- cls();
- // start at beginning again
- _actPos[Line] = 0;
- _direction[Line] =1;
- return(true);
+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);
+ return(true);
+ } else {
+ return(false);
+ }
+}
+
+bool TextLCDScroll::setScrollMode( ScrollModes mode) {
+ _mode = mode;
+ return(true);
+}
+
+void TextLCDScroll::ScrollRightLeft() {
+ int i;
+ for (i=0; i<rows(); i++) {
+ locate(0,i);
+ if (_stringArray[i].length() > columns()) {
+ printf(_stringArray[i].substr(_actPos[i],columns()).c_str());
+ if (_direction[i] == 1) {
+ if (_stringArray[i].length() > _actPos[i]+columns()) {
+ _actPos[i] += 1;
+ } else {
+ _direction[i] = -1;
+ }
+ } else {
+ if (_actPos[i] > 0) {
+ _actPos[i] -= 1;
+ } else {
+ _direction[i]=1;
+ }
+ }
} else {
- return (false);
- }
- }
-
- 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);
- return(true);
- } else {
- return(false);
+ printf(_stringArray[i].c_str());
}
}
-
- bool TextLCDScroll::setScrollMode( ScrollModes mode) {
- _mode = mode;
- return(true);
- }
+}
- void TextLCDScroll::ScrollRightLeft() {
- int i;
- for (i=0; i<rows(); i++) {
- locate(0,i);
- if (_stringArray[i].length() > columns()) {
- printf(_stringArray[i].substr(_actPos[i],columns()).c_str());
- if (_direction[i] == 1) {
- if (_stringArray[i].length() > _actPos[i]+columns()) {
- _actPos[i] += 1;
- } else {
- _direction[i] = -1;
- }
+void TextLCDScroll::ScrollLeft() {
+ int i;
+ for (i=0; i<rows(); i++) {
+ locate(0,i);
+ if (_stringArray[i].length() > columns()) {
+ printf(_stringArray[i].substr(_actPos[i],columns()).c_str());
+ if (_direction[i] == 1) {
+ if (_stringArray[i].length() > _actPos[i]+columns()) {
+ _actPos[i] += 1;
} else {
- if (_actPos[i] > 0) {
- _actPos[i] -= 1;
- } else {
- _direction[i]=1;
- }
+ _actPos[i]=0;
}
- } else {
- printf(_stringArray[i].c_str());
}
+ } else {
+ printf(_stringArray[i].c_str());
}
}
+}
- void TextLCDScroll::ScrollLeft() {
- int i;
- for (i=0; i<rows(); i++) {
- locate(0,i);
- if (_stringArray[i].length() > columns()) {
- printf(_stringArray[i].substr(_actPos[i],columns()).c_str());
- if (_direction[i] == 1) {
- if (_stringArray[i].length() > _actPos[i]+columns()) {
- _actPos[i] += 1;
- } else {
- _actPos[i]=0;
- }
- }
- } else {
- printf(_stringArray[i].c_str());
- }
- }
- }
-
--- a/TextLCDScroll.h Tue Mar 27 20:30:27 2012 +0000
+++ b/TextLCDScroll.h Tue Apr 24 06:18:21 2012 +0000
@@ -89,11 +89,14 @@
void ScrollLeft();
Ticker tick;
- int* _direction;
- int* _actPos;
string* _stringArray;
string _spaces;
ScrollModes _mode;
+
+ // these are changed in interrupt-routine!
+ volatile int* _direction;
+ volatile int* _actPos;
+
};
#endif
\ No newline at end of file