From 3d29f79323897824740a153f22f08463c8f0a3a7 Mon Sep 17 00:00:00 2001 From: Luc Date: Sun, 21 Apr 2024 14:59:22 +0800 Subject: [PATCH] Code base for grbl Remove any reference to 3D printer elements Rename bed to workspace --- CMakeLists.txt | 4 +- .../cnc/grbl/screens/auto_leveling_screen.cpp | 302 ------- .../cnc/grbl/screens/auto_leveling_screen.h | 26 - .../cnc/grbl/screens/esp3d_screen_type.h | 13 +- main/display/cnc/grbl/screens/fan_screen.cpp | 434 ---------- main/display/cnc/grbl/screens/fan_screen.h | 27 - .../cnc/grbl/screens/filament_screen.cpp | 440 ----------- .../cnc/grbl/screens/filament_screen.h | 30 - .../cnc/grbl/screens/leveling_screen.cpp | 150 ---- .../cnc/grbl/screens/leveling_screen.h | 24 - main/display/cnc/grbl/screens/main_screen.cpp | 400 +--------- main/display/cnc/grbl/screens/main_screen.h | 13 - .../grbl/screens/manual_leveling_screen.cpp | 455 ----------- .../cnc/grbl/screens/manual_leveling_screen.h | 28 - main/display/cnc/grbl/screens/menu_screen.cpp | 114 +-- main/display/cnc/grbl/screens/menu_screen.h | 1 - .../cnc/grbl/screens/positions_screen.cpp | 500 ------------ .../cnc/grbl/screens/positions_screen.h | 32 - .../cnc/grbl/screens/settings_screen.cpp | 157 +--- .../display/cnc/grbl/screens/speed_screen.cpp | 288 ------- main/display/cnc/grbl/screens/speed_screen.h | 28 - .../cnc/grbl/screens/temperatures_screen.cpp | 746 ------------------ .../cnc/grbl/screens/temperatures_screen.h | 35 - .../cnc/grbl/esp3d_gcode_parser_service.cpp | 552 ++++++------- main/target/cnc/grbl/esp3d_settings.cpp | 12 +- main/target/cnc/grbl/esp3d_settings.h | 6 +- .../cnc/grbl/esp3d_translations_init.cpp | 14 +- .../target/cnc/grbl/esp3d_translations_list.h | 8 +- main/target/cnc/grbl/esp3d_values.cpp | 156 +--- main/target/cnc/grbl/esp3d_values_list.h | 11 +- 30 files changed, 425 insertions(+), 4581 deletions(-) delete mode 100644 main/display/cnc/grbl/screens/auto_leveling_screen.cpp delete mode 100644 main/display/cnc/grbl/screens/auto_leveling_screen.h delete mode 100644 main/display/cnc/grbl/screens/fan_screen.cpp delete mode 100644 main/display/cnc/grbl/screens/fan_screen.h delete mode 100644 main/display/cnc/grbl/screens/filament_screen.cpp delete mode 100644 main/display/cnc/grbl/screens/filament_screen.h delete mode 100644 main/display/cnc/grbl/screens/leveling_screen.cpp delete mode 100644 main/display/cnc/grbl/screens/leveling_screen.h delete mode 100644 main/display/cnc/grbl/screens/manual_leveling_screen.cpp delete mode 100644 main/display/cnc/grbl/screens/manual_leveling_screen.h delete mode 100644 main/display/cnc/grbl/screens/positions_screen.cpp delete mode 100644 main/display/cnc/grbl/screens/positions_screen.h delete mode 100644 main/display/cnc/grbl/screens/speed_screen.cpp delete mode 100644 main/display/cnc/grbl/screens/speed_screen.h delete mode 100644 main/display/cnc/grbl/screens/temperatures_screen.cpp delete mode 100644 main/display/cnc/grbl/screens/temperatures_screen.h diff --git a/CMakeLists.txt b/CMakeLists.txt index af5f0530..73fbe2db 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -39,10 +39,10 @@ OPTION(HARDWARE_MOD_EXT_PSRAM "Hardware Mod: External PSRAM" OFF) # ####################################### # Select one targeted firmware # ####################################### -OPTION(TARGET_FW_MARLIN "Marlin firmware" ON) +OPTION(TARGET_FW_MARLIN "Marlin firmware" OFF) OPTION(TARGET_FW_REPETIER "Repetier firmware" OFF) OPTION(TARGET_FW_SMOOTHIEWARE "Smoothieware firmware" OFF) -OPTION(TARGET_FW_GRBL "GRBL firmware" OFF) +OPTION(TARGET_FW_GRBL "GRBL firmware" ON) # ####################################### diff --git a/main/display/cnc/grbl/screens/auto_leveling_screen.cpp b/main/display/cnc/grbl/screens/auto_leveling_screen.cpp deleted file mode 100644 index 283748a1..00000000 --- a/main/display/cnc/grbl/screens/auto_leveling_screen.cpp +++ /dev/null @@ -1,302 +0,0 @@ -/* - esp3d_tft - - Copyright (c) 2022 Luc Lebosse. All rights reserved. - - This code is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This code 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#include "screens/auto_leveling_screen.h" - -#include - -#include "components/back_button_component.h" -#include "components/symbol_button_component.h" -#include "esp3d_log.h" -#include "esp3d_string.h" -#include "esp3d_styles.h" -#include "esp3d_tft_ui.h" -#include "screens/leveling_screen.h" -#include "rendering/esp3d_rendering_client.h" -#include "translations/esp3d_translation_service.h" - -/* -Command -G29 V4 -*/ -/* -Response: -G29 Auto Bed Leveling -Bed X: 50.000 Y: 50.000 Z: -0.013 -Bed X: 133.000 Y: 50.000 Z: 0.009 -Bed X: 216.000 Y: 50.000 Z: -0.020 -Bed X: 299.000 Y: 50.000 Z: -0.056 -Bed X: 299.000 Y: 133.000 Z: -0.010 -Bed X: 216.000 Y: 133.000 Z: -0.055 -Bed X: 133.000 Y: 133.000 Z: -0.040 -Bed X: 50.000 Y: 133.000 Z: -0.049 -Bed X: 50.000 Y: 216.000 Z: -0.055 -Bed X: 133.000 Y: 216.000 Z: 0.044 -Bed X: 216.000 Y: 216.000 Z: 0.044 -Bed X: 299.000 Y: 216.000 Z: 0.025 -Bed X: 299.000 Y: 299.000 Z: -0.023 -Bed X: 216.000 Y: 299.000 Z: -0.058 -Bed X: 133.000 Y: 299.000 Z: -0.036 -Bed X: 50.000 Y: 299.000 Z: -0.054 -Bilinear Leveling Grid: - 0 1 2 3 - 0 -0.0125 +0.0087 -0.0200 -0.0563 - 1 -0.0488 -0.0400 -0.0550 -0.0100 - 2 -0.0550 +0.0437 +0.0437 +0.0250 - 3 -0.0538 -0.0363 -0.0575 -0.0225 -echo:enqueueing "G0 F3600 X180 Y180" -echo:Settings Stored (526 bytes; crc 45727) -X:50.00 Y:299.00 Z:13.55 E:0.00 Count X:4000 Y:23920 Z:10800 -ok -*/ - -/********************** - * STATIC PROTOTYPES - **********************/ -namespace autoLevelingScreen { -lv_timer_t *auto_leveling_screen_delay_timer = NULL; -lv_timer_t *auto_leveling_screen_probe_delay_timer = NULL; -bool auto_leveling_started = false; -lv_obj_t *auto_leveling_screen_table = NULL; -lv_obj_t *btn_back = NULL; -lv_obj_t *btn_start = NULL; -lv_obj_t *label_status = nullptr; -bool homing_done = false; - -double get_value(const char *str, const char *value) { - char *pstr = strstr(str, value); - if (pstr == NULL) return 0; - pstr += strlen(value); - double val = strtod(pstr, NULL); - return val; -} - -void auto_leveling_screen_probe_delay_timer_cb(lv_timer_t *timer) { - if (esp3dTftui.get_current_screen() != ESP3DScreenType::auto_leveling) { - return; - } - if (auto_leveling_screen_probe_delay_timer) { - lv_timer_del(auto_leveling_screen_probe_delay_timer); - auto_leveling_screen_probe_delay_timer = NULL; - } - const char *text = (const char *)timer->user_data; - esp3d_log("Update status %s", text); - lv_label_set_text(label_status, text); -} - -bool auto_leveling_value_cb(ESP3DValuesIndex index, const char *value, - ESP3DValuesCbAction action) { - static uint8_t col = 0; - static uint8_t row = 0; - static double x = 0; - static double y = 0; - static uint8_t nb_points = 0; - if (esp3dTftui.get_current_screen() != ESP3DScreenType::auto_leveling) { - return false; - } - if (index == ESP3DValuesIndex::bed_leveling) { - if (action == ESP3DValuesCbAction::Add) { - esp3d_log("Start auto leveling"); - auto_leveling_started = true; - nb_points = 0; - std::string text = - esp3dTranslationService.translate(ESP3DLabel::start_probing); - lv_label_set_text(label_status, text.c_str()); - return true; - } else if (action == ESP3DValuesCbAction::Delete) { - esp3d_log("Stop auto leveling"); - if (auto_leveling_started) { - lv_label_set_text(label_status, ""); - lv_obj_clear_flag(btn_start, LV_OBJ_FLAG_HIDDEN); - } - auto_leveling_started = false; - return true; - } else if (action == ESP3DValuesCbAction::Update && auto_leveling_started) { - esp3d_log("Collect auto leveling data"); - double new_x = get_value(value, "X:"); - double new_y = get_value(value, "Y:"); - double z = get_value(value, "Z:"); - esp3d_log("Got X: %f Y: %f Z: %f", new_x, new_y, z); - int8_t max_col = -1; - if (nb_points == 0) { - col = 0; - row = 0; - x = new_x; - y = new_y; - } else { - if (new_x == x) { - if (max_col == -1 && col > 0) { - esp3d_log("Max col found is:%d", max_col); - max_col = col; - } - if (new_y > y) { - row++; - } else { - row--; - } - } else { - if (new_x > x) { - col++; - if (row == 0) { - lv_table_set_col_cnt(auto_leveling_screen_table, col + 1); - for (uint8_t i = 0; i <= col; i++) { - lv_table_set_col_width( - auto_leveling_screen_table, i, - ((LV_HOR_RES) - (2 * CURRENT_BUTTON_PRESSED_OUTLINE)) / - (col + 1)); - } - } - } else { - col--; - } - } - x = new_x; - y = new_y; - } - - std::string str = esp3d_string::set_precision(std::to_string(z), 3); - esp3d_log_w("Row: %d Col: %d Z: %f , string: %s", row, col, z, - str.c_str()); - lv_table_set_cell_value(auto_leveling_screen_table, row, col, - str.c_str()); - static std::string text; - - text = esp3dTranslationService.translate( - ESP3DLabel::auto_bed_probing, std::to_string(nb_points + 1).c_str()); - auto_leveling_screen_probe_delay_timer = lv_timer_create( - auto_leveling_screen_probe_delay_timer_cb, 1, (void *)text.c_str()); - - if (max_col != -1 && col == max_col && row == 1) { - esp3d_log( - "Max col found is:%d, col wdith:%d", max_col, - ((LV_HOR_RES) - (2 * CURRENT_BUTTON_PRESSED_OUTLINE)) / max_col); - lv_table_set_col_cnt(auto_leveling_screen_table, max_col + 1); - - for (uint8_t i = 0; i <= max_col; i++) { - lv_table_set_col_width( - auto_leveling_screen_table, i, - ((LV_HOR_RES) - (2 * CURRENT_BUTTON_PRESSED_OUTLINE)) / - (max_col + 1)); - } - } - nb_points++; - - return true; - } - } - esp3d_log("auto_leveling_value_cb %d, action: %d, value: %s", (uint16_t)index, - (uint16_t)action, value); - return false; -} - -void auto_leveling_screen_delay_timer_cb(lv_timer_t *timer) { - if (auto_leveling_screen_delay_timer) { - lv_timer_del(auto_leveling_screen_delay_timer); - auto_leveling_screen_delay_timer = NULL; - } - if (auto_leveling_started) { - auto_leveling_started = false; - // TODO send abort command if any and if supported / have emergency parser - // available - } - if (auto_leveling_screen_probe_delay_timer) { - lv_timer_del(auto_leveling_screen_probe_delay_timer); - auto_leveling_screen_probe_delay_timer = NULL; - } - lv_obj_clear_flag(btn_start, LV_OBJ_FLAG_HIDDEN); - levelingScreen::leveling_screen(true); -} - -void event_button_auto_leveling_start_handler(lv_event_t *e) { - esp3d_log("start Clicked"); - if (auto_leveling_started) return; - if (!homing_done) { - renderingClient.sendGcode("G28"); - homing_done = true; - } - esp3d_log("start leveling"); - lv_obj_add_flag(btn_start, LV_OBJ_FLAG_HIDDEN); - // clear table - // set one row - lv_table_set_row_cnt(auto_leveling_screen_table, 0); - - renderingClient.sendGcode("G29 V4"); -} - -void event_button_fan_back_handler(lv_event_t *e) { - esp3d_log("back Clicked"); - if (BUTTON_ANIMATION_DELAY) { - if (auto_leveling_screen_delay_timer) return; - auto_leveling_screen_delay_timer = lv_timer_create( - auto_leveling_screen_delay_timer_cb, BUTTON_ANIMATION_DELAY, NULL); - } else { - auto_leveling_screen_delay_timer_cb(NULL); - } -} - -void auto_leveling_screen() { - esp3dTftui.set_current_screen(ESP3DScreenType::none); - // Screen creation - esp3d_log("Auto leveling screen creation"); - lv_obj_t *ui_new_screen = lv_obj_create(NULL); - // Display new screen and delete old one - lv_obj_t *ui_current_screen = lv_scr_act(); - lv_scr_load(ui_new_screen); - apply_style(ui_new_screen, ESP3DStyleType::main_bg); - lv_obj_del(ui_current_screen); - - homing_done = false; - btn_back = backButton::create_back_button(ui_new_screen); - lv_obj_add_event_cb(btn_back, event_button_fan_back_handler, LV_EVENT_CLICKED, - NULL); - lv_obj_update_layout(btn_back); - // Create a table - auto_leveling_screen_table = lv_table_create(ui_new_screen); - lv_obj_set_size(auto_leveling_screen_table, - (LV_HOR_RES) - (2 * CURRENT_BUTTON_PRESSED_OUTLINE), - LV_VER_RES - (3 * CURRENT_BUTTON_PRESSED_OUTLINE) - - lv_obj_get_height(btn_back)); - lv_obj_set_pos(auto_leveling_screen_table, CURRENT_BUTTON_PRESSED_OUTLINE, - CURRENT_BUTTON_PRESSED_OUTLINE); - lv_obj_clear_flag(auto_leveling_screen_table, LV_OBJ_FLAG_SCROLL_ELASTIC); - lv_obj_set_style_radius(auto_leveling_screen_table, - CURRENT_BUTTON_RADIUS_VALUE, 0); - // button start - btn_start = symbolButton::create_symbol_button( - ui_new_screen, LV_SYMBOL_PLAY, BACK_BUTTON_WIDTH, BACK_BUTTON_HEIGHT); - lv_obj_align_to(btn_start, auto_leveling_screen_table, - LV_ALIGN_OUT_BOTTOM_MID, 0, CURRENT_BUTTON_PRESSED_OUTLINE); - - lv_obj_add_event_cb(btn_start, event_button_auto_leveling_start_handler, - LV_EVENT_CLICKED, NULL); - - label_status = lv_label_create(ui_new_screen); - apply_style(label_status, ESP3DStyleType::bg_label); - lv_label_set_text(label_status, ""); - lv_obj_align_to(label_status, auto_leveling_screen_table, - LV_ALIGN_OUT_BOTTOM_LEFT, 0, CURRENT_BUTTON_PRESSED_OUTLINE); - lv_obj_set_width(label_status, LV_HOR_RES - - (3 * CURRENT_BUTTON_PRESSED_OUTLINE) - - lv_obj_get_width(btn_start)); - lv_label_set_long_mode(label_status, LV_LABEL_LONG_SCROLL_CIRCULAR); - esp3dTftui.set_current_screen(ESP3DScreenType::auto_leveling); -} - -} // namespace autoLevelingScreen \ No newline at end of file diff --git a/main/display/cnc/grbl/screens/auto_leveling_screen.h b/main/display/cnc/grbl/screens/auto_leveling_screen.h deleted file mode 100644 index d4a6d9e1..00000000 --- a/main/display/cnc/grbl/screens/auto_leveling_screen.h +++ /dev/null @@ -1,26 +0,0 @@ -/* - auto_leveling__screen.h - esp3d - Copyright (c) 2022 Luc Lebosse. All rights reserved. - - This code is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This code 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#pragma once -#include "esp3d_values.h" -namespace autoLevelingScreen { -extern void auto_leveling_screen(); -extern bool auto_leveling_value_cb(ESP3DValuesIndex index, const char *value, - ESP3DValuesCbAction action); -} // namespace autoLevelingScreen diff --git a/main/display/cnc/grbl/screens/esp3d_screen_type.h b/main/display/cnc/grbl/screens/esp3d_screen_type.h index 1d328fb8..9d104cad 100644 --- a/main/display/cnc/grbl/screens/esp3d_screen_type.h +++ b/main/display/cnc/grbl/screens/esp3d_screen_type.h @@ -27,20 +27,17 @@ enum class ESP3DScreenType : uint8_t { splash, main, status_list, - temperatures, - positions, files, - fan, - speed, settings, wifi, - leveling, - filament, menu, informations, station, access_point, - manual_leveling, - auto_leveling, + positions, + probing, + milling, + laser, + overload, empty }; diff --git a/main/display/cnc/grbl/screens/fan_screen.cpp b/main/display/cnc/grbl/screens/fan_screen.cpp deleted file mode 100644 index d31ad5e4..00000000 --- a/main/display/cnc/grbl/screens/fan_screen.cpp +++ /dev/null @@ -1,434 +0,0 @@ -/* - esp3d_tft - - Copyright (c) 2022 Luc Lebosse. All rights reserved. - - This code is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This code 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#include "screens/fan_screen.h" - -#include - -#include "components/back_button_component.h" -#include "components/symbol_button_component.h" -#include "esp3d_log.h" -#include "esp3d_string.h" -#include "esp3d_styles.h" -#include "esp3d_tft_ui.h" -#include "screens/main_screen.h" -#include "rendering/esp3d_rendering_client.h" - -/********************** - * STATIC PROTOTYPES - **********************/ -namespace fanScreen { -std::string fan_value = "0"; -const char *fan_steps_buttons_map[] = {"1", "5", "10", "50", ""}; -uint8_t fan_steps_buttons_map_id = 0; -lv_obj_t *label_current_fan_value = NULL; -lv_obj_t *btnm_target = NULL; -lv_obj_t *btnback = NULL; -lv_obj_t *label_current_fan = NULL; - -bool intialization_done = false; - -#define FAN_COUNT 2 -#define FAN_LABEL_SIZE 2 -uint8_t nb_fans = FAN_COUNT; -char *fan_buttons_map[FAN_COUNT + 1]; -uint8_t fan_buttons_map_id = 0; -const char *fan_buttons_label_map[FAN_COUNT] = {LV_SYMBOL_FAN "1", - LV_SYMBOL_FAN "2"}; - -lv_timer_t *fan_screen_delay_timer = NULL; - -uint8_t get_map_size() { - for (uint8_t i = 0; i < FAN_COUNT + 1; i++) { - if (strlen(fan_buttons_map[i]) == 0) { - return i; - } - } - esp3d_log("fan_buttons_map size is undefined"); - return 0; -} - -const char **get_fan_buttons_map() { - esp3d_log("get_fan_buttons_map"); - esp3d_log("fan_buttons_map size is : %d", get_map_size()); - - // if yes update - if (get_map_size() != nb_fans) { - esp3d_log("Update matrix buttons"); - // update matrix buttons - if (nb_fans == 1) { - strcpy(fan_buttons_map[1], ""); - } else { - strcpy(fan_buttons_map[1], fan_buttons_label_map[1]); - } - } - esp3d_log("fan_buttons_map size is : %d", get_map_size()); - // then return - return (const char **)fan_buttons_map; -} - -bool updateBtnMatrix() { - // check if different from current - // if yes update - // then apply style - lv_btnmatrix_set_map(btnm_target, get_fan_buttons_map()); - apply_style(btnm_target, ESP3DStyleType::buttons_matrix); - lv_obj_update_layout(btnm_target); - size_t i = get_map_size(); - lv_obj_set_size(btnm_target, MATRIX_BUTTON_WIDTH * i, MATRIX_BUTTON_HEIGHT); - esp3d_log("child count: %d", i); - // lv_obj_add_state(obj, LV_STATE_DISABLED); - if (fan_buttons_map_id > i) fan_buttons_map_id = 0; - lv_btnmatrix_set_btn_ctrl(btnm_target, fan_buttons_map_id, - LV_BTNMATRIX_CTRL_CHECKED); - lv_obj_align_to(btnm_target, btnback, LV_ALIGN_OUT_LEFT_BOTTOM, - -CURRENT_BUTTON_PRESSED_OUTLINE, 0); - return true; -} - -void fan_screen_delay_timer_cb(lv_timer_t *timer) { - if (fan_screen_delay_timer) { - lv_timer_del(fan_screen_delay_timer); - fan_screen_delay_timer = NULL; - } - mainScreen::main_screen(); -} - -void event_button_fan_back_handler(lv_event_t *e) { - esp3d_log("back Clicked"); - if (BUTTON_ANIMATION_DELAY) { - if (fan_screen_delay_timer) return; - fan_screen_delay_timer = lv_timer_create(fan_screen_delay_timer_cb, - BUTTON_ANIMATION_DELAY, NULL); - } else { - fan_screen_delay_timer_cb(NULL); - } -} - -void send_gcode_fan() { - std::string fan_value_str = "M106 P"; - if (fan_buttons_map_id == 0) { - fan_value_str += "0 S"; - } else { - fan_value_str += "1 S"; - } - // convert % to 0-255 - double vfan = (std::stod(fan_value.c_str()) * 255) / 100; - fan_value_str += esp3d_string::set_precision(std::to_string(vfan), 0); - renderingClient.sendGcode(fan_value_str.c_str()); -} - -void fan_ta_event_cb(lv_event_t *e) { - lv_event_code_t code = lv_event_get_code(e); - lv_obj_t *ta = lv_event_get_target(e); - lv_obj_t *kb = (lv_obj_t *)lv_event_get_user_data(e); - if (code == LV_EVENT_FOCUSED || code == LV_EVENT_PRESSED) { - lv_keyboard_set_textarea(kb, ta); - lv_obj_add_state(ta, LV_STATE_FOCUSED); - lv_obj_clear_flag(kb, LV_OBJ_FLAG_HIDDEN); - lv_obj_set_scrollbar_mode(ta, LV_SCROLLBAR_MODE_AUTO); - } else if (code == LV_EVENT_DEFOCUSED || code == LV_EVENT_READY || - code == LV_EVENT_CANCEL) { - esp3d_log("Ready, Value: %s", lv_textarea_get_text(ta)); - lv_textarea_set_cursor_pos(ta, 0); - lv_obj_set_scrollbar_mode(ta, LV_SCROLLBAR_MODE_OFF); - lv_keyboard_set_textarea(kb, NULL); - lv_obj_add_flag(kb, LV_OBJ_FLAG_HIDDEN); - lv_obj_clear_state(ta, LV_STATE_FOCUSED); - fan_value = lv_textarea_get_text(ta); - if (std::atoi(fan_value.c_str()) > 100) { - lv_textarea_set_text(ta, "100"); - } - if (std::atoi(fan_value.c_str()) < 0) { - lv_textarea_set_text(ta, "0"); - } - if (fan_value.length() == 0) { - lv_textarea_set_text(ta, "1"); - } - } else if (code == LV_EVENT_VALUE_CHANGED) { - fan_value = lv_textarea_get_text(ta); - esp3d_log("Value changed: %s", fan_value.c_str()); - } -} - -void fan_btn_up_event_cb(lv_event_t *e) { - esp3d_log("Up"); - lv_obj_t *fan_ta = (lv_obj_t *)lv_event_get_user_data(e); - std::string fan = lv_textarea_get_text(fan_ta); - int fan_int = std::stoi(fan); - int step = atoi(fan_steps_buttons_map[fan_steps_buttons_map_id]); - esp3d_log("Step: %d, Speed: %d", step, fan_int); - fan_int += step; - if (fan_int > 100) fan_int = 100; - esp3d_log("new Speed: %d", fan_int); - fan = std::to_string(fan_int); - lv_textarea_set_text(fan_ta, fan.c_str()); - send_gcode_fan(); -} - -void fan_btn_down_event_cb(lv_event_t *e) { - lv_obj_t *fan_ta = (lv_obj_t *)lv_event_get_user_data(e); - std::string fan = lv_textarea_get_text(fan_ta); - int fan_int = std::stoi(fan); - int step = atoi(fan_steps_buttons_map[fan_steps_buttons_map_id]); - fan_int -= step; - if (fan_int < 0) fan_int = 0; - fan = std::to_string(fan_int); - lv_textarea_set_text(fan_ta, fan.c_str()); - send_gcode_fan(); -} - -void fan_btn_ok_event_cb(lv_event_t *e) { - esp3d_log("Ok clicked"); - send_gcode_fan(); -} - -void fan_btn_reset_event_cb(lv_event_t *e) { - lv_obj_t *fan_ta = (lv_obj_t *)lv_event_get_user_data(e); - esp3d_log("Reset"); - lv_textarea_set_text(fan_ta, "0"); - send_gcode_fan(); -} - -void fan_steps_matrix_buttons_event_cb(lv_event_t *e) { - lv_obj_t *obj = lv_event_get_target(e); - uint32_t id = lv_btnmatrix_get_selected_btn(obj); - fan_steps_buttons_map_id = id; - esp3d_log("Button %s clicked", fan_steps_buttons_map[id]); -} - -void fan_matrix_buttons_event_cb(lv_event_t *e) { - lv_obj_t *obj = lv_event_get_target(e); - // lv_event_code_t code = lv_event_get_code(e); - lv_obj_t *fan_ta = (lv_obj_t *)lv_event_get_user_data(e); - uint32_t id = lv_btnmatrix_get_selected_btn(obj); - fan_buttons_map_id = id; - lv_label_set_text(label_current_fan, fan_buttons_map[fan_buttons_map_id]); - std::string temp_value; - if (fan_buttons_map_id == 0) { - temp_value = esp3dTftValues.get_string_value(ESP3DValuesIndex::ext_0_fan); - - } else { - temp_value = esp3dTftValues.get_string_value(ESP3DValuesIndex::ext_1_fan); - } - lv_label_set_text(label_current_fan_value, temp_value.c_str()); - lv_textarea_set_text(fan_ta, temp_value.c_str()); - - esp3d_log("Button %s clicked", fan_buttons_map[id]); -} - -bool fan_value_cb(ESP3DValuesIndex index, const char *value, - ESP3DValuesCbAction action) { - esp3d_log("fan_value_cb %s", value); - if (esp3dTftui.get_current_screen() != ESP3DScreenType::fan) { - esp3d_log("Not current screen"); - return false; - } - if (index == ESP3DValuesIndex::ext_1_temperature || - index == ESP3DValuesIndex::ext_1_target_temperature) { - esp3d_log("Check if extruder 1 data %s:", value); - uint nb_fans_tmp = 2; - if (strcmp(value, "#") == 0) { - esp3d_log("No extruder 1, only one fan"); - nb_fans_tmp = 1; - } - if (nb_fans_tmp != nb_fans) { - esp3d_log("Update nb of fans"); - nb_fans = nb_fans_tmp; - } else { - // no update needed - esp3d_log("No update needed"); - return false; - } - // update needed for fan buttons - esp3d_log("Update fan buttons matrix"); - updateBtnMatrix(); - return true; - } - - esp3d_log("index %d (E0:%d, E1:%d), fan_steps_buttons_map_id %d", - (uint16_t)index, (uint16_t)ESP3DValuesIndex::ext_0_fan, - (uint16_t)ESP3DValuesIndex::ext_1_fan, (uint8_t)fan_buttons_map_id); - if (index == ESP3DValuesIndex::ext_0_fan && fan_buttons_map_id == 0) { - esp3d_log("Update fan value %s", value); - lv_label_set_text(label_current_fan_value, value); - return true; - } - if (index == ESP3DValuesIndex::ext_1_fan && fan_buttons_map_id == 1) { - esp3d_log("Update fan value %s", value); - lv_label_set_text(label_current_fan_value, value); - return true; - } - esp3d_log("No update needed"); - return false; -} - -void fan_screen() { - esp3dTftui.set_current_screen(ESP3DScreenType::none); - // Screen creation - esp3d_log("Fan screen creation"); - if (!intialization_done) { - esp3d_log("fan screen initialization"); - // by default all fans are detected - // update will occur only if different - for (uint8_t i = 0; i < FAN_COUNT; i++) { - // this one must be called only once or need to free memory - fan_buttons_map[i] = (char *)calloc(FAN_LABEL_SIZE + 1, sizeof(char)); - strcpy(fan_buttons_map[i], fan_buttons_label_map[i]); - } - // the real max final is 0 - fan_buttons_map[FAN_COUNT] = (char *)calloc(1, sizeof(char)); - // last map entry must be empty - strcpy(fan_buttons_map[FAN_COUNT], ""); - get_fan_buttons_map(); - intialization_done = true; - } - - lv_obj_t *ui_new_screen = lv_obj_create(NULL); - // Display new screen and delete old one - lv_obj_t *ui_current_screen = lv_scr_act(); - lv_scr_load(ui_new_screen); - apply_style(ui_new_screen, ESP3DStyleType::main_bg); - lv_obj_del(ui_current_screen); - - btnback = backButton::create_back_button(ui_new_screen); - lv_obj_add_event_cb(btnback, event_button_fan_back_handler, LV_EVENT_CLICKED, - NULL); - - // Steps in button matrix - lv_obj_t *btnm = lv_btnmatrix_create(ui_new_screen); - lv_btnmatrix_set_map(btnm, fan_steps_buttons_map); - apply_style(btnm, ESP3DStyleType::buttons_matrix); - size_t i = - (sizeof(fan_steps_buttons_map) / sizeof(fan_steps_buttons_map[0])) - 1; - lv_obj_set_size(btnm, MATRIX_BUTTON_WIDTH * i, MATRIX_BUTTON_HEIGHT); - lv_obj_align(btnm, LV_ALIGN_TOP_RIGHT, -CURRENT_BUTTON_PRESSED_OUTLINE, - CURRENT_BUTTON_PRESSED_OUTLINE / 2); - lv_btnmatrix_set_btn_ctrl(btnm, fan_steps_buttons_map_id, - LV_BTNMATRIX_CTRL_CHECKED); - lv_obj_add_event_cb(btnm, fan_steps_matrix_buttons_event_cb, - LV_EVENT_VALUE_CHANGED, NULL); - - // Current Fan label - label_current_fan = lv_label_create(ui_new_screen); - lv_label_set_text(label_current_fan, fan_buttons_map[fan_buttons_map_id]); - apply_style(label_current_fan, ESP3DStyleType::bg_label); - lv_obj_align(label_current_fan, LV_ALIGN_TOP_LEFT, - CURRENT_BUTTON_PRESSED_OUTLINE, CURRENT_BUTTON_PRESSED_OUTLINE); - lv_obj_update_layout(label_current_fan); - - // Current Fan value - std::string current_fan_value_init = - esp3dTftValues.get_string_value(ESP3DValuesIndex::ext_0_fan); - - label_current_fan_value = lv_label_create(ui_new_screen); - lv_label_set_text(label_current_fan_value, current_fan_value_init.c_str()); - apply_style(label_current_fan_value, ESP3DStyleType::read_only_value); - lv_obj_set_width(label_current_fan_value, LV_HOR_RES / 6); - lv_obj_align_to(label_current_fan_value, label_current_fan, - LV_ALIGN_OUT_RIGHT_MID, CURRENT_BUTTON_PRESSED_OUTLINE / 2, - 0); - - // unit - lv_obj_t *label_unit1 = lv_label_create(ui_new_screen); - lv_label_set_text(label_unit1, "%"); - apply_style(label_unit1, ESP3DStyleType::bg_label); - lv_obj_align_to(label_unit1, label_current_fan_value, LV_ALIGN_OUT_RIGHT_MID, - CURRENT_BUTTON_PRESSED_OUTLINE / 2, 0); - - // Button up - lv_obj_t *btn_up = symbolButton::create_symbol_button( - ui_new_screen, LV_SYMBOL_UP "\n" LV_SYMBOL_PLUS); - lv_obj_align_to(btn_up, label_current_fan_value, LV_ALIGN_OUT_BOTTOM_MID, 0, - CURRENT_BUTTON_PRESSED_OUTLINE / 2); - // fan input - lv_obj_t *fan_ta = lv_textarea_create(ui_new_screen); - lv_obj_add_event_cb(fan_ta, fan_ta_event_cb, LV_EVENT_VALUE_CHANGED, NULL); - lv_textarea_set_accepted_chars(fan_ta, "0123456789"); - lv_textarea_set_max_length(fan_ta, 3); - lv_textarea_set_one_line(fan_ta, true); - lv_textarea_set_text(fan_ta, current_fan_value_init.c_str()); - lv_obj_set_style_text_align(fan_ta, LV_TEXT_ALIGN_CENTER, 0); - lv_obj_set_width(fan_ta, LV_HOR_RES / 6); - lv_obj_align_to(fan_ta, btn_up, LV_ALIGN_OUT_BOTTOM_MID, 0, - CURRENT_BUTTON_PRESSED_OUTLINE / 2); - - // label - lv_obj_t *label_ta = lv_label_create(ui_new_screen); - lv_label_set_text(label_ta, LV_SYMBOL_FAN); - apply_style(label_ta, ESP3DStyleType::bg_label); - lv_obj_align_to(label_ta, fan_ta, LV_ALIGN_OUT_LEFT_MID, - -CURRENT_BUTTON_PRESSED_OUTLINE / 2, 0); - - // unit - lv_obj_t *label_unit2 = lv_label_create(ui_new_screen); - lv_label_set_text(label_unit2, "%"); - apply_style(label_unit2, ESP3DStyleType::bg_label); - lv_obj_align_to(label_unit2, fan_ta, LV_ALIGN_OUT_RIGHT_MID, - CURRENT_BUTTON_PRESSED_OUTLINE / 2, 0); - - // button down - lv_obj_t *btn_down = symbolButton::create_symbol_button( - ui_new_screen, LV_SYMBOL_MINUS "\n" LV_SYMBOL_DOWN); - lv_obj_align_to(btn_down, fan_ta, LV_ALIGN_OUT_BOTTOM_MID, 0, - CURRENT_BUTTON_PRESSED_OUTLINE / 2); - lv_obj_add_event_cb(btn_down, fan_btn_down_event_cb, LV_EVENT_CLICKED, - fan_ta); - - lv_obj_add_event_cb(btn_up, fan_btn_up_event_cb, LV_EVENT_CLICKED, fan_ta); - - // Button Ok - lv_obj_t *btn_ok = - symbolButton::create_symbol_button(ui_new_screen, LV_SYMBOL_OK); - lv_obj_align_to(btn_ok, label_unit2, LV_ALIGN_OUT_RIGHT_MID, - CURRENT_BUTTON_PRESSED_OUTLINE, 0); - lv_obj_add_event_cb(btn_ok, fan_btn_ok_event_cb, LV_EVENT_CLICKED, fan_ta); - - // Button Reset - lv_obj_t *btn_reset = - symbolButton::create_symbol_button(ui_new_screen, LV_SYMBOL_POWER); - lv_obj_align_to(btn_reset, btn_ok, LV_ALIGN_OUT_RIGHT_MID, - CURRENT_BUTTON_PRESSED_OUTLINE, 0); - lv_obj_add_event_cb(btn_reset, fan_btn_reset_event_cb, LV_EVENT_CLICKED, - fan_ta); - - // keypad - lv_obj_t *fan_kb = lv_keyboard_create(ui_new_screen); - lv_keyboard_set_mode(fan_kb, LV_KEYBOARD_MODE_NUMBER); - lv_keyboard_set_textarea(fan_kb, NULL); - lv_obj_align_to(fan_kb, fan_ta, LV_ALIGN_OUT_RIGHT_MID, - CURRENT_BUTTON_PRESSED_OUTLINE / 2, 0); - lv_obj_update_layout(fan_kb); - lv_obj_set_content_width(fan_kb, LV_HOR_RES - lv_obj_get_x(fan_kb) - - 2 * CURRENT_BUTTON_PRESSED_OUTLINE); - lv_obj_set_style_radius(fan_kb, CURRENT_BUTTON_RADIUS_VALUE, LV_PART_MAIN); - lv_obj_add_flag(fan_kb, LV_OBJ_FLAG_HIDDEN); - lv_obj_add_event_cb(fan_ta, fan_ta_event_cb, LV_EVENT_ALL, fan_kb); - - // Target selector button matrix - btnm_target = lv_btnmatrix_create(ui_new_screen); - // build fan buttons map - updateBtnMatrix(); - lv_obj_add_event_cb(btnm_target, fan_matrix_buttons_event_cb, - LV_EVENT_VALUE_CHANGED, fan_ta); - - esp3dTftui.set_current_screen(ESP3DScreenType::fan); -} -} // namespace fanScreen \ No newline at end of file diff --git a/main/display/cnc/grbl/screens/fan_screen.h b/main/display/cnc/grbl/screens/fan_screen.h deleted file mode 100644 index 817fe82d..00000000 --- a/main/display/cnc/grbl/screens/fan_screen.h +++ /dev/null @@ -1,27 +0,0 @@ -/* -fan_screen.h - ESP3D screens styles definition - - Copyright (c) 2022 Luc Lebosse. All rights reserved. - - This code is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This code 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#pragma once -#include "esp3d_values.h" -namespace fanScreen { -extern void fan_screen(); -extern bool fan_value_cb(ESP3DValuesIndex index, const char *value, - ESP3DValuesCbAction action); -} // namespace fanScreen diff --git a/main/display/cnc/grbl/screens/filament_screen.cpp b/main/display/cnc/grbl/screens/filament_screen.cpp deleted file mode 100644 index afb9bf24..00000000 --- a/main/display/cnc/grbl/screens/filament_screen.cpp +++ /dev/null @@ -1,440 +0,0 @@ -/* - esp3d_tft - - Copyright (c) 2022 Luc Lebosse. All rights reserved. - - This code is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This code 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#include "screens/filament_screen.h" - -#include - -#include "components/back_button_component.h" -#include "components/symbol_button_component.h" -#include "esp3d_log.h" -#include "esp3d_string.h" -#include "esp3d_styles.h" -#include "esp3d_tft_ui.h" -#include "screens/menu_screen.h" -#include "rendering/esp3d_rendering_client.h" -#include "screens/temperatures_screen.h" -#include "translations/esp3d_translation_service.h" - -/********************** - * STATIC PROTOTYPES - **********************/ -namespace filamentScreen { -std::string filament_value = "0"; -const char *filament_distance_steps_buttons_map[] = {"1", "5", "10", "50", ""}; -uint8_t filament_distance_steps_buttons_map_id = 0; -lv_obj_t *label_current_temperature_filament_value = NULL; -lv_obj_t *btnm_target = NULL; -lv_obj_t *btnback = NULL; -lv_obj_t *label_current_temperature_filament = NULL; - -bool intialization_done = false; - -#define FILAMENT_COUNT 2 -#define FILAMENT_LABEL_SIZE 2 -uint8_t nb_filaments = FILAMENT_COUNT; -char *filament_buttons_map[FILAMENT_COUNT + 1]; -uint8_t filament_buttons_map_id = 0; -const char *filament_buttons_label_map[FILAMENT_COUNT] = { - LV_SYMBOL_EXTRUDER "1", LV_SYMBOL_EXTRUDER "2"}; - -lv_timer_t *filament_screen_delay_timer = NULL; - -uint8_t get_map_size() { - for (uint8_t i = 0; i < FILAMENT_COUNT + 1; i++) { - if (strlen(filament_buttons_map[i]) == 0) { - return i; - } - } - esp3d_log("filament_buttons_map size is undefined"); - return 0; -} - -const char **get_filament_buttons_map() { - esp3d_log("get_filament_buttons_map"); - esp3d_log("filament_buttons_map size is : %d", get_map_size()); - - // if yes update - if (get_map_size() != nb_filaments) { - esp3d_log("Update matrix buttons"); - // update matrix buttons - if (nb_filaments == 1) { - strcpy(filament_buttons_map[1], ""); - } else { - strcpy(filament_buttons_map[1], filament_buttons_label_map[1]); - } - } - esp3d_log("filament_buttons_map size is : %d", get_map_size()); - // then return - return (const char **)filament_buttons_map; -} - -bool updateBtnMatrix() { - // check if different from current - // if yes update - // then apply style - lv_btnmatrix_set_map(btnm_target, get_filament_buttons_map()); - apply_style(btnm_target, ESP3DStyleType::buttons_matrix); - lv_obj_update_layout(btnm_target); - size_t i = get_map_size(); - lv_obj_set_size(btnm_target, MATRIX_BUTTON_WIDTH * i, MATRIX_BUTTON_HEIGHT); - esp3d_log("child count: %d", i); - // lv_obj_add_state(obj, LV_STATE_DISABLED); - if (filament_buttons_map_id > i) filament_buttons_map_id = 0; - lv_btnmatrix_set_btn_ctrl(btnm_target, filament_buttons_map_id, - LV_BTNMATRIX_CTRL_CHECKED); - lv_obj_align_to(btnm_target, btnback, LV_ALIGN_OUT_LEFT_BOTTOM, - -CURRENT_BUTTON_PRESSED_OUTLINE, 0); - return true; -} - -void filament_screen_delay_timer_cb(lv_timer_t *timer) { - if (filament_screen_delay_timer) { - lv_timer_del(filament_screen_delay_timer); - filament_screen_delay_timer = NULL; - } - menuScreen::menu_screen(); -} - -void filament_screen_edit_delay_timer_cb(lv_timer_t *timer) { - if (filament_screen_delay_timer) { - lv_timer_del(filament_screen_delay_timer); - filament_screen_delay_timer = NULL; - } - temperaturesScreen::temperatures_screen(filament_buttons_map_id, - ESP3DScreenType::filament); -} - -void event_button_filament_back_handler(lv_event_t *e) { - esp3d_log("back Clicked"); - if (BUTTON_ANIMATION_DELAY) { - if (filament_screen_delay_timer) return; - filament_screen_delay_timer = lv_timer_create( - filament_screen_delay_timer_cb, BUTTON_ANIMATION_DELAY, NULL); - } else { - filament_screen_delay_timer_cb(NULL); - } -} - -void event_button_filament_edit_handler(lv_event_t *e) { - esp3d_log("edit Clicked"); - if (BUTTON_ANIMATION_DELAY) { - if (filament_screen_delay_timer) return; - filament_screen_delay_timer = lv_timer_create( - filament_screen_edit_delay_timer_cb, BUTTON_ANIMATION_DELAY, NULL); - } else { - filament_screen_edit_delay_timer_cb(NULL); - } -} - -void send_gcode_filament(const char *sign = "") { - std::string filament_value_str = "G91"; - renderingClient.sendGcode(filament_value_str.c_str()); - - if (filament_buttons_map_id == 0) { - filament_value_str = "T0"; - } else { - filament_value_str = "T1"; - } - renderingClient.sendGcode(filament_value_str.c_str()); - - filament_value_str = "G1 E"; - filament_value_str += sign; - filament_value_str += filament_value; - renderingClient.sendGcode(filament_value_str.c_str()); - - filament_value_str = "G90"; - renderingClient.sendGcode(filament_value_str.c_str()); -} - -void filament_ta_event_cb(lv_event_t *e) { - lv_event_code_t code = lv_event_get_code(e); - lv_obj_t *ta = lv_event_get_target(e); - lv_obj_t *kb = (lv_obj_t *)lv_event_get_user_data(e); - if (code == LV_EVENT_FOCUSED || code == LV_EVENT_PRESSED) { - lv_keyboard_set_textarea(kb, ta); - lv_obj_add_state(ta, LV_STATE_FOCUSED); - lv_obj_clear_flag(kb, LV_OBJ_FLAG_HIDDEN); - lv_obj_set_scrollbar_mode(ta, LV_SCROLLBAR_MODE_AUTO); - } else if (code == LV_EVENT_DEFOCUSED || code == LV_EVENT_READY || - code == LV_EVENT_CANCEL) { - esp3d_log("Ready, Value: %s", lv_textarea_get_text(ta)); - lv_textarea_set_cursor_pos(ta, 0); - lv_obj_set_scrollbar_mode(ta, LV_SCROLLBAR_MODE_OFF); - lv_keyboard_set_textarea(kb, NULL); - lv_obj_add_flag(kb, LV_OBJ_FLAG_HIDDEN); - lv_obj_clear_state(ta, LV_STATE_FOCUSED); - filament_value = lv_textarea_get_text(ta); - - if (filament_value.length() == 0) { - lv_textarea_set_text(ta, "0"); - } - } else if (code == LV_EVENT_VALUE_CHANGED) { - filament_value = lv_textarea_get_text(ta); - esp3d_log("Value changed: %s", filament_value.c_str()); - } -} - -void filament_btn_up_event_cb(lv_event_t *e) { - esp3d_log("Up"); - send_gcode_filament(); -} - -void filament_btn_down_event_cb(lv_event_t *e) { send_gcode_filament("-"); } - -void filament_distance_steps_matrix_buttons_event_cb(lv_event_t *e) { - lv_obj_t *ta = (lv_obj_t *)lv_event_get_user_data(e); - lv_obj_t *obj = lv_event_get_target(e); - uint32_t id = lv_btnmatrix_get_selected_btn(obj); - filament_distance_steps_buttons_map_id = id; - esp3d_log("Button %s clicked", filament_distance_steps_buttons_map[id]); - lv_textarea_set_text(ta, filament_distance_steps_buttons_map[id]); -} - -void filament_matrix_buttons_event_cb(lv_event_t *e) { - lv_obj_t *obj = lv_event_get_target(e); - filament_buttons_map_id = lv_btnmatrix_get_selected_btn(obj); - std::string current_temperature_filament_value_init = - filament_buttons_map_id == 0 - ? esp3dTftValues.get_string_value(ESP3DValuesIndex::ext_0_temperature) - : esp3dTftValues.get_string_value( - ESP3DValuesIndex::ext_1_temperature); - lv_label_set_text(label_current_temperature_filament, - filament_buttons_map[filament_buttons_map_id]); - lv_label_set_text(label_current_temperature_filament_value, - current_temperature_filament_value_init.c_str()); - esp3d_log("Button %s clicked", filament_buttons_map[filament_buttons_map_id]); -} - -bool filament_value_cb(ESP3DValuesIndex index, const char *value, - ESP3DValuesCbAction action) { - if (esp3dTftui.get_current_screen() != ESP3DScreenType::filament) - return false; - if (index == ESP3DValuesIndex::ext_1_temperature || - index == ESP3DValuesIndex::ext_1_target_temperature) { - if (index == ESP3DValuesIndex::ext_1_temperature && - filament_distance_steps_buttons_map_id == 1) { - esp3d_log("Update temperature value %s", value); - lv_label_set_text(label_current_temperature_filament_value, value); - } - esp3d_log("Check if extruder 1 data %s:", value); - uint nb_filaments_tmp = 2; - if (strcmp(value, "#") == 0) { - esp3d_log("No extruder 1, only one filament"); - nb_filaments_tmp = 1; - } - if (nb_filaments_tmp != nb_filaments) { - esp3d_log("Update nb of filaments"); - nb_filaments = nb_filaments_tmp; - } else { - // no update needed - esp3d_log("No update needed"); - return false; - } - // update needed for filament buttons - updateBtnMatrix(); - return true; - } - - if (index == ESP3DValuesIndex::ext_0_temperature && - filament_distance_steps_buttons_map_id == 0) { - esp3d_log("Update filament value %s", value); - lv_label_set_text(label_current_temperature_filament_value, value); - return true; - } - - return false; -} - -void filament_screen() { - esp3dTftui.set_current_screen(ESP3DScreenType::none); - // Screen creation - esp3d_log("Filament screen creation"); - if (!intialization_done) { - esp3d_log("filament screen initialization"); - // by default all filaments are detected - // update will occur only if different - for (uint8_t i = 0; i < FILAMENT_COUNT; i++) { - // this one must be called only once or need to free memory - filament_buttons_map[i] = - (char *)calloc(FILAMENT_LABEL_SIZE + 1, sizeof(char)); - strcpy(filament_buttons_map[i], filament_buttons_label_map[i]); - } - // the real max final is 0 - filament_buttons_map[FILAMENT_COUNT] = (char *)calloc(1, sizeof(char)); - // last map entry must be empty - strcpy(filament_buttons_map[FILAMENT_COUNT], ""); - get_filament_buttons_map(); - intialization_done = true; - } - - lv_obj_t *ui_new_screen = lv_obj_create(NULL); - // Display new screen and delete old one - lv_obj_t *ui_current_screen = lv_scr_act(); - lv_scr_load(ui_new_screen); - apply_style(ui_new_screen, ESP3DStyleType::main_bg); - lv_obj_del(ui_current_screen); - - btnback = backButton::create_back_button(ui_new_screen); - lv_obj_add_event_cb(btnback, event_button_filament_back_handler, - LV_EVENT_CLICKED, NULL); - - // Steps in button matrix - lv_obj_t *btnm = lv_btnmatrix_create(ui_new_screen); - lv_btnmatrix_set_map(btnm, filament_distance_steps_buttons_map); - apply_style(btnm, ESP3DStyleType::buttons_matrix); - size_t i = (sizeof(filament_distance_steps_buttons_map) / - sizeof(filament_distance_steps_buttons_map[0])) - - 1; - lv_obj_set_size(btnm, MATRIX_BUTTON_WIDTH * i, MATRIX_BUTTON_HEIGHT); - lv_obj_align(btnm, LV_ALIGN_TOP_RIGHT, -CURRENT_BUTTON_PRESSED_OUTLINE, - CURRENT_BUTTON_PRESSED_OUTLINE / 2); - lv_btnmatrix_set_btn_ctrl(btnm, filament_distance_steps_buttons_map_id, - LV_BTNMATRIX_CTRL_CHECKED); - - // Text area label - lv_obj_t *label_ta = lv_label_create(ui_new_screen); - lv_label_set_text(label_ta, LV_SYMBOL_FILAMENT); - apply_style(label_ta, ESP3DStyleType::bg_label); - lv_obj_update_layout(label_ta); - int32_t label_width = lv_obj_get_width(label_ta); - int32_t label_height = lv_obj_get_height(label_ta); - lv_obj_set_style_transform_pivot_x(label_ta, label_width / 2, 0); - lv_obj_set_style_transform_pivot_y(label_ta, label_height / 2, 0); - lv_obj_set_style_transform_angle(label_ta, 900, 0); - lv_obj_update_layout(label_ta); - - size_t x = lv_obj_get_width(label_ta) + (2 * CURRENT_BUTTON_PRESSED_OUTLINE); - size_t y = MATRIX_BUTTON_HEIGHT + CURRENT_BUTTON_PRESSED_OUTLINE; - - // Button up - lv_obj_t *btn_up = symbolButton::create_symbol_button( - ui_new_screen, LV_SYMBOL_UP "\n" LV_SYMBOL_PLUS); - lv_obj_set_pos(btn_up, x, y); - // filament input - lv_obj_t *filament_ta = lv_textarea_create(ui_new_screen); - lv_obj_add_event_cb(filament_ta, filament_ta_event_cb, LV_EVENT_VALUE_CHANGED, - NULL); - lv_textarea_set_accepted_chars(filament_ta, "0123456789-."); - lv_textarea_set_max_length(filament_ta, 3); - lv_textarea_set_one_line(filament_ta, true); - - lv_textarea_set_text(filament_ta, - filament_distance_steps_buttons_map - [filament_distance_steps_buttons_map_id]); - lv_obj_set_style_text_align(filament_ta, LV_TEXT_ALIGN_CENTER, 0); - lv_obj_set_width(filament_ta, LV_HOR_RES / 6); - lv_obj_align_to(filament_ta, btn_up, LV_ALIGN_OUT_BOTTOM_MID, 0, - CURRENT_BUTTON_PRESSED_OUTLINE / 2); - - lv_obj_add_event_cb(btnm, filament_distance_steps_matrix_buttons_event_cb, - LV_EVENT_VALUE_CHANGED, filament_ta); - - // Text area label - lv_obj_align_to(label_ta, filament_ta, LV_ALIGN_OUT_LEFT_MID, - -CURRENT_BUTTON_PRESSED_OUTLINE / 2, 0); - - // unit - lv_obj_t *label_unit2 = lv_label_create(ui_new_screen); - lv_label_set_text(label_unit2, - esp3dTranslationService.translate(ESP3DLabel::millimeters)); - apply_style(label_unit2, ESP3DStyleType::bg_label); - lv_obj_align_to(label_unit2, filament_ta, LV_ALIGN_OUT_RIGHT_MID, - CURRENT_BUTTON_PRESSED_OUTLINE / 2, 0); - - // Current filament label - label_current_temperature_filament = lv_label_create(ui_new_screen); - lv_label_set_text(label_current_temperature_filament, - filament_buttons_map[filament_buttons_map_id]); - apply_style(label_current_temperature_filament, ESP3DStyleType::bg_label); - lv_obj_align_to(label_current_temperature_filament, label_unit2, - LV_ALIGN_OUT_RIGHT_MID, CURRENT_BUTTON_PRESSED_OUTLINE * 3, - 0); - lv_obj_update_layout(label_current_temperature_filament); - - // Current filament temperature value - std::string current_temperature_filament_value_init = - filament_buttons_map_id == 0 - ? esp3dTftValues.get_string_value(ESP3DValuesIndex::ext_0_temperature) - : esp3dTftValues.get_string_value( - ESP3DValuesIndex::ext_1_temperature); - - label_current_temperature_filament_value = lv_label_create(ui_new_screen); - lv_label_set_text(label_current_temperature_filament_value, - current_temperature_filament_value_init.c_str()); - apply_style(label_current_temperature_filament_value, - ESP3DStyleType::read_only_value); - lv_obj_set_width(label_current_temperature_filament_value, LV_HOR_RES / 6); - lv_obj_align_to(label_current_temperature_filament_value, - label_current_temperature_filament, LV_ALIGN_OUT_RIGHT_MID, - CURRENT_BUTTON_PRESSED_OUTLINE / 2, 0); - - // unit - lv_obj_t *label_unit1 = lv_label_create(ui_new_screen); - lv_label_set_text(label_unit1, - esp3dTranslationService.translate(ESP3DLabel::celsius)); - apply_style(label_unit1, ESP3DStyleType::bg_label); - lv_obj_align_to(label_unit1, label_current_temperature_filament_value, - LV_ALIGN_OUT_RIGHT_MID, CURRENT_BUTTON_PRESSED_OUTLINE / 2, - 0); - - lv_obj_t *btn_edit = - symbolButton::create_symbol_button(ui_new_screen, LV_SYMBOL_EDIT); - lv_obj_align_to(btn_edit, label_unit1, LV_ALIGN_OUT_RIGHT_MID, - CURRENT_BUTTON_PRESSED_OUTLINE / 2, 0); - lv_obj_add_event_cb(btn_edit, event_button_filament_edit_handler, - LV_EVENT_CLICKED, NULL); - - // button down - lv_obj_t *btn_down = symbolButton::create_symbol_button( - ui_new_screen, LV_SYMBOL_MINUS "\n" LV_SYMBOL_DOWN); - lv_obj_align_to(btn_down, filament_ta, LV_ALIGN_OUT_BOTTOM_MID, 0, - CURRENT_BUTTON_PRESSED_OUTLINE / 2); - lv_obj_add_event_cb(btn_down, filament_btn_down_event_cb, LV_EVENT_CLICKED, - filament_ta); - - lv_obj_add_event_cb(btn_up, filament_btn_up_event_cb, LV_EVENT_CLICKED, - filament_ta); - - // keypad - lv_obj_t *filament_kb = lv_keyboard_create(ui_new_screen); - lv_keyboard_set_mode(filament_kb, LV_KEYBOARD_MODE_NUMBER); - lv_keyboard_set_textarea(filament_kb, NULL); - lv_obj_align_to(filament_kb, filament_ta, LV_ALIGN_OUT_RIGHT_MID, - CURRENT_BUTTON_PRESSED_OUTLINE / 2, 0); - lv_obj_update_layout(filament_kb); - lv_obj_set_content_width(filament_kb, LV_HOR_RES - lv_obj_get_x(filament_kb) - - 2 * CURRENT_BUTTON_PRESSED_OUTLINE); - lv_obj_set_style_radius(filament_kb, CURRENT_BUTTON_RADIUS_VALUE, - LV_PART_MAIN); - lv_obj_add_flag(filament_kb, LV_OBJ_FLAG_HIDDEN); - lv_obj_add_event_cb(filament_ta, filament_ta_event_cb, LV_EVENT_ALL, - filament_kb); - - // Target selector button matrix - btnm_target = lv_btnmatrix_create(ui_new_screen); - // build filament buttons map - updateBtnMatrix(); - lv_obj_add_event_cb(btnm_target, filament_matrix_buttons_event_cb, - LV_EVENT_VALUE_CHANGED, filament_ta); - - esp3dTftui.set_current_screen(ESP3DScreenType::filament); -} -} // namespace filamentScreen \ No newline at end of file diff --git a/main/display/cnc/grbl/screens/filament_screen.h b/main/display/cnc/grbl/screens/filament_screen.h deleted file mode 100644 index c7f028fe..00000000 --- a/main/display/cnc/grbl/screens/filament_screen.h +++ /dev/null @@ -1,30 +0,0 @@ -/* -filament_screen.h - ESP3D screens styles definition - - Copyright (c) 2022 Luc Lebosse. All rights reserved. - - This code is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This code 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#pragma once - -#include "esp3d_values.h" - -namespace filamentScreen { -extern void filament_screen(); -extern bool filament_value_cb(ESP3DValuesIndex index, const char *value, - ESP3DValuesCbAction action); - -} // namespace filamentScreen diff --git a/main/display/cnc/grbl/screens/leveling_screen.cpp b/main/display/cnc/grbl/screens/leveling_screen.cpp deleted file mode 100644 index f21f2d3c..00000000 --- a/main/display/cnc/grbl/screens/leveling_screen.cpp +++ /dev/null @@ -1,150 +0,0 @@ -/* - esp3d_tft - - Copyright (c) 2022 Luc Lebosse. All rights reserved. - - This code is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This code 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ -#include "screens/leveling_screen.h" - -#include - -#include "screens/auto_leveling_screen.h" -#include "components/back_button_component.h" -#include "components/main_container_component.h" -#include "components/spinner_component.h" -#include "components/symbol_button_component.h" -#include "esp3d_log.h" -#include "esp3d_settings.h" -#include "esp3d_string.h" -#include "esp3d_styles.h" -#include "esp3d_tft_ui.h" -#include "screens/manual_leveling_screen.h" -#include "screens/menu_screen.h" -#include "translations/esp3d_translation_service.h" - -/********************** - * STATIC PROTOTYPES - **********************/ -namespace levelingScreen { -lv_timer_t *leveling_screen_delay_timer = NULL; -lv_obj_t *btnback = nullptr; -bool auto_leveling = false; - -void leveling_screen_auto_on(bool auto_on) { auto_leveling = auto_on; } - -ESP3DScreenType leveling_next_screen = ESP3DScreenType::none; - -void leveling_screen_delay_timer_cb(lv_timer_t *timer) { - if (leveling_screen_delay_timer) { - lv_timer_del(leveling_screen_delay_timer); - leveling_screen_delay_timer = NULL; - } - - switch (leveling_next_screen) { - case ESP3DScreenType::auto_leveling: - autoLevelingScreen::auto_leveling_screen(); - break; - case ESP3DScreenType::manual_leveling: - manualLevelingScreen::manual_leveling_screen(auto_leveling); - break; - case ESP3DScreenType::menu: - menuScreen::menu_screen(); - break; - default: - break; - } -} - -void event_button_leveling_back_handler(lv_event_t *e) { - esp3d_log("back Clicked"); - if (leveling_screen_delay_timer) return; - leveling_next_screen = ESP3DScreenType::menu; - if (BUTTON_ANIMATION_DELAY) { - if (leveling_screen_delay_timer) return; - leveling_screen_delay_timer = lv_timer_create( - leveling_screen_delay_timer_cb, BUTTON_ANIMATION_DELAY, NULL); - } else { - leveling_screen_delay_timer_cb(NULL); - } -} - -void event_button_manual_handler(lv_event_t *e) { - esp3d_log("MANUAL Clicked"); - if (leveling_screen_delay_timer) return; - leveling_next_screen = ESP3DScreenType::manual_leveling; - if (BUTTON_ANIMATION_DELAY) { - if (leveling_screen_delay_timer) return; - leveling_screen_delay_timer = lv_timer_create( - leveling_screen_delay_timer_cb, BUTTON_ANIMATION_DELAY, NULL); - } else { - leveling_screen_delay_timer_cb(NULL); - } -} - -void event_button_auto_handler(lv_event_t *e) { - esp3d_log("AUTO Clicked"); - if (leveling_screen_delay_timer) return; - leveling_next_screen = ESP3DScreenType::auto_leveling; - if (BUTTON_ANIMATION_DELAY) { - if (leveling_screen_delay_timer) return; - leveling_screen_delay_timer = lv_timer_create( - leveling_screen_delay_timer_cb, BUTTON_ANIMATION_DELAY, NULL); - } else { - leveling_screen_delay_timer_cb(NULL); - } -} - -void leveling_screen(bool autoleveling) { - esp3dTftui.set_current_screen(ESP3DScreenType::none); - auto_leveling = autoleveling; - // Screen creation - esp3d_log("Leveling screen creation"); - lv_obj_t *ui_new_screen = lv_obj_create(NULL); - // Display new screen and delete old one - lv_obj_t *ui_current_screen = lv_scr_act(); - lv_scr_load(ui_new_screen); - apply_style(ui_new_screen, ESP3DStyleType::main_bg); - lv_obj_del(ui_current_screen); - - btnback = backButton::create_back_button(ui_new_screen); - lv_obj_add_event_cb(btnback, event_button_leveling_back_handler, - LV_EVENT_CLICKED, NULL); - - lv_obj_t *ui_main_container = mainContainer::create_main_container( - ui_new_screen, btnback, ESP3DStyleType::col_container); - - lv_obj_t *ui_buttons_container = lv_obj_create(ui_main_container); - apply_style(ui_buttons_container, ESP3DStyleType::row_container); - lv_obj_set_size(ui_buttons_container, LV_HOR_RES, LV_SIZE_CONTENT); - apply_outline_pad(ui_buttons_container); - lv_obj_clear_flag(ui_buttons_container, LV_OBJ_FLAG_SCROLLABLE); - - lv_obj_t *btn = nullptr; - - // Create button and label for manual leveling - btn = symbolButton::create_symbol_button( - ui_buttons_container, LV_SYMBOL_MANUAL "\n" LV_SYMBOL_LEVELING, - BUTTON_WIDTH, BUTTON_WIDTH); - lv_obj_add_event_cb(btn, event_button_manual_handler, LV_EVENT_CLICKED, NULL); - - // Create button and label for auto leveling - btn = symbolButton::create_symbol_button( - ui_buttons_container, LV_SYMBOL_AUTOMATIC "\n" LV_SYMBOL_LEVELING, - BUTTON_WIDTH, BUTTON_WIDTH); - lv_obj_add_event_cb(btn, event_button_auto_handler, LV_EVENT_CLICKED, NULL); - esp3dTftui.set_current_screen(ESP3DScreenType::leveling); -} -} // namespace levelingScreen \ No newline at end of file diff --git a/main/display/cnc/grbl/screens/leveling_screen.h b/main/display/cnc/grbl/screens/leveling_screen.h deleted file mode 100644 index 53bce646..00000000 --- a/main/display/cnc/grbl/screens/leveling_screen.h +++ /dev/null @@ -1,24 +0,0 @@ -/* - leveling_screen.h - esp3d - Copyright (c) 2022 Luc Lebosse. All rights reserved. - - This code is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This code 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#pragma once - -namespace levelingScreen { -extern void leveling_screen(bool auto_leveling); -} // namespace levelingScreen diff --git a/main/display/cnc/grbl/screens/main_screen.cpp b/main/display/cnc/grbl/screens/main_screen.cpp index aee22fb6..18471bff 100644 --- a/main/display/cnc/grbl/screens/main_screen.cpp +++ b/main/display/cnc/grbl/screens/main_screen.cpp @@ -28,7 +28,6 @@ #include "esp3d_string.h" #include "esp3d_styles.h" #include "esp3d_tft_ui.h" -#include "screens/fan_screen.h" #if ESP3D_SD_CARD_FEATURE #include "screens/files_screen.h" @@ -38,24 +37,16 @@ #include "components/status_bar_component.h" #include "components/symbol_button_component.h" #include "esp3d_json_settings.h" -#include "screens/filament_screen.h" #include "gcode_host/esp3d_gcode_host_service.h" #include "screens/menu_screen.h" -#include "screens/positions_screen.h" -#include "screens/speed_screen.h" -#include "screens/temperatures_screen.h" +//#include "screens/positions_screen.h" #include "translations/esp3d_translation_service.h" /********************** * STATIC PROTOTYPES **********************/ namespace mainScreen { -void main_display_extruder_0(); -void main_display_extruder_1(); -void main_display_bed(); -void main_display_fan(); -void main_display_speed(); -void main_display_positions(); +//void main_display_positions(); void main_display_status_area(); void main_display_pause(); void main_display_resume(); @@ -65,22 +56,15 @@ void main_display_files(); #endif // ESP3D_SD_CARD_FEATURE void main_display_menu(); -uint8_t main_screen_temperature_target = 0; lv_timer_t *main_screen_delay_timer = NULL; ESP3DScreenType next_screen = ESP3DScreenType::none; -uint8_t nb_fans = 2; -bool show_fan_button = true; bool intialization_done = false; /********************** * STATIC VARIABLES **********************/ -lv_obj_t *main_btn_extruder_0 = nullptr; -lv_obj_t *main_btn_extruder_1 = nullptr; -lv_obj_t *main_btn_bed = nullptr; -lv_obj_t *main_btn_fan = nullptr; -lv_obj_t *main_btn_speed = nullptr; -lv_obj_t *main_btn_positions = nullptr; + +//lv_obj_t *main_btn_positions = nullptr; lv_obj_t *main_btn_files = nullptr; lv_obj_t *main_btn_pause = nullptr; lv_obj_t *main_btn_stop = nullptr; @@ -92,111 +76,17 @@ lv_obj_t *main_btn_menu = nullptr; * GLOBAL FUNCTIONS **********************/ std::string progression_area_str = ""; -void update_show_fan_controls(bool show) { show_fan_button = show; } - -bool extruder_0_value_cb(ESP3DValuesIndex index, const char *value, - ESP3DValuesCbAction action) { - if (action == ESP3DValuesCbAction::Update) { - if (esp3dTftui.get_current_screen() == ESP3DScreenType::main) { - main_display_extruder_0(); - } else { - // update other screens calling each callback update function - temperaturesScreen::extruder_0_value_cb(index, value, action); - filamentScreen::filament_value_cb(index, value, action); - } - } - return true; -} - -bool extruder_1_value_cb(ESP3DValuesIndex index, const char *value, - ESP3DValuesCbAction action) { - if (action == ESP3DValuesCbAction::Update) { - if (esp3dTftui.get_current_screen() == ESP3DScreenType::main) { - main_display_extruder_1(); - fan_value_cb(index, value, action); - } else { - // update other screens calling each callback update function - temperaturesScreen::extruder_1_value_cb(index, value, action); - fanScreen::fan_value_cb(index, value, action); - filamentScreen::filament_value_cb(index, value, action); - } - } - return true; -} - -bool bed_value_cb(ESP3DValuesIndex index, const char *value, - ESP3DValuesCbAction action) { - if (action == ESP3DValuesCbAction::Update) { - if (esp3dTftui.get_current_screen() == ESP3DScreenType::main) { - main_display_bed(); - } else { - // update other screens calling each callback update function - temperaturesScreen::bed_value_cb(index, value, action); - } - } - return true; -} - -bool position_value_cb(ESP3DValuesIndex index, const char *value, - ESP3DValuesCbAction action) { - if (action == ESP3DValuesCbAction::Update) { - if (esp3dTftui.get_current_screen() == ESP3DScreenType::main) { - main_display_positions(); - } else { - positionsScreen::positions_values_cb(index, value, action); - } - } - return true; -} - -bool fan_value_cb(ESP3DValuesIndex index, const char *value, - ESP3DValuesCbAction action) { - esp3d_log("fan_value_cb"); - if (!show_fan_button) { - esp3d_log("No control to show"); - return false; - } - - if (action == ESP3DValuesCbAction::Update) { - esp3d_log("Check if main screen"); - if (esp3dTftui.get_current_screen() == ESP3DScreenType::main) { - // this call back is called for each fan value, so check if need to update - // and for each extruder 1 update, so check if need to update nb of fans - if (index == ESP3DValuesIndex::ext_1_temperature || - index == ESP3DValuesIndex::ext_1_target_temperature) { - esp3d_log("Check if extruder 1 data %s:", value); - uint nb_fans_tmp = 2; - if (strcmp(value, "#") == 0) { - esp3d_log("No extruder 1, only one fan"); - nb_fans_tmp = 1; - } - if (nb_fans_tmp != nb_fans) { - esp3d_log("Update nb of fans"); - nb_fans = nb_fans_tmp; - } else { - // no update needed - esp3d_log("No update needed"); - return false; - } - } - main_display_fan(); - } else { - fanScreen::fan_value_cb(index, value, action); - } - } - return true; -} -bool speed_value_cb(ESP3DValuesIndex index, const char *value, - ESP3DValuesCbAction action) { - if (action == ESP3DValuesCbAction::Update) { - if (esp3dTftui.get_current_screen() == ESP3DScreenType::main) { - main_display_speed(); - } else { - speedScreen::speed_value_cb(index, value, action); - } - } - return true; -} +// bool position_value_cb(ESP3DValuesIndex index, const char *value, +// ESP3DValuesCbAction action) { +// if (action == ESP3DValuesCbAction::Update) { +// if (esp3dTftui.get_current_screen() == ESP3DScreenType::main) { +// main_display_positions(); +// } else { +// positionsScreen::positions_values_cb(index, value, action); +// } +// } +// return true; +// } bool job_status_value_cb(ESP3DValuesIndex index, const char *value, ESP3DValuesCbAction action) { if (action == ESP3DValuesCbAction::Update) { @@ -293,74 +183,13 @@ bool job_status_value_cb(ESP3DValuesIndex index, const char *value, /********************** * LOCAL FUNCTIONS **********************/ - -void main_display_extruder_0() { - std::string label_text = esp3dTftValues.get_string_value( - ESP3DValuesIndex::ext_0_target_temperature); - std::string tmpstr; - if (std::stod(label_text) == 0) { - tmpstr = LV_SYMBOL_EXTRUDER; - } else { - tmpstr = LV_SYMBOL_HEAT_EXTRUDER; - } - lv_label_set_text_fmt( - lv_obj_get_child(main_btn_extruder_0, 0), "%s\n%s\n%s1", - esp3dTftValues.get_string_value(ESP3DValuesIndex::ext_0_temperature), - esp3dTftValues.get_string_value( - ESP3DValuesIndex::ext_0_target_temperature), - tmpstr.c_str()); -} - -void main_display_extruder_1() { - std::string label_text = esp3dTftValues.get_string_value( - ESP3DValuesIndex::ext_1_target_temperature); - if (label_text == "#") { - lv_obj_add_flag(main_btn_extruder_1, LV_OBJ_FLAG_HIDDEN); - return; - } - lv_obj_clear_flag(main_btn_extruder_1, LV_OBJ_FLAG_HIDDEN); - std::string tmpstr; - if (std::stod(label_text) == 0) { - tmpstr = LV_SYMBOL_EXTRUDER; - } else { - tmpstr = LV_SYMBOL_HEAT_EXTRUDER; - } - lv_label_set_text_fmt( - lv_obj_get_child(main_btn_extruder_1, 0), "%s\n%s\n%s2", - esp3dTftValues.get_string_value(ESP3DValuesIndex::ext_1_temperature), - esp3dTftValues.get_string_value( - ESP3DValuesIndex::ext_1_target_temperature), - tmpstr.c_str()); -} - -void main_display_bed() { - std::string label_text = - esp3dTftValues.get_string_value(ESP3DValuesIndex::bed_target_temperature); - if (label_text == "#") { - lv_obj_add_flag(main_btn_bed, LV_OBJ_FLAG_HIDDEN); - return; - } - lv_obj_clear_flag(main_btn_bed, LV_OBJ_FLAG_HIDDEN); - std::string tmpstr; - if (std::stod(label_text) == 0) { - tmpstr = LV_SYMBOL_NO_HEAT_BED; - } else { - tmpstr = LV_SYMBOL_HEAT_BED; - } - lv_label_set_text_fmt( - lv_obj_get_child(main_btn_bed, 0), "%s\n%s\n%s", - esp3dTftValues.get_string_value(ESP3DValuesIndex::bed_temperature), - esp3dTftValues.get_string_value(ESP3DValuesIndex::bed_target_temperature), - tmpstr.c_str()); -} - -void main_display_positions() { - lv_label_set_text_fmt( - lv_obj_get_child(main_btn_positions, 0), "X: %s\nY: %s\nZ: %s", - esp3dTftValues.get_string_value(ESP3DValuesIndex::position_x), - esp3dTftValues.get_string_value(ESP3DValuesIndex::position_y), - esp3dTftValues.get_string_value(ESP3DValuesIndex::position_z)); -} +// void main_display_positions() { +// lv_label_set_text_fmt( +// lv_obj_get_child(main_btn_positions, 0), "X: %s\nY: %s\nZ: %s", +// esp3dTftValues.get_string_value(ESP3DValuesIndex::position_x), +// esp3dTftValues.get_string_value(ESP3DValuesIndex::position_y), +// esp3dTftValues.get_string_value(ESP3DValuesIndex::position_z)); +// } void main_display_status_area() { if (main_label_progression_area) @@ -368,37 +197,6 @@ void main_display_status_area() { progression_area_str.c_str()); } -void main_display_fan() { - esp3d_log("main_display_fan"); - if (!show_fan_button) { - esp3d_log("No control to show"); - return; - } - if (nb_fans == 2) { - esp3d_log("Update button with 2 fans"); - lv_label_set_text_fmt( - lv_obj_get_child(main_btn_fan, 0), "%s%%\n%s%%\n%s", - esp3dTftValues.get_string_value(ESP3DValuesIndex::ext_0_fan), - - esp3dTftValues.get_string_value(ESP3DValuesIndex::ext_1_fan), - LV_SYMBOL_FAN); - } else { - esp3d_log("Update button with 1 fan"); - lv_label_set_text_fmt( - - lv_obj_get_child(main_btn_fan, 0), "%s%%\n%s", - esp3dTftValues.get_string_value(ESP3DValuesIndex::ext_0_fan), - LV_SYMBOL_FAN); - } -} - -void main_display_speed() { - lv_label_set_text_fmt( - lv_obj_get_child(main_btn_speed, 0), "%s%%\n%s", - esp3dTftValues.get_string_value(ESP3DValuesIndex::speed), - LV_SYMBOL_SPEED); -} - void main_display_pause() { std::string label_text = esp3dTftValues.get_string_value(ESP3DValuesIndex::job_status); @@ -472,18 +270,9 @@ void main_screen_delay_timer_cb(lv_timer_t *timer) { case ESP3DScreenType::none: emptyScreen::empty_screen(); break; - case ESP3DScreenType::temperatures: - temperaturesScreen::temperatures_screen(main_screen_temperature_target); - break; - case ESP3DScreenType::positions: - positionsScreen::positions_screen(); - break; - case ESP3DScreenType::fan: - fanScreen::fan_screen(); - break; - case ESP3DScreenType::speed: - speedScreen::speed_screen(); - break; + // case ESP3DScreenType::positions: + // positionsScreen::positions_screen(); + // break; #if ESP3D_SD_CARD_FEATURE case ESP3DScreenType::files: filesScreen::files_screen(); @@ -500,47 +289,6 @@ void main_screen_delay_timer_cb(lv_timer_t *timer) { next_screen = ESP3DScreenType::none; } -void event_button_E0_handler(lv_event_t *e) { - esp3d_log("E0 Clicked"); - if (main_screen_delay_timer) return; - next_screen = ESP3DScreenType::temperatures; - main_screen_temperature_target = 0; - if (BUTTON_ANIMATION_DELAY) { - if (main_screen_delay_timer) return; - main_screen_delay_timer = lv_timer_create(main_screen_delay_timer_cb, - BUTTON_ANIMATION_DELAY, NULL); - } else { - main_screen_delay_timer_cb(NULL); - } -} - -void event_button_E1_handler(lv_event_t *e) { - esp3d_log("E1 Clicked"); - if (main_screen_delay_timer) return; - next_screen = ESP3DScreenType::temperatures; - main_screen_temperature_target = 1; - if (BUTTON_ANIMATION_DELAY) { - if (main_screen_delay_timer) return; - main_screen_delay_timer = lv_timer_create(main_screen_delay_timer_cb, - BUTTON_ANIMATION_DELAY, NULL); - } else { - main_screen_delay_timer_cb(NULL); - } -} - -void event_button_Bed_handler(lv_event_t *e) { - esp3d_log("Bed Clicked"); - if (main_screen_delay_timer) return; - next_screen = ESP3DScreenType::temperatures; - main_screen_temperature_target = 2; - if (BUTTON_ANIMATION_DELAY) { - if (main_screen_delay_timer) return; - main_screen_delay_timer = lv_timer_create(main_screen_delay_timer_cb, - BUTTON_ANIMATION_DELAY, NULL); - } else { - main_screen_delay_timer_cb(NULL); - } -} void event_button_positions_handler(lv_event_t *e) { esp3d_log("Positions Clicked"); @@ -555,31 +303,18 @@ void event_button_positions_handler(lv_event_t *e) { } } -void event_button_fan_handler(lv_event_t *e) { - esp3d_log("Fan Clicked"); - if (main_screen_delay_timer) return; - next_screen = ESP3DScreenType::fan; - if (BUTTON_ANIMATION_DELAY) { - if (main_screen_delay_timer) return; - main_screen_delay_timer = lv_timer_create(main_screen_delay_timer_cb, - BUTTON_ANIMATION_DELAY, NULL); - } else { - main_screen_delay_timer_cb(NULL); - } -} - -void event_button_speed_handler(lv_event_t *e) { - esp3d_log("Speed Clicked"); - if (main_screen_delay_timer) return; - next_screen = ESP3DScreenType::speed; - if (BUTTON_ANIMATION_DELAY) { - if (main_screen_delay_timer) return; - main_screen_delay_timer = lv_timer_create(main_screen_delay_timer_cb, - BUTTON_ANIMATION_DELAY, NULL); - } else { - main_screen_delay_timer_cb(NULL); - } -} +// void event_button_fan_handler(lv_event_t *e) { +// esp3d_log("Fan Clicked"); +// if (main_screen_delay_timer) return; +// next_screen = ESP3DScreenType::fan; +// if (BUTTON_ANIMATION_DELAY) { +// if (main_screen_delay_timer) return; +// main_screen_delay_timer = lv_timer_create(main_screen_delay_timer_cb, +// BUTTON_ANIMATION_DELAY, NULL); +// } else { +// main_screen_delay_timer_cb(NULL); +// } +// } #if ESP3D_SD_CARD_FEATURE void event_button_files_handler(lv_event_t *e) { @@ -640,14 +375,6 @@ void main_screen() { // Screen creation esp3d_log("Main screen creation"); if (!intialization_done) { - esp3d_log("main screen initialization"); - std::string value = - esp3dTftJsonSettings.readString("settings", "showfanctrls"); - if (value == "true") { - show_fan_button = true; - } else { - show_fan_button = false; - } intialization_done = true; } // Background @@ -691,33 +418,12 @@ void main_screen() { apply_outline_pad(ui_bottom_buttons_container); lv_obj_clear_flag(ui_bottom_buttons_container, LV_OBJ_FLAG_SCROLLABLE); - //********************************** - // Create button and label for Extruder 0 - main_btn_extruder_0 = - menuButton::create_menu_button(ui_top_buttons_container, ""); - - lv_obj_add_event_cb(main_btn_extruder_0, event_button_E0_handler, - LV_EVENT_CLICKED, NULL); - - // Create button and label for Extruder 1 - main_btn_extruder_1 = - menuButton::create_menu_button(ui_top_buttons_container, ""); - - lv_obj_add_event_cb(main_btn_extruder_1, event_button_E1_handler, - LV_EVENT_CLICKED, NULL); - - // Create button and label for Bed - main_btn_bed = menuButton::create_menu_button(ui_top_buttons_container, ""); - - lv_obj_add_event_cb(main_btn_bed, event_button_Bed_handler, LV_EVENT_CLICKED, - NULL); - // Create button and label for positions - main_btn_positions = symbolButton::create_symbol_button( - ui_top_buttons_container, "", BUTTON_WIDTH * 1.5, BUTTON_HEIGHT); + // main_btn_positions = symbolButton::create_symbol_button( + // ui_top_buttons_container, "", BUTTON_WIDTH * 1.5, BUTTON_HEIGHT); - lv_obj_add_event_cb(main_btn_positions, event_button_positions_handler, - LV_EVENT_CLICKED, NULL); + // lv_obj_add_event_cb(main_btn_positions, event_button_positions_handler, + // LV_EVENT_CLICKED, NULL); // Create button and label for middle container main_label_progression_area = lv_label_create(ui_middle_container); @@ -726,22 +432,7 @@ void main_screen() { lv_obj_center(main_label_progression_area); lv_obj_set_size(main_label_progression_area, CURRENT_STATUS_AREA_WIDTH, CURRENT_STATUS_AREA_HEIGHT); - if (show_fan_button) { - // Create button and label for fan - main_btn_fan = - menuButton::create_menu_button(ui_bottom_buttons_container, ""); - - lv_obj_add_event_cb(main_btn_fan, event_button_fan_handler, - LV_EVENT_CLICKED, NULL); - } - - // Create button and label for speed - main_btn_speed = - menuButton::create_menu_button(ui_bottom_buttons_container, ""); - - lv_obj_add_event_cb(main_btn_speed, event_button_speed_handler, - LV_EVENT_CLICKED, NULL); - + // Create button and label for pause main_btn_pause = menuButton::create_menu_button(ui_bottom_buttons_container, LV_SYMBOL_PAUSE); @@ -773,10 +464,7 @@ void main_screen() { lv_obj_add_event_cb(main_btn_menu, event_button_menu_handler, LV_EVENT_CLICKED, NULL); esp3dTftui.set_current_screen(ESP3DScreenType::main); - main_display_extruder_0(); - main_display_extruder_1(); - main_display_bed(); - main_display_positions(); + //main_display_positions(); main_display_status_area(); main_display_pause(); main_display_resume(); @@ -785,7 +473,5 @@ void main_screen() { #endif // ESP3D_SD_CARD_FEATURE main_display_stop(); main_display_menu(); - main_display_speed(); - if (show_fan_button) main_display_fan(); } } // namespace mainScreen \ No newline at end of file diff --git a/main/display/cnc/grbl/screens/main_screen.h b/main/display/cnc/grbl/screens/main_screen.h index f4f5f487..73290eb1 100644 --- a/main/display/cnc/grbl/screens/main_screen.h +++ b/main/display/cnc/grbl/screens/main_screen.h @@ -24,20 +24,7 @@ namespace mainScreen { extern void main_screen(); -extern bool extruder_0_value_cb(ESP3DValuesIndex index, const char *value, - ESP3DValuesCbAction action); -extern bool extruder_1_value_cb(ESP3DValuesIndex index, const char *value, - ESP3DValuesCbAction action); -extern bool bed_value_cb(ESP3DValuesIndex index, const char *value, - ESP3DValuesCbAction action); -extern bool position_value_cb(ESP3DValuesIndex index, const char *value, - ESP3DValuesCbAction action); -extern bool fan_value_cb(ESP3DValuesIndex index, const char *value, - ESP3DValuesCbAction action); -extern bool speed_value_cb(ESP3DValuesIndex index, const char *value, - ESP3DValuesCbAction action); extern bool job_status_value_cb(ESP3DValuesIndex index, const char *value, ESP3DValuesCbAction action); -extern void update_show_fan_controls(bool show); } // namespace mainScreen diff --git a/main/display/cnc/grbl/screens/manual_leveling_screen.cpp b/main/display/cnc/grbl/screens/manual_leveling_screen.cpp deleted file mode 100644 index ca9d4e50..00000000 --- a/main/display/cnc/grbl/screens/manual_leveling_screen.cpp +++ /dev/null @@ -1,455 +0,0 @@ -/* - esp3d_tft - - Copyright (c) 2022 Luc Lebosse. All rights reserved. - - This code is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This code 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#include "screens/manual_leveling_screen.h" - -#include - -#include "components/back_button_component.h" -#include "components/message_box_component.h" -#include "components/symbol_button_component.h" -#include "esp3d_log.h" -#include "esp3d_styles.h" -#include "esp3d_tft_ui.h" -#include "screens/leveling_screen.h" -#include "screens/menu_screen.h" -#include "rendering/esp3d_rendering_client.h" -#include "translations/esp3d_translation_service.h" - -/********************** - * STATIC PROTOTYPES - **********************/ -namespace manualLevelingScreen { -bool auto_leveling = false; -bool homing_done = false; -const char *leveling_position_buttons_map[] = {"4", - LV_SYMBOL_BULLET, - "5", - "\n", - LV_SYMBOL_BULLET, - "1", - LV_SYMBOL_BULLET, - "\n", - "2", - LV_SYMBOL_BULLET, - "3", - ""}; -int8_t leveling_position_buttons_map_id = -1; -lv_obj_t *btnm_leveling_position = NULL; -lv_obj_t *btn_next = NULL; -lv_obj_t *btn_previous = NULL; -lv_obj_t *btn_start = NULL; -lv_obj_t *status_container = NULL; -double intialization_done = false; -double bed_width = 100; -double bed_depth = 100; -bool invert_x = false; -bool invert_y = false; -#define DEFAULT_Z_DISTANCE 15 -lv_timer_t *manual_leveling_screen_delay_timer = NULL; -void update_bed_width(double value) { bed_width = value; } - -void update_bed_depth(double value) { bed_depth = value; } -void update_invert_x(bool value) { invert_x = value; } -void update_invert_y(bool value) { invert_y = value; } - -void manual_leveling_screen_delay_timer_cb(lv_timer_t *timer) { - if (manual_leveling_screen_delay_timer) { - lv_timer_del(manual_leveling_screen_delay_timer); - manual_leveling_screen_delay_timer = NULL; - } - if (auto_leveling) { - levelingScreen::leveling_screen(auto_leveling); - } else { - menuScreen::menu_screen(); - } -} - -void event_button_manual_leveling_back_handler(lv_event_t *e) { - esp3d_log("back Clicked"); - if (BUTTON_ANIMATION_DELAY) { - if (manual_leveling_screen_delay_timer) return; - manual_leveling_screen_delay_timer = lv_timer_create( - manual_leveling_screen_delay_timer_cb, BUTTON_ANIMATION_DELAY, NULL); - } else { - manual_leveling_screen_delay_timer_cb(NULL); - } -} - -void move_to_position(int pos) { - if (!homing_done) { - esp3d_log("Homing not done, doing now..."); - renderingClient.sendGcode("G28"); - // In theory when homing, if 2 extruders, E0 is set by default - // TBC if need to explicilty set it to E0 using T0 command - homing_done = true; - } - std::string gcode_command = "G1 Z" + std::to_string(DEFAULT_Z_DISTANCE); - renderingClient.sendGcode(gcode_command.c_str()); - double x = 0; - double y = 0; - double x_pad = bed_width / 10; - double y_pad = bed_depth / 10; - switch (pos) { - case 0: - // Move to position 0 - esp3d_log("Move to position 0"); - if (invert_x) { - x = bed_width - x_pad; - } else { - x = x_pad; - } - if (invert_y) { - y = y_pad; - } else { - y = bed_depth - y_pad; - } - break; - case 1: - // Move to position 1 - esp3d_log("Move to position 1"); - x = bed_width / 2; - if (invert_y) { - y = y_pad; - } else { - y = bed_depth - y_pad; - } - break; - case 2: - // Move to position 2 - esp3d_log("Move to position 2"); - if (invert_x) { - x = x_pad; - } else { - x = bed_width - x_pad; - } - if (invert_y) { - y = y_pad; - } else { - y = bed_depth - y_pad; - } - break; - case 3: - // Move to position 3 - esp3d_log("Move to position 3"); - if (invert_x) { - x = bed_width - x_pad; - } else { - x = x_pad; - } - y = bed_depth / 2; - break; - case 4: - // Move to position 4 - esp3d_log("Move to position 4"); - x = bed_width / 2; - y = bed_depth / 2; - break; - case 5: - // Move to position 5 - esp3d_log("Move to position 5"); - if (invert_x) { - x = x_pad; - } else { - x = bed_width - x_pad; - } - y = bed_depth / 2; - break; - case 6: - // Move to position 6 - esp3d_log("Move to position 6"); - if (invert_x) { - x = bed_width - x_pad; - } else { - x = x_pad; - } - if (invert_y) { - y = bed_depth - y_pad; - } else { - y = y_pad; - } - break; - case 7: - // Move to position 7 - esp3d_log("Move to position 7"); - x = bed_width / 2; - if (invert_y) { - y = bed_depth - y_pad; - } else { - y = y_pad; - } - break; - case 8: - // Move to position 8 - esp3d_log("Move to position 8"); - if (invert_x) { - x = x_pad; - } else { - x = bed_width - x_pad; - } - if (invert_y) { - y = bed_depth - y_pad; - } else { - y = y_pad; - } - break; - default: - break; - } - // Move to position - gcode_command = "G1 X" + std::to_string(x) + " Y" + std::to_string(y); - renderingClient.sendGcode(gcode_command.c_str()); - // Move to Z0 - renderingClient.sendGcode("G1 Z0"); -} - -void event_button_manual_leveling_next_handler(lv_event_t *e) { - lv_obj_t *table_position = (lv_obj_t *)lv_event_get_user_data(e); - if (leveling_position_buttons_map_id == -1) { - leveling_position_buttons_map_id = 4; - } else { - switch (leveling_position_buttons_map_id) { - case 0: - leveling_position_buttons_map_id = 2; - break; - case 1: - leveling_position_buttons_map_id = 2; - break; - case 2: - leveling_position_buttons_map_id = 4; - break; - case 3: - leveling_position_buttons_map_id = 4; - break; - case 4: - leveling_position_buttons_map_id = 6; - break; - case 5: - leveling_position_buttons_map_id = 6; - break; - case 6: - leveling_position_buttons_map_id = 8; - break; - case 7: - leveling_position_buttons_map_id = 8; - break; - case 8: - leveling_position_buttons_map_id = 0; - break; - default: - break; - } - } - lv_btnmatrix_set_btn_ctrl(table_position, leveling_position_buttons_map_id, - LV_BTNMATRIX_CTRL_CHECKED); - move_to_position(leveling_position_buttons_map_id); - - esp3d_log("Next Clicked"); -} - -void event_button_manual_leveling_previous_handler(lv_event_t *e) { - lv_obj_t *table_position = (lv_obj_t *)lv_event_get_user_data(e); - if (leveling_position_buttons_map_id == -1) { - leveling_position_buttons_map_id = 4; - } else { - switch (leveling_position_buttons_map_id) { - case 0: - leveling_position_buttons_map_id = 8; - break; - case 1: - leveling_position_buttons_map_id = 0; - break; - case 2: - leveling_position_buttons_map_id = 0; - break; - case 3: - leveling_position_buttons_map_id = 2; - break; - case 4: - leveling_position_buttons_map_id = 2; - break; - case 5: - leveling_position_buttons_map_id = 4; - break; - case 6: - leveling_position_buttons_map_id = 4; - break; - case 7: - leveling_position_buttons_map_id = 6; - break; - case 8: - leveling_position_buttons_map_id = 6; - break; - default: - break; - } - } - lv_btnmatrix_set_btn_ctrl(table_position, leveling_position_buttons_map_id, - LV_BTNMATRIX_CTRL_CHECKED); - move_to_position(leveling_position_buttons_map_id); - esp3d_log("Previous Clicked"); -} - -void leveling_posiiton_matrix_buttons_event_cb(lv_event_t *e) { - // lv_obj_t *ta = (lv_obj_t *)lv_event_get_user_data(e); - lv_obj_t *obj = lv_event_get_target(e); - uint32_t id = lv_btnmatrix_get_selected_btn(obj); - leveling_position_buttons_map_id = id; - esp3d_log("Button %d clicked", leveling_position_buttons_map_id); - move_to_position(leveling_position_buttons_map_id); -} - -void event_button_manual_leveling_help_handler(lv_event_t *e) { - esp3d_log("Help Clicked"); - std::string text = - esp3dTranslationService.translate(ESP3DLabel::manual_leveling_help); - msgBox::messageBox(NULL, MsgBoxType::information, text.c_str()); -} - -void event_button_manual_leveling_start_handler(lv_event_t *e) { - lv_obj_t *table_position = (lv_obj_t *)lv_event_get_user_data(e); - esp3d_log("Start Clicked"); - // send G28 - lv_obj_clear_state(btn_next, LV_STATE_DISABLED); - lv_obj_clear_state(btn_previous, LV_STATE_DISABLED); - lv_obj_clear_state(btnm_leveling_position, LV_STATE_DISABLED); - lv_obj_add_flag(btn_start, LV_OBJ_FLAG_HIDDEN); - lv_obj_clear_flag(status_container, LV_OBJ_FLAG_HIDDEN); - - // once G28 is done - leveling_position_buttons_map_id = 4; - lv_btnmatrix_set_btn_ctrl(table_position, leveling_position_buttons_map_id, - LV_BTNMATRIX_CTRL_CHECKED); - move_to_position(leveling_position_buttons_map_id); -} -void manual_leveling_screen(bool autoleveling) { - auto_leveling = autoleveling; - leveling_position_buttons_map_id = -1; - homing_done = false; - esp3dTftui.set_current_screen(ESP3DScreenType::none); - // Screen creation - esp3d_log("Manual leveling screen creation"); - if (!intialization_done) { - esp3d_log("Manual leveling screen initialization"); - char buffer[16]; - uint8_t byte_value = - esp3dTftsettings.readByte(ESP3DSettingIndex::esp3d_inverved_x); - update_invert_x(byte_value == 1 ? true : false); - byte_value = esp3dTftsettings.readByte(ESP3DSettingIndex::esp3d_inverved_y); - update_invert_y(byte_value == 1 ? true : false); - std::string str_value = esp3dTftsettings.readString( - ESP3DSettingIndex::esp3d_bed_width, buffer, 16); - update_bed_width(std::strtod(str_value.c_str(), - NULL)); // update width value - str_value = esp3dTftsettings.readString(ESP3DSettingIndex::esp3d_bed_depth, - buffer, 16); - update_bed_depth(std::strtod(str_value.c_str(), - NULL)); // update depth value - intialization_done = true; - } - lv_obj_t *ui_new_screen = lv_obj_create(NULL); - // Display new screen and delete old one - lv_obj_t *ui_current_screen = lv_scr_act(); - lv_scr_load(ui_new_screen); - apply_style(ui_new_screen, ESP3DStyleType::main_bg); - lv_obj_del(ui_current_screen); - - // Button back - lv_obj_t *btn_back = backButton::create_back_button(ui_new_screen); - lv_obj_add_event_cb(btn_back, event_button_manual_leveling_back_handler, - LV_EVENT_CLICKED, NULL); - lv_obj_update_layout(btn_back); - - // Manual leveling button matrix - btnm_leveling_position = lv_btnmatrix_create(ui_new_screen); - lv_btnmatrix_set_map(btnm_leveling_position, leveling_position_buttons_map); - apply_style(btnm_leveling_position, ESP3DStyleType::buttons_matrix); - lv_obj_update_layout(btnm_leveling_position); - lv_obj_set_pos(btnm_leveling_position, CURRENT_BUTTON_PRESSED_OUTLINE, - CURRENT_BUTTON_PRESSED_OUTLINE); - lv_obj_set_size(btnm_leveling_position, LV_HOR_RES / 2, - LV_VER_RES - (CURRENT_BUTTON_PRESSED_OUTLINE * 3) - - lv_obj_get_height(btn_back)); - lv_obj_add_event_cb(btnm_leveling_position, - leveling_posiiton_matrix_buttons_event_cb, - LV_EVENT_VALUE_CHANGED, NULL); - - // Button Previous - btn_previous = symbolButton::create_symbol_button( - ui_new_screen, LV_SYMBOL_PREVIOUS, BACK_BUTTON_WIDTH, BACK_BUTTON_HEIGHT); - lv_obj_align(btn_previous, LV_ALIGN_BOTTOM_LEFT, - CURRENT_BUTTON_PRESSED_OUTLINE, -CURRENT_BUTTON_PRESSED_OUTLINE); - lv_obj_add_event_cb(btn_previous, - event_button_manual_leveling_previous_handler, - LV_EVENT_CLICKED, btnm_leveling_position); - - // Button Next - btn_next = symbolButton::create_symbol_button( - ui_new_screen, LV_SYMBOL_NEXT, BACK_BUTTON_WIDTH, BACK_BUTTON_HEIGHT); - lv_obj_align_to(btn_next, btnm_leveling_position, LV_ALIGN_OUT_BOTTOM_RIGHT, - 0, CURRENT_BUTTON_PRESSED_OUTLINE); - - lv_obj_add_event_cb(btn_next, event_button_manual_leveling_next_handler, - LV_EVENT_CLICKED, btnm_leveling_position); - - // Help button - lv_obj_t *btn_help = symbolButton::create_symbol_button( - ui_new_screen, "?", BACK_BUTTON_WIDTH, BACK_BUTTON_HEIGHT); - lv_obj_align(btn_help, LV_ALIGN_TOP_RIGHT, -CURRENT_BUTTON_PRESSED_OUTLINE, - CURRENT_BUTTON_PRESSED_OUTLINE); - lv_obj_add_event_cb(btn_help, event_button_manual_leveling_help_handler, - LV_EVENT_CLICKED, NULL); - - // Start button - btn_start = symbolButton::create_symbol_button(ui_new_screen, LV_SYMBOL_PLAY); - lv_obj_align_to(btn_start, btnm_leveling_position, LV_ALIGN_OUT_RIGHT_MID, - (LV_HOR_RES / 4) - SYMBOL_BUTTON_WIDTH / 2, 0); - lv_obj_add_event_cb(btn_start, event_button_manual_leveling_start_handler, - LV_EVENT_CLICKED, btnm_leveling_position); - - // Status container - status_container = lv_obj_create(ui_new_screen); - - apply_style(status_container, ESP3DStyleType::text_container); - lv_obj_set_size(status_container, - (LV_HOR_RES / 2) - (3 * CURRENT_BUTTON_PRESSED_OUTLINE), - LV_VER_RES - (CURRENT_BUTTON_PRESSED_OUTLINE * 4) - - lv_obj_get_height(btn_back) * 2); - lv_obj_align_to(status_container, btn_help, LV_ALIGN_OUT_BOTTOM_RIGHT, 0, - CURRENT_BUTTON_PRESSED_OUTLINE); - - // status text - std::string t = - esp3dTranslationService.translate(ESP3DLabel::manual_leveling_text); - lv_obj_t *status_text = lv_label_create(status_container); - lv_obj_set_width(status_text, lv_obj_get_content_width(status_container)); - lv_label_set_long_mode(status_text, LV_LABEL_LONG_WRAP); - lv_label_set_text(status_text, t.c_str()); - - // Init state - lv_obj_add_state(btn_next, LV_STATE_DISABLED); - lv_obj_add_state(btn_previous, LV_STATE_DISABLED); - lv_obj_add_state(btnm_leveling_position, LV_STATE_DISABLED); - lv_obj_add_flag(status_container, LV_OBJ_FLAG_HIDDEN); - - esp3dTftui.set_current_screen(ESP3DScreenType::manual_leveling); -} - -} // namespace manualLevelingScreen \ No newline at end of file diff --git a/main/display/cnc/grbl/screens/manual_leveling_screen.h b/main/display/cnc/grbl/screens/manual_leveling_screen.h deleted file mode 100644 index 992c948c..00000000 --- a/main/display/cnc/grbl/screens/manual_leveling_screen.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - manual_leveling__screen.h - esp3d - Copyright (c) 2022 Luc Lebosse. All rights reserved. - - This code is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This code 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#pragma once - -namespace manualLevelingScreen { -extern void manual_leveling_screen(bool auto_leveling); -extern void update_bed_width(double value); -extern void update_bed_depth(double value); -extern void update_invert_x(bool value); -extern void update_invert_y(bool value); -} // namespace manualLevelingScreen diff --git a/main/display/cnc/grbl/screens/menu_screen.cpp b/main/display/cnc/grbl/screens/menu_screen.cpp index a1fc0419..618cb959 100644 --- a/main/display/cnc/grbl/screens/menu_screen.cpp +++ b/main/display/cnc/grbl/screens/menu_screen.cpp @@ -32,11 +32,8 @@ #include "esp3d_styles.h" #include "esp3d_tft_ui.h" #include "esp3d_values.h" -#include "screens/filament_screen.h" #include "screens/informations_screen.h" -#include "screens/leveling_screen.h" #include "screens/main_screen.h" -#include "screens/manual_leveling_screen.h" #include "screens/menu_screen.h" #include "screens/settings_screen.h" #include "translations/esp3d_translation_service.h" @@ -51,43 +48,13 @@ namespace menuScreen { lv_timer_t *menu_screen_delay_timer = NULL; ESP3DScreenType menu_next_screen = ESP3DScreenType::none; -lv_obj_t *main_btn_leveling = NULL; -lv_obj_t *main_btn_disable_steppers = NULL; bool intialization_done = false; -bool auto_leveling = false; - -void enable_auto_leveling(bool enable) { auto_leveling = enable; } - -void menu_display_leveling() { - std::string label_text = - esp3dTftValues.get_string_value(ESP3DValuesIndex::job_status); - if (label_text == "paused") { - lv_obj_add_flag(main_btn_leveling, LV_OBJ_FLAG_HIDDEN); - } else if (label_text == "processing") { - lv_obj_add_flag(main_btn_leveling, LV_OBJ_FLAG_HIDDEN); - } else { - lv_obj_clear_flag(main_btn_leveling, LV_OBJ_FLAG_HIDDEN); - } -} - -void menu_display_disable_steppers() { - std::string label_text = - esp3dTftValues.get_string_value(ESP3DValuesIndex::job_status); - if (label_text == "paused") { - lv_obj_add_flag(main_btn_disable_steppers, LV_OBJ_FLAG_HIDDEN); - } else if (label_text == "processing") { - lv_obj_add_flag(main_btn_disable_steppers, LV_OBJ_FLAG_HIDDEN); - } else { - lv_obj_clear_flag(main_btn_disable_steppers, LV_OBJ_FLAG_HIDDEN); - } -} void menu_screen_job_status_value_cb(ESP3DValuesIndex index, const char *value, ESP3DValuesCbAction action) { if (action == ESP3DValuesCbAction::Update) { if (esp3dTftui.get_current_screen() == ESP3DScreenType::menu) { - menu_display_leveling(); - menu_display_disable_steppers(); + // Update buttons display according status } } // Todo update buttons display according status @@ -102,19 +69,11 @@ void menu_screen_delay_timer_cb(lv_timer_t *timer) { case ESP3DScreenType::main: mainScreen::main_screen(); break; - case ESP3DScreenType::filament: - filamentScreen::filament_screen(); - break; + case ESP3DScreenType::settings: settingsScreen::settings_screen(); break; - case ESP3DScreenType::leveling: - if (auto_leveling) { - levelingScreen::leveling_screen(auto_leveling); - } else { - manualLevelingScreen::manual_leveling_screen(auto_leveling); - } - break; + case ESP3DScreenType::informations: informationsScreen::informations_screen(); break; @@ -141,19 +100,6 @@ void event_button_menu_back_handler(lv_event_t *e) { } } -void event_button_filament_handler(lv_event_t *e) { - esp3d_log("filament Clicked"); - if (menu_screen_delay_timer) return; - menu_next_screen = ESP3DScreenType::filament; - if (BUTTON_ANIMATION_DELAY) { - if (menu_screen_delay_timer) return; - menu_screen_delay_timer = lv_timer_create(menu_screen_delay_timer_cb, - BUTTON_ANIMATION_DELAY, NULL); - } else { - menu_screen_delay_timer_cb(NULL); - } -} - #if ESP3D_WIFI_FEATURE void event_button_wifi_handler(lv_event_t *e) { esp3d_log("wifi Clicked"); @@ -181,18 +127,6 @@ void event_button_settings_handler(lv_event_t *e) { menu_screen_delay_timer_cb(NULL); } -void event_button_leveling_handler(lv_event_t *e) { - esp3d_log("leveling Clicked"); - if (menu_screen_delay_timer) return; - menu_next_screen = ESP3DScreenType::leveling; - if (BUTTON_ANIMATION_DELAY) { - if (menu_screen_delay_timer) return; - menu_screen_delay_timer = lv_timer_create(menu_screen_delay_timer_cb, - BUTTON_ANIMATION_DELAY, NULL); - } else - menu_screen_delay_timer_cb(NULL); -} - void event_button_informations_handler(lv_event_t *e) { esp3d_log("informations Clicked"); if (menu_screen_delay_timer) return; @@ -205,24 +139,11 @@ void event_button_informations_handler(lv_event_t *e) { menu_screen_delay_timer_cb(NULL); } -void event_button_disable_steppers_handler(lv_event_t *e) { - esp3d_log("Disable Steppers Clicked"); - renderingClient.sendGcode("M84"); - std::string text = - esp3dTranslationService.translate(ESP3DLabel::motors_disabled); - msgBox::messageBox(NULL, MsgBoxType::information, text.c_str()); - esp3dTftValues.set_string_value(ESP3DValuesIndex::status_bar_label, - text.c_str()); -} - void menu_screen() { esp3dTftui.set_current_screen(ESP3DScreenType::none); if (!intialization_done) { esp3d_log("menu screen initialization"); - uint8_t byteValue = - esp3dTftsettings.readByte(ESP3DSettingIndex::esp3d_auto_level_on); - - auto_leveling = byteValue == 1 ? true : false; + intialization_done = true; } // Screen creation @@ -256,26 +177,11 @@ void menu_screen() { //********************************** // Create button and label for filament button - lv_obj_t *btn1 = symbolButton::create_symbol_button( - ui_top_buttons_container, LV_SYMBOL_FILAMENT, BUTTON_WIDTH, BUTTON_HEIGHT, - true, false, 90); - lv_obj_add_event_cb(btn1, event_button_filament_handler, LV_EVENT_CLICKED, - NULL); - - // Create button and label for leveling button - std::string label2 = LV_SYMBOL_LEVELING; - main_btn_leveling = - menuButton::create_menu_button(ui_top_buttons_container, label2.c_str()); - lv_obj_add_event_cb(main_btn_leveling, event_button_leveling_handler, - LV_EVENT_CLICKED, NULL); - - // Create button and label for disable steppers button - main_btn_disable_steppers = symbolButton::create_symbol_button( - ui_top_buttons_container, LV_SYMBOL_ENGINE, BUTTON_WIDTH, BUTTON_HEIGHT, - true, true, 90); - lv_obj_add_event_cb(main_btn_disable_steppers, - event_button_disable_steppers_handler, LV_EVENT_CLICKED, - NULL); + // lv_obj_t *btn1 = symbolButton::create_symbol_button( + // ui_top_buttons_container, LV_SYMBOL_FILAMENT, BUTTON_WIDTH, BUTTON_HEIGHT, + // true, false, 90); + // lv_obj_add_event_cb(btn1, event_button_filament_handler, LV_EVENT_CLICKED, + // NULL); #if ESP3D_WIFI_FEATURE // Create button and label for wifi button @@ -299,7 +205,5 @@ void menu_screen() { lv_obj_add_event_cb(btn6, event_button_informations_handler, LV_EVENT_CLICKED, NULL); esp3dTftui.set_current_screen(ESP3DScreenType::menu); - menu_display_disable_steppers(); - menu_display_leveling(); } } // namespace menuScreen \ No newline at end of file diff --git a/main/display/cnc/grbl/screens/menu_screen.h b/main/display/cnc/grbl/screens/menu_screen.h index 1b398c26..f2fa8027 100644 --- a/main/display/cnc/grbl/screens/menu_screen.h +++ b/main/display/cnc/grbl/screens/menu_screen.h @@ -27,5 +27,4 @@ extern void menu_screen(); extern void menu_screen_job_status_value_cb(ESP3DValuesIndex index, const char *value, ESP3DValuesCbAction action); -extern void enable_auto_leveling(bool enable); } // namespace menuScreen diff --git a/main/display/cnc/grbl/screens/positions_screen.cpp b/main/display/cnc/grbl/screens/positions_screen.cpp deleted file mode 100644 index faa9d564..00000000 --- a/main/display/cnc/grbl/screens/positions_screen.cpp +++ /dev/null @@ -1,500 +0,0 @@ -/* - esp3d_tft - - Copyright (c) 2022 Luc Lebosse. All rights reserved. - - This code is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This code 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#include "screens/positions_screen.h" - -#include - -#include "components/back_button_component.h" -#include "components/symbol_button_component.h" -#include "esp3d_log.h" -#include "esp3d_settings.h" -#include "esp3d_string.h" -#include "esp3d_styles.h" -#include "esp3d_tft_ui.h" -#include "screens/main_screen.h" -#include "rendering/esp3d_rendering_client.h" -#include "translations/esp3d_translation_service.h" - -/********************** - * STATIC PROTOTYPES - **********************/ - -namespace positionsScreen { -std::string position_value = "0.00"; -const char *positions_buttons_map[] = {"0.1", "1", "10", "50", ""}; -uint8_t positions_buttons_map_id = 0; - -bool absolute_position = false; - -const char *axis_buttons_map[] = {"X", "Y", "Z", ""}; - -uint8_t axis_buttons_map_id = 0; - -lv_obj_t *label_current_position_value = NULL; -lv_obj_t *label_current_position = NULL; -lv_timer_t *positions_screen_delay_timer = NULL; -lv_obj_t *position_ta = NULL; -lv_obj_t *btn_set = NULL; - -bool intialization_done = false; - -bool positions_values_cb(ESP3DValuesIndex index, const char *value, - ESP3DValuesCbAction action) { - if (esp3dTftui.get_current_screen() != ESP3DScreenType::positions) - return false; - - switch (index) { - case ESP3DValuesIndex::position_x: - if (action == ESP3DValuesCbAction::Update && axis_buttons_map_id == 0) { - lv_label_set_text(label_current_position_value, value); - } - break; - case ESP3DValuesIndex::position_y: - if (action == ESP3DValuesCbAction::Update && axis_buttons_map_id == 1) { - lv_label_set_text(label_current_position_value, value); - } - break; - case ESP3DValuesIndex::position_z: - if (action == ESP3DValuesCbAction::Update && axis_buttons_map_id == 2) { - lv_label_set_text(label_current_position_value, value); - } - break; - default: - break; - } - return true; -} - -void positions_screen_delay_timer_cb(lv_timer_t *timer) { - if (positions_screen_delay_timer) { - lv_timer_del(positions_screen_delay_timer); - positions_screen_delay_timer = NULL; - } - mainScreen::main_screen(); -} - -void event_button_positions_back_handler(lv_event_t *e) { - esp3d_log("back Clicked"); - if (BUTTON_ANIMATION_DELAY) { - if (positions_screen_delay_timer) return; - positions_screen_delay_timer = lv_timer_create( - positions_screen_delay_timer_cb, BUTTON_ANIMATION_DELAY, NULL); - } else { - positions_screen_delay_timer_cb(NULL); - } -} - -void position_ta_event_cb(lv_event_t *e) { - lv_event_code_t code = lv_event_get_code(e); - lv_obj_t *ta = lv_event_get_target(e); - lv_obj_t *kb = (lv_obj_t *)lv_event_get_user_data(e); - if (code == LV_EVENT_FOCUSED || code == LV_EVENT_PRESSED) { - esp3d_log("Clicked, Value"); - lv_keyboard_set_textarea(kb, ta); - lv_obj_add_state(ta, LV_STATE_FOCUSED); - lv_obj_clear_flag(kb, LV_OBJ_FLAG_HIDDEN); - lv_obj_set_scrollbar_mode(ta, LV_SCROLLBAR_MODE_AUTO); - } else if (code == LV_EVENT_DEFOCUSED) { - esp3d_log("Defocused, Value"); - lv_textarea_set_cursor_pos(ta, 0); - lv_obj_set_scrollbar_mode(ta, LV_SCROLLBAR_MODE_OFF); - lv_keyboard_set_textarea(kb, NULL); - lv_obj_add_flag(kb, LV_OBJ_FLAG_HIDDEN); - position_value = lv_textarea_get_text(ta); - } else if (code == LV_EVENT_READY || code == LV_EVENT_CANCEL) { - esp3d_log("Ready/Cancel, Value: %s", lv_textarea_get_text(ta)); - position_value = lv_textarea_get_text(ta); - esp3d_log("Value changed: %s", position_value.c_str()); - lv_textarea_set_cursor_pos(ta, 0); - lv_obj_set_scrollbar_mode(ta, LV_SCROLLBAR_MODE_OFF); - lv_keyboard_set_textarea(kb, NULL); - lv_obj_clear_state(ta, LV_STATE_FOCUSED); - lv_obj_add_flag(kb, LV_OBJ_FLAG_HIDDEN); - // - } else if (code == LV_EVENT_VALUE_CHANGED) { - // position_value = lv_textarea_get_text(ta); - // esp3d_log("Value changed: %s", position_value.c_str()); - } -} -void send_gcode_position(const char *position_value) { - if (absolute_position) { - std::string gcode = "G1 "; - gcode += axis_buttons_map[axis_buttons_map_id]; - gcode += position_value; - renderingClient.sendGcode(gcode.c_str()); - } else { - std::string gcode = "G91"; - renderingClient.sendGcode(gcode.c_str()); - gcode = "G1 "; - gcode += axis_buttons_map[axis_buttons_map_id]; - gcode += position_value; - renderingClient.sendGcode(gcode.c_str()); - gcode = "G90"; - renderingClient.sendGcode(gcode.c_str()); - } -} - -void positions_btn_up_event_cb(lv_event_t *e) { - lv_obj_t *position_ta = (lv_obj_t *)lv_event_get_user_data(e); - std::string position_value = lv_textarea_get_text(position_ta); - if (absolute_position) { - double position_double = std::stod(position_value); - double step = std::stod(positions_buttons_map[positions_buttons_map_id]); - esp3d_log("Current pos: %s, %f", position_value.c_str(), position_double); - position_double += step; - esp3d_log("Up: %f, new pos: %f", step, position_double); - position_value = - esp3d_string::set_precision(std::to_string(position_double), 2); - lv_textarea_set_text(position_ta, position_value.c_str()); - } - send_gcode_position(position_value.c_str()); -} - -void positions_btn_down_event_cb(lv_event_t *e) { - lv_obj_t *position_ta = (lv_obj_t *)lv_event_get_user_data(e); - std::string position_value = lv_textarea_get_text(position_ta); - if (absolute_position) { - double position_double = std::stod(position_value); - double step = std::stod(positions_buttons_map[positions_buttons_map_id]); - esp3d_log("Current pos: %s, %f", position_value.c_str(), position_double); - position_double -= step; - esp3d_log("Down: %f, new pos: %f", step, position_double); - position_value = - esp3d_string::set_precision(std::to_string(position_double), 2); - lv_textarea_set_text(position_ta, position_value.c_str()); - } else { - position_value = "-" + position_value; - } - send_gcode_position(position_value.c_str()); -} - -void positions_btn_ok_event_cb(lv_event_t *e) { - lv_obj_t *position_ta = (lv_obj_t *)lv_event_get_user_data(e); - std::string position_value = lv_textarea_get_text(position_ta); - esp3d_log("Ok: %s", position_value.c_str()); - send_gcode_position(position_value.c_str()); -} - -void positions_btn_home_axis_event_cb(lv_event_t *e) { - // lv_obj_t *position_ta = (lv_obj_t *)lv_event_get_user_data(e); - esp3d_log("Home Axis %c", axis_buttons_map[axis_buttons_map_id][0]); - std::string gcode = "G28 "; - gcode += axis_buttons_map[axis_buttons_map_id]; - renderingClient.sendGcode(gcode.c_str()); -} - -void updateMode(bool mode) { - if (mode) { - lv_obj_clear_state(position_ta, LV_STATE_DISABLED); - std::string current_position_value = - lv_label_get_text(label_current_position_value); - lv_textarea_set_text(position_ta, current_position_value == "?" - ? "0.00" - : current_position_value.c_str()); - lv_obj_clear_flag(btn_set, LV_OBJ_FLAG_HIDDEN); - - } else { - lv_obj_add_flag(btn_set, LV_OBJ_FLAG_HIDDEN); - lv_obj_add_state(position_ta, LV_STATE_DISABLED); - lv_textarea_set_text(position_ta, - positions_buttons_map[positions_buttons_map_id]); - } -} -void updateModeLabel(bool mode, lv_obj_t *label) { - std::string absstr = - esp3dTranslationService.translate(ESP3DLabel::absolute_short); - std::string relstr = - esp3dTranslationService.translate(ESP3DLabel::relative_short); - std::string text; - if (mode) { - text = "#00ff00 " + absstr + "# / " + relstr; - } else { - text = absstr + " / #00ff00 " + relstr + "#"; - } - - lv_label_set_text(label, text.c_str()); -} - -void btn_mode_event_cb(lv_event_t *e) { - bool *babsolute = (bool *)lv_event_get_user_data(e); - *babsolute = !(*babsolute); - lv_obj_t *obj = lv_event_get_target(e); - lv_obj_t *label = lv_obj_get_child(obj, 0); - updateModeLabel(*babsolute, label); - updateMode(*babsolute); -} -void home_all_axis_button_event_cb(lv_event_t *e) { - // lv_obj_t *position_ta = (lv_obj_t *)lv_event_get_user_data(e); - esp3d_log("Home All Axis"); - renderingClient.sendGcode("G28"); -} - -void positions_matrix_buttons_event_cb(lv_event_t *e) { - lv_obj_t *obj = lv_event_get_target(e); - uint32_t id = lv_btnmatrix_get_selected_btn(obj); - positions_buttons_map_id = id; - esp3d_log("Button %s clicked", positions_buttons_map[id]); - if (!absolute_position) updateMode(absolute_position); -} - -void axis_matrix_buttons_event_cb(lv_event_t *e) { - lv_obj_t *obj = lv_event_get_target(e); - lv_obj_t *position_ta = (lv_obj_t *)lv_event_get_user_data(e); - uint32_t id = lv_btnmatrix_get_selected_btn(obj); - axis_buttons_map_id = id; - lv_label_set_text(label_current_position, - axis_buttons_map[axis_buttons_map_id]); - std::string current_position_value_init; - switch (axis_buttons_map_id) { - case 0: - current_position_value_init = - esp3dTftValues.get_string_value(ESP3DValuesIndex::position_x); - break; - case 1: - current_position_value_init = - esp3dTftValues.get_string_value(ESP3DValuesIndex::position_y); - break; - case 2: - current_position_value_init = - esp3dTftValues.get_string_value(ESP3DValuesIndex::position_z); - break; - default: - current_position_value_init = "0.00"; - break; - esp3d_log("Button %s clicked", axis_buttons_map[id]); - } - lv_label_set_text(label_current_position_value, - current_position_value_init.c_str()); - if (!absolute_position) return; - std::string position_value_init = esp3d_string::set_precision( - current_position_value_init == "?" ? "0.00" : current_position_value_init, - 2); - lv_textarea_set_text(position_ta, position_value_init.c_str()); -} - -void positions_screen(uint8_t target_id) { - esp3dTftui.set_current_screen(ESP3DScreenType::none); - if (target_id != 255) { - axis_buttons_map_id = target_id; - } - if (!intialization_done) { - absolute_position = - esp3dTftsettings.readByte(ESP3DSettingIndex::esp3d_jog_type) == 0 - ? false - : true; - intialization_done = true; - } - // Screen creation - esp3d_log("Positions screen creation for target %d", axis_buttons_map_id); - lv_obj_t *ui_new_screen = lv_obj_create(NULL); - // Display new screen and delete old one - lv_obj_t *ui_current_screen = lv_scr_act(); - lv_scr_load(ui_new_screen); - apply_style(ui_new_screen, ESP3DStyleType::main_bg); - lv_obj_del(ui_current_screen); - - // back button - lv_obj_t *btnback = backButton::create_back_button(ui_new_screen); - lv_obj_add_event_cb(btnback, event_button_positions_back_handler, - LV_EVENT_CLICKED, NULL); - - // Steps in button matrix - lv_obj_t *btnm = lv_btnmatrix_create(ui_new_screen); - lv_btnmatrix_set_map(btnm, positions_buttons_map); - apply_style(btnm, ESP3DStyleType::buttons_matrix); - size_t i = - (sizeof(positions_buttons_map) / sizeof(positions_buttons_map[0])) - 1; - lv_obj_set_size(btnm, MATRIX_BUTTON_WIDTH * i, MATRIX_BUTTON_HEIGHT); - lv_obj_align(btnm, LV_ALIGN_TOP_RIGHT, -CURRENT_BUTTON_PRESSED_OUTLINE, - CURRENT_BUTTON_PRESSED_OUTLINE / 2); - lv_btnmatrix_set_btn_ctrl(btnm, positions_buttons_map_id, - LV_BTNMATRIX_CTRL_CHECKED); - lv_obj_add_event_cb(btnm, positions_matrix_buttons_event_cb, - LV_EVENT_VALUE_CHANGED, NULL); - - // Target selector button matrix - lv_obj_t *btnm_target = lv_btnmatrix_create(ui_new_screen); - lv_btnmatrix_set_map(btnm_target, axis_buttons_map); - apply_style(btnm_target, ESP3DStyleType::buttons_matrix); - size_t i2 = (sizeof(axis_buttons_map) / sizeof(axis_buttons_map[0])) - 1; - lv_obj_set_size(btnm_target, MATRIX_BUTTON_WIDTH * i2, MATRIX_BUTTON_HEIGHT); - lv_btnmatrix_set_btn_ctrl(btnm_target, axis_buttons_map_id, - LV_BTNMATRIX_CTRL_CHECKED); - - lv_obj_align_to(btnm_target, btnback, LV_ALIGN_OUT_LEFT_BOTTOM, - -CURRENT_BUTTON_PRESSED_OUTLINE, 0); - // Home all axis - lv_obj_t *btn_home_all = symbolButton::create_symbol_button( - ui_new_screen, LV_SYMBOL_HOME "xyz", MATRIX_BUTTON_WIDTH, - MATRIX_BUTTON_HEIGHT); - lv_obj_align_to(btn_home_all, btnm_target, LV_ALIGN_OUT_LEFT_BOTTOM, - -CURRENT_BUTTON_PRESSED_OUTLINE, 0); - - // Label current axis - label_current_position = lv_label_create(ui_new_screen); - lv_label_set_text(label_current_position, - axis_buttons_map[axis_buttons_map_id]); // need to change - // according axis - apply_style(label_current_position, ESP3DStyleType::bg_label); - lv_obj_align(label_current_position, LV_ALIGN_TOP_LEFT, - CURRENT_BUTTON_PRESSED_OUTLINE, CURRENT_BUTTON_PRESSED_OUTLINE); - lv_obj_update_layout(label_current_position); - - // Label current axis e - label_current_position_value = lv_label_create(ui_new_screen); - - std::string current_position_value_init; - switch (axis_buttons_map_id) { - case 0: - current_position_value_init = - esp3dTftValues.get_string_value(ESP3DValuesIndex::position_x); - break; - case 1: - current_position_value_init = - esp3dTftValues.get_string_value(ESP3DValuesIndex::position_y); - break; - case 2: - current_position_value_init = - esp3dTftValues.get_string_value(ESP3DValuesIndex::position_z); - break; - default: - current_position_value_init = "0.00"; - break; - } - - lv_label_set_text(label_current_position_value, - current_position_value_init.c_str()); - - apply_style(label_current_position_value, ESP3DStyleType::read_only_value); - lv_obj_set_width(label_current_position_value, LV_HOR_RES / 5); - lv_obj_align_to(label_current_position_value, label_current_position, - LV_ALIGN_OUT_RIGHT_MID, CURRENT_BUTTON_PRESSED_OUTLINE / 2, - 0); - // unit - lv_obj_t *label_unit1 = lv_label_create(ui_new_screen); - lv_label_set_text(label_unit1, - esp3dTranslationService.translate(ESP3DLabel::millimeters)); - apply_style(label_unit1, ESP3DStyleType::bg_label); - lv_obj_align_to(label_unit1, label_current_position_value, - LV_ALIGN_OUT_RIGHT_MID, CURRENT_BUTTON_PRESSED_OUTLINE / 2, - 0); - // Button up - lv_obj_t *btn_up = symbolButton::create_symbol_button( - ui_new_screen, LV_SYMBOL_UP "\n" LV_SYMBOL_PLUS); - lv_obj_align_to(btn_up, label_current_position_value, LV_ALIGN_OUT_BOTTOM_MID, - 0, CURRENT_BUTTON_PRESSED_OUTLINE); - // Text area - position_ta = lv_textarea_create(ui_new_screen); - lv_obj_add_event_cb(position_ta, position_ta_event_cb, LV_EVENT_VALUE_CHANGED, - NULL); - lv_obj_add_event_cb(btnm_target, axis_matrix_buttons_event_cb, - LV_EVENT_VALUE_CHANGED, position_ta); - lv_textarea_set_accepted_chars(position_ta, "0123456789.-"); - lv_textarea_set_max_length(position_ta, 7); - lv_textarea_set_one_line(position_ta, true); - esp3d_log("value: %s", position_value.c_str()); - std::string position_value_init = esp3d_string::set_precision( - current_position_value_init == "?" ? "0.00" : current_position_value_init, - 2); - lv_textarea_set_text(position_ta, position_value_init.c_str()); - lv_obj_set_style_text_align(position_ta, LV_TEXT_ALIGN_CENTER, 0); - lv_obj_set_width(position_ta, LV_HOR_RES / 5); - - lv_obj_align_to(position_ta, btn_up, LV_ALIGN_OUT_BOTTOM_MID, 0, - CURRENT_BUTTON_PRESSED_OUTLINE / 2); - - lv_obj_add_event_cb(btn_up, positions_btn_up_event_cb, LV_EVENT_CLICKED, - position_ta); - - // Label target axis - lv_obj_t *label_target = lv_label_create(ui_new_screen); - lv_label_set_text(label_target, - LV_SYMBOL_JOG); // need to change according - // axis - apply_style(label_target, ESP3DStyleType::bg_label); - lv_obj_align_to(label_target, position_ta, LV_ALIGN_OUT_LEFT_MID, - -CURRENT_BUTTON_PRESSED_OUTLINE / 2, 0); - - // Unit - lv_obj_t *label_unit2 = lv_label_create(ui_new_screen); - lv_label_set_text(label_unit2, - esp3dTranslationService.translate(ESP3DLabel::millimeters)); - apply_style(label_unit2, ESP3DStyleType::bg_label); - - lv_obj_align_to(label_unit2, position_ta, LV_ALIGN_OUT_RIGHT_MID, - CURRENT_BUTTON_PRESSED_OUTLINE / 2, 0); - // set button - btn_set = symbolButton::create_symbol_button(ui_new_screen, LV_SYMBOL_OK); - lv_obj_align_to(btn_set, label_unit2, LV_ALIGN_OUT_RIGHT_MID, - CURRENT_BUTTON_PRESSED_OUTLINE, 0); - lv_obj_add_event_cb(btn_set, positions_btn_ok_event_cb, LV_EVENT_CLICKED, - position_ta); - // Home axis - lv_obj_t *btn_home_axis = - symbolButton::create_symbol_button(ui_new_screen, LV_SYMBOL_HOME); - lv_obj_align_to(btn_home_axis, btn_set, LV_ALIGN_OUT_RIGHT_MID, - CURRENT_BUTTON_PRESSED_OUTLINE, 0); - lv_obj_add_event_cb(btn_home_axis, positions_btn_home_axis_event_cb, - LV_EVENT_CLICKED, position_ta); - lv_obj_add_event_cb(btn_home_all, home_all_axis_button_event_cb, - LV_EVENT_CLICKED, position_ta); - - // absolute /relative mode button - lv_obj_t *btn_mode = lv_btn_create(ui_new_screen); - apply_style(btn_mode, ESP3DStyleType::button); - lv_obj_t *label = lv_label_create(btn_mode); - lv_label_set_recolor(label, true); - updateModeLabel(absolute_position, label); - - lv_obj_center(label); - lv_obj_add_event_cb(btn_mode, btn_mode_event_cb, LV_EVENT_CLICKED, - &absolute_position); - - lv_obj_align_to(btn_mode, btnm, LV_ALIGN_OUT_BOTTOM_MID, 0, - CURRENT_BUTTON_PRESSED_OUTLINE / 2); - - // Keyboard - lv_obj_t *positions_kb = lv_keyboard_create(ui_new_screen); - lv_keyboard_set_mode(positions_kb, LV_KEYBOARD_MODE_NUMBER); - lv_keyboard_set_textarea(positions_kb, NULL); - lv_obj_update_layout(label_unit2); - lv_obj_set_content_width(positions_kb, - LV_HOR_RES - (lv_obj_get_x(label_unit2) + - CURRENT_BUTTON_PRESSED_OUTLINE)); - lv_obj_align_to(positions_kb, position_ta, LV_ALIGN_OUT_RIGHT_MID, - CURRENT_BUTTON_PRESSED_OUTLINE / 2, - -CURRENT_BUTTON_PRESSED_OUTLINE / 2); - lv_obj_set_style_radius(positions_kb, CURRENT_BUTTON_RADIUS_VALUE, - LV_PART_MAIN); - lv_obj_add_flag(positions_kb, LV_OBJ_FLAG_HIDDEN); - lv_obj_add_event_cb(position_ta, position_ta_event_cb, LV_EVENT_ALL, - positions_kb); - // Button down - lv_obj_t *btn_down = symbolButton::create_symbol_button( - ui_new_screen, LV_SYMBOL_MINUS "\n" LV_SYMBOL_DOWN); - lv_obj_align_to(btn_down, position_ta, LV_ALIGN_OUT_BOTTOM_MID, 0, - CURRENT_BUTTON_PRESSED_OUTLINE / 2); - lv_obj_add_event_cb(btn_down, positions_btn_down_event_cb, LV_EVENT_CLICKED, - position_ta); - updateMode(absolute_position); - esp3dTftui.set_current_screen(ESP3DScreenType::positions); -} -} // namespace positionsScreen \ No newline at end of file diff --git a/main/display/cnc/grbl/screens/positions_screen.h b/main/display/cnc/grbl/screens/positions_screen.h deleted file mode 100644 index 3a1a55b1..00000000 --- a/main/display/cnc/grbl/screens/positions_screen.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - positions_screen.h - esp3d - Copyright (c) 2022 Luc Lebosse. All rights reserved. - - This code is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This code 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#pragma once - -#include - -#include "esp3d_values.h" - - -namespace positionsScreen { -extern void positions_screen(uint8_t target = 255); -extern bool positions_values_cb(ESP3DValuesIndex index, const char *value, - ESP3DValuesCbAction action); - -} // namespace positionsScreen diff --git a/main/display/cnc/grbl/screens/settings_screen.cpp b/main/display/cnc/grbl/screens/settings_screen.cpp index 002672dd..7682a510 100644 --- a/main/display/cnc/grbl/screens/settings_screen.cpp +++ b/main/display/cnc/grbl/screens/settings_screen.cpp @@ -40,7 +40,6 @@ #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "screens/main_screen.h" -#include "screens/manual_leveling_screen.h" #include "screens/menu_screen.h" #include "rendering/esp3d_rendering_client.h" #include "tasks_def.h" @@ -60,15 +59,13 @@ lv_obj_t *ui_settings_list_ctl = NULL; lv_obj_t *language_label = NULL; lv_obj_t *hostname_label = NULL; lv_obj_t *extensions_label = NULL; -lv_obj_t *show_fan_controls_label = NULL; lv_obj_t *output_client_label = NULL; lv_obj_t *serial_baud_rate_label = NULL; lv_obj_t *usb_serial_baud_rate_label = NULL; lv_obj_t *jog_type_label = NULL; lv_obj_t *polling_label = NULL; -lv_obj_t *auto_leveling_label = NULL; -lv_obj_t *bed_width_label = NULL; -lv_obj_t *bed_depth_label = NULL; +lv_obj_t *workspace_width_label = NULL; +lv_obj_t *workspace_depth_label = NULL; lv_obj_t *inverted_x_label = NULL; lv_obj_t *inverted_y_label = NULL; @@ -121,15 +118,6 @@ static void bgLoadJSONSettingsTask(void *pvParameter) { if (extensions_label) { lv_label_set_text(extensions_label, value.c_str()); } - value = esp3dTftJsonSettings.readString("settings", "showfanctrls"); - if (show_fan_controls_label) { - if (value == "true") { - value = esp3dTranslationService.translate(ESP3DLabel::enabled); - } else { - value = esp3dTranslationService.translate(ESP3DLabel::disabled); - } - lv_label_set_text(show_fan_controls_label, value.c_str()); - } static bool refresh = false; if (!settings_screen_apply_timer) { settings_screen_apply_timer = @@ -154,21 +142,7 @@ static void bgSaveJSONSettingsTask(void *pvParameter) { lv_label_set_text(data->label, data->value.c_str()); } break; - case ESP3DSettingIndex::esp3d_show_fan_controls: - if (strcmp(data->value.c_str(), "true") == 0) { - mainScreen::update_show_fan_controls(true); - if (data->label) { - lv_label_set_text(data->label, esp3dTranslationService.translate( - ESP3DLabel::enabled)); - } - } else { - mainScreen::update_show_fan_controls(false); - if (data->label) { - lv_label_set_text(data->label, esp3dTranslationService.translate( - ESP3DLabel::disabled)); - } - } - break; + default: break; } @@ -314,8 +288,8 @@ void setting_edit_done_cb(const char *str, void *data) { case ESP3DSettingIndex::esp3d_hostname: // use string as it is break; - case ESP3DSettingIndex::esp3d_bed_width: - case ESP3DSettingIndex::esp3d_bed_depth: + case ESP3DSettingIndex::esp3d_workspace_width: + case ESP3DSettingIndex::esp3d_workspace_depth: val_string = esp3d_string::set_precision(str, 2); break; default: @@ -393,21 +367,18 @@ void setting_edit_done_cb(const char *str, void *data) { renderingClient.setPolling(val_byte); break; case ESP3DSettingIndex::esp3d_inverved_x: - manualLevelingScreen::update_invert_x(val_byte); + //manualLevelingScreen::update_invert_x(val_byte); break; case ESP3DSettingIndex::esp3d_inverved_y: - manualLevelingScreen::update_invert_y(val_byte); + //manualLevelingScreen::update_invert_y(val_byte); break; case ESP3DSettingIndex::esp3d_auto_level_on: - menuScreen::enable_auto_leveling(val_byte); - break; - case ESP3DSettingIndex::esp3d_bed_width: - manualLevelingScreen::update_bed_width( - strtod(val_string.c_str(), NULL)); + //menuScreen::enable_auto_leveling(val_byte); break; - case ESP3DSettingIndex::esp3d_bed_depth: - manualLevelingScreen::update_bed_depth( - strtod(val_string.c_str(), NULL)); + + case ESP3DSettingIndex::esp3d_workspace_depth: + // manualLevelingScreen::update_workspace_depth( + // strtod(val_string.c_str(), NULL)); break; default: break; @@ -516,40 +487,24 @@ void event_button_edit_setting_cb(lv_event_t *e) { data.choices.push_back( esp3dTranslationService.translate(ESP3DLabel::enabled)); // enabled break; - case ESP3DSettingIndex::esp3d_auto_level_on: - data.label = auto_leveling_label; - title = esp3dTranslationService.translate(ESP3DLabel::auto_leveling); - data.choices.push_back( - esp3dTranslationService.translate(ESP3DLabel::disabled)); // disabled - data.choices.push_back( - esp3dTranslationService.translate(ESP3DLabel::enabled)); // enabled - break; case ESP3DSettingIndex::esp3d_hostname: data.label = hostname_label; title = esp3dTranslationService.translate(ESP3DLabel::hostname); break; - case ESP3DSettingIndex::esp3d_bed_width: - data.label = bed_width_label; - title = esp3dTranslationService.translate(ESP3DLabel::bed_width); + case ESP3DSettingIndex::esp3d_workspace_width: + data.label = workspace_width_label; + title = esp3dTranslationService.translate(ESP3DLabel::workspace_width); break; - case ESP3DSettingIndex::esp3d_bed_depth: - data.label = bed_depth_label; - title = esp3dTranslationService.translate(ESP3DLabel::bed_depth); + case ESP3DSettingIndex::esp3d_workspace_depth: + data.label = workspace_depth_label; + title = esp3dTranslationService.translate(ESP3DLabel::workspace_depth); break; case ESP3DSettingIndex::esp3d_extensions: data.label = extensions_label; title = esp3dTranslationService.translate(ESP3DLabel::extensions); data.entry = "filesfilter"; break; - case ESP3DSettingIndex::esp3d_show_fan_controls: - data.label = show_fan_controls_label; - title = esp3dTranslationService.translate(ESP3DLabel::fan_controls); - data.entry = "showfanctrls"; - data.choices.push_back( - esp3dTranslationService.translate(ESP3DLabel::disabled)); // disabled - data.choices.push_back( - esp3dTranslationService.translate(ESP3DLabel::enabled)); // enabled - break; + default: esp3d_log_e("Unknown setting index %d", (uint16_t)data.index); return; @@ -581,8 +536,8 @@ void event_button_edit_setting_cb(lv_event_t *e) { setting_edit_done_cb, settingPtr->size, NULL, false, (void *)(&data)); break; - case ESP3DSettingIndex::esp3d_bed_width: - case ESP3DSettingIndex::esp3d_bed_depth: + case ESP3DSettingIndex::esp3d_workspace_width: + case ESP3DSettingIndex::esp3d_workspace_depth: textEditor::create_text_editor(lv_scr_act(), data.value.c_str(), setting_edit_done_cb, 15, "0123456789.", true, (void *)(&data)); @@ -817,59 +772,23 @@ void settings_screen() { } // JSON - // show fan controls - static ESP3DSettingIndex show_fan_controls_setting_index = - ESP3DSettingIndex::esp3d_show_fan_controls; - line_container = listLine::create_list_line_container(ui_settings_list_ctl); - LabelStr = esp3dTranslationService.translate(ESP3DLabel::fan_controls); - if (line_container) { - listLine::add_label_to_line(LabelStr.c_str(), line_container, true); - show_fan_controls_label = - listLine::add_label_to_line("", line_container, true); - lv_obj_t *btnEdit = - listLine::add_button_to_line(LV_SYMBOL_EDIT, line_container); - lv_obj_add_event_cb(btnEdit, event_button_edit_setting_cb, LV_EVENT_CLICKED, - (void *)&(show_fan_controls_setting_index)); - } - - // Auto level on - line_container = listLine::create_list_line_container(ui_settings_list_ctl); - LabelStr = esp3dTranslationService.translate(ESP3DLabel::auto_leveling); - if (line_container) { - listLine::add_label_to_line(LabelStr.c_str(), line_container, true); - const ESP3DSettingDescription *settingPtr = - esp3dTftsettings.getSettingPtr(ESP3DSettingIndex::esp3d_auto_level_on); - if (settingPtr) { - uint8_t val = - esp3dTftsettings.readByte(ESP3DSettingIndex::esp3d_auto_level_on); - std::string value = - val == 0 ? esp3dTranslationService.translate(ESP3DLabel::disabled) - : esp3dTranslationService.translate(ESP3DLabel::enabled); - auto_leveling_label = - listLine::add_label_to_line(value.c_str(), line_container, true); - lv_obj_t *btnEdit = - listLine::add_button_to_line(LV_SYMBOL_EDIT, line_container); - lv_obj_add_event_cb(btnEdit, event_button_edit_setting_cb, - LV_EVENT_CLICKED, (void *)(&(settingPtr->index))); - } - } - - // Bed width + + // workspace width line_container = listLine::create_list_line_container(ui_settings_list_ctl); - LabelStr = esp3dTranslationService.translate(ESP3DLabel::bed_width); + LabelStr = esp3dTranslationService.translate(ESP3DLabel::workspace_width); if (line_container) { - std::string bed_width_str; + std::string workspace_width_str; listLine::add_label_to_line(LabelStr.c_str(), line_container, true); const ESP3DSettingDescription *settingPtr = - esp3dTftsettings.getSettingPtr(ESP3DSettingIndex::esp3d_bed_width); + esp3dTftsettings.getSettingPtr(ESP3DSettingIndex::esp3d_workspace_width); if (settingPtr) { char out_str[15 + 1] = {0}; - bed_width_str = esp3dTftsettings.readString( - ESP3DSettingIndex::esp3d_bed_width, out_str, 16); + workspace_width_str = esp3dTftsettings.readString( + ESP3DSettingIndex::esp3d_workspace_width, out_str, 16); } else { - esp3d_log_e("Failed to get bed width setting"); + esp3d_log_e("Failed to get workspace width setting"); } - bed_width_label = listLine::add_label_to_line(bed_width_str.c_str(), + workspace_width_label = listLine::add_label_to_line(workspace_width_str.c_str(), line_container, true); lv_obj_t *btnEdit = listLine::add_button_to_line(LV_SYMBOL_EDIT, line_container); @@ -877,22 +796,22 @@ void settings_screen() { (void *)(&(settingPtr->index))); } - // Bed depth + // workspace depth line_container = listLine::create_list_line_container(ui_settings_list_ctl); - LabelStr = esp3dTranslationService.translate(ESP3DLabel::bed_depth); + LabelStr = esp3dTranslationService.translate(ESP3DLabel::workspace_depth); if (line_container) { - std::string bed_depth_str; + std::string workspace_depth_str; listLine::add_label_to_line(LabelStr.c_str(), line_container, true); const ESP3DSettingDescription *settingPtr = - esp3dTftsettings.getSettingPtr(ESP3DSettingIndex::esp3d_bed_depth); + esp3dTftsettings.getSettingPtr(ESP3DSettingIndex::esp3d_workspace_depth); if (settingPtr) { char out_str[15 + 1] = {0}; - bed_depth_str = esp3dTftsettings.readString( - ESP3DSettingIndex::esp3d_bed_depth, out_str, 16); + workspace_depth_str = esp3dTftsettings.readString( + ESP3DSettingIndex::esp3d_workspace_depth, out_str, 16); } else { - esp3d_log_e("Failed to get bed depth setting"); + esp3d_log_e("Failed to get workspace depth setting"); } - bed_depth_label = listLine::add_label_to_line(bed_depth_str.c_str(), + workspace_depth_label = listLine::add_label_to_line(workspace_depth_str.c_str(), line_container, true); lv_obj_t *btnEdit = listLine::add_button_to_line(LV_SYMBOL_EDIT, line_container); diff --git a/main/display/cnc/grbl/screens/speed_screen.cpp b/main/display/cnc/grbl/screens/speed_screen.cpp deleted file mode 100644 index 0f865dd3..00000000 --- a/main/display/cnc/grbl/screens/speed_screen.cpp +++ /dev/null @@ -1,288 +0,0 @@ -/* - esp3d_tft - - Copyright (c) 2022 Luc Lebosse. All rights reserved. - - This code is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This code 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#include "screens/speed_screen.h" - -#include - -#include "components/back_button_component.h" -#include "components/symbol_button_component.h" -#include "esp3d_log.h" -#include "esp3d_string.h" -#include "esp3d_styles.h" -#include "esp3d_tft_ui.h" -#include "screens/main_screen.h" -#include "rendering/esp3d_rendering_client.h" - -/********************** - * STATIC PROTOTYPES - **********************/ -namespace speedScreen { -std::string speed_value = "100"; -const char *speed_buttons_map[] = {"1", "5", "10", "50", ""}; -uint8_t speed_buttons_map_id = 0; -lv_obj_t *label_current_speed_value = NULL; - -lv_timer_t *speed_screen_delay_timer = NULL; - -void speed_screen_delay_timer_cb(lv_timer_t *timer) { - if (speed_screen_delay_timer) { - lv_timer_del(speed_screen_delay_timer); - speed_screen_delay_timer = NULL; - } - mainScreen::main_screen(); -} - -void event_button_speed_back_handler(lv_event_t *e) { - esp3d_log("back Clicked"); - if (BUTTON_ANIMATION_DELAY) { - if (speed_screen_delay_timer) return; - speed_screen_delay_timer = lv_timer_create(speed_screen_delay_timer_cb, - BUTTON_ANIMATION_DELAY, NULL); - } else { - speed_screen_delay_timer_cb(NULL); - } -} - -void send_gcode_speed() { - std::string speed_value_str = "M220 S"; - speed_value_str += speed_value; - renderingClient.sendGcode(speed_value_str.c_str()); -} - -void speed_ta_event_cb(lv_event_t *e) { - lv_event_code_t code = lv_event_get_code(e); - lv_obj_t *ta = lv_event_get_target(e); - lv_obj_t *kb = (lv_obj_t *)lv_event_get_user_data(e); - if (code == LV_EVENT_FOCUSED || code == LV_EVENT_PRESSED) { - lv_keyboard_set_textarea(kb, ta); - lv_obj_add_state(ta, LV_STATE_FOCUSED); - lv_obj_clear_flag(kb, LV_OBJ_FLAG_HIDDEN); - lv_obj_set_scrollbar_mode(ta, LV_SCROLLBAR_MODE_AUTO); - } else if (code == LV_EVENT_DEFOCUSED || code == LV_EVENT_READY || - code == LV_EVENT_CANCEL) { - esp3d_log("Ready, Value: %s", lv_textarea_get_text(ta)); - lv_textarea_set_cursor_pos(ta, 0); - lv_obj_set_scrollbar_mode(ta, LV_SCROLLBAR_MODE_OFF); - lv_keyboard_set_textarea(kb, NULL); - lv_obj_add_flag(kb, LV_OBJ_FLAG_HIDDEN); - lv_obj_clear_state(ta, LV_STATE_FOCUSED); - speed_value = lv_textarea_get_text(ta); - if (std::atoi(speed_value.c_str()) > 300) { - lv_textarea_set_text(ta, "300"); - } - if (std::atoi(speed_value.c_str()) < 1) { - lv_textarea_set_text(ta, "1"); - } - if (speed_value.length() == 0) { - lv_textarea_set_text(ta, "1"); - } - } else if (code == LV_EVENT_VALUE_CHANGED) { - speed_value = lv_textarea_get_text(ta); - esp3d_log("Value changed: %s", speed_value.c_str()); - } -} - -void speed_btn_up_event_cb(lv_event_t *e) { - esp3d_log("Up"); - lv_obj_t *speed_ta = (lv_obj_t *)lv_event_get_user_data(e); - std::string speed = lv_textarea_get_text(speed_ta); - int speed_int = std::stoi(speed); - int step = atoi(speed_buttons_map[speed_buttons_map_id]); - esp3d_log("Step: %d, Speed: %d", step, speed_int); - speed_int += step; - if (speed_int > 300) speed_int = 300; - esp3d_log("new Speed: %d", speed_int); - speed = std::to_string(speed_int); - lv_textarea_set_text(speed_ta, speed.c_str()); - send_gcode_speed(); -} - -void speed_btn_down_event_cb(lv_event_t *e) { - lv_obj_t *speed_ta = (lv_obj_t *)lv_event_get_user_data(e); - std::string speed = lv_textarea_get_text(speed_ta); - int speed_int = std::stoi(speed); - int step = atoi(speed_buttons_map[speed_buttons_map_id]); - speed_int -= step; - if (speed_int < 1) speed_int = 1; - speed = std::to_string(speed_int); - lv_textarea_set_text(speed_ta, speed.c_str()); - send_gcode_speed(); -} - -void speed_btn_ok_event_cb(lv_event_t *e) { - esp3d_log("Ok clicked"); - send_gcode_speed(); -} - -void speed_btn_reset_event_cb(lv_event_t *e) { - lv_obj_t *speed_ta = (lv_obj_t *)lv_event_get_user_data(e); - esp3d_log("Reset"); - lv_textarea_set_text(speed_ta, "100"); - send_gcode_speed(); -} - -void speed_matrix_buttons_event_cb(lv_event_t *e) { - lv_obj_t *obj = lv_event_get_target(e); - uint32_t id = lv_btnmatrix_get_selected_btn(obj); - speed_buttons_map_id = id; - esp3d_log("Button %s clicked", speed_buttons_map[id]); -} - -bool speed_value_cb(ESP3DValuesIndex index, const char *value, - ESP3DValuesCbAction action) { - if (esp3dTftui.get_current_screen() != ESP3DScreenType::speed) return false; - esp3d_log("Speed value %s", value); - lv_label_set_text(label_current_speed_value, value); - return true; -} - -void speed_screen() { - esp3dTftui.set_current_screen(ESP3DScreenType::none); - // Screen creation - esp3d_log("Speed screen creation"); - lv_obj_t *ui_new_screen = lv_obj_create(NULL); - // Display new screen and delete old one - lv_obj_t *ui_current_screen = lv_scr_act(); - lv_scr_load(ui_new_screen); - apply_style(ui_new_screen, ESP3DStyleType::main_bg); - lv_obj_del(ui_current_screen); - - lv_obj_t *btnback = backButton::create_back_button(ui_new_screen); - lv_obj_add_event_cb(btnback, event_button_speed_back_handler, - LV_EVENT_CLICKED, NULL); - - // Steps in button matrix - lv_obj_t *btnm = lv_btnmatrix_create(ui_new_screen); - lv_btnmatrix_set_map(btnm, speed_buttons_map); - apply_style(btnm, ESP3DStyleType::buttons_matrix); - size_t i = (sizeof(speed_buttons_map) / sizeof(speed_buttons_map[0])) - 1; - lv_obj_set_size(btnm, MATRIX_BUTTON_WIDTH * i, MATRIX_BUTTON_HEIGHT); - lv_obj_align(btnm, LV_ALIGN_TOP_RIGHT, -CURRENT_BUTTON_PRESSED_OUTLINE, - CURRENT_BUTTON_PRESSED_OUTLINE / 2); - lv_btnmatrix_set_btn_ctrl(btnm, speed_buttons_map_id, - LV_BTNMATRIX_CTRL_CHECKED); - lv_obj_add_event_cb(btnm, speed_matrix_buttons_event_cb, - LV_EVENT_VALUE_CHANGED, NULL); - - // Current Speed label - lv_obj_t *label_current_speed = lv_label_create(ui_new_screen); - lv_label_set_text(label_current_speed, LV_SYMBOL_SPEED); - apply_style(label_current_speed, ESP3DStyleType::bg_label); - lv_obj_align(label_current_speed, LV_ALIGN_TOP_LEFT, - CURRENT_BUTTON_PRESSED_OUTLINE, CURRENT_BUTTON_PRESSED_OUTLINE); - lv_obj_update_layout(label_current_speed); - - // Current Speed value - std::string current_speed_value_init = - esp3dTftValues.get_string_value(ESP3DValuesIndex::speed); - - label_current_speed_value = lv_label_create(ui_new_screen); - lv_label_set_text(label_current_speed_value, - current_speed_value_init.c_str()); - apply_style(label_current_speed_value, ESP3DStyleType::read_only_value); - lv_obj_set_width(label_current_speed_value, LV_HOR_RES / 6); - lv_obj_align_to(label_current_speed_value, label_current_speed, - LV_ALIGN_OUT_RIGHT_MID, CURRENT_BUTTON_PRESSED_OUTLINE / 2, - 0); - - // unit - lv_obj_t *label_unit1 = lv_label_create(ui_new_screen); - lv_label_set_text(label_unit1, "%"); - apply_style(label_unit1, ESP3DStyleType::bg_label); - lv_obj_align_to(label_unit1, label_current_speed_value, - LV_ALIGN_OUT_RIGHT_MID, CURRENT_BUTTON_PRESSED_OUTLINE / 2, - 0); - - // Button up - lv_obj_t *btn_up = symbolButton::create_symbol_button( - ui_new_screen, LV_SYMBOL_UP "\n" LV_SYMBOL_PLUS); - lv_obj_align_to(btn_up, label_current_speed_value, LV_ALIGN_OUT_BOTTOM_MID, 0, - CURRENT_BUTTON_PRESSED_OUTLINE / 2); - // speed input - lv_obj_t *speed_ta = lv_textarea_create(ui_new_screen); - lv_obj_add_event_cb(speed_ta, speed_ta_event_cb, LV_EVENT_VALUE_CHANGED, - NULL); - lv_textarea_set_accepted_chars(speed_ta, "0123456789"); - lv_textarea_set_max_length(speed_ta, 3); - lv_textarea_set_one_line(speed_ta, true); - lv_textarea_set_text(speed_ta, current_speed_value_init.c_str()); - lv_obj_set_style_text_align(speed_ta, LV_TEXT_ALIGN_CENTER, 0); - lv_obj_set_width(speed_ta, LV_HOR_RES / 6); - lv_obj_align_to(speed_ta, btn_up, LV_ALIGN_OUT_BOTTOM_MID, 0, - CURRENT_BUTTON_PRESSED_OUTLINE / 2); - - // label - lv_obj_t *label_ta = lv_label_create(ui_new_screen); - lv_label_set_text(label_ta, LV_SYMBOL_SPEED); - apply_style(label_ta, ESP3DStyleType::bg_label); - lv_obj_align_to(label_ta, speed_ta, LV_ALIGN_OUT_LEFT_MID, - -CURRENT_BUTTON_PRESSED_OUTLINE / 2, 0); - - // unit - lv_obj_t *label_unit2 = lv_label_create(ui_new_screen); - lv_label_set_text(label_unit2, "%"); - apply_style(label_unit2, ESP3DStyleType::bg_label); - lv_obj_align_to(label_unit2, speed_ta, LV_ALIGN_OUT_RIGHT_MID, - CURRENT_BUTTON_PRESSED_OUTLINE / 2, 0); - - // button down - lv_obj_t *btn_down = symbolButton::create_symbol_button( - ui_new_screen, LV_SYMBOL_MINUS "\n" LV_SYMBOL_DOWN); - lv_obj_align_to(btn_down, speed_ta, LV_ALIGN_OUT_BOTTOM_MID, 0, - CURRENT_BUTTON_PRESSED_OUTLINE / 2); - lv_obj_add_event_cb(btn_down, speed_btn_down_event_cb, LV_EVENT_CLICKED, - speed_ta); - - lv_obj_add_event_cb(btn_up, speed_btn_up_event_cb, LV_EVENT_CLICKED, - speed_ta); - - // Button Ok - lv_obj_t *btn_ok = - symbolButton::create_symbol_button(ui_new_screen, LV_SYMBOL_OK); - lv_obj_align_to(btn_ok, label_unit2, LV_ALIGN_OUT_RIGHT_MID, - CURRENT_BUTTON_PRESSED_OUTLINE, 0); - lv_obj_add_event_cb(btn_ok, speed_btn_ok_event_cb, LV_EVENT_CLICKED, - speed_ta); - - // Button Reset - lv_obj_t *btn_reset = - symbolButton::create_symbol_button(ui_new_screen, LV_SYMBOL_GAUGE); - lv_obj_align_to(btn_reset, btn_ok, LV_ALIGN_OUT_RIGHT_MID, - CURRENT_BUTTON_PRESSED_OUTLINE, 0); - lv_obj_add_event_cb(btn_reset, speed_btn_reset_event_cb, LV_EVENT_CLICKED, - speed_ta); - - // keypad - lv_obj_t *speed_kb = lv_keyboard_create(ui_new_screen); - lv_keyboard_set_mode(speed_kb, LV_KEYBOARD_MODE_NUMBER); - lv_keyboard_set_textarea(speed_kb, NULL); - lv_obj_align_to(speed_kb, speed_ta, LV_ALIGN_OUT_RIGHT_MID, - CURRENT_BUTTON_PRESSED_OUTLINE / 2, 0); - lv_obj_update_layout(speed_kb); - lv_obj_set_content_width(speed_kb, LV_HOR_RES - lv_obj_get_x(speed_kb) - - 2 * CURRENT_BUTTON_PRESSED_OUTLINE); - lv_obj_set_style_radius(speed_kb, CURRENT_BUTTON_RADIUS_VALUE, LV_PART_MAIN); - lv_obj_add_flag(speed_kb, LV_OBJ_FLAG_HIDDEN); - lv_obj_add_event_cb(speed_ta, speed_ta_event_cb, LV_EVENT_ALL, speed_kb); - - esp3dTftui.set_current_screen(ESP3DScreenType::speed); -} -} // namespace speedScreen \ No newline at end of file diff --git a/main/display/cnc/grbl/screens/speed_screen.h b/main/display/cnc/grbl/screens/speed_screen.h deleted file mode 100644 index 32a40d49..00000000 --- a/main/display/cnc/grbl/screens/speed_screen.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - speed_screen.h - esp3d - Copyright (c) 2022 Luc Lebosse. All rights reserved. - - This code is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This code 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#pragma once -#include "esp3d_values.h" - -namespace speedScreen { -extern void speed_screen(); -extern bool speed_value_cb(ESP3DValuesIndex index, const char *value, - ESP3DValuesCbAction action); - -} // namespace speedScreen diff --git a/main/display/cnc/grbl/screens/temperatures_screen.cpp b/main/display/cnc/grbl/screens/temperatures_screen.cpp deleted file mode 100644 index fe56cae1..00000000 --- a/main/display/cnc/grbl/screens/temperatures_screen.cpp +++ /dev/null @@ -1,746 +0,0 @@ -/* - esp3d_tft - - Copyright (c) 2022 Luc Lebosse. All rights reserved. - - This code is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This code 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#include "screens/temperatures_screen.h" - -#include - -#include "components/back_button_component.h" -#include "components/symbol_button_component.h" -#include "esp3d_log.h" -#include "esp3d_string.h" -#include "esp3d_styles.h" -#include "esp3d_tft_ui.h" -#include "screens/filament_screen.h" -#include "screens/main_screen.h" -#include "rendering/esp3d_rendering_client.h" -#include "translations/esp3d_translation_service.h" - -/********************** - * STATIC PROTOTYPES - **********************/ -namespace temperaturesScreen { -std::string temperatures_value = "0"; -const char *temperatures_buttons_map[] = {"1", "10", "50", "100", ""}; -uint8_t temperatures_buttons_map_id = 0; -ESP3DScreenType screen_return = ESP3DScreenType::main; - -lv_obj_t *btnm_target = NULL; - -bool intialization_done = false; -#define HEATER_COUNT 3 -#define HEATER_LABEL_SIZE 2 -std::string heaters_values[HEATER_COUNT]; -char *heater_buttons_map[HEATER_COUNT + 1]; -bool heater_buttons_visibility_map[HEATER_COUNT] = {false, false, false}; -int8_t heater_buttons_visibility_map_id[HEATER_COUNT]{-1, -1, -1}; - -const char *heater_buttons_label_map[HEATER_COUNT] = { - LV_SYMBOL_EXTRUDER "1", LV_SYMBOL_EXTRUDER "2", LV_SYMBOL_HEAT_BED}; - -uint8_t heater_buttons_map_id = 0; - -lv_obj_t *label_current_temperature_value = NULL; -lv_obj_t *label_current_temperature = NULL; -lv_obj_t *label_target_temperature_value = NULL; -lv_obj_t *label_target_temperature = NULL; -lv_obj_t *btnback = NULL; - -lv_timer_t *temperatures_screen_delay_timer = NULL; - -uint8_t get_map_size() { - for (uint8_t i = 0; i < HEATER_COUNT + 1; i++) { - if (strlen(heater_buttons_map[i]) == 0) { - return i; - } - } - esp3d_log("heater_buttons_map size is undefined"); - return 0; -} - -const char **get_heater_buttons_map() { - esp3d_log("get_heater_buttons_map"); - esp3d_log("heater_buttons_map size is : %d", get_map_size()); - bool update = false; - // check if different from current - for (int i = 0; i < HEATER_COUNT; i++) { - bool detected = heaters_values[i] != "#"; - esp3d_log("Heater %d, value : %s detected: %s", i, - heaters_values[i].c_str(), detected ? "true" : "false"); - if (detected != heater_buttons_visibility_map[i]) { - esp3d_log("Update needed because detected, current %s new: %s", - heater_buttons_visibility_map[i] ? "true" : "false ", - detected ? "true" : "false "); - update = true; - heater_buttons_visibility_map[i] = detected; - } - } - // if yes update - if (update) { - esp3d_log("Update matrix buttons"); - heater_buttons_map_id = 0; - uint8_t h = 0; - for (int i = 0; i < HEATER_COUNT; i++) { - esp3d_log("Heater %d, detected: %s", i, - heater_buttons_visibility_map[i] ? "true" : "false"); - strcpy(heater_buttons_map[h], ""); - if (heater_buttons_visibility_map[i]) { - esp3d_log("Add heater %d to matrix to position %d", i, h); - strcpy(heater_buttons_map[h], heater_buttons_label_map[i]); - heater_buttons_visibility_map[i] = true; - heater_buttons_visibility_map_id[i] = h; - esp3d_log("Heater button %d, label: %s", h, heater_buttons_map[h]); - h++; - } else { - esp3d_log("remove heater %d to matrix ", i); - heater_buttons_visibility_map[i] = false; - heater_buttons_visibility_map_id[i] = -1; - } - } - // last map entries must be empty - for (int i = h; i < HEATER_COUNT; i++) { - strcpy(heater_buttons_map[i], ""); - } - } - esp3d_log("heater_buttons_map size is : %d", get_map_size()); - // then return - return (const char **)heater_buttons_map; -} - -bool updateBtnMatrix() { - // check if different from current - // if yes update - // then apply style - lv_btnmatrix_set_map(btnm_target, get_heater_buttons_map()); - apply_style(btnm_target, ESP3DStyleType::buttons_matrix); - lv_obj_update_layout(btnm_target); - size_t i = get_map_size(); - lv_obj_set_size(btnm_target, MATRIX_BUTTON_WIDTH * i, MATRIX_BUTTON_HEIGHT); - esp3d_log("child count: %d", i); - // lv_obj_add_state(obj, LV_STATE_DISABLED); - if (heater_buttons_map_id > i) heater_buttons_map_id = 0; - lv_btnmatrix_set_btn_ctrl(btnm_target, heater_buttons_map_id, - LV_BTNMATRIX_CTRL_CHECKED); - lv_obj_align_to(btnm_target, btnback, LV_ALIGN_OUT_LEFT_BOTTOM, - -CURRENT_BUTTON_PRESSED_OUTLINE, 0); - return true; -} - -uint8_t get_heater_buttons_map_id(int8_t id) { - esp3d_log("get_heater_buttons_map_id %d", id); - for (uint8_t i = 0; i < HEATER_COUNT; i++) { - if (heater_buttons_visibility_map_id[i] == id) { - esp3d_log("give id %d", i); - return i; - } - } - esp3d_log("get_heater_buttons_map_id %d not found", id); - return 0; -} - -int8_t get_heater_buttons_map_button_id(uint8_t id) { - if (id >= HEATER_COUNT) { - esp3d_log_e("get_heater_buttons_map_button_id %d not found", id); - return -1; - } - esp3d_log("get_heater_buttons_map_button_id %d, give id %d", id, - heater_buttons_visibility_map_id[id]); - return heater_buttons_visibility_map_id[id]; -} - -void temperatures_screen_delay_timer_cb(lv_timer_t *timer) { - if (temperatures_screen_delay_timer) { - lv_timer_del(temperatures_screen_delay_timer); - temperatures_screen_delay_timer = NULL; - } - if (screen_return == ESP3DScreenType::main) { - mainScreen::main_screen(); - } else if (screen_return == ESP3DScreenType::filament) { - filamentScreen::filament_screen(); - } else { - esp3d_log_e("Screen return not supported"); - } -} - -void event_button_temperatures_back_handler(lv_event_t *e) { - esp3d_log("back Clicked"); - if (BUTTON_ANIMATION_DELAY) { - if (temperatures_screen_delay_timer) return; - temperatures_screen_delay_timer = lv_timer_create( - temperatures_screen_delay_timer_cb, BUTTON_ANIMATION_DELAY, NULL); - } else { - temperatures_screen_delay_timer_cb(NULL); - } -} - -void temperatures_ta_event_cb(lv_event_t *e) { - lv_event_code_t code = lv_event_get_code(e); - lv_obj_t *ta = lv_event_get_target(e); - lv_obj_t *kb = (lv_obj_t *)lv_event_get_user_data(e); - if (code == LV_EVENT_FOCUSED || code == LV_EVENT_PRESSED) { - lv_keyboard_set_textarea(kb, ta); - lv_obj_add_state(ta, LV_STATE_FOCUSED); - lv_obj_clear_flag(kb, LV_OBJ_FLAG_HIDDEN); - lv_obj_set_scrollbar_mode(ta, LV_SCROLLBAR_MODE_AUTO); - } else if (code == LV_EVENT_DEFOCUSED || code == LV_EVENT_READY || - code == LV_EVENT_CANCEL) { - esp3d_log("Ready, Value: %s", lv_textarea_get_text(ta)); - lv_textarea_set_cursor_pos(ta, 0); - lv_obj_set_scrollbar_mode(ta, LV_SCROLLBAR_MODE_OFF); - lv_keyboard_set_textarea(kb, NULL); - lv_obj_add_flag(kb, LV_OBJ_FLAG_HIDDEN); - lv_obj_clear_state(ta, LV_STATE_FOCUSED); - temperatures_value = lv_textarea_get_text(ta); - if (std::atoi(temperatures_value.c_str()) > 400) { - lv_textarea_set_text(ta, "400"); - } - if (temperatures_value.length() == 0) { - lv_textarea_set_text(ta, "0"); - } - } else if (code == LV_EVENT_VALUE_CHANGED) { - temperatures_value = lv_textarea_get_text(ta); - esp3d_log("Value changed: %s", temperatures_value.c_str()); - } -} - -// power_all_heaters_event_cb -void power_all_heaters_event_cb(lv_event_t *e) { - lv_obj_t *temperatures_ta = (lv_obj_t *)lv_event_get_user_data(e); - std::string temperatures_value = "0"; - int temperatures_int = std::stoi(temperatures_value); - temperatures_value = std::to_string(temperatures_int); - lv_textarea_set_text(temperatures_ta, temperatures_value.c_str()); - std::string val = - esp3dTftValues.get_string_value(ESP3DValuesIndex::ext_0_temperature); - - if (val == "?") { - renderingClient.sendGcode("M104 T0 S0"); // power off extruder 0 - renderingClient.sendGcode("M104 T1 S0"); // power off extruder 1 - renderingClient.sendGcode("M140 S0"); // power off bed - } else { - for (uint8_t i = 0; i < HEATER_COUNT; i++) { - if (heater_buttons_visibility_map_id[i] != -1) { - std::string gcode; - switch (i) { - case 0: // extruder 0 - gcode = "M104 T0 S0"; // power off current heater - break; - case 1: // extruder 1 - gcode = "M104 T1 S0"; // power off current heater - break; - case 2: // bed - gcode = "M140 S0"; // power off current heater - break; - default: - return; - }; - renderingClient.sendGcode(gcode.c_str()); - } - } - } - esp3d_log("Power off all heaters"); -} - -// Increase temperature -void temperatures_btn_up_event_cb(lv_event_t *e) { - lv_obj_t *temperatures_ta = (lv_obj_t *)lv_event_get_user_data(e); - std::string temperatures_value = lv_textarea_get_text(temperatures_ta); - int temperatures_int = std::stoi(temperatures_value); - int step = atoi(temperatures_buttons_map[temperatures_buttons_map_id]); - temperatures_int += step; - if (temperatures_int > 400) temperatures_int = 400; - temperatures_value = std::to_string(temperatures_int); - lv_textarea_set_text(temperatures_ta, temperatures_value.c_str()); -} - -// Decrease temperature -void temperatures_btn_down_event_cb(lv_event_t *e) { - lv_obj_t *temperatures_ta = (lv_obj_t *)lv_event_get_user_data(e); - std::string temperatures_value = lv_textarea_get_text(temperatures_ta); - int temperatures_int = std::stoi(temperatures_value); - int step = atoi(temperatures_buttons_map[temperatures_buttons_map_id]); - temperatures_int -= step; - if (temperatures_int < 0) temperatures_int = 0; - temperatures_value = std::to_string(temperatures_int); - lv_textarea_set_text(temperatures_ta, temperatures_value.c_str()); -} - -void temperatures_btn_ok_event_cb(lv_event_t *e) { - lv_obj_t *temperatures_ta = (lv_obj_t *)lv_event_get_user_data(e); - std::string temperatures_value = lv_textarea_get_text(temperatures_ta); - esp3d_log("Ok: %s", temperatures_value.c_str()); - std::string gcode; - uint8_t target = get_heater_buttons_map_id(heater_buttons_map_id); - switch (target) { - case 0: // extruder 0 - gcode = "M104 T0 S"; // power off current heater - break; - case 1: // extruder 1 - gcode = "M104 T1 S"; // power off current heater - break; - case 2: // bed - gcode = "M140 S"; // power off current heater - break; - default: - return; - }; - gcode += temperatures_value; - renderingClient.sendGcode(gcode.c_str()); -} - -void temperatures_btn_power_off_event_cb(lv_event_t *e) { - lv_obj_t *temperatures_ta = (lv_obj_t *)lv_event_get_user_data(e); - esp3d_log("Power off current heater %d", heater_buttons_map_id); - lv_textarea_set_text(temperatures_ta, "0"); - std::string gcode; - uint8_t target = get_heater_buttons_map_id(heater_buttons_map_id); - switch (target) { - case 0: // extruder 0 - gcode = "M104 S0 T0"; // power off current heater - break; - case 1: // extruder 1 - gcode = "M104 S0 T1"; // power off current heater - break; - case 2: // bed - gcode = "M140 S0"; // power off current heater - break; - default: - return; - }; - renderingClient.sendGcode(gcode.c_str()); -} - -void temperatures_matrix_buttons_event_cb(lv_event_t *e) { - lv_obj_t *obj = lv_event_get_target(e); - uint32_t id = lv_btnmatrix_get_selected_btn(obj); - if (temperatures_buttons_map_id != id) { - esp3d_log("Button %s clicked", temperatures_buttons_map[id]); - // update value label - temperatures_buttons_map_id = id; - } - - esp3d_log("Button %s clicked", temperatures_buttons_map[id]); -} - -void heater_matrix_buttons_event_cb(lv_event_t *e) { - lv_obj_t *obj = lv_event_get_target(e); - lv_event_code_t code = lv_event_get_code(e); - lv_obj_t *temperatures_ta = (lv_obj_t *)lv_event_get_user_data(e); - if (code == LV_EVENT_VALUE_CHANGED) { - uint32_t id = lv_btnmatrix_get_selected_btn(obj); - heater_buttons_map_id = id; - lv_label_set_text(label_current_temperature, - heater_buttons_map[heater_buttons_map_id]); - lv_label_set_text(label_target_temperature, - heater_buttons_map[heater_buttons_map_id]); - uint8_t target = get_heater_buttons_map_id(id); - std::string temp_value; - std::string temperatures_value_init; - switch (target) { - case 0: // extruder 0 - temp_value = esp3dTftValues.get_string_value( - ESP3DValuesIndex::ext_0_temperature); - if (temp_value == "?") temp_value = "0"; - lv_label_set_text(label_current_temperature_value, temp_value.c_str()); - lv_label_set_text(label_target_temperature_value, - esp3dTftValues.get_string_value( - ESP3DValuesIndex::ext_0_target_temperature)); - - temperatures_value_init = std::to_string( - std::atoi(temp_value.c_str()) > 0 ? std::atoi(temp_value.c_str()) - : 0); - temperatures_value = temperatures_value_init; - lv_textarea_set_text(temperatures_ta, temperatures_value_init.c_str()); - break; - case 1: // extruder 1 - temp_value = esp3dTftValues.get_string_value( - ESP3DValuesIndex::ext_1_temperature); - if (temp_value == "?") temp_value = "0"; - lv_label_set_text(label_current_temperature_value, temp_value.c_str()); - lv_label_set_text(label_target_temperature_value, - esp3dTftValues.get_string_value( - ESP3DValuesIndex::ext_1_target_temperature)); - temperatures_value_init = std::to_string( - std::atoi(temp_value.c_str()) > 0 ? std::atoi(temp_value.c_str()) - : 0); - temperatures_value = temperatures_value_init; - lv_textarea_set_text(temperatures_ta, temperatures_value_init.c_str()); - break; - case 2: // bed - temp_value = - esp3dTftValues.get_string_value(ESP3DValuesIndex::bed_temperature); - if (temp_value == "?") temp_value = "0"; - lv_label_set_text(label_current_temperature_value, temp_value.c_str()); - lv_label_set_text(label_target_temperature_value, - esp3dTftValues.get_string_value( - ESP3DValuesIndex::bed_target_temperature)); - temperatures_value_init = std::to_string( - std::atoi(temp_value.c_str()) > 0 ? std::atoi(temp_value.c_str()) - : 0); - temperatures_value = temperatures_value_init; - lv_textarea_set_text(temperatures_ta, temperatures_value_init.c_str()); - break; - default: - break; - }; - esp3d_log("Button %s clicked", heater_buttons_map[id]); - } -} - -void temperatures_screen(uint8_t target, ESP3DScreenType screenreturn) { - esp3dTftui.set_current_screen(ESP3DScreenType::none); - screen_return = screenreturn; - if (!intialization_done) { - esp3d_log("Temperatures screen initialization"); - // by default all heater are detected - // update will occur only if different - for (uint8_t i = 0; i < HEATER_COUNT; i++) { - heaters_values[i] = "?"; - // this one must be called only once or need to free memory - heater_buttons_map[i] = - (char *)calloc(HEATER_LABEL_SIZE + 1, sizeof(char)); - strcpy(heater_buttons_map[i], heater_buttons_label_map[i]); - esp3d_log("Heater %d, value : %s, label: %s", i, - heaters_values[i].c_str(), heater_buttons_map[i]); - } - // the real max final is 0 - heater_buttons_map[HEATER_COUNT] = (char *)calloc(1, sizeof(char)); - - intialization_done = true; - // last map entry must be empty - strcpy(heater_buttons_map[HEATER_COUNT], ""); - esp3d_log("Temperatures screen initialization done, map size: %d", - get_map_size()); - get_heater_buttons_map(); - } - - int8_t index = get_heater_buttons_map_button_id(target); - heater_buttons_map_id = index == -1 ? target : index; - - // Screen creation - esp3d_log("Temperatures screen creation for target %d, %s", target, - heater_buttons_label_map[target]); - - lv_obj_t *ui_new_screen = lv_obj_create(NULL); - // Display new screen and delete old one - lv_obj_t *ui_current_screen = lv_scr_act(); - lv_scr_load(ui_new_screen); - apply_style(ui_new_screen, ESP3DStyleType::main_bg); - lv_obj_del(ui_current_screen); - - // back button - btnback = backButton::create_back_button(ui_new_screen); - lv_obj_add_event_cb(btnback, event_button_temperatures_back_handler, - LV_EVENT_CLICKED, NULL); - - // Steps in button matrix - lv_obj_t *btnm = lv_btnmatrix_create(ui_new_screen); - lv_btnmatrix_set_map(btnm, temperatures_buttons_map); - apply_style(btnm, ESP3DStyleType::buttons_matrix); - size_t i = - (sizeof(temperatures_buttons_map) / sizeof(temperatures_buttons_map[0])) - - 1; - lv_obj_set_size(btnm, MATRIX_BUTTON_WIDTH * i, MATRIX_BUTTON_HEIGHT); - lv_obj_align(btnm, LV_ALIGN_TOP_RIGHT, -CURRENT_BUTTON_PRESSED_OUTLINE, - CURRENT_BUTTON_PRESSED_OUTLINE / 2); - lv_btnmatrix_set_btn_ctrl(btnm, temperatures_buttons_map_id, - LV_BTNMATRIX_CTRL_CHECKED); - lv_obj_add_event_cb(btnm, temperatures_matrix_buttons_event_cb, - LV_EVENT_VALUE_CHANGED, NULL); - - // Target selector button matrix - btnm_target = lv_btnmatrix_create(ui_new_screen); - // build heater buttons map - updateBtnMatrix(); - - // Power off all heater - lv_obj_t *btn_power_off_all = symbolButton::create_symbol_button( - ui_new_screen, LV_SYMBOL_POWER "...", MATRIX_BUTTON_WIDTH, - MATRIX_BUTTON_HEIGHT); - lv_obj_align_to(btn_power_off_all, btnm_target, LV_ALIGN_OUT_LEFT_BOTTOM, - -CURRENT_BUTTON_PRESSED_OUTLINE, 0); - - // Label current heater - label_current_temperature = lv_label_create(ui_new_screen); - esp3d_log("Label id: %d", heater_buttons_map_id); - lv_label_set_text( - label_current_temperature, - heater_buttons_map[heater_buttons_map_id]); // need to change according - // heater - apply_style(label_current_temperature, ESP3DStyleType::bg_label); - lv_obj_align(label_current_temperature, LV_ALIGN_TOP_LEFT, - CURRENT_BUTTON_PRESSED_OUTLINE, CURRENT_BUTTON_PRESSED_OUTLINE); - lv_obj_update_layout(label_current_temperature); - - // Label current heater e - label_current_temperature_value = lv_label_create(ui_new_screen); - std::string current_temperature_value_init; - std::string current_temperature_target_value_init; - switch (target) { - case 0: - current_temperature_value_init = - esp3dTftValues.get_string_value(ESP3DValuesIndex::ext_0_temperature); - current_temperature_target_value_init = esp3dTftValues.get_string_value( - ESP3DValuesIndex::ext_0_target_temperature); - break; - case 1: - current_temperature_value_init = - esp3dTftValues.get_string_value(ESP3DValuesIndex::ext_1_temperature); - current_temperature_target_value_init = esp3dTftValues.get_string_value( - ESP3DValuesIndex::ext_1_target_temperature); - break; - case 2: - current_temperature_value_init = esp3dTftValues.get_string_value( - ESP3DValuesIndex::bed_target_temperature); - current_temperature_target_value_init = esp3dTftValues.get_string_value( - ESP3DValuesIndex::bed_target_temperature); - break; - default: - current_temperature_value_init = "0"; - break; - esp3d_log("Button %s clicked", heater_buttons_label_map[target]); - } - if (current_temperature_value_init == "#" || - current_temperature_value_init == "?") { - current_temperature_value_init = "0"; - } - lv_label_set_text(label_current_temperature_value, - current_temperature_value_init.c_str()); - apply_style(label_current_temperature_value, ESP3DStyleType::read_only_value); - lv_obj_set_width(label_current_temperature_value, LV_HOR_RES / 6); - lv_obj_align_to(label_current_temperature_value, label_current_temperature, - LV_ALIGN_OUT_RIGHT_MID, CURRENT_BUTTON_PRESSED_OUTLINE / 2, - 0); - // unit - lv_obj_t *label_unit1 = lv_label_create(ui_new_screen); - lv_label_set_text(label_unit1, - esp3dTranslationService.translate(ESP3DLabel::celsius)); - apply_style(label_unit1, ESP3DStyleType::bg_label); - lv_obj_align_to(label_unit1, label_current_temperature_value, - LV_ALIGN_OUT_RIGHT_MID, CURRENT_BUTTON_PRESSED_OUTLINE / 2, - 0); - // Button up - lv_obj_t *btn_up = symbolButton::create_symbol_button( - ui_new_screen, LV_SYMBOL_UP "\n" LV_SYMBOL_PLUS); - lv_obj_align_to(btn_up, label_current_temperature_value, - LV_ALIGN_OUT_BOTTOM_MID, 0, - CURRENT_BUTTON_PRESSED_OUTLINE / 2); - // Text area - lv_obj_t *temperatures_ta = lv_textarea_create(ui_new_screen); - lv_obj_add_event_cb(temperatures_ta, temperatures_ta_event_cb, - LV_EVENT_VALUE_CHANGED, NULL); - lv_textarea_set_accepted_chars(temperatures_ta, "0123456789"); - lv_textarea_set_max_length(temperatures_ta, 3); - lv_textarea_set_one_line(temperatures_ta, true); - - std::string temperatures_value_init = std::to_string( - std::atoi(current_temperature_target_value_init.c_str()) > 0 - ? std::atoi(current_temperature_target_value_init.c_str()) - : 0); - lv_textarea_set_text(temperatures_ta, temperatures_value_init.c_str()); - lv_obj_set_style_text_align(temperatures_ta, LV_TEXT_ALIGN_CENTER, 0); - lv_obj_set_width(temperatures_ta, LV_HOR_RES / 6); - - lv_obj_align_to(temperatures_ta, btn_up, LV_ALIGN_OUT_BOTTOM_MID, 0, - CURRENT_BUTTON_PRESSED_OUTLINE / 2); - - lv_obj_add_event_cb(btn_up, temperatures_btn_up_event_cb, LV_EVENT_CLICKED, - temperatures_ta); - lv_obj_add_event_cb(btn_power_off_all, power_all_heaters_event_cb, - LV_EVENT_CLICKED, temperatures_ta); - lv_obj_add_event_cb(btnm_target, heater_matrix_buttons_event_cb, - LV_EVENT_VALUE_CHANGED, temperatures_ta); - - // Label target heater - lv_obj_t *label_target = lv_label_create(ui_new_screen); - lv_label_set_text(label_target, - LV_SYMBOL_HEAT_EXTRUDER); // need to change according - // heater - apply_style(label_target, ESP3DStyleType::bg_label); - lv_obj_align_to(label_target, temperatures_ta, LV_ALIGN_OUT_LEFT_MID, - -CURRENT_BUTTON_PRESSED_OUTLINE / 2, 0); - - // Unit - lv_obj_t *label_unit2 = lv_label_create(ui_new_screen); - lv_label_set_text(label_unit2, - esp3dTranslationService.translate(ESP3DLabel::celsius)); - apply_style(label_unit2, ESP3DStyleType::bg_label); - - lv_obj_align_to(label_unit2, temperatures_ta, LV_ALIGN_OUT_RIGHT_MID, - CURRENT_BUTTON_PRESSED_OUTLINE / 2, 0); - // set button - lv_obj_t *btn_set = - symbolButton::create_symbol_button(ui_new_screen, LV_SYMBOL_OK); - lv_obj_align_to(btn_set, label_unit2, LV_ALIGN_OUT_RIGHT_MID, - CURRENT_BUTTON_PRESSED_OUTLINE, 0); - lv_obj_add_event_cb(btn_set, temperatures_btn_ok_event_cb, LV_EVENT_CLICKED, - temperatures_ta); - // Power off button to 0 - lv_obj_t *btn_stop = - symbolButton::create_symbol_button(ui_new_screen, LV_SYMBOL_POWER); - lv_obj_align_to(btn_stop, btn_set, LV_ALIGN_OUT_RIGHT_MID, - CURRENT_BUTTON_PRESSED_OUTLINE, 0); - lv_obj_add_event_cb(btn_stop, temperatures_btn_power_off_event_cb, - LV_EVENT_CLICKED, temperatures_ta); - // Keyboard - lv_obj_t *temperatures_kb = lv_keyboard_create(ui_new_screen); - lv_keyboard_set_mode(temperatures_kb, LV_KEYBOARD_MODE_NUMBER); - lv_keyboard_set_textarea(temperatures_kb, NULL); - lv_obj_update_layout(label_unit2); - lv_obj_set_content_width(temperatures_kb, - LV_HOR_RES - (lv_obj_get_x(label_unit2) + - CURRENT_BUTTON_PRESSED_OUTLINE)); - lv_obj_align_to(temperatures_kb, temperatures_ta, LV_ALIGN_OUT_RIGHT_MID, - CURRENT_BUTTON_PRESSED_OUTLINE / 2, - -CURRENT_BUTTON_PRESSED_OUTLINE / 2); - lv_obj_set_style_radius(temperatures_kb, CURRENT_BUTTON_RADIUS_VALUE, - LV_PART_MAIN); - lv_obj_add_flag(temperatures_kb, LV_OBJ_FLAG_HIDDEN); - lv_obj_add_event_cb(temperatures_ta, temperatures_ta_event_cb, LV_EVENT_ALL, - temperatures_kb); - // Button down - lv_obj_t *btn_down = symbolButton::create_symbol_button( - ui_new_screen, LV_SYMBOL_MINUS "\n" LV_SYMBOL_DOWN); - lv_obj_align_to(btn_down, temperatures_ta, LV_ALIGN_OUT_BOTTOM_MID, 0, - CURRENT_BUTTON_PRESSED_OUTLINE / 2); - lv_obj_add_event_cb(btn_down, temperatures_btn_down_event_cb, - LV_EVENT_CLICKED, temperatures_ta); - - // Label target heater e - label_target_temperature_value = lv_label_create(ui_new_screen); - - lv_label_set_text(label_target_temperature_value, - temperatures_value_init.c_str()); - apply_style(label_target_temperature_value, - ESP3DStyleType::read_only_setting); - lv_obj_set_width(label_target_temperature_value, LV_HOR_RES / 6); - lv_obj_align_to(label_target_temperature_value, btn_down, - LV_ALIGN_OUT_BOTTOM_MID, 0, - CURRENT_BUTTON_PRESSED_OUTLINE / 2); - - // unit - label_unit1 = lv_label_create(ui_new_screen); - lv_label_set_text(label_unit1, - esp3dTranslationService.translate(ESP3DLabel::celsius)); - apply_style(label_unit1, ESP3DStyleType::bg_label); - lv_obj_align_to(label_unit1, label_target_temperature_value, - LV_ALIGN_OUT_RIGHT_MID, CURRENT_BUTTON_PRESSED_OUTLINE / 2, - 0); - - // Label target heater - label_target_temperature = lv_label_create(ui_new_screen); - lv_label_set_text( - label_target_temperature, - heater_buttons_map[heater_buttons_map_id]); // need to change according - // heater - apply_style(label_target_temperature, ESP3DStyleType::bg_label); - - lv_obj_align_to(label_target_temperature, label_target_temperature_value, - LV_ALIGN_OUT_LEFT_MID, -CURRENT_BUTTON_PRESSED_OUTLINE / 2, - 0); - - esp3dTftui.set_current_screen(ESP3DScreenType::temperatures); -} - -bool extruder_0_value_cb(ESP3DValuesIndex index, const char *value, - ESP3DValuesCbAction action) { - // the callback is ignored because the bed callback will be used instead to - // avoid duplicate code - return false; -} - -bool extruder_1_value_cb(ESP3DValuesIndex index, const char *value, - ESP3DValuesCbAction action) { - // the callback is ignored because the bed callback will be used instead to - // avoid duplicate code - return false; -} - -void updateUiValues() { - uint8_t target = get_heater_buttons_map_id(heater_buttons_map_id); - if (target == 255) { - target = 0; - heater_buttons_map_id = 0; - } - switch (target) { - case 0: - lv_label_set_text( - label_current_temperature_value, - esp3dTftValues.get_string_value(ESP3DValuesIndex::ext_0_temperature)); - lv_label_set_text(label_target_temperature_value, - esp3dTftValues.get_string_value( - ESP3DValuesIndex::ext_0_target_temperature)); - break; - case 1: - lv_label_set_text( - label_current_temperature_value, - esp3dTftValues.get_string_value(ESP3DValuesIndex::ext_1_temperature)); - lv_label_set_text(label_target_temperature_value, - esp3dTftValues.get_string_value( - ESP3DValuesIndex::ext_1_target_temperature)); - break; - case 2: - lv_label_set_text( - label_current_temperature_value, - esp3dTftValues.get_string_value(ESP3DValuesIndex::bed_temperature)); - lv_label_set_text(label_target_temperature_value, - esp3dTftValues.get_string_value( - ESP3DValuesIndex::bed_target_temperature)); - break; - default: - break; - } - lv_label_set_text(label_current_temperature, - heater_buttons_map[heater_buttons_map_id]); - - lv_label_set_text(label_target_temperature, - heater_buttons_map[heater_buttons_map_id]); -} - -bool bed_value_cb(ESP3DValuesIndex index, const char *value, - ESP3DValuesCbAction action) { - // be sure to be on temperatures screen - if (esp3dTftui.get_current_screen() != ESP3DScreenType::temperatures) - return false; - std::string vale0 = - esp3dTftValues.get_string_value(ESP3DValuesIndex::ext_0_temperature); - std::string vale1 = - esp3dTftValues.get_string_value(ESP3DValuesIndex::ext_1_temperature); - std::string valbed = - esp3dTftValues.get_string_value(ESP3DValuesIndex::bed_temperature); - esp3d_log("Bed value callback, %s, %s, %s", vale0.c_str(), vale1.c_str(), - valbed.c_str()); - esp3d_log("Check if update needed, E0:%s, E1:%s, Bed:%s", - heater_buttons_visibility_map[0] ? "visible" : "hidden", - heater_buttons_visibility_map[1] ? "visible" : "hidden", - heater_buttons_visibility_map[2] ? "visible" : "hidden"); - if (((vale0 != "#") != heater_buttons_visibility_map[0]) || - ((vale1 != "#") != heater_buttons_visibility_map[1]) || - ((valbed != "#") != heater_buttons_visibility_map[2])) { - esp3d_log("Update needed"); - heaters_values[0] = vale0; - heaters_values[1] = vale1; - heaters_values[2] = valbed; - updateBtnMatrix(); - } - updateUiValues(); - return true; -} -} // namespace temperaturesScreen \ No newline at end of file diff --git a/main/display/cnc/grbl/screens/temperatures_screen.h b/main/display/cnc/grbl/screens/temperatures_screen.h deleted file mode 100644 index d0f93361..00000000 --- a/main/display/cnc/grbl/screens/temperatures_screen.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - temperatures_screen.h - esp3d - Copyright (c) 2022 Luc Lebosse. All rights reserved. - - This code is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This code 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#pragma once - -#include "esp3d_values.h" -#include "screens/esp3d_screen_type.h" - -namespace temperaturesScreen { -extern void temperatures_screen( - uint8_t target, ESP3DScreenType screenreturn = ESP3DScreenType::main); -extern bool extruder_0_value_cb(ESP3DValuesIndex index, const char *value, - ESP3DValuesCbAction action); -extern bool extruder_1_value_cb(ESP3DValuesIndex index, const char *value, - ESP3DValuesCbAction action); -extern bool bed_value_cb(ESP3DValuesIndex index, const char *value, - ESP3DValuesCbAction action); - -} // namespace temperaturesScreen diff --git a/main/target/cnc/grbl/esp3d_gcode_parser_service.cpp b/main/target/cnc/grbl/esp3d_gcode_parser_service.cpp index 140c1abd..6282535c 100644 --- a/main/target/cnc/grbl/esp3d_gcode_parser_service.cpp +++ b/main/target/cnc/grbl/esp3d_gcode_parser_service.cpp @@ -29,15 +29,17 @@ ESP3DGCodeParserService esp3dGcodeParser; const char* emmergencyGcodeCommand[] = {"M112", "M410", "M999"}; const char* emmergencyESP3DCommand[] = {"[ESP701]"}; const char* pollingCommands[] = { - "M105", // Temperatures - "M114", // Positions - "M220", // Speed + "?", // Status + "$G", // GCode parser state + "$#", // GCode Parameters + "[ESP701]json", // streaming status }; uint64_t pollingCommandsLastUpdate[] = { - 0, // Temperatures - 0, // Positions - 0, // Speed + 0, // Status + 0, // GCode parser state + 0, // GCode Parameters + 0, // streaming status }; const char* screenCommands[] = {"M117", // TFT screen output @@ -115,275 +117,275 @@ bool ESP3DGCodeParserService::hasMultiLineReport(const char* data) { bool ESP3DGCodeParserService::processCommand(const char* data) { esp3d_log("processing Command %s", data); - if (data != nullptr && strlen(data) > 0) { - // is temperature - if (strstr(data, "T:") != nullptr) { - // ok T:25.00 /120.00 B:25.00 /0.00 @:127 B@:0 - // T:25.00 /0.00 B:25.00 /50.00 T0:25.00 /0.00 T1:105.00 /0.00 @:0 B@:127 - char* ptrt = strstr(data, "T:"); - char* ptrt0 = strstr(data, "T0:"); - char* ptrt1 = strstr(data, "T1:"); - char* ptrb = strstr(data, "B:"); - if (ptrt0 && ptrt1) { // dual extruder - esp3d_log("Temperature dual extruders"); - ptrt0 += 3; - ptrt1 += 3; - // Extruder 0 current temperature - char* ptre = strstr(ptrt0, " /"); - if (!ptre) { - esp3d_log_e("Error parsing temperature T0 value"); - return false; - } - ptre[0] = '\0'; - // Extruder 0 target temperature - char* ptrtt = ptre + 2; - ptre = strstr(ptrtt, " "); - if (!ptre) { - esp3d_log_e("Error parsing temperature T0 target"); - return false; - } - ptre[0] = '\0'; - // Dispatch values - esp3dTftValues.set_string_value(ESP3DValuesIndex::ext_0_temperature, - ptrt0); - esp3dTftValues.set_string_value( - ESP3DValuesIndex::ext_0_target_temperature, ptrtt); - esp3d_log("T0: %s / %s", ptrt0, ptrtt); - - // Extruder 1 current temperature - ptre = strstr(ptrt1, " /"); - if (!ptre) { - esp3d_log_e("Error parsing temperature T1 value"); - esp3dTftValues.set_string_value(ESP3DValuesIndex::ext_1_temperature, - "#"); - esp3dTftValues.set_string_value( - ESP3DValuesIndex::ext_1_target_temperature, "#"); - return false; - } - ptre[0] = '\0'; - // Extruder 1 target temperature - ptrtt = ptre + 2; - ptre = strstr(ptrtt, " "); - if (!ptre) { - esp3d_log_e("Error parsing temperature T1 target"); - esp3dTftValues.set_string_value(ESP3DValuesIndex::ext_1_temperature, - "#"); - esp3dTftValues.set_string_value( - ESP3DValuesIndex::ext_1_target_temperature, "#"); - return false; - } - ptre[0] = '\0'; - // Dispatch values - esp3dTftValues.set_string_value(ESP3DValuesIndex::ext_1_temperature, - ptrt1); - esp3dTftValues.set_string_value( - ESP3DValuesIndex::ext_1_target_temperature, ptrtt); - esp3d_log("T1: %s / %s", ptrt1, ptrtt); - } else { // single extruder - esp3d_log("Temperature single extruder"); - esp3dTftValues.set_string_value(ESP3DValuesIndex::ext_1_temperature, - "#"); - esp3dTftValues.set_string_value( - ESP3DValuesIndex::ext_1_target_temperature, "#"); - ptrt += 2; - // Extruder 0 current temperature - char* ptre = strstr(ptrt, " /"); - if (!ptre) { - esp3d_log_e("Error parsing temperature T0 value"); - return false; - } - ptre[0] = '\0'; - // Extruder 0 target temperature - char* ptrtt = ptre + 2; - ptre = strstr(ptrtt, " "); - if (!ptre) { - esp3d_log_e("Error parsing temperature T0 target"); - return false; - } - ptre[0] = '\0'; - // Dispatch values - esp3dTftValues.set_string_value(ESP3DValuesIndex::ext_0_temperature, - ptrt); - esp3dTftValues.set_string_value( - ESP3DValuesIndex::ext_0_target_temperature, ptrtt); - - esp3d_log("T: %s / %s", ptrt, ptrtt); - } - if (ptrb) { // bed - esp3d_log("Temperature bed"); - ptrb += 2; - // Bed current temperature - char* ptre = strstr(ptrb, " /"); - if (!ptre) { - esp3d_log_e("Error parsing temperature bed value"); - return false; - } - ptre[0] = '\0'; - // Bed target temperature - char* ptrtt = ptre + 2; - ptre = strstr(ptrtt, " "); - if (!ptre) { - esp3d_log_e("Error parsing temperature Bed target"); - return false; - } - ptre[0] = '\0'; - // Dispatch values - esp3dTftValues.set_string_value(ESP3DValuesIndex::bed_temperature, - ptrb); - esp3dTftValues.set_string_value( - ESP3DValuesIndex::bed_target_temperature, ptrtt); - esp3d_log("Bed: %s / %s", ptrb, ptrtt); - } else { - esp3d_log("No Temperature bed"); - esp3dTftValues.set_string_value(ESP3DValuesIndex::bed_temperature, "#"); - esp3dTftValues.set_string_value( - ESP3DValuesIndex::bed_target_temperature, "#"); - } - setPollingCommandsLastRun( - ESP3D_POLLING_COMMANDS_INDEX_TEMPERATURE_TEMPERATURE, - esp3d_hal::millis()); - return true; - // is position but not bed leveling - } else if (strstr(data, "X:") != nullptr && - strstr(data, "Bed X:") == nullptr) { - // X:0.00 Y:0.00 Z:0.00 E:0.00 Count X:0 Y:0 Z:0 - esp3d_log("Positions"); - char* ptrx = strstr(data, "X:"); - char* ptry = strstr(data, "Y:"); - char* ptrz = strstr(data, "Z:"); - char* ptre = strstr(data, "E:"); - - if (ptrx && ptry && ptrz && ptre) { - ptrx += 2; - ptry[0] = '\0'; - ptry += 2; - ptrz[0] = '\0'; - ptrz += 2; - if (ptre) { - ptre[0] = '\0'; - } - esp3dTftValues.set_string_value(ESP3DValuesIndex::position_x, ptrx); - esp3dTftValues.set_string_value(ESP3DValuesIndex::position_y, ptry); - esp3dTftValues.set_string_value(ESP3DValuesIndex::position_z, ptrz); - setPollingCommandsLastRun( - ESP3D_POLLING_COMMANDS_INDEX_TEMPERATURE_POSITION, - esp3d_hal::millis()); - return true; - } else { - esp3d_log_e("Error parsing positions"); - } - } else if (strstr(data, "FR:") != nullptr) { - char* ptrfr = strstr(data, "FR:"); - char* ptrpc = strstr(data, "%"); - if (ptrfr && ptrpc) { - ptrfr += 3; - ptrpc[0] = '\0'; - esp3dTftValues.set_string_value(ESP3DValuesIndex::speed, ptrfr); - setPollingCommandsLastRun( - ESP3D_POLLING_COMMANDS_INDEX_TEMPERATURE_SPEED, - esp3d_hal::millis()); - return true; - } else { - esp3d_log_e("Error parsing progress"); - } - // is fan speed ? - } else if (strstr(data, "M106") != nullptr || - strstr(data, "M107") != nullptr) { - char* ptr106 = strstr(data, "M106"); - char* ptr107 = strstr(data, "M107"); - if (ptr106) { - ptr106 += 4; - char* ptrS = strstr(ptr106, "S"); - if (!ptrS) { - esp3d_log_e("Error parsing fan speed"); - return false; - } - - ptrS++; - // get fan speed - static std::string fanSpeed = ""; - fanSpeed = ""; - - for (uint8_t i = 0; i < 3; i++) { - if (ptrS[i] >= '0' && ptrS[i] <= '9') { - fanSpeed += ptrS[i]; - } else { - break; - } - } - // is there an index ? - esp3d_log("Check index in %s", ptr106); - uint8_t index = 0; - char* ptrI = strstr(ptr106, "P"); - if (ptrI) { - esp3d_log("Index found %s", ptrI); - if (ptrI[1] == '1') { - index = 1; - } - } - // conversion 0~255 to 0~100 - double fspeed = (std::stod(fanSpeed.c_str()) * 100) / 255; - // limit to 100% - if (fspeed > 100) { - fspeed = 100; - } - - fanSpeed = esp3d_string::set_precision(std::to_string(fspeed), 0); - // set fan speed according index - esp3d_log("Fan speed 106, index: %d, %s", index, fanSpeed.c_str()); - if (index == 0) { - esp3dTftValues.set_string_value(ESP3DValuesIndex::ext_0_fan, - fanSpeed.c_str()); - } else { - esp3dTftValues.set_string_value(ESP3DValuesIndex::ext_1_fan, - fanSpeed.c_str()); - } - return true; - } else if (ptr107) { - ptr107 += 4; - char* ptrI = strstr(ptr107, "P"); - uint8_t index = 0; - // is there an index ? - if (ptrI) { - if (ptrI[1] == '1') { - index = 1; - } - } - esp3d_log("Fan speed 107, index: %d", index); - // set fan speed to 0 according index - if (index == 0) { - esp3dTftValues.set_string_value(ESP3DValuesIndex::ext_0_fan, "0"); - } else { - esp3dTftValues.set_string_value(ESP3DValuesIndex::ext_1_fan, "0"); - } - return true; - } else { - esp3d_log_e("Error parsing fan speed"); - } - // G29 Auto Bed Leveling - } else if (strstr(data, "G29 Auto Bed Leveling") != nullptr || - strstr(data, "Bed X:") != nullptr || - strstr(data, "Bilinear Leveling Grid:") != nullptr) { - static bool isLeveling = false; - if (strstr(data, "G29 Auto Bed Leveling") != nullptr) { - isLeveling = true; - // Send start of leveling - esp3dTftValues.set_string_value(ESP3DValuesIndex::bed_leveling, "Start", - ESP3DValuesCbAction::Add); - } else if (isLeveling) { - if (strstr(data, "Bilinear Leveling Grid:") != nullptr) { - isLeveling = false; - // Send end of leveling - esp3dTftValues.set_string_value(ESP3DValuesIndex::bed_leveling, "End", - ESP3DValuesCbAction::Delete); - } else { - // Send leveling data - esp3dTftValues.set_string_value(ESP3DValuesIndex::bed_leveling, data, - ESP3DValuesCbAction::Update); - } - } - } - } + // if (data != nullptr && strlen(data) > 0) { + // // is temperature + // if (strstr(data, "T:") != nullptr) { + // // ok T:25.00 /120.00 B:25.00 /0.00 @:127 B@:0 + // // T:25.00 /0.00 B:25.00 /50.00 T0:25.00 /0.00 T1:105.00 /0.00 @:0 B@:127 + // char* ptrt = strstr(data, "T:"); + // char* ptrt0 = strstr(data, "T0:"); + // char* ptrt1 = strstr(data, "T1:"); + // char* ptrb = strstr(data, "B:"); + // if (ptrt0 && ptrt1) { // dual extruder + // esp3d_log("Temperature dual extruders"); + // ptrt0 += 3; + // ptrt1 += 3; + // // Extruder 0 current temperature + // char* ptre = strstr(ptrt0, " /"); + // if (!ptre) { + // esp3d_log_e("Error parsing temperature T0 value"); + // return false; + // } + // ptre[0] = '\0'; + // // Extruder 0 target temperature + // char* ptrtt = ptre + 2; + // ptre = strstr(ptrtt, " "); + // if (!ptre) { + // esp3d_log_e("Error parsing temperature T0 target"); + // return false; + // } + // ptre[0] = '\0'; + // // Dispatch values + // esp3dTftValues.set_string_value(ESP3DValuesIndex::ext_0_temperature, + // ptrt0); + // esp3dTftValues.set_string_value( + // ESP3DValuesIndex::ext_0_target_temperature, ptrtt); + // esp3d_log("T0: %s / %s", ptrt0, ptrtt); + + // // Extruder 1 current temperature + // ptre = strstr(ptrt1, " /"); + // if (!ptre) { + // esp3d_log_e("Error parsing temperature T1 value"); + // esp3dTftValues.set_string_value(ESP3DValuesIndex::ext_1_temperature, + // "#"); + // esp3dTftValues.set_string_value( + // ESP3DValuesIndex::ext_1_target_temperature, "#"); + // return false; + // } + // ptre[0] = '\0'; + // // Extruder 1 target temperature + // ptrtt = ptre + 2; + // ptre = strstr(ptrtt, " "); + // if (!ptre) { + // esp3d_log_e("Error parsing temperature T1 target"); + // esp3dTftValues.set_string_value(ESP3DValuesIndex::ext_1_temperature, + // "#"); + // esp3dTftValues.set_string_value( + // ESP3DValuesIndex::ext_1_target_temperature, "#"); + // return false; + // } + // ptre[0] = '\0'; + // // Dispatch values + // esp3dTftValues.set_string_value(ESP3DValuesIndex::ext_1_temperature, + // ptrt1); + // esp3dTftValues.set_string_value( + // ESP3DValuesIndex::ext_1_target_temperature, ptrtt); + // esp3d_log("T1: %s / %s", ptrt1, ptrtt); + // } else { // single extruder + // esp3d_log("Temperature single extruder"); + // esp3dTftValues.set_string_value(ESP3DValuesIndex::ext_1_temperature, + // "#"); + // esp3dTftValues.set_string_value( + // ESP3DValuesIndex::ext_1_target_temperature, "#"); + // ptrt += 2; + // // Extruder 0 current temperature + // char* ptre = strstr(ptrt, " /"); + // if (!ptre) { + // esp3d_log_e("Error parsing temperature T0 value"); + // return false; + // } + // ptre[0] = '\0'; + // // Extruder 0 target temperature + // char* ptrtt = ptre + 2; + // ptre = strstr(ptrtt, " "); + // if (!ptre) { + // esp3d_log_e("Error parsing temperature T0 target"); + // return false; + // } + // ptre[0] = '\0'; + // // Dispatch values + // esp3dTftValues.set_string_value(ESP3DValuesIndex::ext_0_temperature, + // ptrt); + // esp3dTftValues.set_string_value( + // ESP3DValuesIndex::ext_0_target_temperature, ptrtt); + + // esp3d_log("T: %s / %s", ptrt, ptrtt); + // } + // if (ptrb) { // bed + // esp3d_log("Temperature bed"); + // ptrb += 2; + // // Bed current temperature + // char* ptre = strstr(ptrb, " /"); + // if (!ptre) { + // esp3d_log_e("Error parsing temperature bed value"); + // return false; + // } + // ptre[0] = '\0'; + // // Bed target temperature + // char* ptrtt = ptre + 2; + // ptre = strstr(ptrtt, " "); + // if (!ptre) { + // esp3d_log_e("Error parsing temperature Bed target"); + // return false; + // } + // ptre[0] = '\0'; + // // Dispatch values + // esp3dTftValues.set_string_value(ESP3DValuesIndex::bed_temperature, + // ptrb); + // esp3dTftValues.set_string_value( + // ESP3DValuesIndex::bed_target_temperature, ptrtt); + // esp3d_log("Bed: %s / %s", ptrb, ptrtt); + // } else { + // esp3d_log("No Temperature bed"); + // esp3dTftValues.set_string_value(ESP3DValuesIndex::bed_temperature, "#"); + // esp3dTftValues.set_string_value( + // ESP3DValuesIndex::bed_target_temperature, "#"); + // } + // setPollingCommandsLastRun( + // ESP3D_POLLING_COMMANDS_INDEX_TEMPERATURE_TEMPERATURE, + // esp3d_hal::millis()); + // return true; + // // is position but not bed leveling + // } else if (strstr(data, "X:") != nullptr && + // strstr(data, "Bed X:") == nullptr) { + // // X:0.00 Y:0.00 Z:0.00 E:0.00 Count X:0 Y:0 Z:0 + // esp3d_log("Positions"); + // char* ptrx = strstr(data, "X:"); + // char* ptry = strstr(data, "Y:"); + // char* ptrz = strstr(data, "Z:"); + // char* ptre = strstr(data, "E:"); + + // if (ptrx && ptry && ptrz && ptre) { + // ptrx += 2; + // ptry[0] = '\0'; + // ptry += 2; + // ptrz[0] = '\0'; + // ptrz += 2; + // if (ptre) { + // ptre[0] = '\0'; + // } + // esp3dTftValues.set_string_value(ESP3DValuesIndex::position_x, ptrx); + // esp3dTftValues.set_string_value(ESP3DValuesIndex::position_y, ptry); + // esp3dTftValues.set_string_value(ESP3DValuesIndex::position_z, ptrz); + // setPollingCommandsLastRun( + // ESP3D_POLLING_COMMANDS_INDEX_TEMPERATURE_POSITION, + // esp3d_hal::millis()); + // return true; + // } else { + // esp3d_log_e("Error parsing positions"); + // } + // } else if (strstr(data, "FR:") != nullptr) { + // char* ptrfr = strstr(data, "FR:"); + // char* ptrpc = strstr(data, "%"); + // if (ptrfr && ptrpc) { + // ptrfr += 3; + // ptrpc[0] = '\0'; + // esp3dTftValues.set_string_value(ESP3DValuesIndex::speed, ptrfr); + // setPollingCommandsLastRun( + // ESP3D_POLLING_COMMANDS_INDEX_TEMPERATURE_SPEED, + // esp3d_hal::millis()); + // return true; + // } else { + // esp3d_log_e("Error parsing progress"); + // } + // // is fan speed ? + // } else if (strstr(data, "M106") != nullptr || + // strstr(data, "M107") != nullptr) { + // char* ptr106 = strstr(data, "M106"); + // char* ptr107 = strstr(data, "M107"); + // if (ptr106) { + // ptr106 += 4; + // char* ptrS = strstr(ptr106, "S"); + // if (!ptrS) { + // esp3d_log_e("Error parsing fan speed"); + // return false; + // } + + // ptrS++; + // // get fan speed + // static std::string fanSpeed = ""; + // fanSpeed = ""; + + // for (uint8_t i = 0; i < 3; i++) { + // if (ptrS[i] >= '0' && ptrS[i] <= '9') { + // fanSpeed += ptrS[i]; + // } else { + // break; + // } + // } + // // is there an index ? + // esp3d_log("Check index in %s", ptr106); + // uint8_t index = 0; + // char* ptrI = strstr(ptr106, "P"); + // if (ptrI) { + // esp3d_log("Index found %s", ptrI); + // if (ptrI[1] == '1') { + // index = 1; + // } + // } + // // conversion 0~255 to 0~100 + // double fspeed = (std::stod(fanSpeed.c_str()) * 100) / 255; + // // limit to 100% + // if (fspeed > 100) { + // fspeed = 100; + // } + + // fanSpeed = esp3d_string::set_precision(std::to_string(fspeed), 0); + // // set fan speed according index + // esp3d_log("Fan speed 106, index: %d, %s", index, fanSpeed.c_str()); + // if (index == 0) { + // esp3dTftValues.set_string_value(ESP3DValuesIndex::ext_0_fan, + // fanSpeed.c_str()); + // } else { + // esp3dTftValues.set_string_value(ESP3DValuesIndex::ext_1_fan, + // fanSpeed.c_str()); + // } + // return true; + // } else if (ptr107) { + // ptr107 += 4; + // char* ptrI = strstr(ptr107, "P"); + // uint8_t index = 0; + // // is there an index ? + // if (ptrI) { + // if (ptrI[1] == '1') { + // index = 1; + // } + // } + // esp3d_log("Fan speed 107, index: %d", index); + // // set fan speed to 0 according index + // if (index == 0) { + // esp3dTftValues.set_string_value(ESP3DValuesIndex::ext_0_fan, "0"); + // } else { + // esp3dTftValues.set_string_value(ESP3DValuesIndex::ext_1_fan, "0"); + // } + // return true; + // } else { + // esp3d_log_e("Error parsing fan speed"); + // } + // // G29 Auto Bed Leveling + // } else if (strstr(data, "G29 Auto Bed Leveling") != nullptr || + // strstr(data, "Bed X:") != nullptr || + // strstr(data, "Bilinear Leveling Grid:") != nullptr) { + // static bool isLeveling = false; + // if (strstr(data, "G29 Auto Bed Leveling") != nullptr) { + // isLeveling = true; + // // Send start of leveling + // esp3dTftValues.set_string_value(ESP3DValuesIndex::bed_leveling, "Start", + // ESP3DValuesCbAction::Add); + // } else if (isLeveling) { + // if (strstr(data, "Bilinear Leveling Grid:") != nullptr) { + // isLeveling = false; + // // Send end of leveling + // esp3dTftValues.set_string_value(ESP3DValuesIndex::bed_leveling, "End", + // ESP3DValuesCbAction::Delete); + // } else { + // // Send leveling data + // esp3dTftValues.set_string_value(ESP3DValuesIndex::bed_leveling, data, + // ESP3DValuesCbAction::Update); + // } + // } + // } + // } return false; } diff --git a/main/target/cnc/grbl/esp3d_settings.cpp b/main/target/cnc/grbl/esp3d_settings.cpp index ee70d402..9838bd0e 100644 --- a/main/target/cnc/grbl/esp3d_settings.cpp +++ b/main/target/cnc/grbl/esp3d_settings.cpp @@ -174,9 +174,9 @@ const ESP3DSettingDescription ESP3DSettingsData[] = { {ESP3DSettingIndex::esp3d_inverved_x, ESP3DSettingType::byte_t, 1, "0"}, {ESP3DSettingIndex::esp3d_inverved_y, ESP3DSettingType::byte_t, 1, "0"}, {ESP3DSettingIndex::esp3d_auto_level_on, ESP3DSettingType::byte_t, 1, "0"}, - {ESP3DSettingIndex::esp3d_bed_width, ESP3DSettingType::float_t, 3, + {ESP3DSettingIndex::esp3d_workspace_width, ESP3DSettingType::float_t, 3, "100.00"}, - {ESP3DSettingIndex::esp3d_bed_depth, ESP3DSettingType::float_t, 3, + {ESP3DSettingIndex::esp3d_workspace_depth, ESP3DSettingType::float_t, 3, "100.00"}, #endif // ESP3D_DISPLAY_FEATURE {ESP3DSettingIndex::esp3d_stop_script, ESP3DSettingType::string_t, @@ -212,8 +212,8 @@ bool ESP3DSettings::isValidStringSetting(const char* value, return false; } switch (settingElement) { - case ESP3DSettingIndex::esp3d_bed_width: - case ESP3DSettingIndex::esp3d_bed_depth: + case ESP3DSettingIndex::esp3d_workspace_width: + case ESP3DSettingIndex::esp3d_workspace_depth: if (strtod(value, NULL) == 0) { return false; } @@ -486,7 +486,7 @@ bool ESP3DSettings::isValidByteSetting(uint8_t value, static_cast(value) == ESP3DTargetFirmware::marlin || static_cast(value) == - ESP3DTargetFirmware::marlin_embedded || + ESP3DTargetFirmware::marlin_emworkspaceded || static_cast(value) == ESP3DTargetFirmware::smoothieware || static_cast(value) == @@ -595,7 +595,7 @@ const char* ESP3DSettings::GetFirmwareTargetShortName( return "grbl"; case ESP3DTargetFirmware::marlin: return "marlin"; - case ESP3DTargetFirmware::marlin_embedded: + case ESP3DTargetFirmware::marlin_emworkspaceded: return "marlin"; case ESP3DTargetFirmware::smoothieware: return "smoothieware"; diff --git a/main/target/cnc/grbl/esp3d_settings.h b/main/target/cnc/grbl/esp3d_settings.h index 46ecb96f..bf0bd004 100644 --- a/main/target/cnc/grbl/esp3d_settings.h +++ b/main/target/cnc/grbl/esp3d_settings.h @@ -91,8 +91,8 @@ enum class ESP3DSettingIndex : uint16_t { esp3d_jog_type, esp3d_polling_on, esp3d_auto_level_on, - esp3d_bed_width, - esp3d_bed_depth, + esp3d_workspace_width, + esp3d_workspace_depth, esp3d_inverved_x, esp3d_inverved_y, esp3d_extensions, // json setting, in preferences.json @@ -113,7 +113,7 @@ enum class ESP3DTargetFirmware : uint8_t { unknown = 0, grbl = 10, marlin = 20, - marlin_embedded = 30, + marlin_emworkspaceded = 30, smoothieware = 40, repetier = 50, reprap = 70, diff --git a/main/target/cnc/grbl/esp3d_translations_init.cpp b/main/target/cnc/grbl/esp3d_translations_init.cpp index deac56e8..6c3256ee 100644 --- a/main/target/cnc/grbl/esp3d_translations_init.cpp +++ b/main/target/cnc/grbl/esp3d_translations_init.cpp @@ -65,21 +65,11 @@ void ESP3DTranslationService::init() { {ESP3DLabel::polling, "Polling"}, {ESP3DLabel::enabled, "Enabled"}, {ESP3DLabel::disabled, "Disabled"}, - {ESP3DLabel::motors_disabled, "Motors disabled"}, {ESP3DLabel::information, "Information"}, {ESP3DLabel::fan_controls, "Fan controls"}, {ESP3DLabel::serial, "Serial"}, - {ESP3DLabel::auto_leveling, "Auto leveling"}, - {ESP3DLabel::manual_leveling_help, - "Adjust each knobs corresponding to active position until a sheet of " - "paper just slides amid nozzle and plate.\n" - "Repeat operation for each point until no correction is needed."}, - {ESP3DLabel::manual_leveling_text, - "Adjust knobs to level, then click on next.\nYou can also select " - "manually each point."}, - {ESP3DLabel::bed_width, "Bed width"}, - {ESP3DLabel::bed_depth, "Bed depth"}, - {ESP3DLabel::auto_bed_probing, "Probing location: %s"}, + {ESP3DLabel::workspace_width, "Workspace width"}, + {ESP3DLabel::workspace_depth, "Workspace depth"}, {ESP3DLabel::invert_axis, "Invert %s axis"}, {ESP3DLabel::start_probing, "Start probing"}, {ESP3DLabel::ui_language, "Language"}, diff --git a/main/target/cnc/grbl/esp3d_translations_list.h b/main/target/cnc/grbl/esp3d_translations_list.h index ec5379ba..6db64cc4 100644 --- a/main/target/cnc/grbl/esp3d_translations_list.h +++ b/main/target/cnc/grbl/esp3d_translations_list.h @@ -70,12 +70,8 @@ enum class ESP3DLabel : uint16_t { motors_disabled, fan_controls, information, - auto_leveling, - manual_leveling_help, - manual_leveling_text, - bed_width, - bed_depth, - auto_bed_probing, + workspace_width, + workspace_depth, start_probing, invert_axis, ui_language, diff --git a/main/target/cnc/grbl/esp3d_values.cpp b/main/target/cnc/grbl/esp3d_values.cpp index 51acb8ff..9eba9db0 100644 --- a/main/target/cnc/grbl/esp3d_values.cpp +++ b/main/target/cnc/grbl/esp3d_values.cpp @@ -25,7 +25,6 @@ #if ESP3D_DISPLAY_FEATURE #include "components/status_bar_component.h" #include "components/wifi_status_component.h" -#include "screens/auto_leveling_screen.h" #include "screens/main_screen.h" #endif // ESP3D_DISPLAY_FEATURE @@ -47,125 +46,44 @@ bool ESP3DValues::intialize() { nullptr, }); - // ext 0 temperature - _values.push_back({ - ESP3DValuesIndex::ext_0_temperature, - ESP3DValuesType::float_t, - 2, // precision - std::string("?"), - mainScreen::extruder_0_value_cb, - }); - - // ext 1 temperature - _values.push_back({ - ESP3DValuesIndex::ext_1_temperature, - ESP3DValuesType::float_t, - 2, // precision - std::string("?"), - mainScreen::extruder_1_value_cb, - }); - - // bed temperature - _values.push_back({ - ESP3DValuesIndex::bed_temperature, - ESP3DValuesType::float_t, - 2, // precision - std::string("?"), - mainScreen::bed_value_cb, - }); + + // // x position + + // _values.push_back({ + // ESP3DValuesIndex::position_x, + // ESP3DValuesType::float_t, + // 4, // precision + // std::string("?"), + // mainScreen::position_value_cb, + // }); + + // // y position + // _values.push_back({ + // ESP3DValuesIndex::position_y, + // ESP3DValuesType::float_t, + // 4, // precision + // std::string("?"), + // mainScreen::position_value_cb, + // }); + + // // z position + // _values.push_back({ + // ESP3DValuesIndex::position_z, + // ESP3DValuesType::float_t, + // 4, // precision + // std::string("?"), + // mainScreen::position_value_cb, + // }); + + // // a position + // _values.push_back({ + // ESP3DValuesIndex::position_a, + // ESP3DValuesType::float_t, + // 4, // precision + // std::string("?"), + // mainScreen::position_value_cb, + // }); - // ext 0 target temperature - _values.push_back({ - ESP3DValuesIndex::ext_0_target_temperature, - ESP3DValuesType::float_t, - 2, // precision - std::string("0"), - mainScreen::extruder_0_value_cb, - }); - - // ext 1 target temperature - _values.push_back({ - ESP3DValuesIndex::ext_1_target_temperature, - ESP3DValuesType::float_t, - 2, // precision - std::string("0"), - mainScreen::extruder_1_value_cb, - }); - - // bed target temperature - _values.push_back({ - ESP3DValuesIndex::bed_target_temperature, - ESP3DValuesType::float_t, - 2, // precision - std::string("0"), - mainScreen::bed_value_cb, - }); - - // ext 0 fan - _values.push_back({ - ESP3DValuesIndex::ext_0_fan, - ESP3DValuesType::integer_t, - 0, // precision - std::string("0"), - mainScreen::fan_value_cb, - }); - - // ext 1 fan - _values.push_back({ - ESP3DValuesIndex::ext_1_fan, - ESP3DValuesType::integer_t, - 0, // precision - std::string("0"), - mainScreen::fan_value_cb, - }); - - // - _values.push_back({ - ESP3DValuesIndex::speed, - ESP3DValuesType::integer_t, - 0, // precision - std::string("100"), - mainScreen::speed_value_cb, - }); - - // x position - - _values.push_back({ - ESP3DValuesIndex::position_x, - ESP3DValuesType::float_t, - 2, // precision - std::string("?"), - mainScreen::position_value_cb, - }); - - // y position - _values.push_back({ - ESP3DValuesIndex::position_y, - ESP3DValuesType::float_t, - 2, // precision - std::string("?"), - mainScreen::position_value_cb, - }); - - // z position - - _values.push_back({ - ESP3DValuesIndex::position_z, - ESP3DValuesType::float_t, - 2, // precision - std::string("?"), - mainScreen::position_value_cb, - }); - - // bed leveling - - _values.push_back({ - ESP3DValuesIndex::bed_leveling, - ESP3DValuesType::string_t, - 100, // precision - std::string("?"), - autoLevelingScreen::auto_leveling_value_cb, - }); // print status _values.push_back({ diff --git a/main/target/cnc/grbl/esp3d_values_list.h b/main/target/cnc/grbl/esp3d_values_list.h index 74e5eaef..a4ccdeeb 100644 --- a/main/target/cnc/grbl/esp3d_values_list.h +++ b/main/target/cnc/grbl/esp3d_values_list.h @@ -41,24 +41,15 @@ extern "C" { enum class ESP3DValuesIndex : uint16_t { status_bar_label, current_ip, - ext_0_temperature, - ext_1_temperature, - bed_temperature, - ext_0_target_temperature, - ext_1_target_temperature, - bed_target_temperature, - ext_0_fan, - ext_1_fan, - speed, position_x, position_y, position_z, + position_a, job_status, file_path, file_name, network_status, network_mode, - bed_leveling, job_progress, job_duration, job_id,