Merge branch 'setup-ports' of https://github.com/suchmememanyskill/CYD-Klipper-Display into setup-ports

This commit is contained in:
suchmememanyskill
2024-02-07 21:04:01 +01:00

View File

@@ -8,10 +8,25 @@
#include "panels/panel.h"
bool connect_ok = false;
lv_obj_t * ipEntry;
lv_obj_t * hostEntry;
lv_obj_t * portEntry;
lv_obj_t * label = NULL;
/* Create a custom keyboard to allow hostnames or ip addresses (a-z, 0 - 9, and -) */
static const char * kb_map[] = {
"1", "2", "3", "4", "5", "6", "7", "8", "9", "0", LV_SYMBOL_BACKSPACE, "\n",
"q", "w", "e", "r", "t", "y", "u", "i", "o", "p", "\n",
"a", "s", "d", "f", "g", "h", "j", "k", "l", LV_SYMBOL_OK, "\n",
"z", "x", "c", "v", "b", "n", "m", ".", "-", " ", NULL
};
static const lv_btnmatrix_ctrl_t kb_ctrl[] = {
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
4, 4, 4, 4, 4, 4, 4, 4, 4, 6,
4, 4, 4, 4, 4, 4, 4, 4, 4, LV_BTNMATRIX_CTRL_HIDDEN | 4
};
void ip_init_inner();
bool verify_ip(){
@@ -46,7 +61,7 @@ static void ta_event_cb(lv_event_t * e) {
}
else if (code == LV_EVENT_READY)
{
strcpy(global_config.klipperHost, lv_textarea_get_text(ipEntry));
strcpy(global_config.klipperHost, lv_textarea_get_text(hostEntry));
global_config.klipperPort = atoi(lv_textarea_get_text(portEntry));
if (verify_ip())
@@ -60,6 +75,19 @@ static void ta_event_cb(lv_event_t * e) {
lv_label_set_text(label, "Failed to connect");
}
}
else
{
return;
}
if (lv_obj_has_flag(ta, LV_OBJ_FLAG_USER_1))
{
lv_keyboard_set_mode(kb, LV_KEYBOARD_MODE_USER_1);
}
else
{
lv_keyboard_set_mode(kb, LV_KEYBOARD_MODE_NUMBER);
}
}
static void reset_btn_event_handler(lv_event_t * e){
@@ -139,7 +167,7 @@ void ip_init_inner(){
lv_obj_set_style_pad_all(top_root, CYD_SCREEN_GAP_PX, 0);
label = lv_label_create(top_root);
lv_label_set_text(label, "Enter Klipper IP and Port");
lv_label_set_text(label, "Enter Klipper IP/Hostname and Port");
lv_obj_set_width(label, CYD_SCREEN_WIDTH_PX - CYD_SCREEN_GAP_PX * 2);
lv_obj_t * textbow_row = lv_create_empty_panel(top_root);
@@ -147,23 +175,25 @@ void ip_init_inner(){
lv_obj_set_flex_grow(textbow_row, 1);
lv_layout_flex_row(textbow_row);
ipEntry = lv_textarea_create(textbow_row);
lv_textarea_set_one_line(ipEntry, true);
lv_textarea_set_max_length(ipEntry, 63);
lv_textarea_set_text(ipEntry, "");
lv_obj_set_flex_grow(ipEntry, 3);
hostEntry = lv_textarea_create(textbow_row);
lv_textarea_set_one_line(hostEntry, true);
lv_obj_add_flag(hostEntry, LV_OBJ_FLAG_USER_1);
lv_textarea_set_max_length(hostEntry, 63);
lv_textarea_set_text(hostEntry, "");
lv_obj_set_flex_grow(hostEntry, 3);
portEntry = lv_textarea_create(textbow_row);
lv_textarea_set_one_line(portEntry, true);
lv_textarea_set_max_length(portEntry, 5);
lv_textarea_set_text(portEntry, "80");
lv_obj_set_flex_grow(portEntry, 1);
lv_obj_t * keyboard = lv_keyboard_create(root);
lv_keyboard_set_mode(keyboard, LV_KEYBOARD_MODE_NUMBER);
lv_keyboard_set_textarea(keyboard, ipEntry);
lv_obj_add_event_cb(ipEntry, ta_event_cb, LV_EVENT_ALL, keyboard);
lv_keyboard_set_map(keyboard, LV_KEYBOARD_MODE_USER_1, kb_map, kb_ctrl);
lv_obj_add_event_cb(hostEntry, ta_event_cb, LV_EVENT_ALL, keyboard);
lv_obj_add_event_cb(portEntry, ta_event_cb, LV_EVENT_ALL, keyboard);
lv_keyboard_set_mode(keyboard, LV_KEYBOARD_MODE_USER_1);
lv_keyboard_set_textarea(keyboard, hostEntry);
}
long last_data_update_ip = -10000;