🎨 Consolidate Ender-3 V2 DWIN common code (#22778)

This commit is contained in:
Scott Lahteine
2021-09-15 19:48:29 -05:00
committed by Scott Lahteine
parent 5b593da04d
commit e705a7724e
39 changed files with 1512 additions and 4078 deletions

View File

@ -40,6 +40,9 @@
#include "../../../libs/buzzer.h"
#include "../../../inc/Conditionals_post.h"
//#define DEBUG_OUT 1
#include "../../../core/debug_out.h"
#if ENABLED(ADVANCED_PAUSE_FEATURE)
#include "../../../feature/pause.h"
#endif
@ -200,7 +203,6 @@ CrealityDWINClass CrealityDWIN;
uint8_t mesh_y = 0;
#if ENABLED(AUTO_BED_LEVELING_UBL)
bed_mesh_t &mesh_z_values = ubl.z_values;
uint8_t tilt_grid = 1;
void manual_value_update(bool undefined=false) {
@ -213,11 +215,11 @@ CrealityDWINClass CrealityDWIN;
struct linear_fit_data lsf_results;
incremental_LSF_reset(&lsf_results);
GRID_LOOP(x, y) {
if (!isnan(mesh_z_values[x][y])) {
if (!isnan(Z_VALUES_ARR[x][y])) {
xy_pos_t rpos;
rpos.x = ubl.mesh_index_to_xpos(x);
rpos.y = ubl.mesh_index_to_ypos(y);
incremental_LSF(&lsf_results, rpos, mesh_z_values[x][y]);
incremental_LSF(&lsf_results, rpos, Z_VALUES_ARR[x][y]);
}
}
@ -232,7 +234,7 @@ CrealityDWINClass CrealityDWIN;
GRID_LOOP(i, j) {
float mx = ubl.mesh_index_to_xpos(i),
my = ubl.mesh_index_to_ypos(j),
mz = mesh_z_values[i][j];
mz = Z_VALUES_ARR[i][j];
if (DEBUGGING(LEVELING)) {
DEBUG_ECHOPAIR_F("before rotation = [", mx, 7);
@ -256,13 +258,12 @@ CrealityDWINClass CrealityDWIN;
DEBUG_DELAY(20);
}
mesh_z_values[i][j] = mz - lsf_results.D;
Z_VALUES_ARR[i][j] = mz - lsf_results.D;
}
return false;
}
#else
bed_mesh_t &mesh_z_values = z_values;
void manual_value_update() {
sprintf_P(cmd, PSTR("G29 I%i J%i Z%s"), mesh_x, mesh_y, dtostrf(current_position.z, 1, 3, str_1));
@ -275,7 +276,7 @@ CrealityDWINClass CrealityDWIN;
void manual_move(bool zmove=false) {
if (zmove) {
planner.synchronize();
current_position.z = goto_mesh_value ? mesh_z_values[mesh_x][mesh_y] : Z_CLEARANCE_BETWEEN_PROBES;
current_position.z = goto_mesh_value ? Z_VALUES_ARR[mesh_x][mesh_y] : Z_CLEARANCE_BETWEEN_PROBES;
planner.buffer_line(current_position, homing_feedrate(Z_AXIS), active_extruder);
planner.synchronize();
}
@ -286,7 +287,7 @@ CrealityDWINClass CrealityDWIN;
sprintf_P(cmd, PSTR("G42 F4000 I%i J%i"), mesh_x, mesh_y);
gcode.process_subcommands_now_P(cmd);
planner.synchronize();
current_position.z = goto_mesh_value ? mesh_z_values[mesh_x][mesh_y] : Z_CLEARANCE_BETWEEN_PROBES;
current_position.z = goto_mesh_value ? Z_VALUES_ARR[mesh_x][mesh_y] : Z_CLEARANCE_BETWEEN_PROBES;
planner.buffer_line(current_position, homing_feedrate(Z_AXIS), active_extruder);
planner.synchronize();
CrealityDWIN.Redraw_Menu();
@ -296,8 +297,8 @@ CrealityDWINClass CrealityDWIN;
float get_max_value() {
float max = __FLT_MIN__;
GRID_LOOP(x, y) {
if (!isnan(mesh_z_values[x][y]) && mesh_z_values[x][y] > max)
max = mesh_z_values[x][y];
if (!isnan(Z_VALUES_ARR[x][y]) && Z_VALUES_ARR[x][y] > max)
max = Z_VALUES_ARR[x][y];
}
return max;
}
@ -305,8 +306,8 @@ CrealityDWINClass CrealityDWIN;
float get_min_value() {
float min = __FLT_MAX__;
GRID_LOOP(x, y) {
if (!isnan(mesh_z_values[x][y]) && mesh_z_values[x][y] < min)
min = mesh_z_values[x][y];
if (!isnan(Z_VALUES_ARR[x][y]) && Z_VALUES_ARR[x][y] < min)
min = Z_VALUES_ARR[x][y];
}
return min;
}
@ -335,12 +336,12 @@ CrealityDWINClass CrealityDWIN;
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;
DWIN_Draw_Rectangle(1, // RGB565 colors: http://www.barth-dev.de/online/rgb565-color-picker/
isnan(mesh_z_values[x][y]) ? Color_Grey : ( // gray if undefined
(mesh_z_values[x][y] < 0 ?
(uint16_t)round(0x1F * -mesh_z_values[x][y] / (!viewer_asymmetric_range ? range : v_min)) << 11 : // red if mesh point value is negative
(uint16_t)round(0x3F * mesh_z_values[x][y] / (!viewer_asymmetric_range ? range : v_max)) << 5) | // green if mesh point value is positive
_MIN(0x1F, (((uint8_t)abs(mesh_z_values[x][y]) / 10) * 4))), // + blue stepping for every mm
DWIN_Draw_Rectangle(1, // RGB565 colors: http://www.barth-dev.de/online/rgb565-color-picker/
isnan(Z_VALUES_ARR[x][y]) ? Color_Grey : ( // gray if undefined
(Z_VALUES_ARR[x][y] < 0 ?
(uint16_t)round(0x1F * -Z_VALUES_ARR[x][y] / (!viewer_asymmetric_range ? range : v_min)) << 11 : // red if mesh point value is negative
(uint16_t)round(0x3F * Z_VALUES_ARR[x][y] / (!viewer_asymmetric_range ? range : v_max)) << 5) | // green if mesh point value is positive
_MIN(0x1F, (((uint8_t)abs(Z_VALUES_ARR[x][y]) / 10) * 4))), // + blue stepping for every mm
start_x_px, start_y_px, end_x_px, end_y_px
);
@ -350,18 +351,18 @@ CrealityDWINClass CrealityDWIN;
// Draw value text on
if (viewer_print_value) {
int8_t offset_x, offset_y = cell_height_px / 2 - 6;
if (isnan(mesh_z_values[x][y])) { // undefined
DWIN_Draw_String(false, false, font6x12, Color_White, Color_Bg_Blue, start_x_px + cell_width_px / 2 - 5, start_y_px + offset_y, F("X"));
if (isnan(Z_VALUES_ARR[x][y])) { // undefined
DWIN_Draw_String(false, font6x12, 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 < 10)
sprintf_P(buf, PSTR("%s"), dtostrf(abs(mesh_z_values[x][y]), 1, 2, str_1));
sprintf_P(buf, PSTR("%s"), dtostrf(abs(Z_VALUES_ARR[x][y]), 1, 2, str_1));
else
sprintf_P(buf, PSTR("%02i"), (uint16_t)(abs(mesh_z_values[x][y] - (int16_t)mesh_z_values[x][y]) * 100));
sprintf_P(buf, PSTR("%02i"), (uint16_t)(abs(Z_VALUES_ARR[x][y] - (int16_t)Z_VALUES_ARR[x][y]) * 100));
offset_x = cell_width_px / 2 - 3 * (strlen(buf)) - 2;
if (!(GRID_MAX_POINTS_X < 10))
DWIN_Draw_String(false, false, font6x12, Color_White, Color_Bg_Blue, start_x_px - 2 + offset_x, start_y_px + offset_y /*+ square / 2 - 6*/, F("."));
DWIN_Draw_String(false, false, font6x12, Color_White, Color_Bg_Blue, start_x_px + 1 + offset_x, start_y_px + offset_y /*+ square / 2 - 6*/, buf);
DWIN_Draw_String(false, font6x12, Color_White, Color_Bg_Blue, start_x_px - 2 + offset_x, start_y_px + offset_y /*+ square / 2 - 6*/, F("."));
DWIN_Draw_String(false, font6x12, Color_White, Color_Bg_Blue, start_x_px + 1 + offset_x, start_y_px + offset_y /*+ square / 2 - 6*/, buf);
}
safe_delay(10);
LCD_SERIAL.flushTX();
@ -415,16 +416,11 @@ void CrealityDWINClass::Draw_Float(float value, uint8_t row, bool selected/*=fal
const uint16_t bColor = (selected) ? Select_Color : Color_Bg_Black;
const uint16_t xpos = 240 - (digits * 8);
DWIN_Draw_Rectangle(1, Color_Bg_Black, 194, MBASE(row), 234 - (digits * 8), MBASE(row) + 16);
if (isnan(value)) {
DWIN_Draw_String(false, true, DWIN_FONT_MENU, Color_White, bColor, xpos - 8, MBASE(row), F(" NaN"));
}
else if (value < 0) {
DWIN_Draw_FloatValue(true, true, 0, DWIN_FONT_MENU, Color_White, bColor, digits - log10(minunit) + 1, log10(minunit), xpos, MBASE(row), -value * minunit);
DWIN_Draw_String(false, true, DWIN_FONT_MENU, Color_White, bColor, xpos - 8, MBASE(row), F("-"));
}
if (isnan(value))
DWIN_Draw_String(true, DWIN_FONT_MENU, Color_White, bColor, xpos - 8, MBASE(row), F(" NaN"));
else {
DWIN_Draw_FloatValue(true, true, 0, DWIN_FONT_MENU, Color_White, bColor, digits - log10(minunit) + 1, log10(minunit), xpos, MBASE(row), value * minunit);
DWIN_Draw_String(false, true, DWIN_FONT_MENU, Color_White, bColor, xpos - 8, MBASE(row), F(" "));
DWIN_Draw_FloatValue(true, true, 0, DWIN_FONT_MENU, Color_White, bColor, digits - log10(minunit) + 1, log10(minunit), xpos, MBASE(row), (value < 0 ? -value : value) * minunit);
DWIN_Draw_String(true, DWIN_FONT_MENU, Color_White, bColor, xpos - 8, MBASE(row), value < 0 ? F("-") : F(" "));
}
}
@ -432,7 +428,7 @@ void CrealityDWINClass::Draw_Option(uint8_t value, const char * const * options,
uint16_t bColor = (selected) ? Select_Color : Color_Bg_Black;
uint16_t tColor = (color) ? GetColor(value, Color_White, false) : Color_White;
DWIN_Draw_Rectangle(1, bColor, 202, MBASE(row) + 14, 258, MBASE(row) - 2);
DWIN_Draw_String(false, false, DWIN_FONT_MENU, tColor, bColor, 202, MBASE(row) - 1, options[value]);
DWIN_Draw_String(false, DWIN_FONT_MENU, tColor, bColor, 202, MBASE(row) - 1, options[value]);
}
uint16_t CrealityDWINClass::GetColor(uint8_t color, uint16_t original, bool light/*=false*/) {
@ -475,15 +471,15 @@ uint16_t CrealityDWINClass::GetColor(uint8_t color, uint16_t original, bool ligh
}
void CrealityDWINClass::Draw_Title(const char * title) {
DWIN_Draw_String(false, false, DWIN_FONT_HEAD, GetColor(eeprom_settings.menu_top_txt, Color_White, false), Color_Bg_Blue, (DWIN_WIDTH - strlen(title) * STAT_CHR_W) / 2, 5, title);
DWIN_Draw_String(false, DWIN_FONT_HEAD, GetColor(eeprom_settings.menu_top_txt, Color_White, false), Color_Bg_Blue, (DWIN_WIDTH - strlen(title) * STAT_CHR_W) / 2, 5, title);
}
void CrealityDWINClass::Draw_Menu_Item(uint8_t row, uint8_t icon/*=0*/, const char * label1, const char * label2, bool more/*=false*/, bool centered/*=false*/) {
const uint8_t label_offset_y = !(label1 && label2) ? 0 : MENU_CHR_H * 3 / 5;
const uint8_t label1_offset_x = !centered ? LBLX : LBLX * 4/5 + _MAX(LBLX * 1U/5, (DWIN_WIDTH - LBLX - (label1 ? strlen(label1) : 0) * MENU_CHR_W) / 2);
const uint8_t label2_offset_x = !centered ? LBLX : LBLX * 4/5 + _MAX(LBLX * 1U/5, (DWIN_WIDTH - LBLX - (label2 ? strlen(label2) : 0) * MENU_CHR_W) / 2);
if (label1) DWIN_Draw_String(false, false, DWIN_FONT_MENU, Color_White, Color_Bg_Black, label1_offset_x, MBASE(row) - 1 - label_offset_y, label1); // Draw Label
if (label2) DWIN_Draw_String(false, false, DWIN_FONT_MENU, Color_White, Color_Bg_Black, label2_offset_x, MBASE(row) - 1 + label_offset_y, label2); // Draw Label
if (label1) DWIN_Draw_String(false, DWIN_FONT_MENU, Color_White, Color_Bg_Black, label1_offset_x, MBASE(row) - 1 - label_offset_y, label1); // Draw Label
if (label2) DWIN_Draw_String(false, DWIN_FONT_MENU, Color_White, Color_Bg_Black, label2_offset_x, MBASE(row) - 1 + label_offset_y, label2); // Draw Label
if (icon) DWIN_ICON_Show(ICON, icon, 26, MBASE(row) - 3); //Draw Menu Icon
if (more) DWIN_ICON_Show(ICON, ICON_More, 226, MBASE(row) - 3); // Draw More Arrow
DWIN_Draw_Line(GetColor(eeprom_settings.menu_split_line, Line_Color, true), 16, MBASE(row) + 33, 256, MBASE(row) + 33); // Draw Menu Line
@ -547,50 +543,49 @@ void CrealityDWINClass::Main_Menu_Icons() {
if (selection == 0) {
DWIN_ICON_Show(ICON, ICON_Print_1, 17, 130);
DWIN_Draw_Rectangle(0, GetColor(eeprom_settings.highlight_box, Color_White), 17, 130, 126, 229);
DWIN_Draw_String(false, false, DWIN_FONT_MENU, Color_White, Color_Bg_Blue, 52, 200, F("Print"));
DWIN_Draw_String(false, DWIN_FONT_MENU, Color_White, Color_Bg_Blue, 52, 200, F("Print"));
}
else {
DWIN_ICON_Show(ICON, ICON_Print_0, 17, 130);
DWIN_Draw_String(false, false, DWIN_FONT_MENU, Color_White, Color_Bg_Blue, 52, 200, F("Print"));
DWIN_Draw_String(false, DWIN_FONT_MENU, Color_White, Color_Bg_Blue, 52, 200, F("Print"));
}
if (selection == 1) {
DWIN_ICON_Show(ICON, ICON_Prepare_1, 145, 130);
DWIN_Draw_Rectangle(0, GetColor(eeprom_settings.highlight_box, Color_White), 145, 130, 254, 229);
DWIN_Draw_String(false, false, DWIN_FONT_MENU, Color_White, Color_Bg_Blue, 170, 200, F("Prepare"));
DWIN_Draw_String(false, DWIN_FONT_MENU, Color_White, Color_Bg_Blue, 170, 200, F("Prepare"));
}
else {
DWIN_ICON_Show(ICON, ICON_Prepare_0, 145, 130);
DWIN_Draw_String(false, false, DWIN_FONT_MENU, Color_White, Color_Bg_Blue, 170, 200, F("Prepare"));
DWIN_Draw_String(false, DWIN_FONT_MENU, Color_White, Color_Bg_Blue, 170, 200, F("Prepare"));
}
if (selection == 2) {
DWIN_ICON_Show(ICON, ICON_Control_1, 17, 246);
DWIN_Draw_Rectangle(0, GetColor(eeprom_settings.highlight_box, Color_White), 17, 246, 126, 345);
DWIN_Draw_String(false, false, DWIN_FONT_MENU, Color_White, Color_Bg_Blue, 43, 317, F("Control"));
DWIN_Draw_String(false, DWIN_FONT_MENU, Color_White, Color_Bg_Blue, 43, 317, F("Control"));
}
else {
DWIN_ICON_Show(ICON, ICON_Control_0, 17, 246);
DWIN_Draw_String(false, false, DWIN_FONT_MENU, Color_White, Color_Bg_Blue, 43, 317, F("Control"));
DWIN_Draw_String(false, DWIN_FONT_MENU, Color_White, Color_Bg_Blue, 43, 317, F("Control"));
}
#if HAS_ABL_OR_UBL
if (selection == 3) {
DWIN_ICON_Show(ICON, ICON_Leveling_1, 145, 246);
DWIN_Draw_Rectangle(0, GetColor(eeprom_settings.highlight_box, Color_White), 145, 246, 254, 345);
DWIN_Draw_String(false, false, DWIN_FONT_MENU, Color_White, Color_Bg_Blue, 179, 317, F("Level"));
DWIN_Draw_String(false, DWIN_FONT_MENU, Color_White, Color_Bg_Blue, 179, 317, F("Level"));
}
else {
DWIN_ICON_Show(ICON, ICON_Leveling_0, 145, 246);
DWIN_Draw_String(false, false, DWIN_FONT_MENU, Color_White, Color_Bg_Blue, 179, 317, F("Level"));
DWIN_Draw_String(false, DWIN_FONT_MENU, Color_White, Color_Bg_Blue, 179, 317, F("Level"));
}
#else
if (selection == 3) {
DWIN_ICON_Show(ICON, ICON_Info_1, 145, 246);
DWIN_Draw_Rectangle(0, GetColor(eeprom_settings.highlight_box, Color_White), 145, 246, 254, 345);
DWIN_Draw_String(false, false, DWIN_FONT_MENU, Color_White, Color_Bg_Blue, 181, 317, F("Info"));
DWIN_Draw_String(false, DWIN_FONT_MENU, Color_White, Color_Bg_Blue, 181, 317, F("Info"));
}
else {
DWIN_ICON_Show(ICON, ICON_Info_0, 145, 246);
DWIN_Draw_String(false, false, DWIN_FONT_MENU, Color_White, Color_Bg_Blue, 181, 317, F("Info"));
//DWIN_Frame_AreaCopy(1, 132, 423, 159, 435, 186, 318);
DWIN_Draw_String(false, DWIN_FONT_MENU, Color_White, Color_Bg_Blue, 181, 317, F("Info"));
}
#endif
}
@ -610,41 +605,41 @@ void CrealityDWINClass::Print_Screen_Icons() {
if (selection == 0) {
DWIN_ICON_Show(ICON, ICON_Setup_1, 8, 252);
DWIN_Draw_Rectangle(0, GetColor(eeprom_settings.highlight_box, Color_White), 8, 252, 87, 351);
DWIN_Draw_String(false, false, DWIN_FONT_MENU, Color_White, Color_Bg_Blue, 30, 322, F("Tune"));
DWIN_Draw_String(false, DWIN_FONT_MENU, Color_White, Color_Bg_Blue, 30, 322, F("Tune"));
}
else {
DWIN_ICON_Show(ICON, ICON_Setup_0, 8, 252);
DWIN_Draw_String(false, false, DWIN_FONT_MENU, Color_White, Color_Bg_Blue, 30, 322, F("Tune"));
DWIN_Draw_String(false, DWIN_FONT_MENU, Color_White, Color_Bg_Blue, 30, 322, F("Tune"));
}
if (selection == 2) {
DWIN_ICON_Show(ICON, ICON_Stop_1, 184, 252);
DWIN_Draw_Rectangle(0, GetColor(eeprom_settings.highlight_box, Color_White), 184, 252, 263, 351);
DWIN_Draw_String(false, false, DWIN_FONT_MENU, Color_White, Color_Bg_Blue, 205, 322, F("Stop"));
DWIN_Draw_String(false, DWIN_FONT_MENU, Color_White, Color_Bg_Blue, 205, 322, F("Stop"));
}
else {
DWIN_ICON_Show(ICON, ICON_Stop_0, 184, 252);
DWIN_Draw_String(false, false, DWIN_FONT_MENU, Color_White, Color_Bg_Blue, 205, 322, F("Stop"));
DWIN_Draw_String(false, DWIN_FONT_MENU, Color_White, Color_Bg_Blue, 205, 322, F("Stop"));
}
if (paused) {
if (selection == 1) {
DWIN_ICON_Show(ICON, ICON_Continue_1, 96, 252);
DWIN_Draw_Rectangle(0, GetColor(eeprom_settings.highlight_box, Color_White), 96, 252, 175, 351);
DWIN_Draw_String(false, false, DWIN_FONT_MENU, Color_White, Color_Bg_Blue, 114, 322, F("Print"));
DWIN_Draw_String(false, DWIN_FONT_MENU, Color_White, Color_Bg_Blue, 114, 322, F("Print"));
}
else {
DWIN_ICON_Show(ICON, ICON_Continue_0, 96, 252);
DWIN_Draw_String(false, false, DWIN_FONT_MENU, Color_White, Color_Bg_Blue, 114, 322, F("Print"));
DWIN_Draw_String(false, DWIN_FONT_MENU, Color_White, Color_Bg_Blue, 114, 322, F("Print"));
}
}
else {
if (selection == 1) {
DWIN_ICON_Show(ICON, ICON_Pause_1, 96, 252);
DWIN_Draw_Rectangle(0, GetColor(eeprom_settings.highlight_box, Color_White), 96, 252, 175, 351);
DWIN_Draw_String(false, false, DWIN_FONT_MENU, Color_White, Color_Bg_Blue, 114, 322, F("Pause"));
DWIN_Draw_String(false, DWIN_FONT_MENU, Color_White, Color_Bg_Blue, 114, 322, F("Pause"));
}
else {
DWIN_ICON_Show(ICON, ICON_Pause_0, 96, 252);
DWIN_Draw_String(false, false, DWIN_FONT_MENU, Color_White, Color_Bg_Blue, 114, 322, F("Pause"));
DWIN_Draw_String(false, DWIN_FONT_MENU, Color_White, Color_Bg_Blue, 114, 322, F("Pause"));
}
}
}
@ -658,8 +653,8 @@ void CrealityDWINClass::Draw_Print_Screen() {
Print_Screen_Icons();
DWIN_ICON_Show(ICON, ICON_PrintTime, 14, 171);
DWIN_ICON_Show(ICON, ICON_RemainTime, 147, 169);
DWIN_Draw_String(false, false, DWIN_FONT_MENU, Color_White, Color_Bg_Black, 41, 163, "Elapsed");
DWIN_Draw_String(false, false, DWIN_FONT_MENU, Color_White, Color_Bg_Black, 176, 163, "Remaining");
DWIN_Draw_String(false, DWIN_FONT_MENU, Color_White, Color_Bg_Black, 41, 163, F("Elapsed"));
DWIN_Draw_String(false, DWIN_FONT_MENU, Color_White, Color_Bg_Black, 176, 163, F("Remaining"));
Update_Status_Bar(true);
Draw_Print_ProgressBar();
Draw_Print_ProgressElapsed();
@ -687,14 +682,14 @@ void CrealityDWINClass::Draw_Print_Filename(const bool reset/*=false*/) {
dispname[len] = '\0';
DWIN_Draw_Rectangle(1, Color_Bg_Black, 8, 50, DWIN_WIDTH - 8, 80);
const int8_t npos = (DWIN_WIDTH - 30 * MENU_CHR_W) / 2;
DWIN_Draw_String(false, false, DWIN_FONT_MENU, Color_White, Color_Bg_Black, npos, 60, dispname);
DWIN_Draw_String(false, DWIN_FONT_MENU, Color_White, Color_Bg_Black, npos, 60, dispname);
if (-pos >= 30) namescrl = 0;
namescrl++;
}
else {
DWIN_Draw_Rectangle(1, Color_Bg_Black, 8, 50, DWIN_WIDTH - 8, 80);
const int8_t npos = (DWIN_WIDTH - strlen(filename) * MENU_CHR_W) / 2;
DWIN_Draw_String(false, false, DWIN_FONT_MENU, Color_White, Color_Bg_Black, npos, 60, filename);
DWIN_Draw_String(false, DWIN_FONT_MENU, Color_White, Color_Bg_Black, npos, 60, filename);
}
}
}
@ -704,7 +699,7 @@ void CrealityDWINClass::Draw_Print_ProgressBar() {
DWIN_ICON_Show(ICON, ICON_Bar, 15, 93);
DWIN_Draw_Rectangle(1, BarFill_Color, 16 + printpercent * 240 / 100, 93, 256, 113);
DWIN_Draw_IntValue(true, true, 0, DWIN_FONT_MENU, GetColor(eeprom_settings.progress_percent, Percent_Color), Color_Bg_Black, 3, 109, 133, printpercent);
DWIN_Draw_String(false, false, DWIN_FONT_MENU, GetColor(eeprom_settings.progress_percent, Percent_Color), Color_Bg_Black, 133, 133, "%");
DWIN_Draw_String(false, DWIN_FONT_MENU, GetColor(eeprom_settings.progress_percent, Percent_Color), Color_Bg_Black, 133, 133, F("%"));
}
#if ENABLED(USE_M73_REMAINING_TIME)
@ -714,11 +709,11 @@ void CrealityDWINClass::Draw_Print_ProgressBar() {
DWIN_Draw_IntValue(true, true, 1, DWIN_FONT_MENU, GetColor(eeprom_settings.progress_time, Color_White), Color_Bg_Black, 2, 176, 187, remainingtime / 3600);
DWIN_Draw_IntValue(true, true, 1, DWIN_FONT_MENU, GetColor(eeprom_settings.progress_time, Color_White), Color_Bg_Black, 2, 200, 187, (remainingtime % 3600) / 60);
if (eeprom_settings.time_format_textual) {
DWIN_Draw_String(false, false, DWIN_FONT_MENU, GetColor(eeprom_settings.progress_time, Color_White), Color_Bg_Black, 192, 187, "h");
DWIN_Draw_String(false, false, DWIN_FONT_MENU, GetColor(eeprom_settings.progress_time, Color_White), Color_Bg_Black, 216, 187, "m");
DWIN_Draw_String(false, DWIN_FONT_MENU, GetColor(eeprom_settings.progress_time, Color_White), Color_Bg_Black, 192, 187, F("h"));
DWIN_Draw_String(false, DWIN_FONT_MENU, GetColor(eeprom_settings.progress_time, Color_White), Color_Bg_Black, 216, 187, F("m"));
}
else
DWIN_Draw_String(false, false, DWIN_FONT_MENU, GetColor(eeprom_settings.progress_time, Color_White), Color_Bg_Black, 192, 187, ":");
DWIN_Draw_String(false, DWIN_FONT_MENU, GetColor(eeprom_settings.progress_time, Color_White), Color_Bg_Black, 192, 187, F(":"));
}
#endif
@ -728,11 +723,11 @@ void CrealityDWINClass::Draw_Print_ProgressElapsed() {
DWIN_Draw_IntValue(true, true, 1, DWIN_FONT_MENU, GetColor(eeprom_settings.progress_time, Color_White), Color_Bg_Black, 2, 42, 187, elapsed.value / 3600);
DWIN_Draw_IntValue(true, true, 1, DWIN_FONT_MENU, GetColor(eeprom_settings.progress_time, Color_White), Color_Bg_Black, 2, 66, 187, (elapsed.value % 3600) / 60);
if (eeprom_settings.time_format_textual) {
DWIN_Draw_String(false, false, DWIN_FONT_MENU, GetColor(eeprom_settings.progress_time, Color_White), Color_Bg_Black, 58, 187, "h");
DWIN_Draw_String(false, false, DWIN_FONT_MENU, GetColor(eeprom_settings.progress_time, Color_White), Color_Bg_Black, 82, 187, "m");
DWIN_Draw_String(false, DWIN_FONT_MENU, GetColor(eeprom_settings.progress_time, Color_White), Color_Bg_Black, 58, 187, F("h"));
DWIN_Draw_String(false, DWIN_FONT_MENU, GetColor(eeprom_settings.progress_time, Color_White), Color_Bg_Black, 82, 187, F("m"));
}
else
DWIN_Draw_String(false, false, DWIN_FONT_MENU, GetColor(eeprom_settings.progress_time, Color_White), Color_Bg_Black, 58, 187, ":");
DWIN_Draw_String(false, DWIN_FONT_MENU, GetColor(eeprom_settings.progress_time, Color_White), Color_Bg_Black, 58, 187, F(":"));
}
void CrealityDWINClass::Draw_Print_confirm() {
@ -779,7 +774,7 @@ void CrealityDWINClass::Draw_SD_List(bool removed/*=false*/) {
else {
Draw_Menu_Item(0, ICON_Back, "Back");
DWIN_Draw_Rectangle(1, Color_Bg_Red, 10, MBASE(3) - 10, DWIN_WIDTH - 10, MBASE(4));
DWIN_Draw_String(false, false, font16x32, Color_Yellow, Color_Bg_Red, ((DWIN_WIDTH) - 8 * 16) / 2, MBASE(3), "No Media");
DWIN_Draw_String(false, font16x32, Color_Yellow, Color_Bg_Red, ((DWIN_WIDTH) - 8 * 16) / 2, MBASE(3), F("No Media"));
}
DWIN_Draw_Rectangle(1, GetColor(eeprom_settings.cursor_color, Rectangle_Color), 0, MBASE(0) - 18, 14, MBASE(0) + 33);
}
@ -795,7 +790,7 @@ void CrealityDWINClass::Draw_Status_Area(bool icons/*=false*/) {
hotend = -1;
hotendtarget = -1;
DWIN_ICON_Show(ICON, ICON_HotendTemp, 10, 383);
DWIN_Draw_String(false, false, DWIN_FONT_STAT, GetColor(eeprom_settings.status_area_text, Color_White), Color_Bg_Black, 25 + 3 * STAT_CHR_W + 5, 384, F("/"));
DWIN_Draw_String(false, DWIN_FONT_STAT, GetColor(eeprom_settings.status_area_text, Color_White), Color_Bg_Black, 25 + 3 * STAT_CHR_W + 5, 384, F("/"));
}
if (thermalManager.temp_hotend[0].celsius != hotend) {
hotend = thermalManager.temp_hotend[0].celsius;
@ -810,7 +805,7 @@ void CrealityDWINClass::Draw_Status_Area(bool icons/*=false*/) {
if (icons) {
flow = -1;
DWIN_ICON_Show(ICON, ICON_StepE, 112, 417);
DWIN_Draw_String(false, false, DWIN_FONT_STAT, GetColor(eeprom_settings.status_area_text, Color_White), Color_Bg_Black, 116 + 5 * STAT_CHR_W + 2, 417, F("%"));
DWIN_Draw_String(false, DWIN_FONT_STAT, GetColor(eeprom_settings.status_area_text, Color_White), Color_Bg_Black, 116 + 5 * STAT_CHR_W + 2, 417, F("%"));
}
if (planner.flow_percentage[0] != flow) {
flow = planner.flow_percentage[0];
@ -825,7 +820,7 @@ void CrealityDWINClass::Draw_Status_Area(bool icons/*=false*/) {
bed = -1;
bedtarget = -1;
DWIN_ICON_Show(ICON, ICON_BedTemp, 10, 416);
DWIN_Draw_String(false, false, DWIN_FONT_STAT, GetColor(eeprom_settings.status_area_text, Color_White), Color_Bg_Black, 25 + 3 * STAT_CHR_W + 5, 417, F("/"));
DWIN_Draw_String(false, DWIN_FONT_STAT, GetColor(eeprom_settings.status_area_text, Color_White), Color_Bg_Black, 25 + 3 * STAT_CHR_W + 5, 417, F("/"));
}
if (thermalManager.temp_bed.celsius != bed) {
bed = thermalManager.temp_bed.celsius;
@ -860,14 +855,8 @@ void CrealityDWINClass::Draw_Status_Area(bool icons/*=false*/) {
}
if (zoffsetvalue != offset) {
offset = zoffsetvalue;
if (zoffsetvalue < 0) {
DWIN_Draw_FloatValue(true, true, 0, DWIN_FONT_STAT, GetColor(eeprom_settings.status_area_text, Color_White), Color_Bg_Black, 2, 2, 207, 417, -zoffsetvalue * 100);
DWIN_Draw_String(false, true, DWIN_FONT_MENU, GetColor(eeprom_settings.status_area_text, Color_White), Color_Bg_Black, 205, 419, "-");
}
else {
DWIN_Draw_FloatValue(true, true, 0, DWIN_FONT_STAT, GetColor(eeprom_settings.status_area_text, Color_White), Color_Bg_Black, 2, 2, 207, 417, zoffsetvalue* 100);
DWIN_Draw_String(false, true, DWIN_FONT_MENU, GetColor(eeprom_settings.status_area_text, Color_White), Color_Bg_Black, 205, 419, " ");
}
DWIN_Draw_FloatValue(true, true, 0, DWIN_FONT_STAT, GetColor(eeprom_settings.status_area_text, Color_White), Color_Bg_Black, 2, 2, 207, 417, (zoffsetvalue < 0 ? -zoffsetvalue : zoffsetvalue) * 100);
DWIN_Draw_String(true, DWIN_FONT_MENU, GetColor(eeprom_settings.status_area_text, Color_White), Color_Bg_Black, 205, 419, zoffsetvalue < 0 ? F("-") : F(" "));
}
#endif
@ -875,7 +864,7 @@ void CrealityDWINClass::Draw_Status_Area(bool icons/*=false*/) {
if (icons) {
feedrate = -1;
DWIN_ICON_Show(ICON, ICON_Speed, 113, 383);
DWIN_Draw_String(false, false, DWIN_FONT_STAT, GetColor(eeprom_settings.status_area_text, Color_White), Color_Bg_Black, 116 + 5 * STAT_CHR_W + 2, 384, F("%"));
DWIN_Draw_String(false, DWIN_FONT_STAT, GetColor(eeprom_settings.status_area_text, Color_White), Color_Bg_Black, 116 + 5 * STAT_CHR_W + 2, 384, F("%"));
}
if (feedrate_percentage != feedrate) {
feedrate = feedrate_percentage;
@ -897,21 +886,21 @@ void CrealityDWINClass::Draw_Status_Area(bool icons/*=false*/) {
if (update_x) {
x = current_position.x;
if ((update_x = axis_should_home(X_AXIS) && ui.get_blink()))
DWIN_Draw_String(false, true, DWIN_FONT_MENU, GetColor(eeprom_settings.coordinates_text, Color_White), Color_Bg_Black, 35, 459, " -?- ");
DWIN_Draw_String(true, DWIN_FONT_MENU, GetColor(eeprom_settings.coordinates_text, Color_White), Color_Bg_Black, 35, 459, F(" -?- "));
else
DWIN_Draw_FloatValue(true, true, 0, DWIN_FONT_MENU, GetColor(eeprom_settings.coordinates_text, Color_White), Color_Bg_Black, 3, 1, 35, 459, current_position.x * 10);
}
if (update_y) {
y = current_position.y;
if ((update_y = axis_should_home(Y_AXIS) && ui.get_blink()))
DWIN_Draw_String(false, true, DWIN_FONT_MENU, GetColor(eeprom_settings.coordinates_text, Color_White), Color_Bg_Black, 120, 459, " -?- ");
DWIN_Draw_String(true, DWIN_FONT_MENU, GetColor(eeprom_settings.coordinates_text, Color_White), Color_Bg_Black, 120, 459, F(" -?- "));
else
DWIN_Draw_FloatValue(true, true, 0, DWIN_FONT_MENU, GetColor(eeprom_settings.coordinates_text, Color_White), Color_Bg_Black, 3, 1, 120, 459, current_position.y * 10);
}
if (update_z) {
z = current_position.z;
if ((update_z = axis_should_home(Z_AXIS) && ui.get_blink()))
DWIN_Draw_String(false, true, DWIN_FONT_MENU, GetColor(eeprom_settings.coordinates_text, Color_White), Color_Bg_Black, 205, 459, " -?- ");
DWIN_Draw_String(true, DWIN_FONT_MENU, GetColor(eeprom_settings.coordinates_text, Color_White), Color_Bg_Black, 205, 459, F(" -?- "));
else
DWIN_Draw_FloatValue(true, true, 0, DWIN_FONT_MENU, GetColor(eeprom_settings.coordinates_text, Color_White), Color_Bg_Black, 3, 2, 205, 459, (current_position.z>=0) ? current_position.z * 100 : 0);
}
@ -927,20 +916,20 @@ void CrealityDWINClass::Draw_Popup(PGM_P const line1, PGM_P const line2, PGM_P c
DWIN_Draw_Rectangle(1, Color_Bg_Window, 14, 60, 258, 350);
const uint8_t ypos = (mode == Popup || mode == Confirm) ? 150 : 230;
if (icon > 0) DWIN_ICON_Show(ICON, icon, 101, 105);
DWIN_Draw_String(false, true, DWIN_FONT_MENU, Popup_Text_Color, Color_Bg_Window, (272 - 8 * strlen_P(line1)) / 2, ypos, line1);
DWIN_Draw_String(false, true, DWIN_FONT_MENU, Popup_Text_Color, Color_Bg_Window, (272 - 8 * strlen_P(line2)) / 2, ypos + 30, line2);
DWIN_Draw_String(false, true, DWIN_FONT_MENU, Popup_Text_Color, Color_Bg_Window, (272 - 8 * strlen_P(line3)) / 2, ypos + 60, line3);
DWIN_Draw_String(true, DWIN_FONT_MENU, Popup_Text_Color, Color_Bg_Window, (272 - 8 * strlen_P(line1)) / 2, ypos, line1);
DWIN_Draw_String(true, DWIN_FONT_MENU, Popup_Text_Color, Color_Bg_Window, (272 - 8 * strlen_P(line2)) / 2, ypos + 30, line2);
DWIN_Draw_String(true, DWIN_FONT_MENU, Popup_Text_Color, Color_Bg_Window, (272 - 8 * strlen_P(line3)) / 2, ypos + 60, line3);
if (mode == Popup) {
selection = 0;
DWIN_Draw_Rectangle(1, Confirm_Color, 26, 280, 125, 317);
DWIN_Draw_Rectangle(1, Cancel_Color, 146, 280, 245, 317);
DWIN_Draw_String(false, false, DWIN_FONT_STAT, Color_White, Color_Bg_Window, 39, 290, "Confirm");
DWIN_Draw_String(false, false, DWIN_FONT_STAT, Color_White, Color_Bg_Window, 165, 290, "Cancel");
DWIN_Draw_String(false, DWIN_FONT_STAT, Color_White, Color_Bg_Window, 39, 290, F("Confirm"));
DWIN_Draw_String(false, DWIN_FONT_STAT, Color_White, Color_Bg_Window, 165, 290, F("Cancel"));
Popup_Select();
}
else if (mode == Confirm) {
DWIN_Draw_Rectangle(1, Confirm_Color, 87, 280, 186, 317);
DWIN_Draw_String(false, false, DWIN_FONT_STAT, Color_White, Color_Bg_Window, 96, 290, "Continue");
DWIN_Draw_String(false, DWIN_FONT_STAT, Color_White, Color_Bg_Window, 96, 290, F("Continue"));
}
}
@ -985,12 +974,12 @@ void CrealityDWINClass::Update_Status_Bar(bool refresh/*=false*/) {
if (process == Print) {
DWIN_Draw_Rectangle(1, Color_Grey, 8, 214, DWIN_WIDTH - 8, 238);
const int8_t npos = (DWIN_WIDTH - 30 * MENU_CHR_W) / 2;
DWIN_Draw_String(false, false, DWIN_FONT_MENU, GetColor(eeprom_settings.status_bar_text, Color_White), Color_Bg_Black, npos, 219, dispmsg);
DWIN_Draw_String(false, DWIN_FONT_MENU, GetColor(eeprom_settings.status_bar_text, Color_White), Color_Bg_Black, npos, 219, dispmsg);
}
else {
DWIN_Draw_Rectangle(1, Color_Bg_Black, 8, 352, DWIN_WIDTH - 8, 376);
const int8_t npos = (DWIN_WIDTH - 30 * MENU_CHR_W) / 2;
DWIN_Draw_String(false, false, DWIN_FONT_MENU, GetColor(eeprom_settings.status_bar_text, Color_White), Color_Bg_Black, npos, 357, dispmsg);
DWIN_Draw_String(false, DWIN_FONT_MENU, GetColor(eeprom_settings.status_bar_text, Color_White), Color_Bg_Black, npos, 357, dispmsg);
}
if (-pos >= 30) msgscrl = 0;
msgscrl++;
@ -1001,12 +990,12 @@ void CrealityDWINClass::Update_Status_Bar(bool refresh/*=false*/) {
if (process == Print) {
DWIN_Draw_Rectangle(1, Color_Grey, 8, 214, DWIN_WIDTH - 8, 238);
const int8_t npos = (DWIN_WIDTH - strlen(statusmsg) * MENU_CHR_W) / 2;
DWIN_Draw_String(false, false, DWIN_FONT_MENU, GetColor(eeprom_settings.status_bar_text, Color_White), Color_Bg_Black, npos, 219, statusmsg);
DWIN_Draw_String(false, DWIN_FONT_MENU, GetColor(eeprom_settings.status_bar_text, Color_White), Color_Bg_Black, npos, 219, statusmsg);
}
else {
DWIN_Draw_Rectangle(1, Color_Bg_Black, 8, 352, DWIN_WIDTH - 8, 376);
const int8_t npos = (DWIN_WIDTH - strlen(statusmsg) * MENU_CHR_W) / 2;
DWIN_Draw_String(false, false, DWIN_FONT_MENU, GetColor(eeprom_settings.status_bar_text, Color_White), Color_Bg_Black, npos, 357, statusmsg);
DWIN_Draw_String(false, DWIN_FONT_MENU, GetColor(eeprom_settings.status_bar_text, Color_White), Color_Bg_Black, npos, 357, statusmsg);
}
}
}
@ -1280,7 +1269,7 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/
#if HAS_BED_PROBE
case MOVE_P:
if (draw) {
Draw_Menu_Item(row, ICON_StockConfiguraton, "Probe");
Draw_Menu_Item(row, ICON_StockConfiguration, "Probe");
Draw_Checkbox(row, probe_deployed);
}
else {
@ -2866,7 +2855,7 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/
case Advanced:
#define ADVANCED_BACK 0
#define ADVANCED_BEEPER (ADVANCED_BACK + 1)
#define ADVANCED_BEEPER (ADVANCED_BACK + ENABLED(SOUND_MENU_ITEM))
#define ADVANCED_PROBE (ADVANCED_BEEPER + ENABLED(HAS_BED_PROBE))
#define ADVANCED_CORNER (ADVANCED_PROBE + 1)
#define ADVANCED_LA (ADVANCED_CORNER + ENABLED(LIN_ADVANCE))
@ -2886,16 +2875,18 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/
Draw_Menu(Control, CONTROL_ADVANCED);
break;
case ADVANCED_BEEPER:
if (draw) {
Draw_Menu_Item(row, ICON_Version, "LCD Beeper");
Draw_Checkbox(row, eeprom_settings.beeperenable);
}
else {
eeprom_settings.beeperenable = !eeprom_settings.beeperenable;
Draw_Checkbox(row, eeprom_settings.beeperenable);
}
break;
#if ENABLED(SOUND_MENU_ITEM)
case ADVANCED_BEEPER:
if (draw) {
Draw_Menu_Item(row, ICON_Version, "LCD Beeper");
Draw_Checkbox(row, ui.buzzer_enabled);
}
else {
ui.buzzer_enabled = !ui.buzzer_enabled;
Draw_Checkbox(row, ui.buzzer_enabled);
}
break;
#endif
#if HAS_BED_PROBE
case ADVANCED_PROBE:
@ -3122,7 +3113,7 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/
break;
case LEVELING_ACTIVE:
if (draw) {
Draw_Menu_Item(row, ICON_StockConfiguraton, "Leveling Active");
Draw_Menu_Item(row, ICON_StockConfiguration, "Leveling Active");
Draw_Checkbox(row, planner.leveling_active);
}
else {
@ -3407,7 +3398,7 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/
if (draw)
Draw_Menu_Item(row, ICON_Mesh, "Zero Current Mesh");
else
ZERO(mesh_conf.mesh_z_values);
ZERO(Z_VALUES_ARR);
break;
case LEVELING_SETTINGS_UNDEF:
if (draw)
@ -3493,41 +3484,41 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/
case LEVELING_M_OFFSET:
if (draw) {
Draw_Menu_Item(row, ICON_SetZOffset, "Point Z Offset");
Draw_Float(mesh_conf.mesh_z_values[mesh_conf.mesh_x][mesh_conf.mesh_y], row, false, 100);
Draw_Float(Z_VALUES_ARR[mesh_conf.mesh_x][mesh_conf.mesh_y], row, false, 100);
}
else {
if (isnan(mesh_conf.mesh_z_values[mesh_conf.mesh_x][mesh_conf.mesh_y]))
mesh_conf.mesh_z_values[mesh_conf.mesh_x][mesh_conf.mesh_y] = 0;
Modify_Value(mesh_conf.mesh_z_values[mesh_conf.mesh_x][mesh_conf.mesh_y], MIN_Z_OFFSET, MAX_Z_OFFSET, 100);
if (isnan(Z_VALUES_ARR[mesh_conf.mesh_x][mesh_conf.mesh_y]))
Z_VALUES_ARR[mesh_conf.mesh_x][mesh_conf.mesh_y] = 0;
Modify_Value(Z_VALUES_ARR[mesh_conf.mesh_x][mesh_conf.mesh_y], MIN_Z_OFFSET, MAX_Z_OFFSET, 100);
}
break;
case LEVELING_M_UP:
if (draw)
Draw_Menu_Item(row, ICON_Axis, "Microstep Up");
else if (mesh_conf.mesh_z_values[mesh_conf.mesh_x][mesh_conf.mesh_y] < MAX_Z_OFFSET) {
mesh_conf.mesh_z_values[mesh_conf.mesh_x][mesh_conf.mesh_y] += 0.01;
else if (Z_VALUES_ARR[mesh_conf.mesh_x][mesh_conf.mesh_y] < MAX_Z_OFFSET) {
Z_VALUES_ARR[mesh_conf.mesh_x][mesh_conf.mesh_y] += 0.01;
gcode.process_subcommands_now_P(PSTR("M290 Z0.01"));
planner.synchronize();
current_position.z += 0.01f;
sync_plan_position();
Draw_Float(mesh_conf.mesh_z_values[mesh_conf.mesh_x][mesh_conf.mesh_y], row - 1, false, 100);
Draw_Float(Z_VALUES_ARR[mesh_conf.mesh_x][mesh_conf.mesh_y], row - 1, false, 100);
}
break;
case LEVELING_M_DOWN:
if (draw)
Draw_Menu_Item(row, ICON_AxisD, "Microstep Down");
else if (mesh_conf.mesh_z_values[mesh_conf.mesh_x][mesh_conf.mesh_y] > MIN_Z_OFFSET) {
mesh_conf.mesh_z_values[mesh_conf.mesh_x][mesh_conf.mesh_y] -= 0.01;
else if (Z_VALUES_ARR[mesh_conf.mesh_x][mesh_conf.mesh_y] > MIN_Z_OFFSET) {
Z_VALUES_ARR[mesh_conf.mesh_x][mesh_conf.mesh_y] -= 0.01;
gcode.process_subcommands_now_P(PSTR("M290 Z-0.01"));
planner.synchronize();
current_position.z -= 0.01f;
sync_plan_position();
Draw_Float(mesh_conf.mesh_z_values[mesh_conf.mesh_x][mesh_conf.mesh_y], row - 2, false, 100);
Draw_Float(Z_VALUES_ARR[mesh_conf.mesh_x][mesh_conf.mesh_y], row - 2, false, 100);
}
break;
case LEVELING_M_GOTO_VALUE:
if (draw) {
Draw_Menu_Item(row, ICON_StockConfiguraton, "Go to Mesh Z Value");
Draw_Menu_Item(row, ICON_StockConfiguration, "Go to Mesh Z Value");
Draw_Checkbox(row, mesh_conf.goto_mesh_value);
}
else {
@ -3614,36 +3605,36 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/
case UBL_M_OFFSET:
if (draw) {
Draw_Menu_Item(row, ICON_SetZOffset, "Point Z Offset");
Draw_Float(mesh_conf.mesh_z_values[mesh_conf.mesh_x][mesh_conf.mesh_y], row, false, 100);
Draw_Float(Z_VALUES_ARR[mesh_conf.mesh_x][mesh_conf.mesh_y], row, false, 100);
}
else {
if (isnan(mesh_conf.mesh_z_values[mesh_conf.mesh_x][mesh_conf.mesh_y]))
mesh_conf.mesh_z_values[mesh_conf.mesh_x][mesh_conf.mesh_y] = 0;
Modify_Value(mesh_conf.mesh_z_values[mesh_conf.mesh_x][mesh_conf.mesh_y], MIN_Z_OFFSET, MAX_Z_OFFSET, 100);
if (isnan(Z_VALUES_ARR[mesh_conf.mesh_x][mesh_conf.mesh_y]))
Z_VALUES_ARR[mesh_conf.mesh_x][mesh_conf.mesh_y] = 0;
Modify_Value(Z_VALUES_ARR[mesh_conf.mesh_x][mesh_conf.mesh_y], MIN_Z_OFFSET, MAX_Z_OFFSET, 100);
}
break;
case UBL_M_UP:
if (draw)
Draw_Menu_Item(row, ICON_Axis, "Microstep Up");
else if (mesh_conf.mesh_z_values[mesh_conf.mesh_x][mesh_conf.mesh_y] < MAX_Z_OFFSET) {
mesh_conf.mesh_z_values[mesh_conf.mesh_x][mesh_conf.mesh_y] += 0.01;
else if (Z_VALUES_ARR[mesh_conf.mesh_x][mesh_conf.mesh_y] < MAX_Z_OFFSET) {
Z_VALUES_ARR[mesh_conf.mesh_x][mesh_conf.mesh_y] += 0.01;
gcode.process_subcommands_now_P(PSTR("M290 Z0.01"));
planner.synchronize();
current_position.z += 0.01f;
sync_plan_position();
Draw_Float(mesh_conf.mesh_z_values[mesh_conf.mesh_x][mesh_conf.mesh_y], row - 1, false, 100);
Draw_Float(Z_VALUES_ARR[mesh_conf.mesh_x][mesh_conf.mesh_y], row - 1, false, 100);
}
break;
case UBL_M_DOWN:
if (draw)
Draw_Menu_Item(row, ICON_Axis, "Microstep Down");
else if (mesh_conf.mesh_z_values[mesh_conf.mesh_x][mesh_conf.mesh_y] > MIN_Z_OFFSET) {
mesh_conf.mesh_z_values[mesh_conf.mesh_x][mesh_conf.mesh_y] -= 0.01;
else if (Z_VALUES_ARR[mesh_conf.mesh_x][mesh_conf.mesh_y] > MIN_Z_OFFSET) {
Z_VALUES_ARR[mesh_conf.mesh_x][mesh_conf.mesh_y] -= 0.01;
gcode.process_subcommands_now_P(PSTR("M290 Z-0.01"));
planner.synchronize();
current_position.z -= 0.01f;
sync_plan_position();
Draw_Float(mesh_conf.mesh_z_values[mesh_conf.mesh_x][mesh_conf.mesh_y], row - 2, false, 100);
Draw_Float(Z_VALUES_ARR[mesh_conf.mesh_x][mesh_conf.mesh_y], row - 2, false, 100);
}
break;
}
@ -3733,7 +3724,7 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/
if (mesh_y % 2 == 1)
mesh_x = GRID_MAX_POINTS_X - mesh_x - 1;
const float currval = mesh_conf.mesh_z_values[mesh_x][mesh_y];
const float currval = Z_VALUES_ARR[mesh_x][mesh_y];
if (draw) {
Draw_Menu_Item(row, ICON_Zoffset, "Goto Mesh Value");
@ -4215,7 +4206,7 @@ void CrealityDWINClass::Confirm_Handler(PopupID popupid) {
/* Navigation and Control */
void CrealityDWINClass::Main_Menu_Control() {
ENCODER_DiffState encoder_diffState = Encoder_ReceiveAnalyze();
EncoderState encoder_diffState = Encoder_ReceiveAnalyze();
if (encoder_diffState == ENCODER_DIFF_NO) return;
if (encoder_diffState == ENCODER_DIFF_CW && selection < PAGE_COUNT - 1) {
selection++; // Select Down
@ -4236,7 +4227,7 @@ void CrealityDWINClass::Main_Menu_Control() {
}
void CrealityDWINClass::Menu_Control() {
ENCODER_DiffState encoder_diffState = Encoder_ReceiveAnalyze();
EncoderState encoder_diffState = Encoder_ReceiveAnalyze();
if (encoder_diffState == ENCODER_DIFF_NO) return;
if (encoder_diffState == ENCODER_DIFF_CW && selection < Get_Menu_Size(active_menu)) {
DWIN_Draw_Rectangle(1, Color_Bg_Black, 0, MBASE(selection - scrollpos) - 18, 14, MBASE(selection - scrollpos) + 33);
@ -4264,7 +4255,7 @@ void CrealityDWINClass::Menu_Control() {
}
void CrealityDWINClass::Value_Control() {
ENCODER_DiffState encoder_diffState = Encoder_ReceiveAnalyze();
EncoderState encoder_diffState = Encoder_ReceiveAnalyze();
if (encoder_diffState == ENCODER_DIFF_NO) return;
if (encoder_diffState == ENCODER_DIFF_CW)
tempvalue += EncoderRate.encoderMoveValue;
@ -4329,7 +4320,7 @@ void CrealityDWINClass::Value_Control() {
}
void CrealityDWINClass::Option_Control() {
ENCODER_DiffState encoder_diffState = Encoder_ReceiveAnalyze();
EncoderState encoder_diffState = Encoder_ReceiveAnalyze();
if (encoder_diffState == ENCODER_DIFF_NO) return;
if (encoder_diffState == ENCODER_DIFF_CW)
tempvalue += EncoderRate.encoderMoveValue;
@ -4368,7 +4359,7 @@ void CrealityDWINClass::Option_Control() {
}
void CrealityDWINClass::File_Control() {
ENCODER_DiffState encoder_diffState = Encoder_ReceiveAnalyze();
EncoderState encoder_diffState = Encoder_ReceiveAnalyze();
static uint8_t filescrl = 0;
if (encoder_diffState == ENCODER_DIFF_NO) {
if (selection > 0) {
@ -4456,7 +4447,7 @@ void CrealityDWINClass::File_Control() {
}
void CrealityDWINClass::Print_Screen_Control() {
ENCODER_DiffState encoder_diffState = Encoder_ReceiveAnalyze();
EncoderState encoder_diffState = Encoder_ReceiveAnalyze();
if (encoder_diffState == ENCODER_DIFF_NO) return;
if (encoder_diffState == ENCODER_DIFF_CW && selection < PRINT_COUNT - 1) {
selection++; // Select Down
@ -4509,7 +4500,7 @@ void CrealityDWINClass::Print_Screen_Control() {
}
void CrealityDWINClass::Popup_Control() {
ENCODER_DiffState encoder_diffState = Encoder_ReceiveAnalyze();
EncoderState encoder_diffState = Encoder_ReceiveAnalyze();
if (encoder_diffState == ENCODER_DIFF_NO) return;
if (encoder_diffState == ENCODER_DIFF_CW && selection < 1) {
selection++;
@ -4659,7 +4650,7 @@ void CrealityDWINClass::Popup_Control() {
}
void CrealityDWINClass::Confirm_Control() {
ENCODER_DiffState encoder_diffState = Encoder_ReceiveAnalyze();
EncoderState encoder_diffState = Encoder_ReceiveAnalyze();
if (encoder_diffState == ENCODER_DIFF_NO) return;
if (encoder_diffState == ENCODER_DIFF_ENTER) {
switch (popup) {
@ -4967,14 +4958,14 @@ void CrealityDWINClass::Screen_Update() {
void CrealityDWINClass::AudioFeedback(const bool success/*=true*/) {
if (success) {
if (eeprom_settings.beeperenable) {
if (ui.buzzer_enabled) {
BUZZ(100, 659);
BUZZ( 10, 0);
BUZZ(100, 698);
}
else Update_Status("Success");
}
else if (eeprom_settings.beeperenable)
else if (ui.buzzer_enabled)
BUZZ(40, 440);
else
Update_Status("Failed");
@ -5003,7 +4994,6 @@ void CrealityDWINClass::Load_Settings(const char *buff) {
void CrealityDWINClass::Reset_Settings() {
eeprom_settings.time_format_textual = false;
eeprom_settings.beeperenable = true;
TERN_(AUTO_BED_LEVELING_UBL, eeprom_settings.tilt_grid_size = 0);
eeprom_settings.corner_pos = 325;
eeprom_settings.cursor_color = 0;
@ -5019,6 +5009,7 @@ void CrealityDWINClass::Reset_Settings() {
eeprom_settings.coordinates_split_line = 0;
TERN_(AUTO_BED_LEVELING_UBL, mesh_conf.tilt_grid = eeprom_settings.tilt_grid_size + 1);
corner_pos = eeprom_settings.corner_pos / 10.0f;
TERN_(SOUND_MENU_ITEM, ui.buzzer_enabled = true);
Redraw_Screen();
}

View File

@ -26,10 +26,16 @@
*/
#include "dwin_lcd.h"
#include "rotary_encoder.h"
#include "../common/dwin_set.h"
#include "../common/dwin_font.h"
#include "../common/dwin_color.h"
#include "../common/encoder.h"
#include "../../../libs/BL24CXX.h"
#include "../../../inc/MarlinConfigPre.h"
//#define DWIN_CREALITY_LCD_CUSTOM_ICONS
enum processID : uint8_t {
Main, Print, Menu, Value, Option, File, Popup, Confirm, Wait
};
@ -82,109 +88,6 @@ enum menuID : uint8_t {
PreheatHotend
};
#define Start_Process 0
#define Language_English 1
#define Language_Chinese 2
#define ICON 7 // Icon set file 7.ICO
#define ICON_LOGO 0
#define ICON_Print_0 1
#define ICON_Print_1 2
#define ICON_Prepare_0 3
#define ICON_Prepare_1 4
#define ICON_Control_0 5
#define ICON_Control_1 6
#define ICON_Leveling_0 7
#define ICON_Leveling_1 8
#define ICON_HotendTemp 9
#define ICON_BedTemp 10
#define ICON_Speed 11
#define ICON_Zoffset 12
#define ICON_Back 13
#define ICON_File 14
#define ICON_PrintTime 15
#define ICON_RemainTime 16
#define ICON_Setup_0 17
#define ICON_Setup_1 18
#define ICON_Pause_0 19
#define ICON_Pause_1 20
#define ICON_Continue_0 21
#define ICON_Continue_1 22
#define ICON_Stop_0 23
#define ICON_Stop_1 24
#define ICON_Bar 25
#define ICON_More 26
#define ICON_Axis 27
#define ICON_CloseMotor 28
#define ICON_Homing 29
#define ICON_SetHome 30
#define ICON_PLAPreheat 31
#define ICON_ABSPreheat 32
#define ICON_Cool 33
#define ICON_Language 34
#define ICON_MoveX 35
#define ICON_MoveY 36
#define ICON_MoveZ 37
#define ICON_Extruder 38
#define ICON_Temperature 40
#define ICON_Motion 41
#define ICON_WriteEEPROM 42
#define ICON_ReadEEPROM 43
#define ICON_ResumeEEPROM 44
#define ICON_Info 45
#define ICON_SetEndTemp 46
#define ICON_SetBedTemp 47
#define ICON_FanSpeed 48
#define ICON_SetPLAPreheat 49
#define ICON_SetABSPreheat 50
#define ICON_MaxSpeed 51
#define ICON_MaxAccelerated 52
#define ICON_MaxJerk 53
#define ICON_Step 54
#define ICON_PrintSize 55
#define ICON_Version 56
#define ICON_Contact 57
#define ICON_StockConfiguraton 58
#define ICON_MaxSpeedX 59
#define ICON_MaxSpeedY 60
#define ICON_MaxSpeedZ 61
#define ICON_MaxSpeedE 62
#define ICON_MaxAccX 63
#define ICON_MaxAccY 64
#define ICON_MaxAccZ 65
#define ICON_MaxAccE 66
#define ICON_MaxSpeedJerkX 67
#define ICON_MaxSpeedJerkY 68
#define ICON_MaxSpeedJerkZ 69
#define ICON_MaxSpeedJerkE 70
#define ICON_StepX 71
#define ICON_StepY 72
#define ICON_StepZ 73
#define ICON_StepE 74
#define ICON_Setspeed 75
#define ICON_SetZOffset 76
#define ICON_Rectangle 77
#define ICON_BLTouch 78
#define ICON_TempTooLow 79
#define ICON_AutoLeveling 80
#define ICON_TempTooHigh 81
#define ICON_NoTips_C 82
#define ICON_NoTips_E 83
#define ICON_Continue_C 84
#define ICON_Continue_E 85
#define ICON_Cancel_C 86
#define ICON_Cancel_E 87
#define ICON_Confirm_C 88
#define ICON_Confirm_E 89
#define ICON_Info_0 90
#define ICON_Info_1 91
// Custom icons
#if ENABLED(DWIN_CREALITY_LCD_CUSTOM_ICONS)
// index of every custom icon should be >= CUSTOM_ICON_START
@ -214,25 +117,14 @@ enum menuID : uint8_t {
#define ICON_AxisC ICON_Axis
#endif
#define font6x12 0x00
#define font8x16 0x01
#define font10x20 0x02
#define font12x24 0x03
#define font14x28 0x04
#define font16x32 0x05
#define font20x40 0x06
#define font24x48 0x07
#define font28x56 0x08
#define font32x64 0x09
enum colorID : uint8_t {
Default, White, Green, Cyan, Blue, Magenta, Red, Orange, Yellow, Brown, Black
};
#define Custom_Colors 10
#define Color_White 0xFFFF
#define Color_Aqua RGB(0x00,0x3F,0x1F)
#define Color_Light_White 0xBDD7
#define Color_Green 0x07E0
#define Color_Green RGB(0x00,0x3F,0x00)
#define Color_Light_Green 0x3460
#define Color_Cyan 0x07FF
#define Color_Light_Cyan 0x04F3
@ -240,28 +132,16 @@ enum colorID : uint8_t {
#define Color_Light_Blue 0x3A6A
#define Color_Magenta 0xF81F
#define Color_Light_Magenta 0x9813
#define Color_Red 0xF800
#define Color_Light_Red 0x8800
#define Color_Orange 0xFA20
#define Color_Light_Orange 0xFBC0
#define Color_Yellow 0xFF0F
#define Color_Light_Yellow 0x8BE0
#define Color_Brown 0xCC27
#define Color_Light_Brown 0x6204
#define Color_Black 0x0000
#define Color_Grey 0x18E3
#define Color_Bg_Window 0x31E8 // Popup background color
#define Color_Bg_Blue 0x1125 // Dark blue background color
#define Color_Bg_Black 0x0841 // Black background color
#define Color_Bg_Red 0xF00F // Red background color
#define Popup_Text_Color 0xD6BA // Popup font background color
#define Line_Color 0x3A6A // Split line color
#define Rectangle_Color 0xEE2F // Blue square cursor color
#define Percent_Color 0xFE29 // Percentage color
#define BarFill_Color 0x10E4 // Fill color of progress bar
#define Select_Color 0x33BB // Selected color
#define Check_Color 0x4E5C // Check-box check color
#define Confirm_Color 0x34B9
#define Confirm_Color 0x34B9
#define Cancel_Color 0x3186
class CrealityDWINClass {
@ -269,7 +149,6 @@ public:
static constexpr size_t eeprom_data_size = 48;
static struct EEPROM_Settings { // use bit fields to save space, max 48 bytes
bool time_format_textual : 1;
bool beeperenable : 1;
#if ENABLED(AUTO_BED_LEVELING_UBL)
uint8_t tilt_grid_size : 3;
#endif

View File

@ -29,185 +29,17 @@
#if ENABLED(DWIN_CREALITY_LCD_JYERSUI)
#include "../../../inc/MarlinConfig.h"
#include "dwin_lcd.h"
#include <string.h> // for memset
//#define DEBUG_OUT 1
#include "../../../core/debug_out.h"
// Make sure DWIN_SendBuf is large enough to hold the largest string plus draw command and tail.
// Assume the narrowest (6 pixel) font and 2-byte gb2312-encoded characters.
uint8_t DWIN_SendBuf[11 + DWIN_WIDTH / 6 * 2] = { 0xAA };
uint8_t DWIN_BufTail[4] = { 0xCC, 0x33, 0xC3, 0x3C };
uint8_t databuf[26] = { 0 };
uint8_t receivedType;
int recnum = 0;
inline void DWIN_Byte(size_t &i, const uint16_t bval) {
DWIN_SendBuf[++i] = bval;
}
inline void DWIN_Word(size_t &i, const uint16_t wval) {
DWIN_SendBuf[++i] = wval >> 8;
DWIN_SendBuf[++i] = wval & 0xFF;
}
inline void DWIN_Long(size_t &i, const uint32_t lval) {
DWIN_SendBuf[++i] = (lval >> 24) & 0xFF;
DWIN_SendBuf[++i] = (lval >> 16) & 0xFF;
DWIN_SendBuf[++i] = (lval >> 8) & 0xFF;
DWIN_SendBuf[++i] = lval & 0xFF;
}
inline void DWIN_String(size_t &i, const char * const string) {
const size_t len = _MIN(sizeof(DWIN_SendBuf) - i, strlen(string));
memcpy(&DWIN_SendBuf[i + 1], string, len);
i += len;
}
inline void DWIN_String(size_t &i, const __FlashStringHelper * string) {
if (!string) return;
const size_t len = strlen_P((PGM_P)string); // cast it to PGM_P, which is basically const char *, and measure it using the _P version of strlen.
if (len == 0) return;
memcpy(&DWIN_SendBuf[i + 1], string, len);
i += len;
}
// Send the data in the buffer and the packet end
inline void DWIN_Send(size_t &i) {
++i;
LOOP_L_N(n, i) { LCD_SERIAL.write(DWIN_SendBuf[n]); delayMicroseconds(1); }
LOOP_L_N(n, 4) { LCD_SERIAL.write(DWIN_BufTail[n]); delayMicroseconds(1); }
}
/*-------------------------------------- System variable function --------------------------------------*/
// Handshake (1: Success, 0: Fail)
bool DWIN_Handshake(void) {
#ifndef LCD_BAUDRATE
#define LCD_BAUDRATE 115200
#endif
LCD_SERIAL.begin(LCD_BAUDRATE);
const millis_t serial_connect_timeout = millis() + 1000UL;
while (!LCD_SERIAL.connected() && PENDING(millis(), serial_connect_timeout)) { /*nada*/ }
size_t i = 0;
DWIN_Byte(i, 0x00);
DWIN_Send(i);
while (LCD_SERIAL.available() > 0 && recnum < (signed)sizeof(databuf)) {
databuf[recnum] = LCD_SERIAL.read();
// ignore the invalid data
if (databuf[0] != FHONE) { // prevent the program from running.
if (recnum > 0) {
recnum = 0;
ZERO(databuf);
}
continue;
}
delay(10);
recnum++;
}
return ( recnum >= 3
&& databuf[0] == FHONE
&& databuf[1] == '\0'
&& databuf[2] == 'O'
&& databuf[3] == 'K' );
}
// Set the backlight luminance
// luminance: (0x00-0xFF)
void DWIN_Backlight_SetLuminance(const uint8_t luminance) {
size_t i = 0;
DWIN_Byte(i, 0x30);
DWIN_Byte(i, luminance);
DWIN_Send(i);
}
// Set screen display direction
// dir: 0=0°, 1=90°, 2=180°, 3=270°
void DWIN_Frame_SetDir(uint8_t dir) {
size_t i = 0;
DWIN_Byte(i, 0x34);
DWIN_Byte(i, 0x5A);
DWIN_Byte(i, 0xA5);
DWIN_Byte(i, dir);
DWIN_Send(i);
}
// Update display
void DWIN_UpdateLCD(void) {
size_t i = 0;
DWIN_Byte(i, 0x3D);
DWIN_Send(i);
}
void DWIN_Startup() {}
/*---------------------------------------- Drawing functions ----------------------------------------*/
// Clear screen
// color: Clear screen color
void DWIN_Frame_Clear(const uint16_t color) {
size_t i = 0;
DWIN_Byte(i, 0x01);
DWIN_Word(i, color);
DWIN_Send(i);
}
// Draw a point
// color: Pixel segment color
// width: point width 0x01-0x0F
// height: point height 0x01-0x0F
// x,y: upper left point
void DWIN_Draw_Point(uint16_t color, uint8_t width, uint8_t height, uint16_t x, uint16_t y) {
size_t i = 0;
DWIN_Byte(i, 0x02);
DWIN_Word(i, color);
DWIN_Byte(i, width);
DWIN_Byte(i, height);
DWIN_Word(i, x);
DWIN_Word(i, y);
DWIN_Send(i);
}
// Draw a line
// color: Line segment color
// xStart/yStart: Start point
// xEnd/yEnd: End point
void DWIN_Draw_Line(uint16_t color, uint16_t xStart, uint16_t yStart, uint16_t xEnd, uint16_t yEnd) {
size_t i = 0;
DWIN_Byte(i, 0x03);
DWIN_Word(i, color);
DWIN_Word(i, xStart);
DWIN_Word(i, yStart);
DWIN_Word(i, xEnd);
DWIN_Word(i, yEnd);
DWIN_Send(i);
}
// Draw a rectangle
// mode: 0=frame, 1=fill, 2=XOR fill
// color: Rectangle color
// xStart/yStart: upper left point
// xEnd/yEnd: lower right point
void DWIN_Draw_Rectangle(uint8_t mode, uint16_t color,
uint16_t xStart, uint16_t yStart, uint16_t xEnd, uint16_t yEnd) {
size_t i = 0;
DWIN_Byte(i, 0x05);
DWIN_Byte(i, mode);
DWIN_Word(i, color);
DWIN_Word(i, xStart);
DWIN_Word(i, yStart);
DWIN_Word(i, xEnd);
DWIN_Word(i, yEnd);
DWIN_Send(i);
}
//Color: color
//x/y: Upper-left coordinate of the first pixel
// Draw the degree (°) symbol
// Color: color
// x/y: Upper-left coordinate of the first pixel
void DWIN_Draw_DegreeSymbol(uint16_t Color, uint16_t x, uint16_t y) {
DWIN_Draw_Point(Color, 1, 1, x + 1, y);
DWIN_Draw_Point(Color, 1, 1, x + 2, y);
@ -219,256 +51,14 @@ void DWIN_Draw_DegreeSymbol(uint16_t Color, uint16_t x, uint16_t y) {
DWIN_Draw_Point(Color, 1, 1, x + 2, y + 3);
}
// Move a screen area
// mode: 0, circle shift; 1, translation
// dir: 0=left, 1=right, 2=up, 3=down
// dis: Distance
// color: Fill color
// xStart/yStart: upper left point
// xEnd/yEnd: bottom right point
void DWIN_Frame_AreaMove(uint8_t mode, uint8_t dir, uint16_t dis,
uint16_t color, uint16_t xStart, uint16_t yStart, uint16_t xEnd, uint16_t yEnd) {
size_t i = 0;
DWIN_Byte(i, 0x09);
DWIN_Byte(i, (mode << 7) | dir);
DWIN_Word(i, dis);
DWIN_Word(i, color);
DWIN_Word(i, xStart);
DWIN_Word(i, yStart);
DWIN_Word(i, xEnd);
DWIN_Word(i, yEnd);
DWIN_Send(i);
}
/*---------------------------------------- Text related functions ----------------------------------------*/
// Draw a string
// widthAdjust: true=self-adjust character width; false=no adjustment
// bShow: true=display background color; false=don't display background color
// size: Font size
// color: Character color
// bColor: Background color
// x/y: Upper-left coordinate of the string
// *string: The string
void DWIN_Draw_String(bool widthAdjust, bool bShow, uint8_t size,
uint16_t color, uint16_t bColor, uint16_t x, uint16_t y, const char * string) {
size_t i = 0;
DWIN_Byte(i, 0x11);
// Bit 7: widthAdjust
// Bit 6: bShow
// Bit 5-4: Unused (0)
// Bit 3-0: size
DWIN_Byte(i, (widthAdjust * 0x80) | (bShow * 0x40) | size);
DWIN_Word(i, color);
DWIN_Word(i, bColor);
DWIN_Word(i, x);
DWIN_Word(i, y);
DWIN_String(i, string);
DWIN_Send(i);
}
// Draw a positive integer
// bShow: true=display background color; false=don't display background color
// zeroFill: true=zero fill; false=no zero fill
// zeroMode: 1=leading 0 displayed as 0; 0=leading 0 displayed as a space
// size: Font size
// color: Character color
// bColor: Background color
// iNum: Number of digits
// x/y: Upper-left coordinate
// value: Integer value
void DWIN_Draw_IntValue(uint8_t bShow, bool zeroFill, uint8_t zeroMode, uint8_t size, uint16_t color,
uint16_t bColor, uint8_t iNum, uint16_t x, uint16_t y, uint16_t value) {
size_t i = 0;
DWIN_Byte(i, 0x14);
// Bit 7: bshow
// Bit 6: 1 = signed; 0 = unsigned number;
// Bit 5: zeroFill
// Bit 4: zeroMode
// Bit 3-0: size
DWIN_Byte(i, (bShow * 0x80) | (zeroFill * 0x20) | (zeroMode * 0x10) | size);
DWIN_Word(i, color);
DWIN_Word(i, bColor);
DWIN_Byte(i, iNum);
DWIN_Byte(i, 0); // fNum
DWIN_Word(i, x);
DWIN_Word(i, y);
#if 0
for (char count = 0; count < 8; count++) {
DWIN_Byte(i, value);
value >>= 8;
if (!(value & 0xFF)) break;
}
#else
// Write a big-endian 64 bit integer
const size_t p = i + 1;
for (char count = 8; count--;) { // 7..0
++i;
DWIN_SendBuf[p + count] = value;
value >>= 8;
}
#endif
DWIN_Send(i);
}
// Draw a floating point number
// bShow: true=display background color; false=don't display background color
// zeroFill: true=zero fill; false=no zero fill
// zeroMode: 1=leading 0 displayed as 0; 0=leading 0 displayed as a space
// size: Font size
// color: Character color
// bColor: Background color
// iNum: Number of whole digits
// fNum: Number of decimal digits
// x/y: Upper-left point
// value: Float value
void DWIN_Draw_FloatValue(uint8_t bShow, bool zeroFill, uint8_t zeroMode, uint8_t size, uint16_t color,
uint16_t bColor, uint8_t iNum, uint8_t fNum, uint16_t x, uint16_t y, long value) {
//uint8_t *fvalue = (uint8_t*)&value;
size_t i = 0;
DWIN_Byte(i, 0x14);
DWIN_Byte(i, (bShow * 0x80) | (zeroFill * 0x20) | (zeroMode * 0x10) | size);
DWIN_Word(i, color);
DWIN_Word(i, bColor);
DWIN_Byte(i, iNum);
DWIN_Byte(i, fNum);
DWIN_Word(i, x);
DWIN_Word(i, y);
DWIN_Long(i, value);
/*
DWIN_Byte(i, fvalue[3]);
DWIN_Byte(i, fvalue[2]);
DWIN_Byte(i, fvalue[1]);
DWIN_Byte(i, fvalue[0]);
*/
DWIN_Send(i);
}
/*---------------------------------------- Picture related functions ----------------------------------------*/
// Draw JPG and cached in #0 virtual display area
// id: Picture ID
void DWIN_JPG_ShowAndCache(const uint8_t id) {
size_t i = 0;
DWIN_Word(i, 0x2200);
DWIN_Byte(i, id);
DWIN_Send(i); // AA 23 00 00 00 00 08 00 01 02 03 CC 33 C3 3C
}
// Draw an Icon
// libID: Icon library ID
// picID: Icon ID
// x/y: Upper-left point
void DWIN_ICON_Show(uint8_t libID, uint8_t picID, uint16_t x, uint16_t y) {
NOMORE(x, DWIN_WIDTH - 1);
NOMORE(y, DWIN_HEIGHT - 1); // -- ozy -- srl
size_t i = 0;
DWIN_Byte(i, 0x23);
DWIN_Word(i, x);
DWIN_Word(i, y);
DWIN_Byte(i, 0x80 | libID);
DWIN_Byte(i, picID);
DWIN_Send(i);
DWIN_ICON_Show(true, false, false, libID, picID, x, y);
}
// Unzip the JPG picture to a virtual display area
// n: Cache index
// id: Picture ID
void DWIN_JPG_CacheToN(uint8_t n, uint8_t id) {
size_t i = 0;
DWIN_Byte(i, 0x25);
DWIN_Byte(i, n);
DWIN_Byte(i, id);
DWIN_Send(i);
}
// Copy area from virtual display area to current screen
// cacheID: virtual area number
// xStart/yStart: Upper-left of virtual area
// xEnd/yEnd: Lower-right of virtual area
// x/y: Screen paste point
void DWIN_Frame_AreaCopy(uint8_t cacheID, uint16_t xStart, uint16_t yStart,
uint16_t xEnd, uint16_t yEnd, uint16_t x, uint16_t y) {
size_t i = 0;
DWIN_Byte(i, 0x27);
DWIN_Byte(i, 0x80 | cacheID);
DWIN_Word(i, xStart);
DWIN_Word(i, yStart);
DWIN_Word(i, xEnd);
DWIN_Word(i, yEnd);
DWIN_Word(i, x);
DWIN_Word(i, y);
DWIN_Send(i);
}
// Animate a series of icons
// animID: Animation ID; 0x00-0x0F
// animate: true on; false off;
// libID: Icon library ID
// picIDs: Icon starting ID
// picIDe: Icon ending ID
// x/y: Upper-left point
// interval: Display time interval, unit 10mS
void DWIN_ICON_Animation(uint8_t animID, bool animate, uint8_t libID, uint8_t picIDs, uint8_t picIDe, uint16_t x, uint16_t y, uint16_t interval) {
NOMORE(x, DWIN_WIDTH - 1);
NOMORE(y, DWIN_HEIGHT - 1); // -- ozy -- srl
size_t i = 0;
DWIN_Byte(i, 0x28);
DWIN_Word(i, x);
DWIN_Word(i, y);
// Bit 7: animation on or off
// Bit 6: start from begin or end
// Bit 5-4: unused (0)
// Bit 3-0: animID
DWIN_Byte(i, (animate * 0x80) | 0x40 | animID);
DWIN_Byte(i, libID);
DWIN_Byte(i, picIDs);
DWIN_Byte(i, picIDe);
DWIN_Byte(i, interval);
DWIN_Send(i);
}
// Animation Control
// state: 16 bits, each bit is the state of an animation id
void DWIN_ICON_AnimationControl(uint16_t state) {
size_t i = 0;
DWIN_Byte(i, 0x28);
DWIN_Word(i, state);
DWIN_Send(i);
}
/*---------------------------------------- Memory functions ----------------------------------------*/
// The LCD has an additional 32KB SRAM and 16KB Flash
// Data can be written to the sram and save to one of the jpeg page files
// Write Data Memory
// command 0x31
// Type: Write memory selection; 0x5A=SRAM; 0xA5=Flash
// Address: Write data memory address; 0x000-0x7FFF for SRAM; 0x000-0x3FFF for Flash
// Data: data
//
// Flash writing returns 0xA5 0x4F 0x4B
// Read Data Memory
// command 0x32
// Type: Read memory selection; 0x5A=SRAM; 0xA5=Flash
// Address: Read data memory address; 0x000-0x7FFF for SRAM; 0x000-0x3FFF for Flash
// Length: leangth of data to read; 0x01-0xF0
//
// Response:
// Type, Address, Length, Data
// Write Picture Memory
// Write the contents of the 32KB SRAM data memory into the designated image memory space
// Issued: 0x5A, 0xA5, PIC_ID
// Response: 0xA5 0x4F 0x4B
//
// command 0x33
// 0x5A, 0xA5
// PicId: Picture Memory location, 0x00-0x0F
//
// Flash writing returns 0xA5 0x4F 0x4B
#endif // DWIN_CREALITY_LCD_JYERSUI

View File

@ -26,190 +26,9 @@
* @brief DWIN screen control functions
********************************************************************************/
#include <stdint.h>
#include "../common/dwin_api.h"
#define RECEIVED_NO_DATA 0x00
#define RECEIVED_SHAKE_HAND_ACK 0x01
#define FHONE 0xAA
#define DWIN_SCROLL_UP 2
#define DWIN_SCROLL_DOWN 3
#define DWIN_WIDTH 272
#define DWIN_HEIGHT 480
/*-------------------------------------- System variable function --------------------------------------*/
// Handshake (1: Success, 0: Fail)
bool DWIN_Handshake(void);
// Set the backlight luminance
// luminance: (0x00-0xFF)
void DWIN_Backlight_SetLuminance(const uint8_t luminance);
// Set screen display direction
// dir: 0=0°, 1=90°, 2=180°, 3=270°
void DWIN_Frame_SetDir(uint8_t dir);
// Update display
void DWIN_UpdateLCD(void);
/*---------------------------------------- Drawing functions ----------------------------------------*/
// Clear screen
// color: Clear screen color
void DWIN_Frame_Clear(const uint16_t color);
// Draw a point
// color: Line segment color
// width: point width 0x01-0x0F
// height: point height 0x01-0x0F
// x,y: upper left point
void DWIN_Draw_Point(uint16_t color, uint8_t width, uint8_t height, uint16_t x, uint16_t y);
// Draw a line
// color: Line segment color
// xStart/yStart: Start point
// xEnd/yEnd: End point
void DWIN_Draw_Line(uint16_t color, uint16_t xStart, uint16_t yStart, uint16_t xEnd, uint16_t yEnd);
// Draw a Horizontal line
// color: Line segment color
// xStart/yStart: Start point
// xLength: Line Length
inline void DWIN_Draw_HLine(uint16_t color, uint16_t xStart, uint16_t yStart, uint16_t xLength) {
DWIN_Draw_Line(color, xStart, yStart, xStart + xLength - 1, yStart);
}
// Draw a Vertical line
// color: Line segment color
// xStart/yStart: Start point
// yLength: Line Length
inline void DWIN_Draw_VLine(uint16_t color, uint16_t xStart, uint16_t yStart, uint16_t yLength) {
DWIN_Draw_Line(color, xStart, yStart, xStart, yStart + yLength - 1);
}
// Draw a rectangle
// mode: 0=frame, 1=fill, 2=XOR fill
// color: Rectangle color
// xStart/yStart: upper left point
// xEnd/yEnd: lower right point
void DWIN_Draw_Rectangle(uint8_t mode, uint16_t color,
uint16_t xStart, uint16_t yStart, uint16_t xEnd, uint16_t yEnd);
// Draw a box
// mode: 0=frame, 1=fill, 2=XOR fill
// color: Rectangle color
// xStart/yStart: upper left point
// xSize/ySize: box size
inline void DWIN_Draw_Box(uint8_t mode, uint16_t color, uint16_t xStart, uint16_t yStart, uint16_t xSize, uint16_t ySize) {
DWIN_Draw_Rectangle(mode, color, xStart, yStart, xStart + xSize - 1, yStart + ySize - 1);
}
//Color: color
//x: upper left point
//y: bottom right point
// Draw the degree (°) symbol
// Color: color
// x/y: Upper-left coordinate of the first pixel
void DWIN_Draw_DegreeSymbol(uint16_t Color, uint16_t x, uint16_t y);
// Move a screen area
// mode: 0, circle shift; 1, translation
// dir: 0=left, 1=right, 2=up, 3=down
// dis: Distance
// color: Fill color
// xStart/yStart: upper left point
// xEnd/yEnd: bottom right point
void DWIN_Frame_AreaMove(uint8_t mode, uint8_t dir, uint16_t dis,
uint16_t color, uint16_t xStart, uint16_t yStart, uint16_t xEnd, uint16_t yEnd);
/*---------------------------------------- Text related functions ----------------------------------------*/
// Draw a string
// widthAdjust: true=self-adjust character width; false=no adjustment
// bShow: true=display background color; false=don't display background color
// size: Font size
// color: Character color
// bColor: Background color
// x/y: Upper-left coordinate of the string
// *string: The string
void DWIN_Draw_String(bool widthAdjust, bool bShow, uint8_t size,
uint16_t color, uint16_t bColor, uint16_t x, uint16_t y, const char * string);
class __FlashStringHelper;
inline void DWIN_Draw_String(bool widthAdjust, bool bShow, uint8_t size, uint16_t color, uint16_t bColor, uint16_t x, uint16_t y, const __FlashStringHelper *title) {
// Note that this won't work on AVR. This is for 32-bit systems only!
// Are __FlashStringHelper versions worth keeping?
DWIN_Draw_String(widthAdjust, bShow, size, color, bColor, x, y, reinterpret_cast<const char*>(title));
}
// Draw a positive integer
// bShow: true=display background color; false=don't display background color
// zeroFill: true=zero fill; false=no zero fill
// zeroMode: 1=leading 0 displayed as 0; 0=leading 0 displayed as a space
// size: Font size
// color: Character color
// bColor: Background color
// iNum: Number of digits
// x/y: Upper-left coordinate
// value: Integer value
void DWIN_Draw_IntValue(uint8_t bShow, bool zeroFill, uint8_t zeroMode, uint8_t size, uint16_t color,
uint16_t bColor, uint8_t iNum, uint16_t x, uint16_t y, uint16_t value);
// Draw a floating point number
// bShow: true=display background color; false=don't display background color
// zeroFill: true=zero fill; false=no zero fill
// zeroMode: 1=leading 0 displayed as 0; 0=leading 0 displayed as a space
// size: Font size
// color: Character color
// bColor: Background color
// iNum: Number of whole digits
// fNum: Number of decimal digits
// x/y: Upper-left point
// value: Float value
void DWIN_Draw_FloatValue(uint8_t bShow, bool zeroFill, uint8_t zeroMode, uint8_t size, uint16_t color,
uint16_t bColor, uint8_t iNum, uint8_t fNum, uint16_t x, uint16_t y, long value);
/*---------------------------------------- Picture related functions ----------------------------------------*/
// Draw JPG and cached in #0 virtual display area
// id: Picture ID
void DWIN_JPG_ShowAndCache(const uint8_t id);
// Draw an Icon
// libID: Icon library ID
// picID: Icon ID
// x/y: Upper-left point
void DWIN_ICON_Show(uint8_t libID, uint8_t picID, uint16_t x, uint16_t y);
// Unzip the JPG picture to a virtual display area
// n: Cache index
// id: Picture ID
void DWIN_JPG_CacheToN(uint8_t n, uint8_t id);
// Unzip the JPG picture to virtual display area #1
// id: Picture ID
inline void DWIN_JPG_CacheTo1(uint8_t id) { DWIN_JPG_CacheToN(1, id); }
// Copy area from virtual display area to current screen
// cacheID: virtual area number
// xStart/yStart: Upper-left of virtual area
// xEnd/yEnd: Lower-right of virtual area
// x/y: Screen paste point
void DWIN_Frame_AreaCopy(uint8_t cacheID, uint16_t xStart, uint16_t yStart,
uint16_t xEnd, uint16_t yEnd, uint16_t x, uint16_t y);
// Animate a series of icons
// animID: Animation ID up to 16
// animate: animation on or off
// libID: Icon library ID
// picIDs: Icon starting ID
// picIDe: Icon ending ID
// x/y: Upper-left point
// interval: Display time interval, unit 10mS
void DWIN_ICON_Animation(uint8_t animID, bool animate, uint8_t libID, uint8_t picIDs,
uint8_t picIDe, uint16_t x, uint16_t y, uint16_t interval);
// Animation Control
// state: 16 bits, each bit is the state of an animation id
void DWIN_ICON_AnimationControl(uint16_t state);

View File

@ -1,263 +0,0 @@
/**
* Marlin 3D Printer Firmware
* Copyright (c) 2021 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
/*****************************************************************************
* @file lcd/e3v2/jyersui/rotary_encoder.cpp
* @brief Rotary encoder functions
*****************************************************************************/
#include "../../../inc/MarlinConfigPre.h"
#if ENABLED(DWIN_CREALITY_LCD_JYERSUI)
#include "rotary_encoder.h"
#include "../../buttons.h"
#include "../../../MarlinCore.h"
#include "../../marlinui.h"
#include "../../../HAL/shared/Delay.h"
#if HAS_BUZZER
#include "../../../libs/buzzer.h"
#include "dwin.h"
#endif
#include <stdlib.h>
#ifndef ENCODER_PULSES_PER_STEP
#define ENCODER_PULSES_PER_STEP 4
#endif
ENCODER_Rate EncoderRate;
// Buzzer
void Encoder_tick() {
#if PIN_EXISTS(BEEPER)
if (CrealityDWIN.eeprom_settings.beeperenable) {
WRITE(BEEPER_PIN, HIGH);
delay(10);
WRITE(BEEPER_PIN, LOW);
}
#endif
}
// Encoder initialization
void Encoder_Configuration() {
#if BUTTON_EXISTS(EN1)
SET_INPUT_PULLUP(BTN_EN1);
#endif
#if BUTTON_EXISTS(EN2)
SET_INPUT_PULLUP(BTN_EN2);
#endif
#if BUTTON_EXISTS(ENC)
SET_INPUT_PULLUP(BTN_ENC);
#endif
#if PIN_EXISTS(BEEPER)
SET_OUTPUT(BEEPER_PIN);
#endif
}
// Analyze encoder value and return state
ENCODER_DiffState Encoder_ReceiveAnalyze() {
const millis_t now = millis();
static uint8_t lastEncoderBits;
uint8_t newbutton = 0;
static signed char temp_diff = 0;
ENCODER_DiffState temp_diffState = ENCODER_DIFF_NO;
if (BUTTON_PRESSED(EN1)) newbutton |= EN_A;
if (BUTTON_PRESSED(EN2)) newbutton |= EN_B;
if (BUTTON_PRESSED(ENC)) {
static millis_t next_click_update_ms;
if (ELAPSED(now, next_click_update_ms)) {
next_click_update_ms = millis() + 300;
Encoder_tick();
#if PIN_EXISTS(LCD_LED)
//LED_Action();
#endif
if (ui.backlight) return ENCODER_DIFF_ENTER;
ui.refresh_brightness();
}
else return ENCODER_DIFF_NO;
}
if (newbutton != lastEncoderBits) {
switch (newbutton) {
case ENCODER_PHASE_0:
if (lastEncoderBits == ENCODER_PHASE_3) temp_diff++;
else if (lastEncoderBits == ENCODER_PHASE_1) temp_diff--;
break;
case ENCODER_PHASE_1:
if (lastEncoderBits == ENCODER_PHASE_0) temp_diff++;
else if (lastEncoderBits == ENCODER_PHASE_2) temp_diff--;
break;
case ENCODER_PHASE_2:
if (lastEncoderBits == ENCODER_PHASE_1) temp_diff++;
else if (lastEncoderBits == ENCODER_PHASE_3) temp_diff--;
break;
case ENCODER_PHASE_3:
if (lastEncoderBits == ENCODER_PHASE_2) temp_diff++;
else if (lastEncoderBits == ENCODER_PHASE_0) temp_diff--;
break;
}
lastEncoderBits = newbutton;
}
if (ABS(temp_diff) >= ENCODER_PULSES_PER_STEP) {
#if ENABLED(REVERSE_ENCODER_DIRECTION)
if (temp_diff > 0) temp_diffState = ENCODER_DIFF_CCW;
else temp_diffState = ENCODER_DIFF_CW;
#else
if (temp_diff > 0) temp_diffState = ENCODER_DIFF_CW;
else temp_diffState = ENCODER_DIFF_CCW;
#endif
#if ENABLED(ENCODER_RATE_MULTIPLIER)
millis_t ms = millis();
int32_t encoderMultiplier = 1;
// if must encoder rati multiplier
if (EncoderRate.enabled) {
const float abs_diff = ABS(temp_diff),
encoderMovementSteps = abs_diff / (ENCODER_PULSES_PER_STEP);
if (EncoderRate.lastEncoderTime) {
// Note that the rate is always calculated between two passes through the
// loop and that the abs of the temp_diff value is tracked.
const float encoderStepRate = encoderMovementSteps / float(ms - EncoderRate.lastEncoderTime) * 1000;
if (encoderStepRate >= ENCODER_100X_STEPS_PER_SEC) encoderMultiplier = 100;
else if (encoderStepRate >= ENCODER_10X_STEPS_PER_SEC) encoderMultiplier = 10;
#if ENCODER_5X_STEPS_PER_SEC
else if (encoderStepRate >= ENCODER_5X_STEPS_PER_SEC) encoderMultiplier = 5;
#endif
}
EncoderRate.lastEncoderTime = ms;
}
#else
constexpr int32_t encoderMultiplier = 1;
#endif
// EncoderRate.encoderMoveValue += (temp_diff * encoderMultiplier) / (ENCODER_PULSES_PER_STEP);
EncoderRate.encoderMoveValue = (temp_diff * encoderMultiplier) / (ENCODER_PULSES_PER_STEP);
if (EncoderRate.encoderMoveValue < 0) EncoderRate.encoderMoveValue = -EncoderRate.encoderMoveValue;
temp_diff = 0;
}
return temp_diffState;
}
#if PIN_EXISTS(LCD_LED)
// Take the low 24 valid bits 24Bit: G7 G6 G5 G4 G3 G2 G1 G0 R7 R6 R5 R4 R3 R2 R1 R0 B7 B6 B5 B4 B3 B2 B1 B0
uint16_t LED_DataArray[LED_NUM];
// LED light operation
void LED_Action() {
LED_Control(RGB_SCALE_WARM_WHITE,0x0F);
delay(30);
LED_Control(RGB_SCALE_WARM_WHITE,0x00);
}
// LED initialization
void LED_Configuration() {
SET_OUTPUT(LCD_LED_PIN);
}
// LED write data
void LED_WriteData() {
uint8_t tempCounter_LED, tempCounter_Bit;
for (tempCounter_LED = 0; tempCounter_LED < LED_NUM; tempCounter_LED++) {
for (tempCounter_Bit = 0; tempCounter_Bit < 24; tempCounter_Bit++) {
if (LED_DataArray[tempCounter_LED] & (0x800000 >> tempCounter_Bit)) {
LED_DATA_HIGH;
DELAY_NS(300);
LED_DATA_LOW;
DELAY_NS(200);
}
else {
LED_DATA_HIGH;
LED_DATA_LOW;
DELAY_NS(200);
}
}
}
}
// LED control
// RGB_Scale: RGB color ratio
// luminance: brightness (0~0xFF)
void LED_Control(const uint8_t RGB_Scale, const uint8_t luminance) {
for (uint8_t i = 0; i < LED_NUM; i++) {
LED_DataArray[i] = 0;
switch (RGB_Scale) {
case RGB_SCALE_R10_G7_B5: LED_DataArray[i] = (luminance * 10/10) << 8 | (luminance * 7/10) << 16 | luminance * 5/10; break;
case RGB_SCALE_R10_G7_B4: LED_DataArray[i] = (luminance * 10/10) << 8 | (luminance * 7/10) << 16 | luminance * 4/10; break;
case RGB_SCALE_R10_G8_B7: LED_DataArray[i] = (luminance * 10/10) << 8 | (luminance * 8/10) << 16 | luminance * 7/10; break;
}
}
LED_WriteData();
}
// LED gradient control
// RGB_Scale: RGB color ratio
// luminance: brightness (0~0xFF)
// change_Time: gradient time (ms)
void LED_GraduallyControl(const uint8_t RGB_Scale, const uint8_t luminance, const uint16_t change_Interval) {
struct { uint8_t g, r, b; } led_data[LED_NUM];
for (uint8_t i = 0; i < LED_NUM; i++) {
switch (RGB_Scale) {
case RGB_SCALE_R10_G7_B5:
led_data[i] = { luminance * 7/10, luminance * 10/10, luminance * 5/10 };
break;
case RGB_SCALE_R10_G7_B4:
led_data[i] = { luminance * 7/10, luminance * 10/10, luminance * 4/10 };
break;
case RGB_SCALE_R10_G8_B7:
led_data[i] = { luminance * 8/10, luminance * 10/10, luminance * 7/10 };
break;
}
}
struct { bool g, r, b; } led_flag = { false, false, false };
for (uint8_t i = 0; i < LED_NUM; i++) {
while (1) {
const uint8_t g = uint8_t(LED_DataArray[i] >> 16),
r = uint8_t(LED_DataArray[i] >> 8),
b = uint8_t(LED_DataArray[i]);
if (g == led_data[i].g) led_flag.g = true;
else LED_DataArray[i] += (g > led_data[i].g) ? -0x010000 : 0x010000;
if (r == led_data[i].r) led_flag.r = true;
else LED_DataArray[i] += (r > led_data[i].r) ? -0x000100 : 0x000100;
if (b == led_data[i].b) led_flag.b = true;
else LED_DataArray[i] += (b > led_data[i].b) ? -0x000001 : 0x000001;
LED_WriteData();
if (led_flag.r && led_flag.g && led_flag.b) break;
delay(change_Interval);
}
}
}
#endif // LCD_LED
#endif // DWIN_CREALITY_LCD_JYERSUI

View File

@ -1,91 +0,0 @@
/**
* Marlin 3D Printer Firmware
* Copyright (c) 2021 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
#pragma once
/*****************************************************************************
* @file lcd/e3v2/jyersui/rotary_encoder.h
* @brief Rotary encoder functions
****************************************************************************/
#include "../../../inc/MarlinConfig.h"
/*********************** Encoder Set ***********************/
typedef struct {
bool enabled = false;
int encoderMoveValue = 0;
millis_t lastEncoderTime = 0;
} ENCODER_Rate;
extern ENCODER_Rate EncoderRate;
typedef enum {
ENCODER_DIFF_NO = 0, // no state
ENCODER_DIFF_CW = 1, // clockwise rotation
ENCODER_DIFF_CCW = 2, // counterclockwise rotation
ENCODER_DIFF_ENTER = 3 // click
} ENCODER_DiffState;
// Encoder initialization
void Encoder_Configuration();
// Analyze encoder value and return state
ENCODER_DiffState Encoder_ReceiveAnalyze();
/*********************** Encoder LED ***********************/
#if PIN_EXISTS(LCD_LED)
#define LED_NUM 4
#define LED_DATA_HIGH WRITE(LCD_LED_PIN, 1)
#define LED_DATA_LOW WRITE(LCD_LED_PIN, 0)
#define RGB_SCALE_R10_G7_B5 1
#define RGB_SCALE_R10_G7_B4 2
#define RGB_SCALE_R10_G8_B7 3
#define RGB_SCALE_NEUTRAL_WHITE RGB_SCALE_R10_G7_B5
#define RGB_SCALE_WARM_WHITE RGB_SCALE_R10_G7_B4
#define RGB_SCALE_COOL_WHITE RGB_SCALE_R10_G8_B7
extern unsigned int LED_DataArray[LED_NUM];
// LED light operation
void LED_Action();
// LED initialization
void LED_Configuration();
// LED write data
void LED_WriteData();
// LED control
// RGB_Scale: RGB color ratio
// luminance: brightness (0~0xFF)
void LED_Control(const uint8_t RGB_Scale, const uint8_t luminance);
// LED gradient control
// RGB_Scale: RGB color ratio
// luminance: brightness (0~0xFF)
// change_Time: gradient time (ms)
void LED_GraduallyControl(const uint8_t RGB_Scale, const uint8_t luminance, const uint16_t change_Interval);
#endif // LCD_LED