Skip to content

Commit

Permalink
Adding support for hostname with dual keyboards for port
Browse files Browse the repository at this point in the history
  • Loading branch information
matthawley committed Feb 4, 2024
1 parent c69c523 commit f2d4121
Showing 1 changed file with 33 additions and 13 deletions.
46 changes: 33 additions & 13 deletions CYD-Klipper/src/ui/ip_setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#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;

Expand Down Expand Up @@ -47,7 +47,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())
Expand Down Expand Up @@ -140,31 +140,51 @@ 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);
lv_obj_set_width(textbow_row, CYD_SCREEN_WIDTH_PX - CYD_SCREEN_GAP_PX * 2);
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_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);

/* 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", "-", "\n",
" ", "z", "x", "c", "v", "b", "n", "m", ".", " ", LV_SYMBOL_OK, 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, 4,
LV_BTNMATRIX_CTRL_HIDDEN | 8, 4, 4, 4, 4, 4, 4, 4, 4, LV_BTNMATRIX_CTRL_HIDDEN | 2, 6
};

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_obj_add_event_cb(portEntry, ta_event_cb, LV_EVENT_ALL, keyboard);
lv_obj_t * hostKeyboard = lv_keyboard_create(root);
lv_keyboard_set_map(hostKeyboard, LV_KEYBOARD_MODE_USER_1, kb_map, kb_ctrl);
lv_keyboard_set_mode(hostKeyboard, LV_KEYBOARD_MODE_USER_1);
lv_obj_add_event_cb(hostEntry, ta_event_cb, LV_EVENT_ALL, hostKeyboard);
lv_obj_add_flag(hostKeyboard, LV_OBJ_FLAG_HIDDEN);

lv_obj_t * portKeyboard = lv_keyboard_create(root);
lv_keyboard_set_mode(portKeyboard, LV_KEYBOARD_MODE_NUMBER);
lv_obj_add_event_cb(portEntry, ta_event_cb, LV_EVENT_ALL, portKeyboard);
lv_obj_add_flag(portKeyboard, LV_OBJ_FLAG_HIDDEN);
}

long last_data_update_ip = -10000;
Expand Down

0 comments on commit f2d4121

Please sign in to comment.