@@ -103,8 +103,7 @@ class drvOutQuadAlphaNum : public drvOutputBase {
103
103
}
104
104
105
105
/* !
106
- @brief Writes the first four characters of a message to the quad
107
- alphanumeric display.
106
+ @brief Writes a message to the quad alphanumeric display.
108
107
@param message
109
108
The message to be displayed.
110
109
*/
@@ -115,45 +114,52 @@ class drvOutQuadAlphaNum : public drvOutputBase {
115
114
// Clear before writing
116
115
_alpha4->clear ();
117
116
118
- // Calculate the number of characters to display
119
- size_t len_display = min (strlen (message), (size_t )LED_MAX_CHARS);
117
+ // Calculate the total message length
118
+ size_t msg_len = strlen (message);
119
+
120
+ // Count all characters but excluding decimal points as they are part of the
121
+ // "segment"
122
+ int char_count = 0 ;
123
+ for (size_t i = 0 ; i < msg_len && char_count < LED_MAX_CHARS; i++) {
124
+ if (message[i] != ' .' ) {
125
+ char_count++;
126
+ }
127
+ }
120
128
121
129
// Set the starting position based on alignment
122
130
int pos_start;
123
131
if (_alignment == LED_BACKPACK_ALIGNMENT_LEFT) {
124
- pos_start = 0 ; // start at the leftmost position of the display
132
+ pos_start = 0 ; // start at the leftmost position
125
133
} else {
126
- // Exclude decimal points from the character count because those get
127
- // displayed on a "special" segment of the LED display
128
- int seg_chars = 0 ;
129
- for (size_t i = 0 ; i < len_display; i++) {
130
- if (message[i] != ' .' ) {
131
- seg_chars++;
132
- }
133
- }
134
- // start at the rightmost position of the display
135
- pos_start = LED_MAX_CHARS - seg_chars;
134
+ pos_start = LED_MAX_CHARS - char_count; // start at the rightmost position
136
135
}
137
136
138
137
// Write to the display's buffer
139
138
int cur_idx = pos_start;
140
- for (size_t i = 0 ; i < len_display; i++) {
141
- // Save the character because if there's a decimal, we need to skip it in
142
- // the buffer
139
+ for (size_t i = 0 ; i < msg_len && cur_idx < LED_MAX_CHARS; i++) {
143
140
char ch = message[i];
144
141
145
- // Look-ahead for a decimal point to attach to the current character
146
- bool display_dot = false ;
147
- if (i + 1 < len_display && message[i + 1 ] == ' .' ) {
148
- display_dot = true ;
149
- i++;
150
- len_display++;
142
+ if (ch == ' .' ) {
143
+ // If the previous character has already been processed (or we're at the
144
+ // start of the message), we need to show the decimal as a character
145
+ if (i == 0 || message[i - 1 ] == ' .' ) {
146
+ _alpha4->writeDigitAscii (cur_idx, ch, false );
147
+ cur_idx++;
148
+ } else {
149
+ // Set decimal on an already written character
150
+ _alpha4->writeDigitAscii (cur_idx - 1 , message[i - 1 ], true );
151
+ }
152
+ continue ;
151
153
}
152
154
155
+ // Perform a look-ahead for the decimal
156
+ bool display_dot = (i + 1 < msg_len && message[i + 1 ] == ' .' );
157
+
153
158
// Write the character to the display buffer
154
159
_alpha4->writeDigitAscii (cur_idx, ch, display_dot);
155
160
cur_idx++;
156
161
}
162
+
157
163
// Issue the buffered data in RAM to the display
158
164
_alpha4->writeDisplay ();
159
165
}
@@ -166,7 +172,7 @@ class drvOutQuadAlphaNum : public drvOutputBase {
166
172
*/
167
173
void WriteValue (float value) {
168
174
char message[8 + 1 ];
169
- snprintf (message, sizeof (message), " %.5f " , value);
175
+ snprintf (message, sizeof (message), " %.3f " , value);
170
176
WriteMessage (message);
171
177
}
172
178
0 commit comments