Skip to content

Commit

Permalink
Allow setting absolute xyz pos
Browse files Browse the repository at this point in the history
  • Loading branch information
suchmememanyskill committed Mar 24, 2024
1 parent a9a732d commit ea8a6b5
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 8 deletions.
42 changes: 41 additions & 1 deletion CYD-Klipper/src/ui/panels/move_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,45 @@ static void switch_to_stat_panel(lv_event_t * e) {
nav_buttons_setup(PANEL_STATS);
}

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);
}

static void x_line_custom_callback(lv_event_t * e) {
const char * text = lv_textarea_get_text(lv_event_get_target(e));
line_custom_set("X", text);
}

static void y_line_custom_callback(lv_event_t * e) {
const char * text = lv_textarea_get_text(lv_event_get_target(e));
line_custom_set("Y", text);
}

static void z_line_custom_callback(lv_event_t * e) {
const char * text = lv_textarea_get_text(lv_event_get_target(e));
line_custom_set("Z", text);
}

static void x_line_custom(lv_event_t * e) {
lv_create_keyboard_text_entry(x_line_custom_callback, "Set X position", LV_KEYBOARD_MODE_NUMBER, CYD_SCREEN_PANEL_WIDTH_PX / 2, 6);
}

static void y_line_custom(lv_event_t * e) {
lv_create_keyboard_text_entry(y_line_custom_callback, "Set Y position", LV_KEYBOARD_MODE_NUMBER, CYD_SCREEN_PANEL_WIDTH_PX / 2, 6);
}

static void z_line_custom(lv_event_t * e) {
lv_create_keyboard_text_entry(z_line_custom_callback, "Set Z position", LV_KEYBOARD_MODE_NUMBER, CYD_SCREEN_PANEL_WIDTH_PX / 2, 6);
}

lv_event_cb_t custom_callbacks[] = {x_line_custom, y_line_custom, z_line_custom};

inline void root_panel_steppers_locked(lv_obj_t * root_panel){
const auto width = CYD_SCREEN_PANEL_WIDTH_PX - CYD_SCREEN_GAP_PX * 2;

Expand Down Expand Up @@ -128,7 +167,8 @@ inline void root_panel_steppers_locked(lv_obj_t * root_panel){
lv_obj_center(label);

for (int row = 0; row < 3; row++) {
label = lv_label_create(panel);
label = lv_label_btn_create(panel, custom_callbacks[row]);
lv_obj_align(label, LV_ALIGN_CENTER, 0, 0);
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);
Expand Down
2 changes: 1 addition & 1 deletion CYD-Klipper/src/ui/panels/printer_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ static void btn_printer_secondary(lv_event_t * e)
static void btn_printer_rename(lv_event_t * e)
{
keyboard_config = (PRINTER_CONFIG*)lv_event_get_user_data(e);
lv_create_keyboard_text_entry(keyboard_callback, LV_KEYBOARD_MODE_TEXT_LOWER, CYD_SCREEN_WIDTH_PX * 0.75, 24, keyboard_config->printer_name, false);
lv_create_keyboard_text_entry(keyboard_callback, "Rename Printer", LV_KEYBOARD_MODE_TEXT_LOWER, CYD_SCREEN_WIDTH_PX * 0.75, 24, keyboard_config->printer_name, false);
}

static void btn_printer_activate(lv_event_t * e)
Expand Down
6 changes: 3 additions & 3 deletions CYD-Klipper/src/ui/panels/temp_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,12 @@ static void keyboard_callback(lv_event_t * e){

static void show_keyboard_with_hotend(lv_event_t * e){
keyboard_target = TARGET_HOTEND;
lv_create_keyboard_text_entry(keyboard_callback);
lv_create_keyboard_text_entry(keyboard_callback, "Set Hotend Temp");
}

static void show_keyboard_with_bed(lv_event_t * e){
keyboard_target = TARGET_BED;
lv_create_keyboard_text_entry(keyboard_callback);
lv_create_keyboard_text_entry(keyboard_callback, "Set Bed Temp");
}

static void cooldown_temp(lv_event_t * e){
Expand All @@ -149,7 +149,7 @@ static void set_temp_via_preset(lv_event_t * e){

if (edit_mode) {
keyboard_target = (temp_target)target;
lv_create_keyboard_text_entry(keyboard_callback);
lv_create_keyboard_text_entry(keyboard_callback, "Set Preset Temp");
return;
}

Expand Down
26 changes: 25 additions & 1 deletion CYD-Klipper/src/ui/ui_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ lv_obj_t* lv_create_empty_panel(lv_obj_t* root) {
lv_obj_set_style_border_width(panel, 0, 0);
lv_obj_set_style_bg_opa(panel, LV_OPA_TRANSP, 0);
lv_obj_set_style_pad_all(panel, 0, 0);
lv_obj_set_style_radius(panel, 0, 0);
return panel;
}

Expand Down Expand Up @@ -100,7 +101,7 @@ void lv_keyboard_text_entry_close(lv_event_t * e){
}
}

void lv_create_keyboard_text_entry(lv_event_cb_t keyboard_callback, lv_keyboard_mode_t keyboard_mode, lv_coord_t width, uint8_t max_length, const char* fill_text, bool contain_in_panel)
void lv_create_keyboard_text_entry(lv_event_cb_t keyboard_callback, const char* title, lv_keyboard_mode_t keyboard_mode, lv_coord_t width, uint8_t max_length, const char* fill_text, bool contain_in_panel)
{
lv_obj_t * parent = lv_create_empty_panel(lv_scr_act());
lv_obj_set_style_bg_opa(parent, LV_OPA_50, 0);
Expand All @@ -116,6 +117,19 @@ void lv_create_keyboard_text_entry(lv_event_cb_t keyboard_callback, lv_keyboard_
lv_obj_set_size(parent, CYD_SCREEN_WIDTH_PX, CYD_SCREEN_HEIGHT_PX);
}

if (title != nullptr)
{
lv_obj_t * empty_panel = lv_create_empty_panel(parent);
lv_obj_set_size(empty_panel, 0, 0);

lv_obj_t * title_container = lv_obj_create(parent);
lv_obj_set_style_pad_all(title_container, CYD_SCREEN_GAP_PX / 2, 0);
lv_obj_set_size(title_container, LV_SIZE_CONTENT, LV_SIZE_CONTENT);

lv_obj_t * title_label = lv_label_create(title_container);
lv_label_set_text(title_label, title);
}

lv_obj_t * empty_panel = lv_create_empty_panel(parent);
lv_obj_set_flex_grow(empty_panel, 1);

Expand Down Expand Up @@ -247,4 +261,14 @@ void lv_create_popup_message(const char* message, uint16_t timeout_ms)
lv_label_set_long_mode(label, LV_LABEL_LONG_WRAP);

timer = lv_timer_create(timer_callback, timeout_ms, panel);
}

lv_obj_t * lv_label_btn_create(lv_obj_t * parent, lv_event_cb_t btn_callback, void* user_data)
{
lv_obj_t * panel = lv_create_empty_panel(parent);
lv_obj_set_size(panel, LV_SIZE_CONTENT, LV_SIZE_CONTENT);
lv_obj_add_event_cb(panel, btn_callback, LV_EVENT_CLICKED, user_data);

lv_obj_t * label = lv_label_create(panel);
return label;
}
5 changes: 3 additions & 2 deletions CYD-Klipper/src/ui/ui_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ void lv_layout_flex_column(lv_obj_t* obj, lv_flex_align_t allign = LV_FLEX_ALIGN
void lv_layout_flex_row(lv_obj_t* obj, lv_flex_align_t allign = LV_FLEX_ALIGN_START, lv_coord_t pad_column = CYD_SCREEN_GAP_PX, lv_coord_t pad_row = CYD_SCREEN_GAP_PX);
void lv_create_fullscreen_button_matrix_popup(lv_obj_t * root, lv_event_cb_t title, lv_button_column_t* columns, int column_count);
void destroy_event_user_data(lv_event_t * e);
void lv_create_keyboard_text_entry(lv_event_cb_t keyboard_callback, lv_keyboard_mode_t keyboard_mode = LV_KEYBOARD_MODE_NUMBER, lv_coord_t width = CYD_SCREEN_PANEL_WIDTH_PX / 2, uint8_t max_length = 3, const char* fill_text = "", bool contain_in_panel= true);
void lv_create_keyboard_text_entry(lv_event_cb_t keyboard_callback, const char* title = NULL, lv_keyboard_mode_t keyboard_mode = LV_KEYBOARD_MODE_NUMBER, lv_coord_t width = CYD_SCREEN_PANEL_WIDTH_PX / 2, uint8_t max_length = 3, const char* fill_text = "", bool contain_in_panel= true);
void lv_create_custom_menu_entry(const char* label_text, lv_obj_t* object, lv_obj_t* root_panel, bool set_height = true);
void lv_create_custom_menu_button(const char *label_text, lv_obj_t* root_panel, lv_event_cb_t on_click, const char *btn_text, void * user_data = NULL);
void lv_create_custom_menu_switch(const char *label_text, lv_obj_t* root_panel, lv_event_cb_t on_toggle, bool state, void * user_data = NULL);
void lv_create_custom_menu_dropdown(const char *label_text, lv_obj_t *root_panel, lv_event_cb_t on_change, const char *options, int index, void * user_data = NULL);
void lv_create_custom_menu_label(const char *label_text, lv_obj_t* root_panel, const char *text);
void lv_create_popup_message(const char* message, uint16_t timeout_ms);
void lv_create_popup_message(const char* message, uint16_t timeout_ms);
lv_obj_t * lv_label_btn_create(lv_obj_t * parent, lv_event_cb_t btn_callback, void* user_data = NULL);

0 comments on commit ea8a6b5

Please sign in to comment.