Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: RF22_MAX_test_Send
TextLCDScroll.cpp@2:66723c542cef, 2012-04-24 (annotated)
- Committer:
- charly
- Date:
- Tue Apr 24 06:18:21 2012 +0000
- Revision:
- 2:66723c542cef
- Parent:
- 0:0ae9963c4e06
- Child:
- 3:1d7a7a249647
reduced priority of ticker-Interrupt, so other things come first (needed for RF22)
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| charly | 0:0ae9963c4e06 | 1 | #include "TextLCDScroll.h" |
| charly | 0:0ae9963c4e06 | 2 | #include "mbed.h" |
| charly | 0:0ae9963c4e06 | 3 | |
| charly | 0:0ae9963c4e06 | 4 | #include <string> |
| charly | 0:0ae9963c4e06 | 5 | using namespace std; |
| charly | 0:0ae9963c4e06 | 6 | |
| charly | 2:66723c542cef | 7 | TextLCDScroll::TextLCDScroll(PinName rs, PinName e, PinName d4, PinName d5, |
| charly | 2:66723c542cef | 8 | PinName d6, PinName d7, TextLCD::LCDType type): TextLCD(rs,e,d4,d5,d6,d7,type) { |
| charly | 0:0ae9963c4e06 | 9 | |
| charly | 2:66723c542cef | 10 | _direction = new int[rows()]; |
| charly | 2:66723c542cef | 11 | _actPos = new int[rows()]; |
| charly | 2:66723c542cef | 12 | _stringArray = new string[rows()]; |
| charly | 2:66723c542cef | 13 | for (int i=0; i<rows(); i++) { |
| charly | 2:66723c542cef | 14 | _direction[i]=1; |
| charly | 2:66723c542cef | 15 | _actPos[i] = 0; |
| charly | 2:66723c542cef | 16 | _stringArray[i] = ""; |
| charly | 2:66723c542cef | 17 | } |
| charly | 2:66723c542cef | 18 | _spaces = string(columns(),' '); |
| charly | 2:66723c542cef | 19 | //_mode = leftright; |
| charly | 2:66723c542cef | 20 | _mode = left; |
| charly | 0:0ae9963c4e06 | 21 | |
| charly | 2:66723c542cef | 22 | setSpeed(5); |
| charly | 0:0ae9963c4e06 | 23 | |
| charly | 2:66723c542cef | 24 | // reduce interrupt level for the ticker timers. so other things (RF22 ) come first |
| charly | 2:66723c542cef | 25 | NVIC_SetPriority(TIMER3_IRQn, 10); |
| charly | 2:66723c542cef | 26 | |
| charly | 2:66723c542cef | 27 | } |
| charly | 0:0ae9963c4e06 | 28 | |
| charly | 0:0ae9963c4e06 | 29 | |
| charly | 2:66723c542cef | 30 | bool TextLCDScroll::setLine( int Line, string str) { |
| charly | 2:66723c542cef | 31 | if (Line >= 0 && Line < rows()) { |
| charly | 2:66723c542cef | 32 | if ((str.length() > columns()) && (_mode == left)) |
| charly | 2:66723c542cef | 33 | _stringArray[Line] = _spaces + str + _spaces; |
| charly | 2:66723c542cef | 34 | else |
| charly | 2:66723c542cef | 35 | _stringArray[Line] = str; |
| charly | 2:66723c542cef | 36 | |
| charly | 2:66723c542cef | 37 | // be sure to refresh the display |
| charly | 2:66723c542cef | 38 | cls(); |
| charly | 2:66723c542cef | 39 | // start at beginning again |
| charly | 2:66723c542cef | 40 | _actPos[Line] = 0; |
| charly | 2:66723c542cef | 41 | _direction[Line] =1; |
| charly | 2:66723c542cef | 42 | return(true); |
| charly | 2:66723c542cef | 43 | } else { |
| charly | 2:66723c542cef | 44 | return (false); |
| charly | 2:66723c542cef | 45 | } |
| charly | 2:66723c542cef | 46 | } |
| charly | 0:0ae9963c4e06 | 47 | |
| charly | 2:66723c542cef | 48 | bool TextLCDScroll::setSpeed( int speed) { |
| charly | 2:66723c542cef | 49 | if ((speed >= 0.1) && (speed <= 10)) { |
| charly | 2:66723c542cef | 50 | tick.detach(); |
| charly | 2:66723c542cef | 51 | if (_mode == leftright) |
| charly | 2:66723c542cef | 52 | tick.attach(this,&TextLCDScroll::ScrollRightLeft, 1.0/speed); |
| charly | 2:66723c542cef | 53 | else |
| charly | 2:66723c542cef | 54 | tick.attach(this,&TextLCDScroll::ScrollLeft, 1.0/speed); |
| charly | 2:66723c542cef | 55 | return(true); |
| charly | 2:66723c542cef | 56 | } else { |
| charly | 2:66723c542cef | 57 | return(false); |
| charly | 2:66723c542cef | 58 | } |
| charly | 2:66723c542cef | 59 | } |
| charly | 2:66723c542cef | 60 | |
| charly | 2:66723c542cef | 61 | bool TextLCDScroll::setScrollMode( ScrollModes mode) { |
| charly | 2:66723c542cef | 62 | _mode = mode; |
| charly | 2:66723c542cef | 63 | return(true); |
| charly | 2:66723c542cef | 64 | } |
| charly | 2:66723c542cef | 65 | |
| charly | 2:66723c542cef | 66 | void TextLCDScroll::ScrollRightLeft() { |
| charly | 2:66723c542cef | 67 | int i; |
| charly | 2:66723c542cef | 68 | for (i=0; i<rows(); i++) { |
| charly | 2:66723c542cef | 69 | locate(0,i); |
| charly | 2:66723c542cef | 70 | if (_stringArray[i].length() > columns()) { |
| charly | 2:66723c542cef | 71 | printf(_stringArray[i].substr(_actPos[i],columns()).c_str()); |
| charly | 2:66723c542cef | 72 | if (_direction[i] == 1) { |
| charly | 2:66723c542cef | 73 | if (_stringArray[i].length() > _actPos[i]+columns()) { |
| charly | 2:66723c542cef | 74 | _actPos[i] += 1; |
| charly | 2:66723c542cef | 75 | } else { |
| charly | 2:66723c542cef | 76 | _direction[i] = -1; |
| charly | 2:66723c542cef | 77 | } |
| charly | 2:66723c542cef | 78 | } else { |
| charly | 2:66723c542cef | 79 | if (_actPos[i] > 0) { |
| charly | 2:66723c542cef | 80 | _actPos[i] -= 1; |
| charly | 2:66723c542cef | 81 | } else { |
| charly | 2:66723c542cef | 82 | _direction[i]=1; |
| charly | 2:66723c542cef | 83 | } |
| charly | 2:66723c542cef | 84 | } |
| charly | 0:0ae9963c4e06 | 85 | } else { |
| charly | 2:66723c542cef | 86 | printf(_stringArray[i].c_str()); |
| charly | 0:0ae9963c4e06 | 87 | } |
| charly | 0:0ae9963c4e06 | 88 | } |
| charly | 2:66723c542cef | 89 | } |
| charly | 0:0ae9963c4e06 | 90 | |
| charly | 2:66723c542cef | 91 | void TextLCDScroll::ScrollLeft() { |
| charly | 2:66723c542cef | 92 | int i; |
| charly | 2:66723c542cef | 93 | for (i=0; i<rows(); i++) { |
| charly | 2:66723c542cef | 94 | locate(0,i); |
| charly | 2:66723c542cef | 95 | if (_stringArray[i].length() > columns()) { |
| charly | 2:66723c542cef | 96 | printf(_stringArray[i].substr(_actPos[i],columns()).c_str()); |
| charly | 2:66723c542cef | 97 | if (_direction[i] == 1) { |
| charly | 2:66723c542cef | 98 | if (_stringArray[i].length() > _actPos[i]+columns()) { |
| charly | 2:66723c542cef | 99 | _actPos[i] += 1; |
| charly | 0:0ae9963c4e06 | 100 | } else { |
| charly | 2:66723c542cef | 101 | _actPos[i]=0; |
| charly | 0:0ae9963c4e06 | 102 | } |
| charly | 0:0ae9963c4e06 | 103 | } |
| charly | 2:66723c542cef | 104 | } else { |
| charly | 2:66723c542cef | 105 | printf(_stringArray[i].c_str()); |
| charly | 0:0ae9963c4e06 | 106 | } |
| charly | 0:0ae9963c4e06 | 107 | } |
| charly | 2:66723c542cef | 108 | } |
| charly | 0:0ae9963c4e06 | 109 |