opportunistic-xbee/lcd.h

72 lines
1.5 KiB
C++

#ifndef _LCD_H_
#define _LCD_H_
#include <LiquidCrystal_I2C.h>
class LCDWrapper {
private:
LiquidCrystal_I2C *display;
size_t cursor;
uint8_t cols;
uint8_t rows;
public:
LCDWrapper(uint8_t addr, uint8_t cols, uint8_t rows){
rows = rows;
cols = cols;
*display = LiquidCrystal_I2C(addr, cols, rows, LCD_5x8DOTS);
cursor = 0;
}
~LCDWrapper(){ display = NULL; }
void begin(){
display->begin();
display->backlight();
display->home();
clear();
}
void move(const uint8_t line, const uint8_t c){ display->setCursor(line, c); }
void clear(){ cursor = 0; display->clear(); }
void printf(const char *fmt, ...){
va_list va;
va_start(va, fmt);
char buffer[34] = {0};
int size = sprintf(buffer, fmt, va);
va_end(va);
display->print(buffer);
}
void printfn(const uint8_t line, const char *fmt, ...){
va_list va;
va_start(va, fmt);
char buffer[34] = {0};
int size = sprintf(buffer, fmt, va);
va_end(va);
display->setCursor(0,line);
display->print(buffer);
}
void printfn_overflow(const uint8_t line, const char *fmt, ...){
va_list va;
va_start(va, fmt);
char buffer[34] = {0};
int size = sprintf(buffer, fmt, va);
va_end(va);
display->setCursor(0,line);
display->print(buffer);
for( uint8_t offset = 0 ; size-offset > cols ; offset++ ){
delay(50);
display->setCursor(0,line);
display->print(buffer+offset);
}
}
};
#endif