diff --git a/CYD-Klipper/src/core/macros_query.cpp b/CYD-Klipper/src/core/macros_query.cpp index 9acb12e..2ed0c0c 100644 --- a/CYD-Klipper/src/core/macros_query.cpp +++ b/CYD-Klipper/src/core/macros_query.cpp @@ -42,10 +42,11 @@ static void _macros_query_internal(){ } } -static void _power_devices_query_internal(){ +void _power_devices_query_internal(){ String url = "http://" + String(global_config.klipperHost) + ":" + String(global_config.klipperPort) + "/machine/device_power/devices"; HTTPClient client; client.useHTTP10(true); + client.setTimeout(500); client.begin(url.c_str()); int httpCode = client.GET(); if (httpCode == 200){ diff --git a/CYD-Klipper/src/core/macros_query.h b/CYD-Klipper/src/core/macros_query.h index 954350e..6d58c25 100644 --- a/CYD-Klipper/src/core/macros_query.h +++ b/CYD-Klipper/src/core/macros_query.h @@ -14,4 +14,5 @@ typedef struct { MACROSQUERY macros_query(); POWERQUERY power_devices_query(); void macros_query_setup(); -bool set_power_state(const char* device_name, bool state); \ No newline at end of file +bool set_power_state(const char* device_name, bool state); +void _power_devices_query_internal(); \ No newline at end of file diff --git a/CYD-Klipper/src/ui/ip_setup.cpp b/CYD-Klipper/src/ui/ip_setup.cpp index ffa236e..8763cef 100644 --- a/CYD-Klipper/src/ui/ip_setup.cpp +++ b/CYD-Klipper/src/ui/ip_setup.cpp @@ -5,6 +5,8 @@ #include #include "core/data_setup.h" #include "ui_utils.h" +#include "../core/macros_query.h" +#include "panels/panel.h" bool connect_ok = false; lv_obj_t * ipEntry; @@ -70,25 +72,63 @@ static void reset_btn_event_handler(lv_event_t * e){ } } -void ip_init_inner(){ +static void power_devices_button(lv_event_t * e) { + lv_obj_t * panel = lv_create_empty_panel(lv_scr_act()); + lv_obj_set_style_bg_opa(panel, LV_OPA_COVER, 0); + lv_layout_flex_column(panel); + lv_obj_set_size(panel, CYD_SCREEN_WIDTH_PX, CYD_SCREEN_HEIGHT_PX - CYD_SCREEN_GAP_PX); + lv_obj_align(panel, LV_ALIGN_TOP_LEFT, 0, CYD_SCREEN_GAP_PX); + + lv_obj_t * button = lv_btn_create(panel); + lv_obj_set_size(button, CYD_SCREEN_WIDTH_PX - CYD_SCREEN_GAP_PX * 2, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); + lv_obj_add_event_cb(button, destroy_event_user_data, LV_EVENT_CLICKED, panel); + + lv_obj_t * label = lv_label_create(button); + lv_label_set_text(label, LV_SYMBOL_CLOSE " Close"); + lv_obj_center(label); + + macros_panel_add_power_devices_to_panel(panel, power_devices_query()); +} + +void redraw_connect_screen(){ lv_obj_clean(lv_scr_act()); + label = lv_label_create(lv_scr_act()); + lv_label_set_text(label, "Connecting to Klipper"); + lv_obj_align(label, LV_ALIGN_CENTER, 0, 0); + + lv_obj_t * button_row = lv_create_empty_panel(lv_scr_act()); + lv_obj_set_size(button_row, CYD_SCREEN_WIDTH_PX, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); + lv_layout_flex_row(button_row, LV_FLEX_ALIGN_CENTER); + lv_obj_align(button_row, LV_ALIGN_CENTER, 0, CYD_SCREEN_GAP_PX + CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); + + lv_obj_t * reset_btn = lv_btn_create(button_row); + lv_obj_add_event_cb(reset_btn, reset_btn_event_handler, LV_EVENT_CLICKED, NULL); + lv_obj_set_height(reset_btn, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); + + lv_obj_t * btn_label = lv_label_create(reset_btn); + lv_label_set_text(btn_label, "Reset"); + lv_obj_center(btn_label); + + if (power_devices_query().count >= 1){ + lv_obj_t * power_devices_btn = lv_btn_create(button_row); + lv_obj_add_event_cb(power_devices_btn, power_devices_button, LV_EVENT_CLICKED, NULL); + lv_obj_set_height(power_devices_btn, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); + + btn_label = lv_label_create(power_devices_btn); + lv_label_set_text(btn_label, "Power Devices"); + lv_obj_center(btn_label); + } +} + +void ip_init_inner(){ if (global_config.ipConfigured) { - label = lv_label_create(lv_scr_act()); - lv_label_set_text(label, "Connecting to Klipper"); - lv_obj_align(label, LV_ALIGN_CENTER, 0, 0); - - lv_obj_t * resetBtn = lv_btn_create(lv_scr_act()); - lv_obj_add_event_cb(resetBtn, reset_btn_event_handler, LV_EVENT_ALL, NULL); - lv_obj_set_height(resetBtn, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); - lv_obj_align(resetBtn, LV_ALIGN_CENTER, 0, CYD_SCREEN_GAP_PX + CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); - - lv_obj_t * btnLabel = lv_label_create(resetBtn); - lv_label_set_text(btnLabel, "Reset"); - lv_obj_center(btnLabel); + redraw_connect_screen(); return; } + lv_obj_clean(lv_scr_act()); + lv_obj_t * root = lv_create_empty_panel(lv_scr_act()); lv_obj_set_size(root, CYD_SCREEN_WIDTH_PX, CYD_SCREEN_HEIGHT_PX); lv_layout_flex_column(root); @@ -148,6 +188,10 @@ void ip_init(){ retry_count++; String retry_count_text = "Connecting to Klipper (Try " + String(retry_count + 1) + ")"; lv_label_set_text(label, retry_count_text.c_str()); + + _power_devices_query_internal(); + if (power_devices_query().count >= 1) + redraw_connect_screen(); } } } diff --git a/CYD-Klipper/src/ui/main_ui.cpp b/CYD-Klipper/src/ui/main_ui.cpp index a6f1184..19ebeff 100644 --- a/CYD-Klipper/src/ui/main_ui.cpp +++ b/CYD-Klipper/src/ui/main_ui.cpp @@ -20,10 +20,7 @@ static void btn_click_firmware_restart(lv_event_t * e){ send_gcode(false, "FIRMWARE_RESTART"); } -void error_ui_macros_close(lv_event_t * e){ - lv_obj_t * obj = (lv_obj_t *)lv_event_get_user_data(e); - lv_obj_del(obj); -} + void error_ui_macros_open(lv_event_t * e){ lv_obj_t * panel = lv_create_empty_panel(lv_scr_act()); @@ -34,7 +31,7 @@ void error_ui_macros_open(lv_event_t * e){ lv_obj_t * button = lv_btn_create(panel); lv_obj_set_size(button, CYD_SCREEN_WIDTH_PX - CYD_SCREEN_GAP_PX * 2, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); - lv_obj_add_event_cb(button, error_ui_macros_close, LV_EVENT_CLICKED, panel); + lv_obj_add_event_cb(button, destroy_event_user_data, LV_EVENT_CLICKED, panel); lv_obj_t * label = lv_label_create(button); lv_label_set_text(label, LV_SYMBOL_CLOSE " Close"); diff --git a/CYD-Klipper/src/ui/panels/print_panel.cpp b/CYD-Klipper/src/ui/panels/print_panel.cpp index 32837ab..9f8549f 100644 --- a/CYD-Klipper/src/ui/panels/print_panel.cpp +++ b/CYD-Klipper/src/ui/panels/print_panel.cpp @@ -40,11 +40,6 @@ static void btn_print_file(lv_event_t * e){ Serial.printf("Print start: HTTP %d\n", httpCode); } -static void btn_print_back(lv_event_t * e){ - lv_obj_t * panel = (lv_obj_t*)lv_event_get_user_data(e); - lv_obj_del(panel); -} - static void btn_print_file_verify(lv_event_t * e){ const auto button_size_mult = 1.3f; @@ -69,7 +64,7 @@ static void btn_print_file_verify(lv_event_t * e){ btn = lv_btn_create(panel); lv_obj_align(btn, LV_ALIGN_BOTTOM_LEFT, 0, 0); lv_obj_set_size(btn, CYD_SCREEN_MIN_BUTTON_WIDTH_PX * button_size_mult, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX * button_size_mult); - lv_obj_add_event_cb(btn, btn_print_back, LV_EVENT_CLICKED, panel); + lv_obj_add_event_cb(btn, destroy_event_user_data, LV_EVENT_CLICKED, panel); label = lv_label_create(btn); lv_label_set_text(label, LV_SYMBOL_CLOSE); diff --git a/CYD-Klipper/src/ui/ui_utils.cpp b/CYD-Klipper/src/ui/ui_utils.cpp index 26ce3c5..541dfe5 100644 --- a/CYD-Klipper/src/ui/ui_utils.cpp +++ b/CYD-Klipper/src/ui/ui_utils.cpp @@ -26,9 +26,9 @@ void lv_layout_flex_row(lv_obj_t* obj, lv_flex_align_t allign, lv_coord_t pad_co lv_obj_set_style_pad_row(obj, pad_row, 0); } -static void lv_fullscreen_menu_close(lv_event_t * e){ - lv_obj_t * panel = (lv_obj_t*)lv_event_get_user_data(e); - lv_obj_del(panel); +void destroy_event_user_data(lv_event_t * e){ + lv_obj_t * obj = (lv_obj_t *)lv_event_get_user_data(e); + lv_obj_del(obj); } void lv_create_fullscreen_button_matrix_popup(lv_obj_t * root, lv_event_cb_t title, lv_button_column_t* columns, int column_count){ @@ -51,7 +51,7 @@ void lv_create_fullscreen_button_matrix_popup(lv_obj_t * root, lv_event_cb_t tit lv_obj_t * btn = lv_btn_create(top_menu_row); lv_obj_set_size(btn, CYD_SCREEN_MIN_BUTTON_WIDTH_PX, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); lv_obj_align(btn, LV_ALIGN_RIGHT_MID, 0, 0); - lv_obj_add_event_cb(btn, lv_fullscreen_menu_close, LV_EVENT_CLICKED, panel); + lv_obj_add_event_cb(btn, destroy_event_user_data, LV_EVENT_CLICKED, panel); lv_obj_t * label = lv_label_create(btn); lv_label_set_text(label, LV_SYMBOL_CLOSE); diff --git a/CYD-Klipper/src/ui/ui_utils.h b/CYD-Klipper/src/ui/ui_utils.h index 0245c9e..f5e5fe5 100644 --- a/CYD-Klipper/src/ui/ui_utils.h +++ b/CYD-Klipper/src/ui/ui_utils.h @@ -13,4 +13,5 @@ typedef struct { lv_obj_t* lv_create_empty_panel(lv_obj_t* root); void lv_layout_flex_column(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_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); \ No newline at end of file +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); \ No newline at end of file diff --git a/CYD-Klipper/src/ui/wifi_setup.cpp b/CYD-Klipper/src/ui/wifi_setup.cpp index d221933..6bb3556 100644 --- a/CYD-Klipper/src/ui/wifi_setup.cpp +++ b/CYD-Klipper/src/ui/wifi_setup.cpp @@ -97,7 +97,7 @@ void wifi_init_inner(){ lv_obj_align(label, LV_ALIGN_CENTER, 0, 0); lv_obj_t * resetBtn = lv_btn_create(lv_scr_act()); - lv_obj_add_event_cb(resetBtn, reset_btn_event_handler, LV_EVENT_ALL, NULL); + lv_obj_add_event_cb(resetBtn, reset_btn_event_handler, LV_EVENT_CLICKED, NULL); lv_obj_set_height(resetBtn, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); lv_obj_align(resetBtn, LV_ALIGN_CENTER, 0, CYD_SCREEN_GAP_PX + CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); diff --git a/README.md b/README.md index d8a2d77..fae3287 100644 --- a/README.md +++ b/README.md @@ -16,10 +16,12 @@ A ESP32-2432S028R is required to run this project. You can find out where to buy - View printer status - View print progress - Start a print -- Move the printer +- (When the printer is idle) move the printer +- (During a print) set fan speed, flow rate, speed and z offset - Manage temperature - Extrude/Retract filament - Execute predefined gcode macros +- Toggle Moonraker power devices ### Install