Skip to content

Commit 9af188e

Browse files
authored
Merge pull request #15 from markub3327/patch-1
row_offsets calculated by columns parameter
2 parents b3b83e7 + d77cb78 commit 9af188e

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

src/LiquidCrystal_PCF8574.cpp

+24-3
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ LiquidCrystal_PCF8574::LiquidCrystal_PCF8574(int i2cAddr)
3333

3434
void LiquidCrystal_PCF8574::begin(int cols, int lines)
3535
{
36-
(void)cols; // ignored !
36+
_cols = cols;
3737
_lines = lines;
3838

3939
int functionFlags = 0;
@@ -66,6 +66,8 @@ void LiquidCrystal_PCF8574::begin(int cols, int lines)
6666
display();
6767
clear();
6868
leftToRight();
69+
70+
_row_offsets = _getRowOffsets();
6971
} // begin()
7072

7173

@@ -94,9 +96,8 @@ void LiquidCrystal_PCF8574::home()
9496
/// Set the cursor to a new position.
9597
void LiquidCrystal_PCF8574::setCursor(int col, int row)
9698
{
97-
int row_offsets[] = {0x00, 0x40, 0x14, 0x54};
9899
// Instruction: Set DDRAM address = 0x80
99-
_send(0x80 | (row_offsets[row] + col));
100+
_send(0x80 | (_row_offsets[row] + col));
100101
} // setCursor()
101102

102103

@@ -278,4 +279,24 @@ void LiquidCrystal_PCF8574::_write2Wire(int halfByte, bool isData, bool enable)
278279
Wire.endTransmission();
279280
} // write2Wire
280281

282+
// Prepare row_offsets
283+
int* LiquidCrystal_PCF8574::_getRowOffsets()
284+
{
285+
int *row_offsets = new int[this->_lines];
286+
287+
if (this->_lines > 0)
288+
row_offsets[0] = 0x00;
289+
else if (this->_lines > 1)
290+
row_offsets[1] = 0x40;
291+
else if (this->_lines > 2)
292+
{
293+
for (int i = 0, j = 2; j < this->_lines; i++, j++)
294+
{
295+
row_offsets[j] = row_offsets[i] + _cols;
296+
}
297+
}
298+
299+
return row_offsets;
300+
}
301+
281302
// The End.

src/LiquidCrystal_PCF8574.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,13 @@ class LiquidCrystal_PCF8574 : public Print
7474
int _lines; ///< number of lines of the display
7575
int _entrymode; ///<flags from entrymode
7676
int _displaycontrol; ///<flags from displaycontrol
77-
77+
int* _row_offsets;
78+
7879
// low level functions
7980
void _send(int value, bool isData = false);
8081
void _sendNibble(int halfByte, bool isData = false);
8182
void _write2Wire(int halfByte, bool isData, bool enable);
83+
int* _getRowOffsets();
8284
};
8385

8486
#endif

0 commit comments

Comments
 (0)