Skip to content

Commit 7d4cfb1

Browse files
authored
Merge pull request #25 from markisch/fix-int-size
Use unsigned 8bit instead of signed 16bit integers
2 parents 47c73a4 + 528ec5f commit 7d4cfb1

File tree

2 files changed

+24
-24
lines changed

2 files changed

+24
-24
lines changed

src/LiquidCrystal_PCF8574.cpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@ void LiquidCrystal_PCF8574::init(uint8_t i2cAddr, uint8_t rs, uint8_t rw, uint8_
5656
} // init()
5757

5858

59-
void LiquidCrystal_PCF8574::begin(int cols, int lines)
59+
void LiquidCrystal_PCF8574::begin(uint8_t cols, uint8_t lines)
6060
{
6161
_cols = min(cols, 80);
6262
_lines = min(lines, 4);
6363

64-
int functionFlags = 0;
64+
uint8_t functionFlags = 0;
6565

6666
_row_offsets[0] = 0x00;
6767
_row_offsets[1] = 0x40;
@@ -116,10 +116,10 @@ void LiquidCrystal_PCF8574::home()
116116

117117

118118
/// Set the cursor to a new position.
119-
void LiquidCrystal_PCF8574::setCursor(int col, int row)
119+
void LiquidCrystal_PCF8574::setCursor(uint8_t col, uint8_t row)
120120
{
121121
// check boundaries
122-
if ((col >= 0) && (col < _cols) && (row >= 0) && (row < _lines)) {
122+
if ((col < _cols) && (row < _lines)) {
123123
// Instruction: Set DDRAM address = 0x80
124124
_send(0x80 | (_row_offsets[row] + col));
125125
}
@@ -235,7 +235,7 @@ void LiquidCrystal_PCF8574::noAutoscroll(void)
235235
/// Setting the brightness of the background display light.
236236
/// The backlight can be switched on and off.
237237
/// The current brightness is stored in the private _backlight variable to have it available for further data transfers.
238-
void LiquidCrystal_PCF8574::setBacklight(int brightness)
238+
void LiquidCrystal_PCF8574::setBacklight(uint8_t brightness)
239239
{
240240
_backlight = brightness;
241241
// send no data but set the background-pin right;
@@ -245,12 +245,12 @@ void LiquidCrystal_PCF8574::setBacklight(int brightness)
245245

246246
// Allows us to fill the first 8 CGRAM locations
247247
// with custom characters
248-
void LiquidCrystal_PCF8574::createChar(int location, byte charmap[])
248+
void LiquidCrystal_PCF8574::createChar(uint8_t location, byte charmap[])
249249
{
250250
location &= 0x7; // we only have 8 locations 0-7
251251
// Set CGRAM address
252252
_send(0x40 | (location << 3));
253-
for (int i = 0; i < 8; i++) {
253+
for (uint8_t i = 0; i < 8; i++) {
254254
write(charmap[i]);
255255
}
256256
} // createChar()
@@ -290,7 +290,7 @@ void LiquidCrystal_PCF8574::_send(uint8_t value, bool isData)
290290

291291

292292
// write a nibble / halfByte with handshake
293-
void LiquidCrystal_PCF8574::_sendNibble(int halfByte, bool isData)
293+
void LiquidCrystal_PCF8574::_sendNibble(uint8_t halfByte, bool isData)
294294
{
295295
// map the data to the given pin connections
296296
uint8_t data = 0;

src/LiquidCrystal_PCF8574.h

+16-16
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,19 @@ class LiquidCrystal_PCF8574 : public Print
3737
// There is no sda and scl parameter for i2c in any api.
3838
// The Wire library has standard settings that can be overwritten by using Wire.begin(int sda, int scl) before calling LiquidCrystal_PCF8574::begin();
3939

40-
// constructors, which allows to redefine bit assignments in case your adapter is wired differently
40+
// constructors, which allow to redefine bit assignments in case your adapter is wired differently
4141
LiquidCrystal_PCF8574(uint8_t i2cAddr, uint8_t rs, uint8_t enable,
4242
uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7, uint8_t backlight=255);
4343
LiquidCrystal_PCF8574(uint8_t i2cAddr, uint8_t rs, uint8_t rw, uint8_t enable,
4444
uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7, uint8_t backlight=255);
4545

46-
// Funtions from reference:
46+
// Functions from reference:
4747

48-
void begin(int cols, int rows);
48+
void begin(uint8_t cols, uint8_t rows);
4949

50+
void clear();
5051
void home();
51-
void setCursor(int col, int row);
52+
void setCursor(uint8_t col, uint8_t row);
5253
void cursor();
5354
void noCursor();
5455
void blink();
@@ -61,7 +62,7 @@ class LiquidCrystal_PCF8574 : public Print
6162
void noAutoscroll();
6263
void leftToRight();
6364
void rightToLeft();
64-
void createChar(int, byte[]);
65+
void createChar(uint8_t, byte[]);
6566
#ifdef __AVR__
6667
void createChar_P(uint8_t, const byte *);
6768
inline void createChar(uint8_t n, const byte *data) {
@@ -70,23 +71,22 @@ class LiquidCrystal_PCF8574 : public Print
7071
#endif
7172

7273
// plus functions from LCDAPI:
73-
void clear();
74-
void setBacklight(int brightness);
74+
void setBacklight(uint8_t brightness);
7575
inline void command(uint8_t value) { _send(value); }
7676

7777
// support of Print class
7878
virtual size_t write(uint8_t ch);
7979

8080
private:
8181
// instance variables
82-
int _i2cAddr; ///< Wire Address of the LCD
83-
int _backlight; ///< the backlight intensity
84-
int _cols; ///< number of cols of the display
85-
int _lines; ///< number of lines of the display
86-
int _entrymode; ///<flags from entrymode
87-
int _displaycontrol; ///<flags from displaycontrol
88-
int _row_offsets[4];
89-
82+
uint8_t _i2cAddr; ///< Wire Address of the LCD
83+
uint8_t _backlight; ///< the backlight intensity
84+
uint8_t _cols; ///< number of cols of the display
85+
uint8_t _lines; ///< number of lines of the display
86+
uint8_t _entrymode; ///<flags from entrymode
87+
uint8_t _displaycontrol; ///<flags from displaycontrol
88+
uint8_t _row_offsets[4];
89+
9090
// variables describing how the PCF8574 is connected to the LCD
9191
uint8_t _rs_mask;
9292
uint8_t _rw_mask;
@@ -97,7 +97,7 @@ class LiquidCrystal_PCF8574 : public Print
9797

9898
// low level functions
9999
void _send(uint8_t value, bool isData = false);
100-
void _sendNibble(int halfByte, bool isData = false);
100+
void _sendNibble(uint8_t halfByte, bool isData = false);
101101
void _write2Wire(uint8_t data, bool isData, bool enable);
102102

103103
void init(uint8_t i2cAddr, uint8_t rs, uint8_t rw, uint8_t enable,

0 commit comments

Comments
 (0)