Make move panel responsive

This commit is contained in:
suchmememanyskill
2024-01-29 20:32:38 +01:00
parent c65cc08eb3
commit 292f879780
3 changed files with 102 additions and 4 deletions

View File

@@ -42,7 +42,7 @@ static void on_state_change(void * s, lv_msg_t * m) {
}
MACROSQUERY macros_query() {
return {(const char**)macros, macros_count};
return {(const char**)macros, (unsigned int)macros_count};
}
void macros_query_setup(){

View File

@@ -72,7 +72,6 @@ static void on_state_change(void * s, lv_msg_t * m){
}
}
void main_ui_setup(){
lv_msg_subscribe(DATA_PRINTER_STATE, on_state_change, NULL);
on_state_change(NULL, NULL);

View File

@@ -2,6 +2,9 @@
#include "panel.h"
#include "../../core/data_setup.h"
#include <TFT_eSPI.h>
#include "../ui_utils.h"
static bool last_homing_state = false;
static void move_printer(const char* axis, float amount) {
if (!printer.homed_axis || printer.state == PRINTER_STATE_PRINTING)
@@ -72,7 +75,7 @@ lv_event_cb_t button_callbacks[] = {x_line_button_press, y_line_button_press, z_
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[] = {-25, -1, -0.1, 0.1, 1, 25};
const float z_offsets[] = {-10, -1, -0.1, 0.1, 1, 10};
const float* offsets[] = {
xy_offsets,
xy_offsets,
@@ -80,7 +83,7 @@ const float* offsets[] = {
};
const char* xy_offset_labels[] = {"-100", "-10", "-1", "+1", "+10", "+100"};
const char* z_offset_labels[] = {"-25", "-1", "-0.1", "+0.1", "+1", "+25"};
const char* z_offset_labels[] = {"-10", "-1", "-0.1", "+0.1", "+1", "+10"};
const char** offset_labels[] = {
xy_offset_labels,
@@ -107,7 +110,103 @@ static void stepper_state_update(lv_event_t * e){
lv_label_set_text(label, printer.homed_axis ? LV_SYMBOL_HOME " Steppers locked" : LV_SYMBOL_EYE_CLOSE " Steppers unlocked");
}
inline void root_panel_steppers_locked(lv_obj_t * root_panel){
const auto width = CYD_SCREEN_PANEL_WIDTH_PX - CYD_SCREEN_BIG_GAP_PX * 2;
lv_obj_t * panel = lv_create_empty_panel(root_panel);
lv_obj_set_size(panel, CYD_SCREEN_PANEL_WIDTH_PX, CYD_SCREEN_HEIGHT_PX);
lv_obj_set_style_pad_all(panel, CYD_SCREEN_BIG_GAP_PX, 0);
lv_layout_flex_column(panel, LV_FLEX_ALIGN_SPACE_BETWEEN, 0, 0);
lv_obj_t * home_button_row = lv_create_empty_panel(panel);
lv_obj_set_size(home_button_row, width, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX);
lv_layout_flex_row(home_button_row);
lv_obj_t * btn = lv_btn_create(home_button_row);
lv_obj_set_height(btn, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX);
lv_obj_add_event_cb(btn, home_button_click, LV_EVENT_CLICKED, NULL);
lv_obj_set_flex_grow(btn, 1);
lv_obj_t * label = lv_label_create(btn);
lv_label_set_text(label, LV_SYMBOL_HOME "Home Axis");
lv_obj_center(label);
btn = lv_btn_create(home_button_row);
lv_obj_set_height(btn, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX);
lv_obj_add_event_cb(btn, disable_steppers_click, LV_EVENT_CLICKED, NULL);
lv_obj_set_flex_grow(btn, 1);
label = lv_label_create(btn);
lv_label_set_text(label, LV_SYMBOL_EYE_CLOSE " Disable Step");
lv_obj_center(label);
for (int row = 0; row < 3; row++) {
label = lv_label_create(panel);
lv_label_set_text(label, "???");
lv_obj_set_width(label, width);
lv_obj_add_event_cb(label, position_callbacks[row], LV_EVENT_MSG_RECEIVED, NULL);
lv_msg_subsribe_obj(DATA_PRINTER_DATA, label, NULL);
lv_obj_t * row_panel = lv_create_empty_panel(panel);
lv_obj_set_size(row_panel, width, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX);
lv_layout_flex_row(row_panel);
for (int col = 0; col < 6; col++)
{
btn = lv_btn_create(row_panel);
lv_obj_set_height(btn, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX);
lv_obj_add_event_cb(btn, button_callbacks[row], LV_EVENT_CLICKED, (void*)(offsets[row] + col));
lv_obj_set_flex_grow(btn, 1);
label = lv_label_create(btn);
lv_label_set_text(label, offset_labels[row][col]);
lv_obj_center(label);
}
}
}
inline void root_panel_steppers_unlocked(lv_obj_t * root_panel){
lv_obj_t * panel = lv_create_empty_panel(root_panel);
lv_obj_set_size(panel, CYD_SCREEN_PANEL_WIDTH_PX, CYD_SCREEN_HEIGHT_PX);
lv_obj_set_style_pad_all(panel, CYD_SCREEN_BIG_GAP_PX, 0);
lv_layout_flex_column(panel, LV_FLEX_ALIGN_CENTER);
lv_obj_t * label = lv_label_create(panel);
lv_label_set_text(label, LV_SYMBOL_EYE_CLOSE " Steppers unlocked");
lv_obj_t * btn = lv_btn_create(panel);
lv_obj_set_height(btn, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX);
lv_obj_add_event_cb(btn, home_button_click, LV_EVENT_CLICKED, NULL);
label = lv_label_create(btn);
lv_label_set_text(label, LV_SYMBOL_HOME "Home Axis");
lv_obj_center(label);
}
static void root_panel_state_update(lv_event_t * e){
if (last_homing_state == printer.homed_axis)
return;
lv_obj_t * panel = lv_event_get_target(e);
last_homing_state = printer.homed_axis;
lv_obj_clean(panel);
if (printer.homed_axis)
root_panel_steppers_locked(panel);
else
root_panel_steppers_unlocked(panel);
}
void move_panel_init(lv_obj_t* panel){
last_homing_state = !printer.homed_axis;
lv_obj_add_event_cb(panel, root_panel_state_update, LV_EVENT_MSG_RECEIVED, NULL);
lv_msg_subsribe_obj(DATA_PRINTER_DATA, panel, NULL);
return;
lv_obj_clear_flag(panel, LV_OBJ_FLAG_SCROLLABLE);
const int button_size = 40;
const int button_size_vertical = 40;