Skip to content

Commit

Permalink
🚸 Fixes for ProUI, JyersUI, backlight, etc. (#26086)
Browse files Browse the repository at this point in the history
Co-authored-by: Scott Lahteine <[email protected]>
  • Loading branch information
classicrocker883 and thinkyhead authored Aug 25, 2023
1 parent 4613f85 commit 8fa6a4d
Show file tree
Hide file tree
Showing 16 changed files with 177 additions and 177 deletions.
1 change: 1 addition & 0 deletions Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,7 @@ void unified_bed_leveling::shift_mesh_height() {
const grid_count_t point_num = (GRID_MAX_POINTS - count) + 1;
SERIAL_ECHOLNPGM("Probing mesh point ", point_num, "/", GRID_MAX_POINTS, ".");
TERN_(HAS_STATUS_MESSAGE, ui.status_printf(0, F(S_FMT " %i/%i"), GET_TEXT(MSG_PROBING_POINT), point_num, int(GRID_MAX_POINTS)));
TERN_(LCD_BACKLIGHT_TIMEOUT_MINS, ui.refresh_backlight_timeout());

#if HAS_MARLINUI_MENU
if (ui.button_pressed()) {
Expand Down
6 changes: 3 additions & 3 deletions Marlin/src/inc/SanityCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -2722,16 +2722,16 @@ static_assert(COUNT(arm) == LOGICAL_AXES, "AXIS_RELATIVE_MODES must contain " _L
#endif

#if LCD_BACKLIGHT_TIMEOUT_MINS
#if !HAS_ENCODER_ACTION
#if !HAS_ENCODER_ACTION && DISABLED(HAS_DWIN_E3V2)
#error "LCD_BACKLIGHT_TIMEOUT_MINS requires an LCD with encoder or keypad."
#elif ENABLED(NEOPIXEL_BKGD_INDEX_FIRST)
#if PIN_EXISTS(LCD_BACKLIGHT)
#error "LCD_BACKLIGHT_PIN and NEOPIXEL_BKGD_INDEX_FIRST are not supported at the same time."
#elif ENABLED(NEOPIXEL_BKGD_ALWAYS_ON)
#error "LCD_BACKLIGHT_TIMEOUT is not compatible with NEOPIXEL_BKGD_ALWAYS_ON."
#endif
#elif !PIN_EXISTS(LCD_BACKLIGHT)
#error "LCD_BACKLIGHT_TIMEOUT_MINS requires either LCD_BACKLIGHT_PIN or NEOPIXEL_BKGD_INDEX_FIRST."
#elif !PIN_EXISTS(LCD_BACKLIGHT) && DISABLED(HAS_DWIN_E3V2)
#error "LCD_BACKLIGHT_TIMEOUT_MINS requires LCD_BACKLIGHT_PIN, NEOPIXEL_BKGD_INDEX_FIRST, or an Ender-3 V2 DWIN LCD."
#endif
#endif

Expand Down
18 changes: 15 additions & 3 deletions Marlin/src/lcd/e3v2/common/encoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,13 @@ EncoderState encoderReceiveAnalyze() {
#if PIN_EXISTS(LCD_LED)
//LED_Action();
#endif
if (!ui.backlight) ui.refresh_brightness();
#if LCD_BACKLIGHT_TIMEOUT_MINS
ui.refresh_backlight_timeout();
#endif
if (!ui.backlight) {
ui.refresh_brightness();
return ENCODER_DIFF_NO;
}
const bool was_waiting = wait_for_user;
wait_for_user = false;
return was_waiting ? ENCODER_DIFF_NO : ENCODER_DIFF_ENTER;
Expand Down Expand Up @@ -154,6 +160,12 @@ EncoderState encoderReceiveAnalyze() {

temp_diff = 0;
}
if (temp_diffState != ENCODER_DIFF_NO) {
#if LCD_BACKLIGHT_TIMEOUT_MINS
ui.refresh_backlight_timeout();
#endif
if (!ui.backlight) ui.refresh_brightness();
}
return temp_diffState;
}

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

// LED light operation
void LED_Action() {
LED_Control(RGB_SCALE_WARM_WHITE,0x0F);
LED_Control(RGB_SCALE_WARM_WHITE, 0x0F);
delay(30);
LED_Control(RGB_SCALE_WARM_WHITE,0x00);
LED_Control(RGB_SCALE_WARM_WHITE, 0x00);
}

// LED initialization
Expand Down
35 changes: 15 additions & 20 deletions Marlin/src/lcd/e3v2/jyersui/dwin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,20 +341,14 @@ class TextScroller {
}

float getMaxValue() {
float max = __FLT_MIN__;
GRID_LOOP(x, y) {
if (!isnan(bedlevel.z_values[x][y]) && bedlevel.z_values[x][y] > max)
max = bedlevel.z_values[x][y];
}
float max = -(__FLT_MAX__);
GRID_LOOP(x, y) { const float z = bedlevel.z_values[x][y]; if (!isnan(z)) NOLESS(max, z); }
return max;
}

float getMinValue() {
float min = __FLT_MAX__;
GRID_LOOP(x, y) {
if (!isnan(bedlevel.z_values[x][y]) && bedlevel.z_values[x][y] < min)
min = bedlevel.z_values[x][y];
}
GRID_LOOP(x, y) { const float z = bedlevel.z_values[x][y]; if (!isnan(z)) NOMORE(min, z); }
return min;
}

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

// Clear background from previous selection and select new square
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);
Expand All @@ -381,11 +375,11 @@ class TextScroller {
const auto end_x_px = start_x_px + cell_width_px - 1 - gridline_width;
const auto start_y_px = padding_y_top + (GRID_MAX_POINTS_Y - y - 1) * cell_height_px;
const auto end_y_px = start_y_px + cell_height_px - 1 - gridline_width;
dwinDrawRectangle(1, // RGB565 colors: http://www.barth-dev.de/online/rgb565-color-picker/
isnan(bedlevel.z_values[x][y]) ? COLOR_GREY : ( // gray if undefined
dwinDrawRectangle(1, // RGB565 colors: http://www.barth-dev.de/online/rgb565-color-picker/
isnan(bedlevel.z_values[x][y]) ? COLOR_GREY : ( // gray if undefined
(bedlevel.z_values[x][y] < 0 ?
(uint16_t)round(0x1F * -bedlevel.z_values[x][y] / (!viewer_asymmetric_range ? range : v_min)) << 11 : // red if mesh point value is negative
(uint16_t)round(0x3F * bedlevel.z_values[x][y] / (!viewer_asymmetric_range ? range : v_max)) << 5) | // green if mesh point value is positive
(uint16_t)round(0x1F * -bedlevel.z_values[x][y] / (!viewer_asymmetric_range ? rmax : v_min)) << 11 : // red if mesh point value is negative
(uint16_t)round(0x3F * bedlevel.z_values[x][y] / (!viewer_asymmetric_range ? rmax : v_max)) << 5) | // green if mesh point value is positive
_MIN(0x1F, (((uint8_t)abs(bedlevel.z_values[x][y]) / 10) * 4))), // + blue stepping for every mm
start_x_px, start_y_px, end_x_px, end_y_px
);
Expand Down Expand Up @@ -421,16 +415,17 @@ class TextScroller {
v_min = abs(getMinValue()),
v_max = abs(getMaxValue());
if (viewer_asymmetric_range) {
if (v_min > 3e+10F) v_min = 0.0000001;
if (v_max > 3e+10F) v_max = 0.0000001;
if (v_min > 3e+10f) v_min = 0.0000001;
if (v_max > 3e+10f) v_max = 0.0000001;
v1 = -v_min;
v2 = v_max;
}
else {
float range = _MAX(v_min, v_max);
if (range > 3e+10F) range = 0.0000001;
v1 = -range;
v2 = range;
float rmax = _MAX(v_min, v_max), rmin = _MIN(v_min, v_max);
if (rmax > 3e+10f) rmax = 0.0000001;
if (rmin > 3e+10f) rmin = 0.0000001;
v1 = -rmax;
v2 = rmin;
}
jyersDWIN.updateStatus(TS(F("Red "), p_float_t(v1, 3) , F("..0.."), p_float_t(v2, 3), F(" Green")));
drawing_mesh = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
* Changed unsigned int to uint16_t for use in the professional Ender-3V2/S1 firmware
* Url: https://www.arduino.cc/reference/en/libraries/base64/
*/

#ifndef BASE64_H_INCLUDED
#define BASE64_H_INCLUDED
#pragma once

/* binary_to_base64:
* Description:
Expand Down Expand Up @@ -135,11 +133,11 @@ uint16_t decode_base64_length(unsigned char input[], uint16_t input_length) {
}

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

uint16_t encode_base64(unsigned char input[], uint16_t input_length, unsigned char output[]) {
uint16_t full_sets = input_length/3;
uint16_t full_sets = input_length / 3;

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

switch(input_length % 3) {
switch (input_length % 3) {
case 0:
output[0] = '\0';
break;
Expand Down Expand Up @@ -192,7 +190,7 @@ uint16_t decode_base64(unsigned char input[], uint16_t input_length, unsigned ch
output += 3;
}

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

return output_length;
}

#endif // ifndef
48 changes: 17 additions & 31 deletions Marlin/src/lcd/e3v2/proui/bedlevel_tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@
BedLevelTools bedLevelTools;

#if ENABLED(USE_GRID_MESHVIEWER)
bool BedLevelTools::viewer_asymmetric_range = false;
bool BedLevelTools::viewer_print_value = false;
#endif
bool BedLevelTools::goto_mesh_value = false;
Expand Down Expand Up @@ -186,20 +185,14 @@ void BedLevelTools::meshReset() {

// Accessors
float BedLevelTools::getMaxValue() {
float max = __FLT_MAX__ * -1;
GRID_LOOP(x, y) {
if (!isnan(bedlevel.z_values[x][y]) && bedlevel.z_values[x][y] > max)
max = bedlevel.z_values[x][y];
}
float max = -(__FLT_MAX__);
GRID_LOOP(x, y) { const float z = bedlevel.z_values[x][y]; if (!isnan(z)) NOLESS(max, z); }
return max;
}

float BedLevelTools::getMinValue() {
float min = __FLT_MAX__;
GRID_LOOP(x, y) {
if (!isnan(bedlevel.z_values[x][y]) && bedlevel.z_values[x][y] < min)
min = bedlevel.z_values[x][y];
}
GRID_LOOP(x, y) { const float z = bedlevel.z_values[x][y]; if (!isnan(z)) NOMORE(min, z); }
return min;
}

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

// Clear background from previous selection and select new square
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);
Expand All @@ -242,8 +235,8 @@ bool BedLevelTools::meshValidate() {
dwinDrawRectangle(1, // RGB565 colors: http://www.barth-dev.de/online/rgb565-color-picker/
isnan(bedlevel.z_values[x][y]) ? COLOR_GREY : ( // gray if undefined
(bedlevel.z_values[x][y] < 0 ?
(uint16_t)round(0x1F * -bedlevel.z_values[x][y] / (!viewer_asymmetric_range ? range : v_min)) << 11 : // red if mesh point value is negative
(uint16_t)round(0x3F * bedlevel.z_values[x][y] / (!viewer_asymmetric_range ? range : v_max)) << 5) | // green if mesh point value is positive
(uint16_t)round(0x1F * -bedlevel.z_values[x][y] / rmax) << 11 : // red if mesh point value is negative
(uint16_t)round(0x3F * bedlevel.z_values[x][y] / rmax) << 5) | // green if mesh point value is positive
_MIN(0x1F, (((uint8_t)abs(bedlevel.z_values[x][y]) / 10) * 4))), // + blue stepping for every mm
start_x_px, start_y_px, end_x_px, end_y_px
);
Expand All @@ -252,22 +245,22 @@ bool BedLevelTools::meshValidate() {
LCD_SERIAL.flushTX();

// Draw value text on
char buf[8];
const uint8_t fs = DWINUI::fontWidth(meshfont);
if (viewer_print_value) {
int8_t offset_x, offset_y = cell_height_px / 2 - fs;
if (isnan(bedlevel.z_values[x][y])) { // undefined
dwinDrawString(false, meshfont, COLOR_WHITE, COLOR_BG_BLUE, start_x_px + cell_width_px / 2 - 5, start_y_px + offset_y, F("X"));
}
else { // has value
if (GRID_MAX_POINTS_X < (ENABLED(TJC_DISPLAY) ? 8 : 10))
sprintf_P(buf, PSTR("%s"), dtostrf(abs(bedlevel.z_values[x][y]), 1, 2, str_1));
MString<12> msg;
if ((GRID_MAX_POINTS_X) < TERN(TJC_DISPLAY, 8, 10))
msg.set(p_float_t(abs(bedlevel.z_values[x][y]), 2));
else
sprintf_P(buf, PSTR("%02i"), (uint16_t)(abs(bedlevel.z_values[x][y] - (int16_t)bedlevel.z_values[x][y]) * 100));
offset_x = cell_width_px / 2 - (fs/2) * (strlen(buf)) - 2;
if (!(GRID_MAX_POINTS_X < (ENABLED(TJC_DISPLAY) ? 8 : 10)))
msg.setf(F("%02i"), uint16_t(abs(bedlevel.z_values[x][y] - int16_t(bedlevel.z_values[x][y])) * 100));
offset_x = cell_width_px / 2 - (fs / 2) * msg.length() - 2;
if ((GRID_MAX_POINTS_X) >= TERN(TJC_DISPLAY, 8, 10))
dwinDrawString(false, meshfont, COLOR_WHITE, COLOR_BG_BLUE, start_x_px - 2 + offset_x, start_y_px + offset_y, F("."));
dwinDrawString(false, meshfont, COLOR_WHITE, COLOR_BG_BLUE, start_x_px + 1 + offset_x, start_y_px + offset_y, buf);
dwinDrawString(false, meshfont, COLOR_WHITE, COLOR_BG_BLUE, start_x_px + 1 + offset_x, start_y_px + offset_y, msg);
}
safe_delay(10);
LCD_SERIAL.flushTX();
Expand All @@ -276,17 +269,10 @@ bool BedLevelTools::meshValidate() {
}

void BedLevelTools::setMeshViewerStatus() { // TODO: draw gradient with values as a legend instead
float v_max = abs(getMaxValue()), v_min = abs(getMinValue()), range = _MAX(v_min, v_max);
if (v_min > 3e+10f) v_min = 0.0000001;
if (v_max > 3e+10f) v_max = 0.0000001;
if (range > 3e+10f) range = 0.0000001;
ui.set_status(
&MString<45>(
F("Red "), p_float_t(viewer_asymmetric_range ? -v_min : -range, 3),
F("..0.."), p_float_t(viewer_asymmetric_range ? v_max : range, 3),
F(" Green")
)
);
float v_max = abs(getMaxValue()), v_min = abs(getMinValue()), rmax = _MAX(v_min, v_max), rmin = _MIN(v_min, v_max);
if (rmax > 3e+10f) rmax = 0.0000001;
if (rmin > 3e+10f) rmin = 0.0000001;
ui.set_status(&MString<47>(F("Red "), p_float_t(-rmax, 3), F("..0.."), p_float_t(rmin, 3), F(" Green")));
drawing_mesh = false;
}

Expand Down
Loading

0 comments on commit 8fa6a4d

Please sign in to comment.