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
- Committer:
- charly
- Date:
- 2013-03-12
- Revision:
- 3:1d7a7a249647
- Parent:
- 2:66723c542cef
- Child:
- 4:92a07dbc9222
File content as of revision 3:1d7a7a249647:
#include <string.h>
#include "TextLCDScroll.h"
#include "mbed.h"
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()];
//_mode = leftright;
_mode = left;
setSpeed(5);
cls();
// reduce interrupt level for the ticker timers. so other things (RF22 ) come first
//NVIC_SetPriority(TIMER3_IRQn, 10);
}
void TextLCDScroll::cls()
{
for (int i=0; i<rows(); i++) {
_direction[i]=1;
_actPos[i] = 0;
setLine(i,"");
TextLCD::cls();
}
}
bool TextLCDScroll::setLine( int Line, char *str)
{
if (Line >= 0 && Line < rows()) {
// free the old memory
if (line[Line] != NULL) {
free(line[Line]);
}
// malloc new space for string
line[Line] = (char*)malloc((strlen(str)+1)*sizeof(char));
//copy the string
strcpy(line[Line], str);
// be sure to refresh the display
TextLCD::cls();
// start at beginning again
_actPos[Line] = 0;
_direction[Line] =1;
return(true);
} 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);
}
}
bool TextLCDScroll::setScrollMode( ScrollModes mode)
{
_mode = mode;
return(true);
}
void TextLCDScroll::ScrollRightLeft()
{
int i, j;
//all rows
for (i=0; i<rows(); i++) {
// all columns
for (j=0; j<columns(); j++) {
locate(j,i);
// is string shorter than width of display
if (strlen(line[i]) < columns()) {
if (j < strlen(line[i])) {
putc(line[i][j]);
} else {
putc(' ');
}
} else { // sting is longer -> scroll
if ((_actPos[i]+j < columns()) || (_actPos[i]+j >= columns()+strlen(line[i]))) {
putc(' ');
} else {
putc(line[i][_actPos[i]-columns()+j]);
}
}
}
// shift start-position of string
// left = ++
if (_direction[i] == 1) {
if (_actPos[i] < (strlen(line[i])+(columns()))) {
_actPos[i]++;
} else {
_direction[i] = 0; // reverse direction
_actPos[i]--;
}
} else { //right = --
if (_actPos[i] > 1 ) {
_actPos[i]--;
} else {
_direction[i] = 1; // reverse direction
_actPos[i]++;
}
}
}
}
void TextLCDScroll::ScrollLeft()
{
int i, j;
//all rows
for (i=0; i<rows(); i++) {
// all columns
for (j=0; j<columns(); j++) {
locate(j,i);
// is string shorter than width of display
if (strlen(line[i]) < columns()) {
if (j < strlen(line[i])) {
putc(line[i][j]);
} else {
putc(' ');
}
} else { // sting is longer -> scroll
if ((_actPos[i]+j < columns()) || (_actPos[i]+j >= columns()+strlen(line[i]))) {
putc(' ');
} else {
putc(line[i][_actPos[i]-columns()+j]);
}
}
}
// shift start-position of string
if (_actPos[i] < (strlen(line[i])+(columns()))) {
_actPos[i]++;
} else {
_actPos[i]=0;
}
}
}