diff --git a/CYD-Klipper/src/conf/global_config.cpp b/CYD-Klipper/src/conf/global_config.cpp index d282551..d173fd3 100644 --- a/CYD-Klipper/src/conf/global_config.cpp +++ b/CYD-Klipper/src/conf/global_config.cpp @@ -108,6 +108,16 @@ void load_global_config() global_config.printer_config[0].bed_presets[0] = 0; global_config.printer_config[0].bed_presets[1] = 60; global_config.printer_config[0].bed_presets[2] = 70; + global_config.printer_config[0].printer_move_x_steps[0] = 10; + global_config.printer_config[0].printer_move_x_steps[1] = 100; + global_config.printer_config[0].printer_move_x_steps[2] = 1000; + global_config.printer_config[0].printer_move_y_steps[0] = 10; + global_config.printer_config[0].printer_move_y_steps[1] = 100; + global_config.printer_config[0].printer_move_y_steps[2] = 1000; + global_config.printer_config[0].printer_move_z_steps[0] = 1; + global_config.printer_config[0].printer_move_z_steps[1] = 10; + global_config.printer_config[0].printer_move_z_steps[2] = 100; + verify_version(); Preferences preferences; preferences.begin("global_config", true); diff --git a/CYD-Klipper/src/conf/global_config.h b/CYD-Klipper/src/conf/global_config.h index 8c080f7..77bdf10 100644 --- a/CYD-Klipper/src/conf/global_config.h +++ b/CYD-Klipper/src/conf/global_config.h @@ -3,7 +3,7 @@ #include "lvgl.h" -#define CONFIG_VERSION 5 +#define CONFIG_VERSION 6 #define PRINTER_CONFIG_COUNT 8 enum { @@ -44,6 +44,10 @@ typedef struct _PRINTER_CONFIG { unsigned short hotend_presets[3]; unsigned short bed_presets[3]; + + unsigned short printer_move_x_steps[3]; + unsigned short printer_move_y_steps[3]; + unsigned short printer_move_z_steps[3]; } PRINTER_CONFIG; typedef struct _GLOBAL_CONFIG { @@ -70,8 +74,8 @@ typedef struct _GLOBAL_CONFIG { float screen_cal_y_offset; float screen_cal_y_mult; - char wifi_SSID[32]; - char wifi_password[64]; + char wifi_SSID[33]; + char wifi_password[65]; unsigned char brightness; unsigned char screen_timeout; diff --git a/CYD-Klipper/src/ui/panels/move_panel.cpp b/CYD-Klipper/src/ui/panels/move_panel.cpp index b6db51d..75652ff 100644 --- a/CYD-Klipper/src/ui/panels/move_panel.cpp +++ b/CYD-Klipper/src/ui/panels/move_panel.cpp @@ -4,47 +4,157 @@ #include "../nav_buttons.h" #include "../ui_utils.h" #include +#include static bool last_homing_state = false; +static bool move_edit_mode = false; + +float x_offsets[6] = {0}; +float y_offsets[6] = {0}; +float z_offsets[6] = {0}; + +#define OFFSET_LABEL_SIZE 7 + +char x_offset_labels[6 * OFFSET_LABEL_SIZE] = {0}; +char y_offset_labels[6 * OFFSET_LABEL_SIZE] = {0}; +char z_offset_labels[6 * OFFSET_LABEL_SIZE] = {0}; + +static void calculate_offsets_from_current_printer() +{ + unsigned short* items[] = {get_current_printer_config()->printer_move_x_steps, get_current_printer_config()->printer_move_y_steps, get_current_printer_config()->printer_move_z_steps}; + float* offsets[] = {(float*)x_offsets, (float*)y_offsets, (float*)z_offsets}; + char * labels[] = {(char*)x_offset_labels, (char*)y_offset_labels, (char*)z_offset_labels}; + + for (int i = 0; i < 3; i++) + { + offsets[i][0] = items[i][2] / 10.0f * -1; + offsets[i][1] = items[i][1] / 10.0f * -1; + offsets[i][2] = items[i][0] / 10.0f * -1; + offsets[i][3] = items[i][0] / 10.0f; + offsets[i][4] = items[i][1] / 10.0f; + offsets[i][5] = items[i][2] / 10.0f; + + for (int j = 0; j < 6; j++) { + const char * formats[] = {"%.0f", "%.1f", "+%.0f", "+%.1f"}; + const char ** format = formats; + + if (offsets[i][j] != (int)offsets[i][j]) + { + format += 1; + } + + if (j >= 3) + { + format += 2; + } + + sprintf(labels[i] + OFFSET_LABEL_SIZE * j, *format, offsets[i][j]); + } + } +} + +static int selected_column = 0; +static int selected_row = 0; + +static void keyboard_cb_edit_move_increment(lv_event_t * e) +{ + lv_obj_t * ta = lv_event_get_target(e); + lv_obj_t * kb = (lv_obj_t *)lv_event_get_user_data(e); + const char * text = lv_textarea_get_text(ta); + + float increment = atof(text); + + if (increment < 0) + { + increment *= -1; + } + + if (increment == 0 || increment > 999) + { + return; + } + + unsigned short* items[] = {get_current_printer_config()->printer_move_x_steps, get_current_printer_config()->printer_move_y_steps, get_current_printer_config()->printer_move_z_steps}; + Serial.printf("Setting increment %d %d %f\n", selected_column, selected_row, increment); + items[selected_column][selected_row] = increment * 10; + write_global_config(); + nav_buttons_setup(PANEL_MOVE); +} + +static void edit_move_increment(int column, float* idx) +{ + float* offsets[] = {(float*)x_offsets, (float*)y_offsets, (float*)z_offsets}; + int row = idx - offsets[column]; + + if (row < 3) + { + selected_row = 2 - row; + } + else + { + selected_row = row - 3; + } + + selected_column = column; + lv_create_keyboard_text_entry(keyboard_cb_edit_move_increment, "Set increment", LV_KEYBOARD_MODE_NUMBER, CYD_SCREEN_PANEL_WIDTH_PX / 2, 6); +} static void x_line_button_press(lv_event_t * e) { float* data_pointer = (float*)lv_event_get_user_data(e); + + if (move_edit_mode) + { + edit_move_increment(0, data_pointer); + return; + } + float data = *data_pointer; move_printer("X", data, true); } static void y_line_button_press(lv_event_t * e) { float* data_pointer = (float*)lv_event_get_user_data(e); + + if (move_edit_mode) + { + edit_move_increment(1, data_pointer); + return; + } + float data = *data_pointer; move_printer("Y", data, true); } static void z_line_button_press(lv_event_t * e) { float* data_pointer = (float*)lv_event_get_user_data(e); + + if (move_edit_mode) + { + edit_move_increment(2, data_pointer); + return; + } + float data = *data_pointer; move_printer("Z", data, true); } -char x_pos_buff[12]; - static void x_pos_update(lv_event_t * e){ lv_obj_t * label = lv_event_get_target(e); + char x_pos_buff[12]; sprintf(x_pos_buff, "X: %.1f", printer.position[0]); lv_label_set_text(label, x_pos_buff); } -char y_pos_buff[12]; - static void y_pos_update(lv_event_t * e){ lv_obj_t * label = lv_event_get_target(e); + char y_pos_buff[12]; sprintf(y_pos_buff, "Y: %.1f", printer.position[1]); lv_label_set_text(label, y_pos_buff); } -char z_pos_buff[12]; - static void z_pos_update(lv_event_t * e){ lv_obj_t * label = lv_event_get_target(e); + char z_pos_buff[12]; sprintf(z_pos_buff, "Z: %.2f", printer.position[2]); lv_label_set_text(label, z_pos_buff); } @@ -52,23 +162,6 @@ static void z_pos_update(lv_event_t * e){ lv_event_cb_t button_callbacks[] = {x_line_button_press, y_line_button_press, z_line_button_press}; lv_event_cb_t position_callbacks[] = {x_pos_update, y_pos_update, z_pos_update}; -const float xy_offsets[] = {-100, -10, -1, 1, 10, 100}; -const float z_offsets[] = {-10, -1, -0.1, 0.1, 1, 10}; -const float* offsets[] = { - xy_offsets, - xy_offsets, - z_offsets -}; - -const char* xy_offset_labels[] = {"-100", "-10", "-1", "+1", "+10", "+100"}; -const char* z_offset_labels[] = {"-10", "-1", "-0.1", "+0.1", "+1", "+10"}; - -const char** offset_labels[] = { - xy_offset_labels, - xy_offset_labels, - z_offset_labels -}; - static void home_button_click(lv_event_t * e) { if (printer.state == PRINTER_STATE_PRINTING) return; @@ -88,13 +181,19 @@ static void switch_to_stat_panel(lv_event_t * e) { nav_buttons_setup(PANEL_STATS); } +static void move_edit_toggle(lv_event_t * e) +{ + lv_obj_t * btn = lv_event_get_target(e); + move_edit_mode = lv_obj_get_state(btn) & LV_STATE_CHECKED; +} + static void line_custom_set(const char * axis, const char *text) { float pos = atof(text); if (pos < 0 || pos > 500) return; - // TODO: Move menu goes funky when in light mode + move_printer(axis, pos, false); } @@ -154,7 +253,7 @@ inline void root_panel_steppers_locked(lv_obj_t * root_panel){ lv_obj_set_flex_grow(btn, 1); label = lv_label_create(btn); - lv_label_set_text(label, LV_SYMBOL_EYE_CLOSE " Unlock"); + lv_label_set_text(label, LV_SYMBOL_EYE_CLOSE "Free"); lv_obj_center(label); btn = lv_btn_create(home_button_row); @@ -163,9 +262,26 @@ inline void root_panel_steppers_locked(lv_obj_t * root_panel){ lv_obj_set_flex_grow(btn, 1); label = lv_label_create(btn); - lv_label_set_text(label, LV_SYMBOL_EDIT " Params"); + lv_label_set_text(label, LV_SYMBOL_SETTINGS "Param"); lv_obj_center(label); + btn = lv_btn_create(home_button_row); + lv_obj_set_size(btn, CYD_SCREEN_MIN_BUTTON_WIDTH_PX, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); + lv_obj_add_event_cb(btn, move_edit_toggle, LV_EVENT_CLICKED, NULL); + lv_obj_add_flag(btn, LV_OBJ_FLAG_CHECKABLE); + + if (move_edit_mode) + { + lv_obj_add_state(btn, LV_STATE_CHECKED); + } + + label = lv_label_create(btn); + lv_label_set_text(label, LV_SYMBOL_EDIT); + lv_obj_center(label); + + float* offsets[] = {(float*)x_offsets, (float*)y_offsets, (float*)z_offsets}; + char * labels[] = {(char*)x_offset_labels, (char*)y_offset_labels, (char*)z_offset_labels}; + for (int row = 0; row < 3; row++) { label = lv_label_btn_create(panel, custom_callbacks[row]); lv_obj_align(label, LV_ALIGN_CENTER, 0, 0); @@ -186,7 +302,7 @@ inline void root_panel_steppers_locked(lv_obj_t * root_panel){ lv_obj_set_flex_grow(btn, 1); label = lv_label_create(btn); - lv_label_set_text(label, offset_labels[row][col]); + lv_label_set_text(label, labels[row] + OFFSET_LABEL_SIZE * col); lv_obj_center(label); } } @@ -232,6 +348,7 @@ void move_panel_init(lv_obj_t* panel){ return; } + calculate_offsets_from_current_printer(); last_homing_state = !printer.homed_axis; lv_obj_add_event_cb(panel, root_panel_state_update, LV_EVENT_MSG_RECEIVED, NULL); diff --git a/CYD-Klipper/src/ui/panels/temp_panel.cpp b/CYD-Klipper/src/ui/panels/temp_panel.cpp index 73bb8bf..fc1f57c 100644 --- a/CYD-Klipper/src/ui/panels/temp_panel.cpp +++ b/CYD-Klipper/src/ui/panels/temp_panel.cpp @@ -18,7 +18,7 @@ enum temp_target{ static temp_target keyboard_target; static char hotend_buff[40]; static char bed_buff[40]; -static bool edit_mode = false; +static bool temp_edit_mode = false; lv_obj_t* root_panel; static void update_printer_data_hotend_temp(lv_event_t * e){ @@ -147,7 +147,7 @@ static void set_temp_via_preset(lv_event_t * e){ int target = static_cast(reinterpret_cast(lv_event_get_user_data(e))); int value = get_temp_preset(target); - if (edit_mode) { + if (temp_edit_mode) { keyboard_target = (temp_target)target; lv_create_keyboard_text_entry(keyboard_callback, "Set Preset Temp"); return; @@ -165,7 +165,7 @@ static void set_temp_via_preset(lv_event_t * e){ static void btn_toggleable_edit(lv_event_t * e){ lv_obj_t * btn = lv_event_get_target(e); auto state = lv_obj_get_state(btn); - edit_mode = (state & LV_STATE_CHECKED == LV_STATE_CHECKED); + temp_edit_mode = (state & LV_STATE_CHECKED == LV_STATE_CHECKED); } static void btn_retract(lv_event_t * e){ @@ -301,7 +301,7 @@ void create_temp_buttons(lv_obj_t * root, lv_obj_t * panel) void temp_panel_init(lv_obj_t * panel){ const auto element_width = CYD_SCREEN_PANEL_WIDTH_PX - CYD_SCREEN_GAP_PX * 2; root_panel = panel; - edit_mode = false; + temp_edit_mode = false; lv_obj_t * root_temp_panel = lv_create_empty_panel(panel); lv_obj_set_size(root_temp_panel, CYD_SCREEN_PANEL_WIDTH_PX, CYD_SCREEN_PANEL_HEIGHT_PX);