2018-12-04 08:43:11 +00:00
|
|
|
#ifndef _LCD_H_
|
|
|
|
#define _LCD_H_
|
|
|
|
|
|
|
|
#include <LiquidCrystal_I2C.h>
|
|
|
|
|
2018-12-11 12:08:17 +00:00
|
|
|
#define BUFSIZE 64
|
2018-12-09 14:21:15 +00:00
|
|
|
|
|
|
|
class LCDWrapper : public LiquidCrystal_I2C{
|
|
|
|
|
2018-12-04 08:43:11 +00:00
|
|
|
private:
|
2018-12-09 14:21:15 +00:00
|
|
|
uint8_t rows, cols;
|
|
|
|
char* buffer = NULL;
|
2018-12-04 08:43:11 +00:00
|
|
|
|
2018-12-11 11:42:34 +00:00
|
|
|
|
2018-12-04 08:43:11 +00:00
|
|
|
public:
|
2018-12-09 14:21:15 +00:00
|
|
|
LCDWrapper(uint8_t addr, uint8_t cols, uint8_t rows, uint8_t charsize=LCD_5x8DOTS) : LiquidCrystal_I2C(addr,cols,rows,charsize) {
|
|
|
|
this->cols = cols;
|
|
|
|
this->rows = rows;
|
2018-12-04 08:43:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void begin(){
|
2018-12-09 14:21:15 +00:00
|
|
|
LiquidCrystal_I2C::begin();
|
|
|
|
LiquidCrystal_I2C::backlight();
|
2018-12-04 08:43:11 +00:00
|
|
|
}
|
|
|
|
|
2018-12-11 11:42:34 +00:00
|
|
|
void printfn(const uint8_t line, const char *fmt, ...){
|
2018-12-09 14:21:15 +00:00
|
|
|
buffer = (char*) malloc( BUFSIZE * sizeof(char*));
|
|
|
|
buffer[0] = 0;
|
|
|
|
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, fmt);
|
|
|
|
int size = vsnprintf(buffer, BUFSIZE, fmt, ap);
|
|
|
|
va_end(ap);
|
2018-12-11 11:42:34 +00:00
|
|
|
if( size < 0 || size >= BUFSIZE ){ free(buffer); return; }
|
2018-12-04 08:43:11 +00:00
|
|
|
|
2018-12-11 11:42:34 +00:00
|
|
|
LiquidCrystal_I2C::setCursor(0, line);
|
2018-12-09 14:21:15 +00:00
|
|
|
LiquidCrystal_I2C::print(buffer);
|
|
|
|
free(buffer);
|
2018-12-04 08:43:11 +00:00
|
|
|
}
|
|
|
|
|
2018-12-11 11:42:34 +00:00
|
|
|
void printfn_overflow(const uint8_t line, const char *fmt, ...){
|
2018-12-09 14:21:15 +00:00
|
|
|
buffer = (char*) malloc( BUFSIZE * sizeof(char*));
|
|
|
|
buffer[0] = 0;
|
|
|
|
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, fmt);
|
|
|
|
int size = vsnprintf(buffer, BUFSIZE, fmt, ap);
|
|
|
|
va_end(ap);
|
2018-12-11 11:42:34 +00:00
|
|
|
buffer[BUFSIZE-1] = 0;
|
|
|
|
if( size < 0 || size >= BUFSIZE ){ free(buffer); return; }
|
2018-12-09 14:21:15 +00:00
|
|
|
|
2018-12-11 11:42:34 +00:00
|
|
|
|
|
|
|
LiquidCrystal_I2C::setCursor(0,line);
|
2018-12-09 14:21:15 +00:00
|
|
|
LiquidCrystal_I2C::print(buffer);
|
2018-12-11 11:42:34 +00:00
|
|
|
if( size <= cols ){ free(buffer); return; }
|
|
|
|
|
|
|
|
for( uint8_t offset = 1 ; offset <= size-cols ; offset++ ){
|
|
|
|
delay(200);
|
|
|
|
LiquidCrystal_I2C::setCursor(0,line);
|
|
|
|
LiquidCrystal_I2C::print(buffer+offset);
|
|
|
|
}
|
2018-12-09 14:21:15 +00:00
|
|
|
free(buffer);
|
2018-12-04 08:43:11 +00:00
|
|
|
}
|
|
|
|
|
2018-12-11 11:42:34 +00:00
|
|
|
protected:
|
|
|
|
void printf(const char *fmt, ...) {
|
2018-12-09 14:21:15 +00:00
|
|
|
buffer = (char*) malloc( BUFSIZE * sizeof(char*));
|
|
|
|
buffer[0] = 0;
|
|
|
|
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, fmt);
|
|
|
|
int size = vsnprintf(buffer, BUFSIZE, fmt, ap);
|
|
|
|
va_end(ap);
|
2018-12-11 11:42:34 +00:00
|
|
|
if( size < 0 || size >= BUFSIZE ){ free(buffer); return; }
|
2018-12-09 14:21:15 +00:00
|
|
|
|
|
|
|
LiquidCrystal_I2C::print(buffer);
|
|
|
|
free(buffer);
|
2018-12-04 08:43:11 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|