From c18cd10c69fd3a05cdd43bf1b5d8197507371970 Mon Sep 17 00:00:00 2001 From: Matt Hawley <608302+matthawley@users.noreply.github.com> Date: Tue, 6 Feb 2024 08:30:59 -0800 Subject: [PATCH] Adding support for hostname with dual keyboards for port (#29) * Adding support for hostname with dual keyboards for port * Updating to use a single keyboard * Changing keyboard layout --- CYD-Klipper/src/ui/ip_setup.cpp | 54 +++++++++++++++++++++++++-------- 1 file changed, 42 insertions(+), 12 deletions(-) diff --git a/CYD-Klipper/src/ui/ip_setup.cpp b/CYD-Klipper/src/ui/ip_setup.cpp index 8763cef..0be862b 100644 --- a/CYD-Klipper/src/ui/ip_setup.cpp +++ b/CYD-Klipper/src/ui/ip_setup.cpp @@ -9,10 +9,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(){ @@ -47,7 +62,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()) @@ -61,6 +76,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){ @@ -140,7 +168,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); @@ -148,23 +176,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;