Skip to content

Commit

Permalink
🚸 Fix and update ProUI (MarlinFirmware#24477)
Browse files Browse the repository at this point in the history
  • Loading branch information
mriscoc authored and thinkyhead committed Jul 29, 2022
1 parent 01f16da commit d617002
Show file tree
Hide file tree
Showing 17 changed files with 395 additions and 343 deletions.
2 changes: 2 additions & 0 deletions Marlin/src/lcd/e3v2/common/dwin_font.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
*/
#pragma once

typedef uint8_t fontid_t;

/**
* 3-.0:The font size, 0x00-0x09, corresponds to the font size below:
* 0x00=6*12 0x01=8*16 0x02=10*20 0x03=12*24 0x04=14*28
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,19 @@
*/

/**
* UBL Tools and Mesh Viewer for Pro UI
* Version: 1.0.0
* Date: 2022/04/13
* Bed Level Tools for Pro UI
* Extended by: Miguel A. Risco-Castillo (MRISCOC)
* Version: 2.0.0
* Date: 2022/05/23
*
* Original Author: Henri-J-Norden
* Original Source: https://github.com/Jyers/Marlin/pull/126
* Based on the original work of: Henri-J-Norden
* https://github.com/Jyers/Marlin/pull/126
*/

#include "../../../inc/MarlinConfigPre.h"
#include "ubl_tools.h"
#include "bedlevel_tools.h"

#if ENABLED(DWIN_LCD_PROUI)
#if BOTH(DWIN_LCD_PROUI, HAS_LEVELING)

#include "../../marlinui.h"
#include "../../../core/types.h"
Expand All @@ -47,27 +48,29 @@
#include "../../../libs/least_squares_fit.h"
#include "../../../libs/vector_3.h"

UBLMeshToolsClass ubl_tools;
BedLevelToolsClass BedLevelTools;

#if ENABLED(USE_UBL_VIEWER)
bool UBLMeshToolsClass::viewer_asymmetric_range = false;
bool UBLMeshToolsClass::viewer_print_value = false;
#if USE_UBL_VIEWER
bool BedLevelToolsClass::viewer_asymmetric_range = false;
bool BedLevelToolsClass::viewer_print_value = false;
#endif
bool UBLMeshToolsClass::goto_mesh_value = false;
uint8_t UBLMeshToolsClass::tilt_grid = 1;
bool BedLevelToolsClass::goto_mesh_value = false;
uint8_t BedLevelToolsClass::mesh_x = 0;
uint8_t BedLevelToolsClass::mesh_y = 0;
uint8_t BedLevelToolsClass::tilt_grid = 1;

bool drawing_mesh = false;
char cmd[MAX_CMD_SIZE+16], str_1[16], str_2[16], str_3[16];

#if ENABLED(AUTO_BED_LEVELING_UBL)

void UBLMeshToolsClass::manual_value_update(const uint8_t mesh_x, const uint8_t mesh_y, bool undefined/*=false*/) {
void BedLevelToolsClass::manual_value_update(const uint8_t mesh_x, const uint8_t mesh_y, bool undefined/*=false*/) {
sprintf_P(cmd, PSTR("M421 I%i J%i Z%s %s"), mesh_x, mesh_y, dtostrf(current_position.z, 1, 3, str_1), undefined ? "N" : "");
gcode.process_subcommands_now(cmd);
planner.synchronize();
}

bool UBLMeshToolsClass::create_plane_from_mesh() {
bool BedLevelToolsClass::create_plane_from_mesh() {
struct linear_fit_data lsf_results;
incremental_LSF_reset(&lsf_results);
GRID_LOOP(x, y) {
Expand Down Expand Up @@ -119,15 +122,16 @@ char cmd[MAX_CMD_SIZE+16], str_1[16], str_2[16], str_3[16];

#else

void UBLMeshToolsClass::manual_value_update(const uint8_t mesh_x, const uint8_t mesh_y) {
void BedLevelToolsClass::manual_value_update(const uint8_t mesh_x, const uint8_t mesh_y) {
sprintf_P(cmd, PSTR("G29 I%i J%i Z%s"), mesh_x, mesh_y, dtostrf(current_position.z, 1, 3, str_1));
gcode.process_subcommands_now(cmd);
planner.synchronize();
}

#endif

void UBLMeshToolsClass::manual_move(const uint8_t mesh_x, const uint8_t mesh_y, bool zmove/*=false*/) {
void BedLevelToolsClass::manual_move(const uint8_t mesh_x, const uint8_t mesh_y, bool zmove/*=false*/) {
gcode.process_subcommands_now(F("G28O"));
if (zmove) {
planner.synchronize();
current_position.z = goto_mesh_value ? bedlevel.z_values[mesh_x][mesh_y] : Z_CLEARANCE_BETWEEN_PROBES;
Expand All @@ -149,16 +153,36 @@ void UBLMeshToolsClass::manual_move(const uint8_t mesh_x, const uint8_t mesh_y,
}
}

float UBLMeshToolsClass::get_max_value() {
float max = __FLT_MIN__;
void BedLevelToolsClass::MoveToXYZ() {
BedLevelTools.goto_mesh_value = true;
BedLevelTools.manual_move(BedLevelTools.mesh_x, BedLevelTools.mesh_y, false);
}
void BedLevelToolsClass::MoveToXY() {
BedLevelTools.goto_mesh_value = false;
BedLevelTools.manual_move(BedLevelTools.mesh_x, BedLevelTools.mesh_y, false);
}
void BedLevelToolsClass::MoveToZ() {
BedLevelTools.goto_mesh_value = true;
BedLevelTools.manual_move(BedLevelTools.mesh_x, BedLevelTools.mesh_y, true);
}
void BedLevelToolsClass::ProbeXY() {
sprintf_P(cmd, PSTR("G30X%sY%s"),
dtostrf(bedlevel.get_mesh_x(BedLevelTools.mesh_x), 1, 2, str_1),
dtostrf(bedlevel.get_mesh_y(BedLevelTools.mesh_y), 1, 2, str_2)
);
gcode.process_subcommands_now(cmd);
}

float BedLevelToolsClass::get_max_value() {
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];
}
return max;
}

float UBLMeshToolsClass::get_min_value() {
float BedLevelToolsClass::get_min_value() {
float min = __FLT_MAX__;
GRID_LOOP(x, y) {
if (!isnan(bedlevel.z_values[x][y]) && bedlevel.z_values[x][y] < min)
Expand All @@ -167,19 +191,20 @@ float UBLMeshToolsClass::get_min_value() {
return min;
}

bool UBLMeshToolsClass::validate() {
float min = __FLT_MAX__, max = __FLT_MIN__;
bool BedLevelToolsClass::meshvalidate() {
float min = __FLT_MAX__, max = __FLT_MAX__ * -1;

GRID_LOOP(x, y) {
if (isnan(bedlevel.z_values[x][y])) return false;
if (bedlevel.z_values[x][y] < min) min = bedlevel.z_values[x][y];
if (bedlevel.z_values[x][y] > max) max = bedlevel.z_values[x][y];
}
return max <= UBL_Z_OFFSET_MAX && min >= UBL_Z_OFFSET_MIN;
return WITHIN(max, MESH_Z_OFFSET_MIN, MESH_Z_OFFSET_MAX);
}

#if ENABLED(USE_UBL_VIEWER)
void UBLMeshToolsClass::Draw_Bed_Mesh(int16_t selected /*= -1*/, uint8_t gridline_width /*= 1*/, uint16_t padding_x /*= 8*/, uint16_t padding_y_top /*= 40 + 53 - 7*/) {
#if USE_UBL_VIEWER

void BedLevelToolsClass::Draw_Bed_Mesh(int16_t selected /*= -1*/, uint8_t gridline_width /*= 1*/, uint16_t padding_x /*= 8*/, uint16_t padding_y_top /*= 40 + 53 - 7*/) {
drawing_mesh = true;
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);
Expand Down Expand Up @@ -237,7 +262,7 @@ bool UBLMeshToolsClass::validate() {
}
}

void UBLMeshToolsClass::Set_Mesh_Viewer_Status() { // TODO: draw gradient with values as a legend instead
void BedLevelToolsClass::Set_Mesh_Viewer_Status() { // TODO: draw gradient with values as a legend instead
float v_max = abs(get_max_value()), v_min = abs(get_min_value()), range = _MAX(v_min, v_max);
if (v_min > 3e+10F) v_min = 0.0000001;
if (v_max > 3e+10F) v_max = 0.0000001;
Expand All @@ -255,6 +280,7 @@ bool UBLMeshToolsClass::validate() {
ui.set_status(msg);
drawing_mesh = false;
}
#endif

#endif // DWIN_LCD_PROUI
#endif // USE_UBL_VIEWER

#endif // DWIN_LCD_PROUI && HAS_LEVELING
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
/**
* UBL Tools and Mesh Viewer for Pro UI
* Version: 1.0.0
* Date: 2022/04/13
/*
* Marlin 3D Printer Firmware
* Copyright (c) 2022 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Original Author: Henri-J-Norden (https://github.com/Henri-J-Norden)
* Original Source: https://github.com/Jyers/Marlin/pull/135
* Based on Sprinter and grbl.
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -20,22 +19,37 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/

/**
* Bed Level Tools for Pro UI
* Extended by: Miguel A. Risco-Castillo (MRISCOC)
* Version: 2.0.0
* Date: 2022/05/23
*
* Based on the original work of: Henri-J-Norden
* https://github.com/Jyers/Marlin/pull/126
*/

#pragma once

#include "../../../inc/MarlinConfigPre.h"

//#define USE_UBL_VIEWER 1
#if ENABLED(AUTO_BED_LEVELING_UBL)
//#define USE_UBL_VIEWER 1
#endif

#define UBL_Z_OFFSET_MIN -3.0
#define UBL_Z_OFFSET_MAX 3.0
#define MESH_Z_OFFSET_MIN -3.0
#define MESH_Z_OFFSET_MAX 3.0

class UBLMeshToolsClass {
class BedLevelToolsClass {
public:
#if ENABLED(USE_UBL_VIEWER)
#if USE_UBL_VIEWER
static bool viewer_asymmetric_range;
static bool viewer_print_value;
#endif
static bool goto_mesh_value;
static uint8_t mesh_x;
static uint8_t mesh_y;
static uint8_t tilt_grid;

#if ENABLED(AUTO_BED_LEVELING_UBL)
Expand All @@ -45,15 +59,19 @@ class UBLMeshToolsClass {
static void manual_value_update(const uint8_t mesh_x, const uint8_t mesh_y);
#endif
static void manual_move(const uint8_t mesh_x, const uint8_t mesh_y, bool zmove=false);
static void MoveToXYZ();
static void MoveToXY();
static void MoveToZ();
static void ProbeXY();
static float get_max_value();
static float get_min_value();
static bool validate();
#if ENABLED(USE_UBL_VIEWER)
static bool meshvalidate();
#if USE_UBL_VIEWER
static void Draw_Bed_Mesh(int16_t selected = -1, uint8_t gridline_width = 1, uint16_t padding_x = 8, uint16_t padding_y_top = 40 + 53 - 7);
static void Set_Mesh_Viewer_Status();
#endif
};

extern UBLMeshToolsClass ubl_tools;
extern BedLevelToolsClass BedLevelTools;

void Goto_MeshViewer();
Loading

0 comments on commit d617002

Please sign in to comment.