From d7d5cbd7bbe2ddd7903ae4768a80482dea073738 Mon Sep 17 00:00:00 2001 From: Huba Nagy <12huba@gmail.com> Date: Fri, 29 Aug 2014 16:32:13 +1200 Subject: [PATCH] Added a function to LiquidCrystal to tweak the memory offset of the rows. --- libraries/LiquidCrystal/LiquidCrystal.cpp | 11 +++++++++-- libraries/LiquidCrystal/LiquidCrystal.h | 5 ++++- libraries/LiquidCrystal/keywords.txt | 1 + 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/libraries/LiquidCrystal/LiquidCrystal.cpp b/libraries/LiquidCrystal/LiquidCrystal.cpp index d7bd9e453e5..e81cbfe4393 100644 --- a/libraries/LiquidCrystal/LiquidCrystal.cpp +++ b/libraries/LiquidCrystal/LiquidCrystal.cpp @@ -88,6 +88,8 @@ void LiquidCrystal::begin(uint8_t cols, uint8_t lines, uint8_t dotsize) { } _numlines = lines; _currline = 0; + int row_offsets[] = { 0x00, 0x40, 0x14, 0x54 }; + setRowOffsets(row_offsets); // for some 1 line displays you can select a 10 pixel high font if ((dotsize != 0) && (lines == 1)) { @@ -172,12 +174,17 @@ void LiquidCrystal::home() void LiquidCrystal::setCursor(uint8_t col, uint8_t row) { - int row_offsets[] = { 0x00, 0x40, 0x14, 0x54 }; if ( row >= _numlines ) { row = _numlines-1; // we count rows starting w/0 } - command(LCD_SETDDRAMADDR | (col + row_offsets[row])); + command(LCD_SETDDRAMADDR | (col + _row_offsets[row])); +} + +// Allows the tweaking of the memory offsets for each row. +void LiquidCrystal::setRowOffsets(int row_offsets[]) +{ + _row_offsets = row_offsets; } // Turn the display on/off (quickly) diff --git a/libraries/LiquidCrystal/LiquidCrystal.h b/libraries/LiquidCrystal/LiquidCrystal.h index 24ec5afdf5b..06f17a160cf 100755 --- a/libraries/LiquidCrystal/LiquidCrystal.h +++ b/libraries/LiquidCrystal/LiquidCrystal.h @@ -78,7 +78,8 @@ class LiquidCrystal : public Print { void noAutoscroll(); void createChar(uint8_t, uint8_t[]); - void setCursor(uint8_t, uint8_t); + void setCursor(uint8_t, uint8_t); + void setRowOffsets(int[]); virtual size_t write(uint8_t); void command(uint8_t); @@ -101,6 +102,8 @@ class LiquidCrystal : public Print { uint8_t _initialized; uint8_t _numlines,_currline; + + int *_row_offsets; // array of memory offsets for the start of each row }; #endif diff --git a/libraries/LiquidCrystal/keywords.txt b/libraries/LiquidCrystal/keywords.txt index 132845cb651..4ee24d90d20 100755 --- a/libraries/LiquidCrystal/keywords.txt +++ b/libraries/LiquidCrystal/keywords.txt @@ -30,6 +30,7 @@ rightToLeft KEYWORD2 scrollDisplayLeft KEYWORD2 scrollDisplayRight KEYWORD2 createChar KEYWORD2 +setRowOffsets KEYWORD2 ####################################### # Constants (LITERAL1)