Skip to content

Commit 6bf8118

Browse files
committed
7seg- fix right justification bug, max chars
1 parent 050216d commit 6bf8118

File tree

2 files changed

+20
-29
lines changed

2 files changed

+20
-29
lines changed

src/Wippersnapper_demo.ino.cpp

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

src/components/i2c/drivers/WipperSnapper_I2C_Driver_Out_7Seg.h

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@
3030
#define LED_BACKPACK_ALIGNMENT_RIGHT 2 ///< Right alignment
3131
#define LED_BACKPACK_ALIGNMENT_DEFAULT \
3232
LED_BACKPACK_ALIGNMENT_LEFT ///< Default alignment
33-
#define LED_MAX_CHARS \
34-
4 ///< Maximum number of characters to display on the alphanumeric display
33+
#define LED_MAX_CHARS 5
3534

3635
/*!
3736
@brief Class that provides a driver interface for 7-Segment
@@ -140,12 +139,30 @@ class WipperSnapper_I2C_Driver_Out_7Seg : public WipperSnapper_I2C_Driver_Out {
140139
}
141140
}
142141
// start at the rightmost position of the display
143-
pos_start = LED_MAX_CHARS - seg_chars;
142+
switch (seg_chars) {
143+
case 4:
144+
pos_start = 0;
145+
break;
146+
case 3:
147+
pos_start = 1;
148+
break;
149+
case 2:
150+
pos_start = 3; // if 2 characters, start at position 3 is required
151+
// because ':' is position 2 and we need to skip it
152+
break;
153+
case 1:
154+
pos_start = 4;
155+
break;
156+
default:
157+
pos_start = 0; // if no characters or overflow, start at position 0
158+
break;
159+
}
144160
}
145161

146162
// Write to the display's buffer
147163
int cur_idx = pos_start;
148164
for (size_t i = 0; i < len_display; i++) {
165+
149166
// skip position 2
150167
if (cur_idx == 2) {
151168
cur_idx++;

0 commit comments

Comments
 (0)