Skip to content

Commit c470fa3

Browse files
committed
Tie in enable/disable for charlcd writes
1 parent 3ae7029 commit c470fa3

6 files changed

+41
-202
lines changed

src/components/i2c/WipperSnapper_I2C.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -856,7 +856,7 @@ bool WipperSnapper_Component_I2C::initI2CDevice(
856856
_charLcd = new WipperSnapper_I2C_Driver_Out_CharLcd(this->_i2c, i2cAddress);
857857
_charLcd->ConfigureCharLcd(
858858
msgDeviceInitReq->i2c_output_add.config.char_lcd_config.rows,
859-
msgDeviceInitReq->i2c_output_add.config.char_lcd_config.columns, true);
859+
msgDeviceInitReq->i2c_output_add.config.char_lcd_config.columns);
860860
if (!_charLcd->begin()) {
861861
WS_DEBUG_PRINTLN("ERROR: Failed to initialize Character LCD!");
862862
_busStatusResponse =
@@ -867,9 +867,9 @@ bool WipperSnapper_Component_I2C::initI2CDevice(
867867
WS_DEBUG_PRINTLN("Char LCD Display Initialized Successfully!");
868868
} else if (strcmp("7seg", msgDeviceInitReq->i2c_device_name) == 0) {
869869
_sevenSeg = new WipperSnapper_I2C_Driver_Out_7Seg(this->_i2c, i2cAddress);
870-
_sevenSeg->ConfigureCharLcd(
871-
msgDeviceInitReq->i2c_output_add.config.char_lcd_config.rows,
872-
msgDeviceInitReq->i2c_output_add.config.char_lcd_config.columns, true);
870+
_sevenSeg->ConfigureI2CBackpack(
871+
msgDeviceInitReq->i2c_output_add.config.led_backpack_config.brightness,
872+
msgDeviceInitReq->i2c_output_add.config.led_backpack_config.alignment);
873873
if (!_sevenSeg->begin()) {
874874
WS_DEBUG_PRINTLN("ERROR: Failed to initialize 7-Segement LED Matrix!");
875875
_busStatusResponse =

src/components/i2c/drivers/WipperSnapper_I2C_Driver_Out.h

Lines changed: 16 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -53,26 +53,6 @@ class WipperSnapper_I2C_Driver_Out : public WipperSnapper_I2C_Driver {
5353
// noop
5454
}
5555

56-
/*!
57-
@brief Writes a floating point value to an i2c output device.
58-
@param value
59-
The value to be displayed. Only the first four digits are
60-
displayed.
61-
*/
62-
virtual void WriteValue(float value) {
63-
// noop
64-
}
65-
66-
/*!
67-
@brief Writes a floating point value to an i2c output device.
68-
@param value
69-
The value to be displayed. Only the first four digits are
70-
displayed.
71-
*/
72-
virtual void WriteValue(int32_t value) {
73-
// noop
74-
}
75-
7656
/*!
7757
@brief Configures a LED backpack.
7858
@param brightness
@@ -100,29 +80,10 @@ class WipperSnapper_I2C_Driver_Out : public WipperSnapper_I2C_Driver {
10080
@returns True if the message was written successfully, False otherwise.
10181
*/
10282
bool WriteLedBackpack(wippersnapper_i2c_v1_LedBackpackWrite *msg_write) {
103-
// Check if we should adjust brightness
10483
if (msg_write->adjust_brightness)
10584
SetLedBackpackBrightness((uint8_t)msg_write->brightness);
10685

107-
// Write the message to a LED backpack
108-
switch (msg_write->which_message) {
109-
case wippersnapper_i2c_v1_LedBackpackWrite_text_tag:
110-
WS_DEBUG_PRINTLN("[i2c] Writing text to LED backpack...");
111-
WriteMessage(msg_write->message.text);
112-
break;
113-
case wippersnapper_i2c_v1_LedBackpackWrite_number_int_tag:
114-
WS_DEBUG_PRINTLN("[i2c] Writing int to LED backpack...");
115-
WriteValue(msg_write->message.number_int);
116-
break;
117-
case wippersnapper_i2c_v1_LedBackpackWrite_number_float_tag:
118-
WS_DEBUG_PRINTLN("[i2c] Writing float to LED backpack...");
119-
WriteValue(msg_write->message.number_float);
120-
break;
121-
default:
122-
WS_DEBUG_PRINTLN("[i2c] ERROR: Unable to determine message type!");
123-
return false;
124-
break;
125-
}
86+
WriteMessage(msg_write->message.text);
12687
return true;
12788
}
12889

@@ -132,26 +93,31 @@ class WipperSnapper_I2C_Driver_Out : public WipperSnapper_I2C_Driver {
13293
The number of rows in the LCD.
13394
@param cols
13495
The number of columns in the LCD.
135-
@param enable_backlight
136-
True if the backlight is enabled, False otherwise.
13796
*/
138-
virtual void ConfigureCharLcd(uint32_t rows, uint32_t cols,
139-
bool enable_backlight) {
97+
virtual void ConfigureCharLcd(uint32_t rows, uint32_t cols) {
98+
// noop
99+
}
100+
101+
/*!
102+
@brief Turns the character LCD backlight on or off.
103+
@param enable
104+
True to enable the backlight, false to disable it.
105+
*/
106+
void EnableCharLcdBacklight(bool enable) {
140107
// noop
141108
}
142109

143110
/*!
144111
@brief Writes a message to the LCD.
145112
@param write_char_lcd
146113
Points to a CharLCDWrite message.
147-
@returns True if the message was written successfully, False otherwise.
114+
@param enable_backlight
115+
True if the backlight should be enabled, false otherwise.
148116
*/
149-
bool WriteMessageCharLCD(wippersnapper_i2c_v1_CharLCDWrite *write_char_lcd) {
117+
void WriteMessageCharLCD(wippersnapper_i2c_v1_CharLcdWrite *write_char_lcd,
118+
bool enable_backlight = true) {
119+
EnableCharLcdBacklight(enable_backlight);
150120
WriteMessage(write_char_lcd->message);
151-
// NOTE: While this isn't calling any other funcs in here and ret'ing true,
152-
// I want to keep this function high-level for when we implement backlight
153-
// color and scrolling.
154-
return true;
155121
}
156122
};
157123

src/components/i2c/drivers/WipperSnapper_I2C_Driver_Out_7Seg.h

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -170,31 +170,6 @@ class WipperSnapper_I2C_Driver_Out_7Seg : public WipperSnapper_I2C_Driver_Out {
170170
_matrix->writeDisplay();
171171
}
172172

173-
/*!
174-
@brief Writes a floating point value to the 7-segment display.
175-
@param value
176-
The value to be displayed. Only the first four digits are
177-
displayed.
178-
*/
179-
void WriteValue(float value) {
180-
char message[8 + 1];
181-
snprintf(message, sizeof(message), "%.2f",
182-
value); // Less precision for 7-segment
183-
WriteMessage(message);
184-
}
185-
186-
/*!
187-
@brief Writes an integer value to the 7-segment display.
188-
@param value
189-
The value to be displayed. Only the first four digits are
190-
displayed.
191-
*/
192-
void WriteValue(int32_t value) {
193-
char message[LED_MAX_CHARS + 1];
194-
snprintf(message, sizeof(message), "%ld", value);
195-
WriteMessage(message);
196-
}
197-
198173
protected:
199174
Adafruit_7segment *_matrix =
200175
nullptr; ///< ptr to a 7-segment LED matrix object

src/components/i2c/drivers/WipperSnapper_I2C_Driver_Out_CharLcd.h

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,13 @@ class WipperSnapper_I2C_Driver_Out_CharLcd
2727
: public WipperSnapper_I2C_Driver_Out {
2828

2929
public:
30-
/*******************************************************************************/
3130
/*!
3231
@brief Constructor for a LCD character display.
3332
@param i2c
3433
The I2C interface.
3534
@param sensorAddress
3635
7-bit device address.
3736
*/
38-
/*******************************************************************************/
3937
WipperSnapper_I2C_Driver_Out_CharLcd(TwoWire *i2c, uint16_t sensorAddress)
4038
: WipperSnapper_I2C_Driver_Out(i2c, sensorAddress) {
4139
_i2c = i2c;
@@ -59,7 +57,7 @@ class WipperSnapper_I2C_Driver_Out_CharLcd
5957
bool begin() {
6058
_lcd = new Adafruit_LiquidCrystal(_sensorAddress, _i2c);
6159
bool did_begin = _lcd->begin(_cols, _rows);
62-
if (did_begin && _enable_backlight) {
60+
if (did_begin) {
6361
_lcd->setBacklight(HIGH);
6462
}
6563
return did_begin;
@@ -72,13 +70,26 @@ class WipperSnapper_I2C_Driver_Out_CharLcd
7270
The number of rows in the LCD.
7371
@param cols
7472
The number of columns in the LCD.
75-
@param enable_backlight
76-
True if the backlight is enabled, False otherwise.
7773
*/
78-
void ConfigureCharLcd(uint8_t rows, uint8_t cols, bool enable_backlight) {
74+
void ConfigureCharLcd(uint8_t rows, uint8_t cols) {
7975
_rows = rows;
8076
_cols = cols;
81-
_enable_backlight = enable_backlight;
77+
}
78+
79+
/*!
80+
@brief Turns the character LCD backlight on or off.
81+
@param enable
82+
True to enable the backlight, false to disable it.
83+
*/
84+
void EnableCharLcdBacklight(bool enable) {
85+
if (_lcd == nullptr)
86+
return;
87+
88+
if (enable) {
89+
_lcd->setBacklight(HIGH);
90+
} else {
91+
_lcd->setBacklight(LOW);
92+
}
8293
}
8394

8495
/*!
@@ -93,11 +104,6 @@ class WipperSnapper_I2C_Driver_Out_CharLcd
93104
// Before writing, let's clear the display
94105
_lcd->clear();
95106

96-
// TODO: Remove all the prints!
97-
// Print the message to the serial
98-
Serial.print("Writing message to Char. LCD: ");
99-
Serial.println(message);
100-
101107
size_t message_length = strlen(message);
102108
size_t cur_idx = 0; // Current index in the message
103109

@@ -128,10 +134,9 @@ class WipperSnapper_I2C_Driver_Out_CharLcd
128134

129135
protected:
130136
Adafruit_LiquidCrystal *_lcd =
131-
nullptr; ///< Pointer to the Adafruit_LiquidCrystal object
132-
uint8_t _rows; ///< Number of rows in the display
133-
uint8_t _cols; ///< Number of columns in the display
134-
bool _enable_backlight; ///< Flag to enable/disable backlight
137+
nullptr; ///< Pointer to the Adafruit_LiquidCrystal object
138+
uint8_t _rows; ///< Number of rows in the display
139+
uint8_t _cols; ///< Number of columns in the display
135140
};
136141

137142
#endif // WIPPERSNAPPER_I2C_DRIVER_OUT_CHARLCD_H

src/components/i2c/drivers/WipperSnapper_I2C_Driver_Out_QuadAlphaNum.h

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -157,30 +157,6 @@ class WipperSnapper_I2C_Driver_Out_QuadAlphaNum
157157
_alpha4->writeDisplay();
158158
}
159159

160-
/*!
161-
@brief Writes a floating point value to the quad alphanumeric display.
162-
@param value
163-
The value to be displayed. Only the first four digits are
164-
displayed.
165-
*/
166-
void WriteValue(float value) {
167-
char message[8 + 1];
168-
snprintf(message, sizeof(message), "%.5f", value);
169-
WriteMessage(message);
170-
}
171-
172-
/*!
173-
@brief Writes an integer value to the quad alphanumeric display.
174-
@param value
175-
The value to be displayed. Only the first four digits are
176-
displayed.
177-
*/
178-
void WriteValue(int32_t value) {
179-
char message[LED_MAX_CHARS + 1];
180-
snprintf(message, sizeof(message), "%ld", value);
181-
WriteMessage(message);
182-
}
183-
184160
protected:
185161
Adafruit_AlphaNum4 *_alpha4 =
186162
nullptr; ///< ptr to a 4-digit alphanumeric display object

src/components/i2c/drivers/WipperSnapper_I2C_Driver_Out_Ssd1306.h

Lines changed: 0 additions & 83 deletions
This file was deleted.

0 commit comments

Comments
 (0)