mirror of
https://github.com/suchmememanyskill/CYD-Klipper.git
synced 2026-03-21 13:43:25 +00:00
Add more settings, fix time button estimate
This commit is contained in:
@@ -1,13 +1,22 @@
|
||||
#include "main_ui.h"
|
||||
#include "../core/data_setup.h"
|
||||
#include "../conf/global_config.h"
|
||||
#include "../core/screen_driver.h"
|
||||
#include "lvgl.h"
|
||||
#include "nav_buttons.h"
|
||||
#include <ArduinoJson.h>
|
||||
|
||||
char extruder_temp_buff[20];
|
||||
char bed_temp_buff[20];
|
||||
char position_buff[20];
|
||||
|
||||
static void btn_click_restart(lv_event_t * e){
|
||||
send_gcode(false, "RESTART");
|
||||
}
|
||||
|
||||
static void btn_click_firmware_restart(lv_event_t * e){
|
||||
send_gcode(false, "FIRMWARE_RESTART");
|
||||
}
|
||||
|
||||
void error_ui(){
|
||||
lv_obj_clean(lv_scr_act());
|
||||
|
||||
@@ -22,9 +31,39 @@ void error_ui(){
|
||||
lv_obj_set_size(label, TFT_HEIGHT - 20, TFT_WIDTH - 30);
|
||||
lv_obj_clear_flag(label, LV_OBJ_FLAG_SCROLLABLE);
|
||||
lv_label_set_long_mode(label, LV_LABEL_LONG_WRAP);
|
||||
|
||||
lv_obj_t * btn = lv_btn_create(lv_scr_act());
|
||||
lv_obj_align(btn, LV_ALIGN_BOTTOM_LEFT, 10, -10);
|
||||
lv_obj_set_size(btn, TFT_HEIGHT / 2 - 15, 30);
|
||||
lv_obj_add_event_cb(btn, btn_click_restart, LV_EVENT_CLICKED, NULL);
|
||||
|
||||
label = lv_label_create(btn);
|
||||
lv_label_set_text(label, "Restart");
|
||||
lv_obj_center(label);
|
||||
|
||||
btn = lv_btn_create(lv_scr_act());
|
||||
lv_obj_align(btn, LV_ALIGN_BOTTOM_RIGHT, -10, -10);
|
||||
lv_obj_set_size(btn, TFT_HEIGHT / 2 - 15, 30);
|
||||
lv_obj_add_event_cb(btn, btn_click_firmware_restart, LV_EVENT_CLICKED, NULL);
|
||||
|
||||
label = lv_label_create(btn);
|
||||
lv_label_set_text(label, "Firmware Restart");
|
||||
lv_obj_center(label);
|
||||
}
|
||||
|
||||
void check_if_screen_needs_to_be_disabled(){
|
||||
if (global_config.onDuringPrint && printer.state == PRINTER_STATE_PRINTING){
|
||||
screen_timer_wake();
|
||||
screen_timer_stop();
|
||||
}
|
||||
else {
|
||||
screen_timer_start();
|
||||
}
|
||||
}
|
||||
|
||||
static void on_state_change(void * s, lv_msg_t * m){
|
||||
check_if_screen_needs_to_be_disabled();
|
||||
|
||||
if (printer.state == PRINTER_STATE_ERROR){
|
||||
error_ui();
|
||||
}
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
void main_ui_setup();
|
||||
void main_ui_setup();
|
||||
void check_if_screen_needs_to_be_disabled();
|
||||
@@ -97,7 +97,7 @@ void nav_buttons_setup(unsigned char active_panel){
|
||||
lv_obj_align(label, LV_ALIGN_CENTER, 0, icon_text_spacing);
|
||||
lv_obj_add_style(label, &nav_button_text_style, 0);
|
||||
lv_obj_add_event_cb(label, update_printer_data_time, LV_EVENT_MSG_RECEIVED, NULL);
|
||||
lv_msg_subsribe_obj(DATA_PRINTER_STATE, label, NULL);
|
||||
lv_msg_subsribe_obj(DATA_PRINTER_DATA, label, NULL);
|
||||
|
||||
// Move
|
||||
btn = lv_btn_create(lv_scr_act());
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "lvgl.h"
|
||||
|
||||
#define SIZEOF(arr) (sizeof(arr) / sizeof(*arr))
|
||||
|
||||
void settings_panel_init(lv_obj_t* panel);
|
||||
void temp_panel_init(lv_obj_t* panel);
|
||||
void print_panel_init(lv_obj_t* panel);
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include "panel.h"
|
||||
#include "../../core/screen_driver.h"
|
||||
#include "../../conf/global_config.h"
|
||||
#include "../main_ui.h"
|
||||
|
||||
static void invert_color_switch(lv_event_t * e){
|
||||
auto state = lv_obj_get_state(lv_event_get_target(e));
|
||||
@@ -36,64 +37,164 @@ static void theme_dropdown(lv_event_t * e){
|
||||
lv_obj_t * dropdown = lv_event_get_target(e);
|
||||
auto selected = lv_dropdown_get_selected(dropdown);
|
||||
global_config.color_scheme = selected;
|
||||
WriteGlobalConfig();
|
||||
set_color_scheme();
|
||||
WriteGlobalConfig();
|
||||
}
|
||||
|
||||
const char* brightness_options = "100%\n75%\n50%\n25%";
|
||||
const char brightness_options_values[] = { 255, 192, 128, 64 };
|
||||
|
||||
static void brightness_dropdown(lv_event_t * e){
|
||||
lv_obj_t * dropdown = lv_event_get_target(e);
|
||||
auto selected = lv_dropdown_get_selected(dropdown);
|
||||
global_config.brightness = brightness_options_values[selected];
|
||||
set_screen_brightness();
|
||||
WriteGlobalConfig();
|
||||
}
|
||||
|
||||
const char* wake_timeout_options = "1m\n2m\n5m\n10m\n15m\n30m\n1h\n2h\n4h";
|
||||
const char wake_timeout_options_values[] = { 1, 2, 5, 10, 15, 30, 60, 120, 240 };
|
||||
|
||||
static void wake_timeout_dropdown(lv_event_t * e){
|
||||
lv_obj_t * dropdown = lv_event_get_target(e);
|
||||
auto selected = lv_dropdown_get_selected(dropdown);
|
||||
global_config.screenTimeout = wake_timeout_options_values[selected];
|
||||
set_screen_timer_period();
|
||||
WriteGlobalConfig();
|
||||
}
|
||||
|
||||
static void rotate_screen_switch(lv_event_t* e){
|
||||
auto state = lv_obj_get_state(lv_event_get_target(e));
|
||||
bool checked = (state & LV_STATE_CHECKED == LV_STATE_CHECKED);
|
||||
global_config.rotateScreen = checked;
|
||||
global_config.screenCalibrated = false;
|
||||
WriteGlobalConfig();
|
||||
ESP.restart();
|
||||
}
|
||||
|
||||
static void on_during_print_switch(lv_event_t* e){
|
||||
auto state = lv_obj_get_state(lv_event_get_target(e));
|
||||
bool checked = (state & LV_STATE_CHECKED == LV_STATE_CHECKED);
|
||||
global_config.onDuringPrint = checked;
|
||||
check_if_screen_needs_to_be_disabled();
|
||||
WriteGlobalConfig();
|
||||
}
|
||||
|
||||
int y_offset = 0;
|
||||
const int y_element_size = 50;
|
||||
const int y_seperator_size = 1;
|
||||
const int y_seperator_x_padding = 50;
|
||||
const int panel_width = TFT_HEIGHT - 40;
|
||||
const int y_element_x_padding = 30;
|
||||
const static lv_point_t line_points[] = { {0, 0}, {panel_width - y_seperator_x_padding, 0} };
|
||||
|
||||
void create_settings_widget(const char* label_text, lv_obj_t* object, lv_obj_t* root_panel){
|
||||
lv_obj_t * panel = lv_obj_create(root_panel);
|
||||
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_align(panel, LV_ALIGN_TOP_MID, 0, y_offset);
|
||||
lv_obj_set_size(panel, panel_width - y_element_x_padding, y_element_size);
|
||||
|
||||
lv_obj_t * line = lv_line_create(panel);
|
||||
lv_line_set_points(line, line_points, 2);
|
||||
lv_obj_set_style_line_width(line, y_seperator_size, 0);
|
||||
lv_obj_set_style_line_color(line, lv_color_hex(0xAAAAAA), 0);
|
||||
lv_obj_align(line, LV_ALIGN_BOTTOM_MID, 0, 0);
|
||||
|
||||
lv_obj_t * label = lv_label_create(panel);
|
||||
lv_label_set_text(label, label_text);
|
||||
lv_obj_align(label, LV_ALIGN_LEFT_MID, 0, 0);
|
||||
|
||||
lv_obj_set_parent(object, panel);
|
||||
lv_obj_align(object, LV_ALIGN_RIGHT_MID, 0, 0);
|
||||
y_offset += y_element_size;
|
||||
}
|
||||
|
||||
void settings_panel_init(lv_obj_t* panel){
|
||||
auto panel_width = TFT_HEIGHT - 40;
|
||||
y_offset = 0;
|
||||
|
||||
lv_obj_t * btn = lv_btn_create(panel);
|
||||
lv_obj_align(btn, LV_ALIGN_TOP_LEFT, 10, 5);
|
||||
lv_obj_add_event_cb(btn, reset_wifi_click, LV_EVENT_CLICKED, NULL);
|
||||
lv_obj_set_size(btn, panel_width / 2 - 15, 30);
|
||||
|
||||
lv_obj_t * label = lv_label_create(btn);
|
||||
lv_label_set_text(label, "WiFi Setup");
|
||||
lv_label_set_text(label, "Restart");
|
||||
lv_obj_center(label);
|
||||
|
||||
create_settings_widget("Configure WiFi", btn, panel);
|
||||
|
||||
btn = lv_btn_create(panel);
|
||||
lv_obj_align(btn, LV_ALIGN_TOP_RIGHT, -10, 5);
|
||||
lv_obj_add_event_cb(btn, reset_calibration_click, LV_EVENT_CLICKED, NULL);
|
||||
lv_obj_set_size(btn, panel_width / 2 - 15, 30);
|
||||
|
||||
label = lv_label_create(btn);
|
||||
lv_label_set_text(label, "Touch Cal");
|
||||
lv_label_set_text(label, "Restart");
|
||||
lv_obj_center(label);
|
||||
|
||||
create_settings_widget("Calibrate Touch", btn, panel);
|
||||
|
||||
lv_obj_t * toggle = lv_switch_create(panel);
|
||||
lv_obj_align(toggle, LV_ALIGN_TOP_RIGHT, -14, 57);
|
||||
lv_obj_add_event_cb(toggle, invert_color_switch, LV_EVENT_VALUE_CHANGED, NULL);
|
||||
|
||||
if (global_config.invertColors)
|
||||
lv_obj_add_state(toggle, LV_STATE_CHECKED);
|
||||
|
||||
label = lv_label_create(panel);
|
||||
lv_label_set_text(label, "Invert Colors");
|
||||
lv_obj_align(label, LV_ALIGN_TOP_RIGHT, -10, 40);
|
||||
lv_obj_set_style_text_font(label, &lv_font_montserrat_10, 0);
|
||||
create_settings_widget("Invert Colors", toggle, panel);
|
||||
|
||||
|
||||
toggle = lv_switch_create(panel);
|
||||
lv_obj_align(toggle, LV_ALIGN_TOP_LEFT, 13, 57);
|
||||
lv_obj_add_event_cb(toggle, light_mode_switch, LV_EVENT_VALUE_CHANGED, NULL);
|
||||
|
||||
if (global_config.lightMode)
|
||||
lv_obj_add_state(toggle, LV_STATE_CHECKED);
|
||||
|
||||
label = lv_label_create(panel);
|
||||
lv_label_set_text(label, "Light Mode");
|
||||
lv_obj_align(label, LV_ALIGN_TOP_LEFT, 10, 40);
|
||||
lv_obj_set_style_text_font(label, &lv_font_montserrat_10, 0);
|
||||
create_settings_widget("Light Mode", toggle, panel);
|
||||
|
||||
lv_obj_t * dropdown = lv_dropdown_create(panel);
|
||||
lv_dropdown_set_options(dropdown, "Blue\nGreen\nGrey\nYellow\nOrange\nRed\nPurple");
|
||||
lv_dropdown_set_selected(dropdown, global_config.color_scheme);
|
||||
lv_obj_align(dropdown, LV_ALIGN_TOP_MID, 0, 55);
|
||||
lv_obj_add_event_cb(dropdown, theme_dropdown, LV_EVENT_VALUE_CHANGED, NULL);
|
||||
|
||||
label = lv_label_create(panel);
|
||||
lv_label_set_text(label, "Theme");
|
||||
lv_obj_align(label, LV_ALIGN_TOP_MID, 0, 40);
|
||||
lv_obj_set_style_text_font(label, &lv_font_montserrat_10, 0);
|
||||
create_settings_widget("Theme", dropdown, panel);
|
||||
|
||||
dropdown = lv_dropdown_create(panel);
|
||||
lv_dropdown_set_options(dropdown, brightness_options);
|
||||
lv_obj_add_event_cb(dropdown, brightness_dropdown, LV_EVENT_VALUE_CHANGED, NULL);
|
||||
|
||||
for (int i = 0; i < SIZEOF(brightness_options_values); i++){
|
||||
if (brightness_options_values[i] == global_config.brightness){
|
||||
lv_dropdown_set_selected(dropdown, i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
create_settings_widget("Brightness", dropdown, panel);
|
||||
|
||||
dropdown = lv_dropdown_create(panel);
|
||||
lv_dropdown_set_options(dropdown, wake_timeout_options);
|
||||
lv_obj_add_event_cb(dropdown, wake_timeout_dropdown, LV_EVENT_VALUE_CHANGED, NULL);
|
||||
|
||||
for (int i = 0; i < SIZEOF(wake_timeout_options_values); i++){
|
||||
if (wake_timeout_options_values[i] == global_config.screenTimeout){
|
||||
lv_dropdown_set_selected(dropdown, i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
create_settings_widget("Wake Timeout", dropdown, panel);
|
||||
|
||||
toggle = lv_switch_create(panel);
|
||||
lv_obj_add_event_cb(toggle, rotate_screen_switch, LV_EVENT_VALUE_CHANGED, NULL);
|
||||
|
||||
if (global_config.rotateScreen)
|
||||
lv_obj_add_state(toggle, LV_STATE_CHECKED);
|
||||
|
||||
create_settings_widget("Rotate Screen", toggle, panel);
|
||||
|
||||
toggle = lv_switch_create(panel);
|
||||
lv_obj_add_event_cb(toggle, on_during_print_switch, LV_EVENT_VALUE_CHANGED, NULL);
|
||||
|
||||
if (global_config.onDuringPrint)
|
||||
lv_obj_add_state(toggle, LV_STATE_CHECKED);
|
||||
|
||||
create_settings_widget("Screen On During Print", toggle, panel);
|
||||
}
|
||||
@@ -154,6 +154,6 @@ void wifi_init(){
|
||||
|
||||
void wifi_ok(){
|
||||
if (WiFi.status() != WL_CONNECTED){
|
||||
wifi_init();
|
||||
ESP.restart();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user