Skip to content

Commit 8fa6a4d

Browse files
🚸 Fixes for ProUI, JyersUI, backlight, etc. (#26086)
Co-authored-by: Scott Lahteine <[email protected]>
1 parent 4613f85 commit 8fa6a4d

File tree

16 files changed

+177
-177
lines changed

16 files changed

+177
-177
lines changed

Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -772,6 +772,7 @@ void unified_bed_leveling::shift_mesh_height() {
772772
const grid_count_t point_num = (GRID_MAX_POINTS - count) + 1;
773773
SERIAL_ECHOLNPGM("Probing mesh point ", point_num, "/", GRID_MAX_POINTS, ".");
774774
TERN_(HAS_STATUS_MESSAGE, ui.status_printf(0, F(S_FMT " %i/%i"), GET_TEXT(MSG_PROBING_POINT), point_num, int(GRID_MAX_POINTS)));
775+
TERN_(LCD_BACKLIGHT_TIMEOUT_MINS, ui.refresh_backlight_timeout());
775776

776777
#if HAS_MARLINUI_MENU
777778
if (ui.button_pressed()) {

Marlin/src/inc/SanityCheck.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2722,16 +2722,16 @@ static_assert(COUNT(arm) == LOGICAL_AXES, "AXIS_RELATIVE_MODES must contain " _L
27222722
#endif
27232723

27242724
#if LCD_BACKLIGHT_TIMEOUT_MINS
2725-
#if !HAS_ENCODER_ACTION
2725+
#if !HAS_ENCODER_ACTION && DISABLED(HAS_DWIN_E3V2)
27262726
#error "LCD_BACKLIGHT_TIMEOUT_MINS requires an LCD with encoder or keypad."
27272727
#elif ENABLED(NEOPIXEL_BKGD_INDEX_FIRST)
27282728
#if PIN_EXISTS(LCD_BACKLIGHT)
27292729
#error "LCD_BACKLIGHT_PIN and NEOPIXEL_BKGD_INDEX_FIRST are not supported at the same time."
27302730
#elif ENABLED(NEOPIXEL_BKGD_ALWAYS_ON)
27312731
#error "LCD_BACKLIGHT_TIMEOUT is not compatible with NEOPIXEL_BKGD_ALWAYS_ON."
27322732
#endif
2733-
#elif !PIN_EXISTS(LCD_BACKLIGHT)
2734-
#error "LCD_BACKLIGHT_TIMEOUT_MINS requires either LCD_BACKLIGHT_PIN or NEOPIXEL_BKGD_INDEX_FIRST."
2733+
#elif !PIN_EXISTS(LCD_BACKLIGHT) && DISABLED(HAS_DWIN_E3V2)
2734+
#error "LCD_BACKLIGHT_TIMEOUT_MINS requires LCD_BACKLIGHT_PIN, NEOPIXEL_BKGD_INDEX_FIRST, or an Ender-3 V2 DWIN LCD."
27352735
#endif
27362736
#endif
27372737

Marlin/src/lcd/e3v2/common/encoder.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,13 @@ EncoderState encoderReceiveAnalyze() {
8787
#if PIN_EXISTS(LCD_LED)
8888
//LED_Action();
8989
#endif
90-
if (!ui.backlight) ui.refresh_brightness();
90+
#if LCD_BACKLIGHT_TIMEOUT_MINS
91+
ui.refresh_backlight_timeout();
92+
#endif
93+
if (!ui.backlight) {
94+
ui.refresh_brightness();
95+
return ENCODER_DIFF_NO;
96+
}
9197
const bool was_waiting = wait_for_user;
9298
wait_for_user = false;
9399
return was_waiting ? ENCODER_DIFF_NO : ENCODER_DIFF_ENTER;
@@ -154,6 +160,12 @@ EncoderState encoderReceiveAnalyze() {
154160

155161
temp_diff = 0;
156162
}
163+
if (temp_diffState != ENCODER_DIFF_NO) {
164+
#if LCD_BACKLIGHT_TIMEOUT_MINS
165+
ui.refresh_backlight_timeout();
166+
#endif
167+
if (!ui.backlight) ui.refresh_brightness();
168+
}
157169
return temp_diffState;
158170
}
159171

@@ -164,9 +176,9 @@ EncoderState encoderReceiveAnalyze() {
164176

165177
// LED light operation
166178
void LED_Action() {
167-
LED_Control(RGB_SCALE_WARM_WHITE,0x0F);
179+
LED_Control(RGB_SCALE_WARM_WHITE, 0x0F);
168180
delay(30);
169-
LED_Control(RGB_SCALE_WARM_WHITE,0x00);
181+
LED_Control(RGB_SCALE_WARM_WHITE, 0x00);
170182
}
171183

172184
// LED initialization

Marlin/src/lcd/e3v2/jyersui/dwin.cpp

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -341,20 +341,14 @@ class TextScroller {
341341
}
342342

343343
float getMaxValue() {
344-
float max = __FLT_MIN__;
345-
GRID_LOOP(x, y) {
346-
if (!isnan(bedlevel.z_values[x][y]) && bedlevel.z_values[x][y] > max)
347-
max = bedlevel.z_values[x][y];
348-
}
344+
float max = -(__FLT_MAX__);
345+
GRID_LOOP(x, y) { const float z = bedlevel.z_values[x][y]; if (!isnan(z)) NOLESS(max, z); }
349346
return max;
350347
}
351348

352349
float getMinValue() {
353350
float min = __FLT_MAX__;
354-
GRID_LOOP(x, y) {
355-
if (!isnan(bedlevel.z_values[x][y]) && bedlevel.z_values[x][y] < min)
356-
min = bedlevel.z_values[x][y];
357-
}
351+
GRID_LOOP(x, y) { const float z = bedlevel.z_values[x][y]; if (!isnan(z)) NOMORE(min, z); }
358352
return min;
359353
}
360354

@@ -363,7 +357,7 @@ class TextScroller {
363357
const uint16_t total_width_px = DWIN_WIDTH - padding_x - padding_x,
364358
cell_width_px = total_width_px / (GRID_MAX_POINTS_X),
365359
cell_height_px = total_width_px / (GRID_MAX_POINTS_Y);
366-
const float v_max = abs(getMaxValue()), v_min = abs(getMinValue()), range = _MAX(v_min, v_max);
360+
const float v_max = abs(getMaxValue()), v_min = abs(getMinValue()), rmax = _MAX(v_min, v_max);
367361

368362
// Clear background from previous selection and select new square
369363
dwinDrawRectangle(1, COLOR_BG_BLACK, _MAX(0, padding_x - gridline_width), _MAX(0, padding_y_top - gridline_width), padding_x + total_width_px, padding_y_top + total_width_px);
@@ -381,11 +375,11 @@ class TextScroller {
381375
const auto end_x_px = start_x_px + cell_width_px - 1 - gridline_width;
382376
const auto start_y_px = padding_y_top + (GRID_MAX_POINTS_Y - y - 1) * cell_height_px;
383377
const auto end_y_px = start_y_px + cell_height_px - 1 - gridline_width;
384-
dwinDrawRectangle(1, // RGB565 colors: http://www.barth-dev.de/online/rgb565-color-picker/
385-
isnan(bedlevel.z_values[x][y]) ? COLOR_GREY : ( // gray if undefined
378+
dwinDrawRectangle(1, // RGB565 colors: http://www.barth-dev.de/online/rgb565-color-picker/
379+
isnan(bedlevel.z_values[x][y]) ? COLOR_GREY : ( // gray if undefined
386380
(bedlevel.z_values[x][y] < 0 ?
387-
(uint16_t)round(0x1F * -bedlevel.z_values[x][y] / (!viewer_asymmetric_range ? range : v_min)) << 11 : // red if mesh point value is negative
388-
(uint16_t)round(0x3F * bedlevel.z_values[x][y] / (!viewer_asymmetric_range ? range : v_max)) << 5) | // green if mesh point value is positive
381+
(uint16_t)round(0x1F * -bedlevel.z_values[x][y] / (!viewer_asymmetric_range ? rmax : v_min)) << 11 : // red if mesh point value is negative
382+
(uint16_t)round(0x3F * bedlevel.z_values[x][y] / (!viewer_asymmetric_range ? rmax : v_max)) << 5) | // green if mesh point value is positive
389383
_MIN(0x1F, (((uint8_t)abs(bedlevel.z_values[x][y]) / 10) * 4))), // + blue stepping for every mm
390384
start_x_px, start_y_px, end_x_px, end_y_px
391385
);
@@ -421,16 +415,17 @@ class TextScroller {
421415
v_min = abs(getMinValue()),
422416
v_max = abs(getMaxValue());
423417
if (viewer_asymmetric_range) {
424-
if (v_min > 3e+10F) v_min = 0.0000001;
425-
if (v_max > 3e+10F) v_max = 0.0000001;
418+
if (v_min > 3e+10f) v_min = 0.0000001;
419+
if (v_max > 3e+10f) v_max = 0.0000001;
426420
v1 = -v_min;
427421
v2 = v_max;
428422
}
429423
else {
430-
float range = _MAX(v_min, v_max);
431-
if (range > 3e+10F) range = 0.0000001;
432-
v1 = -range;
433-
v2 = range;
424+
float rmax = _MAX(v_min, v_max), rmin = _MIN(v_min, v_max);
425+
if (rmax > 3e+10f) rmax = 0.0000001;
426+
if (rmin > 3e+10f) rmin = 0.0000001;
427+
v1 = -rmax;
428+
v2 = rmin;
434429
}
435430
jyersDWIN.updateStatus(TS(F("Red "), p_float_t(v1, 3) , F("..0.."), p_float_t(v2, 3), F(" Green")));
436431
drawing_mesh = false;

Marlin/src/lcd/e3v2/proui/base64.hpp renamed to Marlin/src/lcd/e3v2/proui/base64.h

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88
* Changed unsigned int to uint16_t for use in the professional Ender-3V2/S1 firmware
99
* Url: https://www.arduino.cc/reference/en/libraries/base64/
1010
*/
11-
12-
#ifndef BASE64_H_INCLUDED
13-
#define BASE64_H_INCLUDED
11+
#pragma once
1412

1513
/* binary_to_base64:
1614
* Description:
@@ -135,11 +133,11 @@ uint16_t decode_base64_length(unsigned char input[], uint16_t input_length) {
135133
}
136134

137135
input_length = input - start;
138-
return input_length/4*3 + (input_length % 4 ? input_length % 4 - 1 : 0);
136+
return input_length / 4 * 3 + (input_length % 4 ? input_length % 4 - 1 : 0);
139137
}
140138

141139
uint16_t encode_base64(unsigned char input[], uint16_t input_length, unsigned char output[]) {
142-
uint16_t full_sets = input_length/3;
140+
uint16_t full_sets = input_length / 3;
143141

144142
// While there are still full sets of 24 bits...
145143
for (uint16_t i = 0; i < full_sets; ++i) {
@@ -152,7 +150,7 @@ uint16_t encode_base64(unsigned char input[], uint16_t input_length, unsigned ch
152150
output += 4;
153151
}
154152

155-
switch(input_length % 3) {
153+
switch (input_length % 3) {
156154
case 0:
157155
output[0] = '\0';
158156
break;
@@ -192,7 +190,7 @@ uint16_t decode_base64(unsigned char input[], uint16_t input_length, unsigned ch
192190
output += 3;
193191
}
194192

195-
switch(output_length % 3) {
193+
switch (output_length % 3) {
196194
case 1:
197195
output[0] = base64_to_binary(input[0]) << 2 | base64_to_binary(input[1]) >> 4;
198196
break;
@@ -204,5 +202,3 @@ uint16_t decode_base64(unsigned char input[], uint16_t input_length, unsigned ch
204202

205203
return output_length;
206204
}
207-
208-
#endif // ifndef

Marlin/src/lcd/e3v2/proui/bedlevel_tools.cpp

Lines changed: 17 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@
6666
BedLevelTools bedLevelTools;
6767

6868
#if ENABLED(USE_GRID_MESHVIEWER)
69-
bool BedLevelTools::viewer_asymmetric_range = false;
7069
bool BedLevelTools::viewer_print_value = false;
7170
#endif
7271
bool BedLevelTools::goto_mesh_value = false;
@@ -186,20 +185,14 @@ void BedLevelTools::meshReset() {
186185

187186
// Accessors
188187
float BedLevelTools::getMaxValue() {
189-
float max = __FLT_MAX__ * -1;
190-
GRID_LOOP(x, y) {
191-
if (!isnan(bedlevel.z_values[x][y]) && bedlevel.z_values[x][y] > max)
192-
max = bedlevel.z_values[x][y];
193-
}
188+
float max = -(__FLT_MAX__);
189+
GRID_LOOP(x, y) { const float z = bedlevel.z_values[x][y]; if (!isnan(z)) NOLESS(max, z); }
194190
return max;
195191
}
196192

197193
float BedLevelTools::getMinValue() {
198194
float min = __FLT_MAX__;
199-
GRID_LOOP(x, y) {
200-
if (!isnan(bedlevel.z_values[x][y]) && bedlevel.z_values[x][y] < min)
201-
min = bedlevel.z_values[x][y];
202-
}
195+
GRID_LOOP(x, y) { const float z = bedlevel.z_values[x][y]; if (!isnan(z)) NOMORE(min, z); }
203196
return min;
204197
}
205198

@@ -221,7 +214,7 @@ bool BedLevelTools::meshValidate() {
221214
const uint16_t total_width_px = DWIN_WIDTH - padding_x - padding_x;
222215
const uint16_t cell_width_px = total_width_px / (GRID_MAX_POINTS_X);
223216
const uint16_t cell_height_px = total_width_px / (GRID_MAX_POINTS_Y);
224-
const float v_max = abs(getMaxValue()), v_min = abs(getMinValue()), range = _MAX(v_min, v_max);
217+
const float v_max = abs(getMaxValue()), v_min = abs(getMinValue()), rmax = _MAX(v_min, v_max);
225218

226219
// Clear background from previous selection and select new square
227220
dwinDrawRectangle(1, COLOR_BG_BLACK, _MAX(0, padding_x - gridline_width), _MAX(0, padding_y_top - gridline_width), padding_x + total_width_px, padding_y_top + total_width_px);
@@ -242,8 +235,8 @@ bool BedLevelTools::meshValidate() {
242235
dwinDrawRectangle(1, // RGB565 colors: http://www.barth-dev.de/online/rgb565-color-picker/
243236
isnan(bedlevel.z_values[x][y]) ? COLOR_GREY : ( // gray if undefined
244237
(bedlevel.z_values[x][y] < 0 ?
245-
(uint16_t)round(0x1F * -bedlevel.z_values[x][y] / (!viewer_asymmetric_range ? range : v_min)) << 11 : // red if mesh point value is negative
246-
(uint16_t)round(0x3F * bedlevel.z_values[x][y] / (!viewer_asymmetric_range ? range : v_max)) << 5) | // green if mesh point value is positive
238+
(uint16_t)round(0x1F * -bedlevel.z_values[x][y] / rmax) << 11 : // red if mesh point value is negative
239+
(uint16_t)round(0x3F * bedlevel.z_values[x][y] / rmax) << 5) | // green if mesh point value is positive
247240
_MIN(0x1F, (((uint8_t)abs(bedlevel.z_values[x][y]) / 10) * 4))), // + blue stepping for every mm
248241
start_x_px, start_y_px, end_x_px, end_y_px
249242
);
@@ -252,22 +245,22 @@ bool BedLevelTools::meshValidate() {
252245
LCD_SERIAL.flushTX();
253246

254247
// Draw value text on
255-
char buf[8];
256248
const uint8_t fs = DWINUI::fontWidth(meshfont);
257249
if (viewer_print_value) {
258250
int8_t offset_x, offset_y = cell_height_px / 2 - fs;
259251
if (isnan(bedlevel.z_values[x][y])) { // undefined
260252
dwinDrawString(false, meshfont, COLOR_WHITE, COLOR_BG_BLUE, start_x_px + cell_width_px / 2 - 5, start_y_px + offset_y, F("X"));
261253
}
262254
else { // has value
263-
if (GRID_MAX_POINTS_X < (ENABLED(TJC_DISPLAY) ? 8 : 10))
264-
sprintf_P(buf, PSTR("%s"), dtostrf(abs(bedlevel.z_values[x][y]), 1, 2, str_1));
255+
MString<12> msg;
256+
if ((GRID_MAX_POINTS_X) < TERN(TJC_DISPLAY, 8, 10))
257+
msg.set(p_float_t(abs(bedlevel.z_values[x][y]), 2));
265258
else
266-
sprintf_P(buf, PSTR("%02i"), (uint16_t)(abs(bedlevel.z_values[x][y] - (int16_t)bedlevel.z_values[x][y]) * 100));
267-
offset_x = cell_width_px / 2 - (fs/2) * (strlen(buf)) - 2;
268-
if (!(GRID_MAX_POINTS_X < (ENABLED(TJC_DISPLAY) ? 8 : 10)))
259+
msg.setf(F("%02i"), uint16_t(abs(bedlevel.z_values[x][y] - int16_t(bedlevel.z_values[x][y])) * 100));
260+
offset_x = cell_width_px / 2 - (fs / 2) * msg.length() - 2;
261+
if ((GRID_MAX_POINTS_X) >= TERN(TJC_DISPLAY, 8, 10))
269262
dwinDrawString(false, meshfont, COLOR_WHITE, COLOR_BG_BLUE, start_x_px - 2 + offset_x, start_y_px + offset_y, F("."));
270-
dwinDrawString(false, meshfont, COLOR_WHITE, COLOR_BG_BLUE, start_x_px + 1 + offset_x, start_y_px + offset_y, buf);
263+
dwinDrawString(false, meshfont, COLOR_WHITE, COLOR_BG_BLUE, start_x_px + 1 + offset_x, start_y_px + offset_y, msg);
271264
}
272265
safe_delay(10);
273266
LCD_SERIAL.flushTX();
@@ -276,17 +269,10 @@ bool BedLevelTools::meshValidate() {
276269
}
277270

278271
void BedLevelTools::setMeshViewerStatus() { // TODO: draw gradient with values as a legend instead
279-
float v_max = abs(getMaxValue()), v_min = abs(getMinValue()), range = _MAX(v_min, v_max);
280-
if (v_min > 3e+10f) v_min = 0.0000001;
281-
if (v_max > 3e+10f) v_max = 0.0000001;
282-
if (range > 3e+10f) range = 0.0000001;
283-
ui.set_status(
284-
&MString<45>(
285-
F("Red "), p_float_t(viewer_asymmetric_range ? -v_min : -range, 3),
286-
F("..0.."), p_float_t(viewer_asymmetric_range ? v_max : range, 3),
287-
F(" Green")
288-
)
289-
);
272+
float v_max = abs(getMaxValue()), v_min = abs(getMinValue()), rmax = _MAX(v_min, v_max), rmin = _MIN(v_min, v_max);
273+
if (rmax > 3e+10f) rmax = 0.0000001;
274+
if (rmin > 3e+10f) rmin = 0.0000001;
275+
ui.set_status(&MString<47>(F("Red "), p_float_t(-rmax, 3), F("..0.."), p_float_t(rmin, 3), F(" Green")));
290276
drawing_mesh = false;
291277
}
292278

0 commit comments

Comments
 (0)