Skip to content

Commit b0d6f42

Browse files
committed
Merge branch 'ide-1.5.x-lcd' of github.com:matthijskooijman/Arduino
2 parents ca5e30a + 9552db3 commit b0d6f42

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

build/shared/revisions.txt

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ ARDUINO 1.5.9
1010
* sam: added -MMD flag to let gcc produce dependency files (full rebuild on Arduino Due is now triggered only if needed)
1111

1212
[libraries]
13+
* LiquidCrystal: added setRowOffsets function to support different LCD hardware configurations (Mark Sproul)
14+
* LiquidCrystal: various improvements and optimizations (Matthijs Kooijman)
1315
* Fixed PROGMEM error in Robot_Control/examples/explore/R06_Wheel_Calibration
1416

1517
The following changes are included also in the Arduino IDE 1.0.7:

libraries/LiquidCrystal/src/LiquidCrystal.cpp

+17-5
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,11 @@ void LiquidCrystal::begin(uint8_t cols, uint8_t lines, uint8_t dotsize) {
8787
_displayfunction |= LCD_2LINE;
8888
}
8989
_numlines = lines;
90-
_currline = 0;
90+
91+
setRowOffsets(0x00, 0x40, 0x00 + cols, 0x40 + cols);
9192

9293
// for some 1 line displays you can select a 10 pixel high font
93-
if ((dotsize != 0) && (lines == 1)) {
94+
if ((dotsize != LCD_5x8DOTS) && (lines == 1)) {
9495
_displayfunction |= LCD_5x10DOTS;
9596
}
9697

@@ -157,6 +158,14 @@ void LiquidCrystal::begin(uint8_t cols, uint8_t lines, uint8_t dotsize) {
157158

158159
}
159160

161+
void LiquidCrystal::setRowOffsets(int row0, int row1, int row2, int row3)
162+
{
163+
_row_offsets[0] = row0;
164+
_row_offsets[1] = row1;
165+
_row_offsets[2] = row2;
166+
_row_offsets[3] = row3;
167+
}
168+
160169
/********** high level commands, for the user! */
161170
void LiquidCrystal::clear()
162171
{
@@ -172,12 +181,15 @@ void LiquidCrystal::home()
172181

173182
void LiquidCrystal::setCursor(uint8_t col, uint8_t row)
174183
{
175-
int row_offsets[] = { 0x00, 0x40, 0x14, 0x54 };
184+
const size_t max_lines = sizeof(_row_offsets) / sizeof(*_row_offsets);
185+
if ( row >= max_lines ) {
186+
row = max_lines - 1; // we count rows starting w/0
187+
}
176188
if ( row >= _numlines ) {
177-
row = _numlines-1; // we count rows starting w/0
189+
row = _numlines - 1; // we count rows starting w/0
178190
}
179191

180-
command(LCD_SETDDRAMADDR | (col + row_offsets[row]));
192+
command(LCD_SETDDRAMADDR | (col + _row_offsets[row]));
181193
}
182194

183195
// Turn the display on/off (quickly)

libraries/LiquidCrystal/src/LiquidCrystal.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ class LiquidCrystal : public Print {
7777
void autoscroll();
7878
void noAutoscroll();
7979

80+
void setRowOffsets(int row1, int row2, int row3, int row4);
8081
void createChar(uint8_t, uint8_t[]);
8182
void setCursor(uint8_t, uint8_t);
8283
virtual size_t write(uint8_t);
@@ -100,7 +101,8 @@ class LiquidCrystal : public Print {
100101

101102
uint8_t _initialized;
102103

103-
uint8_t _numlines,_currline;
104+
uint8_t _numlines;
105+
uint8_t _row_offsets[4];
104106
};
105107

106108
#endif

0 commit comments

Comments
 (0)