From 5525e8487c507112415e2c2c33f14972685b6496 Mon Sep 17 00:00:00 2001 From: Adam Shiervani Date: Thu, 3 Dec 2026 11:07:10 +0100 Subject: [PATCH 1/3] Show a QR code for hotspot mode on the display While the access point runs, the button strip of the home screen reads QR beside the Down button. That button puts a QR code in the place of the rows below the header, and the Back button puts the rows back. A phone's camera reads the code and joins the access point: the code holds the name and the password as the Wi-Fi network text WIFI:T:WPA;S:;P:;;. The password row of the home screen stays as it is. LVGL's QR code library draws the symbol (CONFIG_LV_USE_QRCODE on the Wi-Fi board): 33 modules of 4 px on a white tile. --- components/jetkvm_screen/README.md | 4 +- components/jetkvm_screen/jetkvm_screen.c | 2 + .../jetkvm_screen_access_point.c | 123 ++++++++++++- .../jetkvm_screen_access_point.h | 41 ++++- .../jetkvm_screen/jetkvm_screen_buttons.c | 78 +++++++-- .../jetkvm_screen/jetkvm_screen_buttons.h | 10 ++ .../tests/host_renderer/lv_conf.h | 2 + .../tests/host_renderer/render_ui_screens.c | 26 ++- .../host_renderer/test_access_point_screen.c | 163 +++++++++++++++++- .../tests/run_home_address_host_test.sh | 5 +- docs/hardware-variants.md | 2 +- sdkconfig.wifi.defaults | 3 + 12 files changed, 419 insertions(+), 40 deletions(-) diff --git a/components/jetkvm_screen/README.md b/components/jetkvm_screen/README.md index b9171433..8e5f9ce9 100644 --- a/components/jetkvm_screen/README.md +++ b/components/jetkvm_screen/README.md @@ -30,6 +30,8 @@ The menu reads Set up Wi-Fi, Regulatory and Hotspot Mode (all three on the Wi-Fi On the Wi-Fi board, Menu > Hotspot Mode turns access point mode on and off (`jetkvm_screen_access_point.c`); the display and the web UI call the mode hotspot mode. The entry is on the menu in every state of the device and reads Hotspot Mode: Off or Hotspot Mode: On. A hold on it asks the handler of `jetkvm_screen_set_wifi_access_point_handler()` for the other state, and when the mode turns on the menu gives way to the home screen of the state. Until the access point runs, the no-network screen reads Hotspot Mode and Starting. Then the home screen shows the access point as it shows a joined network: `192.168.4.1` as the address and the network name in the Wi-Fi row, whose icon is green while a device has joined. The header reads Hotspot in the place of the cloud state and the session count, and a row with a padlock below the Wi-Fi row shows the password. The Wi-Fi driver (`jetkvm_c5_wifi`) owns the mode. +While the access point runs, the strip of the home screen reads QR in the place of the dot beside the Down button, and only the other button opens the menu. The Down button puts a QR code in the place of the rows below the header: a white tile with the Wi-Fi network text `WIFI:T:WPA;S:;P:;;`, which a phone's camera reads to join the access point. The symbol has 33 modules of 4 px (LVGL's QR code library, `CONFIG_LV_USE_QRCODE` in `sdkconfig.wifi.defaults`) and a light margin of 16 px, or 11 px with the strip at the top or the bottom, where the tile has less room. On the code the strip shows Back beside the Back button, which puts the rows back; the Down button does nothing. The code also closes when the access point stops. + While "Web interface through Tailscale only" is on, the Advanced menu starts with the entry Tailscale Only: On (`jetkvm_screen_tailscale_only.c`). A hold on it turns the setting off, with the RPC that the web UI sends, and the entry goes with the next state. The device does not restart. This is the way back for an owner whose Tailscale path stopped working. The entry is not on the page while the setting is off. The button strip takes 22 px of the home screen's lines when it is on the left or right, so the IPv4 address has 194 px there and 216 px otherwise. `jetkvm_screen_home_address.c` draws the address in the layout's font (Inter Bold at 24 px) when it fits its line, and in Inter Bold at 21 px when it does not. Every address fits 194 px in the smaller font. On the Ethernet board, an IPv6 address (the `ipv6_mode` setting) is shown below it. An address that does not fit one line breaks after the colon that makes the two lines most equal in width, so an address of eight groups has four groups on each line, and four groups fit 194 px. A `::` stays whole on one line. The MAC address line has that room only without an IPv6 address, so the two are not shown together. The Wi-Fi board shows the network name in that place and no IPv6 address. @@ -56,4 +58,4 @@ Firmware boots in H.264-only mode. SW3 (active low; GPIO17 on the Wi-Fi board, G `components/jetkvm_screen/tests/run_host_tests.sh` runs the host tests. `components/jetkvm_screen/tests/render_ui_screens.sh wifi|ethernet` renders all twelve generated pages and, for `wifi`, the Regulatory page and the screens of access point mode to PPM (and PNG with ImageMagick) using the LVGL software renderer, with no hardware. The pages are laid out by the production button code, so each one has the button strip, and the home screen is also rendered with the widest IPv4 address and the strip at each edge. -`components/jetkvm_screen/tests/run_home_address_host_test.sh` lays out the home screen in the same way and fails when an IPv4 address crosses the end of its line or an IPv6 address does not fit its two lines or breaks at another colon, without the strip and with the strip at each edge. The same script runs `test_access_point_screen.c` on both boards: Menu > Hotspot Mode is the third entry of the Wi-Fi board's menu, a hold on it asks for the other state, and the name of the mode in the header and the password row of the home screen fit beside the strip at each edge with the widest name and password. Both scripts need cmake, ninja and `managed_components/lvgl__lvgl`. +`components/jetkvm_screen/tests/run_home_address_host_test.sh` lays out the home screen in the same way and fails when an IPv4 address crosses the end of its line or an IPv6 address does not fit its two lines or breaks at another colon, without the strip and with the strip at each edge. The same script runs `test_access_point_screen.c` on both boards: Menu > Hotspot Mode is the third entry of the Wi-Fi board's menu, a hold on it asks for the other state, and the name of the mode in the header and the password row of the home screen fit beside the strip at each edge with the widest name and password. While the access point runs, the Down button opens the QR code and the Back button closes it; the code is the symbol of the name and the password at 4 px a module, fits below the header and beside the strip at each edge, and closes when the access point stops. Both scripts need cmake, ninja and `managed_components/lvgl__lvgl`. diff --git a/components/jetkvm_screen/jetkvm_screen.c b/components/jetkvm_screen/jetkvm_screen.c index 05c0e829..c5f4ea8e 100644 --- a/components/jetkvm_screen/jetkvm_screen.c +++ b/components/jetkvm_screen/jetkvm_screen.c @@ -1111,9 +1111,11 @@ static void apply_state(const jetkvm_screen_state_t *state) jetkvm_screen_buttons_set_wifi_setup(state->wifi_setup_menu || s_wifi_setup_requested, state->wifi_setup_stoppable); if (jetkvm_screen_access_point_apply(state->wifi_ap, + access_point ? state->wifi_ap_ssid : NULL, access_point ? state->wifi_ap_password : NULL)) { s_wifi_access_point_turned_on = true; } + jetkvm_screen_buttons_set_access_point(jetkvm_screen_access_point_runs()); /* Match JetKVM display.go: the unfinished Access menu stays hidden. The * Network entry is Set up Wi-Fi on the Wi-Fi board. */ diff --git a/components/jetkvm_screen/jetkvm_screen_access_point.c b/components/jetkvm_screen/jetkvm_screen_access_point.c index bf11d650..ad13a78d 100644 --- a/components/jetkvm_screen/jetkvm_screen_access_point.c +++ b/components/jetkvm_screen/jetkvm_screen_access_point.c @@ -10,12 +10,19 @@ #include "ui/styles.h" #include "ui/ui.h" -static lv_obj_t *s_entry, *s_row; +static lv_obj_t *s_entry, *s_row, *s_qr_area; #if JETKVM_BOARD_WIFI -static lv_obj_t *s_entry_label, *s_password; +static lv_obj_t *s_entry_label, *s_password, *s_qr_tile, *s_qr; static bool s_enabled; +static char s_qr_text[JETKVM_SCREEN_ACCESS_POINT_QR_TEXT_CAPACITY]; #define COLOR_ICON 0x808080 +/* The text for the device's own name and password is 45 bytes, which the QR + * code library puts in a version 4 symbol of 33 modules. At 4 px a module is + * about 0.5 mm on the panel. */ +#define QR_SIZE (33 * 4) +/* The light margin that a reader needs around the symbol: 4 modules. */ +#define QR_MARGIN (4 * 4) /* The blue of the no-network screen's second line. */ #define COLOR_MODE 0x4f8cff @@ -88,8 +95,82 @@ static void row_init(void) lv_obj_set_style_text_color(s_password, lv_color_hex(0xffffff), LV_PART_MAIN); lv_label_set_text(s_password, ""); } + +/* The tile is the largest square that the area holds, up to the symbol with + * its whole margin: the area is lower when the button strip is at the top or + * the bottom. */ +static void qr_area_resized(lv_event_t *event) +{ + (void)event; + const int32_t side = LV_MIN(LV_MIN(lv_obj_get_content_width(s_qr_area), + lv_obj_get_content_height(s_qr_area)), + QR_SIZE + 2 * QR_MARGIN); + lv_obj_set_size(s_qr_tile, side, side); +} + +/* A reader needs dark modules on a light ground, so the code is on a white + * tile. */ +static void qr_init(void) +{ + s_qr_area = plain(lv_obj_get_parent(objects.home_info_container), 0, 0, 0, 0); + lv_obj_set_width(s_qr_area, LV_PCT(100)); + lv_obj_set_flex_grow(s_qr_area, 1); + lv_obj_add_flag(s_qr_area, LV_OBJ_FLAG_HIDDEN); + lv_obj_add_event_cb(s_qr_area, qr_area_resized, LV_EVENT_SIZE_CHANGED, NULL); + + s_qr_tile = plain(s_qr_area, 0, 0, QR_SIZE, QR_SIZE); + lv_obj_center(s_qr_tile); + lv_obj_set_style_radius(s_qr_tile, 6, LV_PART_MAIN); + lv_obj_set_style_bg_color(s_qr_tile, lv_color_white(), LV_PART_MAIN); + lv_obj_set_style_bg_opa(s_qr_tile, LV_OPA_COVER, LV_PART_MAIN); + + s_qr = lv_qrcode_create(s_qr_tile); + lv_qrcode_set_size(s_qr, QR_SIZE); + lv_obj_center(s_qr); +} + +static char *qr_append(char *at, const char *end, const char *text, bool escape) +{ + for (; *text != '\0' && at + 2 < end; ++text) { + if (escape && strchr("\\;,:\"", *text) != NULL) { + *at++ = '\\'; + } + *at++ = *text; + } + *at = '\0'; + return at; +} + +static void qr_update(const char *ssid, const char *password) +{ + char text[sizeof(s_qr_text)]; + jetkvm_screen_access_point_qr_text(ssid, password, text); + if (strcmp(text, s_qr_text) == 0) { + return; + } + if (lv_qrcode_update(s_qr, text, (uint32_t)strlen(text)) == LV_RESULT_OK) { + memcpy(s_qr_text, text, sizeof(s_qr_text)); + } +} #endif /* JETKVM_BOARD_WIFI */ +void jetkvm_screen_access_point_qr_text(const char *ssid, const char *password, + char text[JETKVM_SCREEN_ACCESS_POINT_QR_TEXT_CAPACITY]) +{ + text[0] = '\0'; +#if JETKVM_BOARD_WIFI + const char *end = text + JETKVM_SCREEN_ACCESS_POINT_QR_TEXT_CAPACITY; + char *at = qr_append(text, end, "WIFI:T:WPA;S:", false); + at = qr_append(at, end, ssid, true); + at = qr_append(at, end, ";P:", false); + at = qr_append(at, end, password, true); + (void)qr_append(at, end, ";;", false); +#else + (void)ssid; + (void)password; +#endif +} + void jetkvm_screen_access_point_init(void) { #if JETKVM_BOARD_WIFI @@ -97,11 +178,12 @@ void jetkvm_screen_access_point_init(void) return; } row_init(); + qr_init(); entry_init(); #endif } -bool jetkvm_screen_access_point_apply(bool enabled, const char *password) +bool jetkvm_screen_access_point_apply(bool enabled, const char *ssid, const char *password) { #if JETKVM_BOARD_WIFI if (s_entry == NULL) { @@ -116,6 +198,11 @@ bool jetkvm_screen_access_point_apply(bool enabled, const char *password) if (shown && strcmp(lv_label_get_text(s_password), password) != 0) { lv_label_set_text(s_password, password); } + if (shown) { + qr_update(ssid != NULL ? ssid : "", password); + } else { + jetkvm_screen_access_point_qr_show(false); + } if (shown == lv_obj_has_flag(s_row, LV_OBJ_FLAG_HIDDEN)) { /* The header's right side names the mode. The cloud is out of reach * from the access point's network, so its icon goes; the caller sets @@ -135,11 +222,36 @@ bool jetkvm_screen_access_point_apply(bool enabled, const char *password) return turned_on; #else (void)enabled; + (void)ssid; (void)password; return false; #endif } +bool jetkvm_screen_access_point_runs(void) +{ + return s_row != NULL && !lv_obj_has_flag(s_row, LV_OBJ_FLAG_HIDDEN); +} + +void jetkvm_screen_access_point_qr_show(bool shown) +{ + if (shown == jetkvm_screen_access_point_qr_shown() || + (shown && !jetkvm_screen_access_point_runs())) { + return; + } + lv_obj_t *rows[] = {objects.home_info_container, objects.divider, + objects.home_status_container}; + for (size_t i = 0; i < sizeof(rows) / sizeof(rows[0]); i++) { + lv_obj_set_flag(rows[i], LV_OBJ_FLAG_HIDDEN, shown); + } + lv_obj_set_flag(s_qr_area, LV_OBJ_FLAG_HIDDEN, !shown); +} + +bool jetkvm_screen_access_point_qr_shown(void) +{ + return s_qr_area != NULL && !lv_obj_has_flag(s_qr_area, LV_OBJ_FLAG_HIDDEN); +} + lv_obj_t *jetkvm_screen_access_point_entry(void) { return s_entry; @@ -149,3 +261,8 @@ lv_obj_t *jetkvm_screen_access_point_password_row(void) { return s_row; } + +lv_obj_t *jetkvm_screen_access_point_qr_area(void) +{ + return s_qr_area; +} diff --git a/components/jetkvm_screen/jetkvm_screen_access_point.h b/components/jetkvm_screen/jetkvm_screen_access_point.h index 6c8d5bad..b954cd89 100644 --- a/components/jetkvm_screen/jetkvm_screen_access_point.h +++ b/components/jetkvm_screen/jetkvm_screen_access_point.h @@ -18,22 +18,47 @@ * what a joined network does not have. The header names the mode: it reads * "Hotspot" in the place of the cloud state and the session count, which the * caller leaves alone meanwhile. A row below the Wi-Fi row shows the - * password. All calls run with LVGL owned by the caller. + * password. + * + * The home screen can also show a QR code that a phone's camera reads to + * join the access point. The code takes the place of the rows below the + * header, which stays. The button code opens and closes it + * (jetkvm_screen_buttons.c). All calls run with LVGL owned by the caller. */ +/* Room for the text of the QR code with the longest name, with each of its + * 32 bytes escaped, and the password. */ +#define JETKVM_SCREEN_ACCESS_POINT_QR_TEXT_CAPACITY 120U + /* Call once after ui_init(), after jetkvm_screen_regulatory_init() (which * orders the menu) and after the home screen has its Wi-Fi row. */ void jetkvm_screen_access_point_init(void); -/* `enabled`: the mode is on. `password`: the password while the access point - * runs, else NULL; the home screen names the mode and shows the row only with - * a password. In the state after the last one with a password, the caller - * sets the header's cloud state and session count again. +/* `enabled`: the mode is on. `ssid` and `password`: the name and the password + * while the access point runs, else NULL; the home screen names the mode and + * shows the row only with a password. In the state after the last one with a + * password, the caller sets the header's cloud state and session count + * again, and the QR code closes. * Returns true when the mode turned on with this call, so that the caller * leaves the menu for the home screen. */ -bool jetkvm_screen_access_point_apply(bool enabled, const char *password); +bool jetkvm_screen_access_point_apply(bool enabled, const char *ssid, const char *password); + +/* The home screen shows the access point: its QR code can open. */ +bool jetkvm_screen_access_point_runs(void); + +/* Puts the QR code in the place of the home screen's rows, or the rows back. + * The code opens only while the access point runs. */ +void jetkvm_screen_access_point_qr_show(bool shown); +bool jetkvm_screen_access_point_qr_shown(void); + +/* What the QR code holds: the Wi-Fi network text that phone cameras read, + * WIFI:T:WPA;S:;P:;; with a backslash before each of + * \ ; , : " in the name and the password. Empty on the Ethernet board. */ +void jetkvm_screen_access_point_qr_text(const char *ssid, const char *password, + char text[JETKVM_SCREEN_ACCESS_POINT_QR_TEXT_CAPACITY]); -/* The menu entry and the password row of the home screen; NULL on the - * Ethernet board, which has no access point. */ +/* The menu entry, the password row of the home screen and the area of the QR + * code; NULL on the Ethernet board, which has no access point. */ lv_obj_t *jetkvm_screen_access_point_entry(void); lv_obj_t *jetkvm_screen_access_point_password_row(void); +lv_obj_t *jetkvm_screen_access_point_qr_area(void); diff --git a/components/jetkvm_screen/jetkvm_screen_buttons.c b/components/jetkvm_screen/jetkvm_screen_buttons.c index 3756b427..edb80759 100644 --- a/components/jetkvm_screen/jetkvm_screen_buttons.c +++ b/components/jetkvm_screen/jetkvm_screen_buttons.c @@ -41,6 +41,9 @@ * screens. A hold counts only while every sample reads the * button pressed and the pin does not change level. On the page of Wi-Fi * setup started from the menu, only a held Back button acts: it ends setup. + * On the home screen of a running access point, the Down button opens the QR + * code of the access point (jetkvm_screen_access_point.c), and there only the + * Back button acts: it closes the code. * * Every press restarts the display's dim and off timers and brings the * backlight back to its set brightness. A press while the timers hold the @@ -74,7 +77,9 @@ static const char *TAG = "screen_buttons"; /* Pillar: a gray column that meets the buttons' edge and the edge at SW2's * end, with a rounded corner on its inner side at SW3's end. It overhangs the * panel at those two edges so only that one corner shows its radius. On the start screens a dot sits beside - * each button and "Menu" runs between them; elsewhere the icons sit on it. */ + * each button and "Menu" runs between them; "QR" takes the place of the Down + * button's dot while that button opens the QR code. Elsewhere the icons sit + * on it. */ #define PILLAR_TOP 52 #define PILLAR_RADIUS 12 /* The square mark at the left of the 116 px JetKVM logo. */ @@ -113,7 +118,7 @@ static uint32_t s_notify_bits; static uint32_t s_changed; static lv_obj_t *strip, *top_icon, *bottom_icon, *hold_hint, *track, *fill; -static lv_obj_t *home_marks, *top_dot, *bottom_dot, *menu_label; +static lv_obj_t *home_marks, *top_dot, *bottom_dot, *menu_label, *qr_mark; /* The Wi-Fi board has one screen more: Menu > Regulatory. */ static lv_obj_t *screens[12 + JETKVM_BOARD_WIFI]; /* The clockwise turn of the picture on the panel. */ @@ -143,6 +148,7 @@ static bool press_used; static bool s_wifi_setup, s_wifi_setup_stoppable; /* Advanced > Tailscale Only is on the page. */ static bool s_tailscale_only; +static bool s_access_point; /* The no-network screen while Wi-Fi setup from the menu runs. */ static bool wifi_setup_page(void) @@ -155,13 +161,23 @@ static bool wifi_setup_hold(void) return pressed == BUTTON_TOP && s_wifi_setup_stoppable && wifi_setup_page(); } +static bool qr_view(void) +{ + return lv_screen_active() == objects.home_screen && jetkvm_screen_access_point_qr_shown(); +} + static bool home(void) { lv_obj_t *screen = lv_screen_active(); - return !wifi_setup_page() && + return !wifi_setup_page() && !qr_view() && (screen == objects.home_screen || screen == objects.no_network_screen); } +static bool qr_offer(void) +{ + return s_access_point && home() && lv_screen_active() == objects.home_screen; +} + static lv_obj_t *plain(lv_obj_t *parent, int x, int y, int w, int h, unsigned color) { lv_obj_t *obj = lv_obj_create(parent); @@ -218,6 +234,17 @@ static void pillar_init(void) lv_obj_add_flag(home_marks, LV_OBJ_FLAG_OVERFLOW_VISIBLE); top_dot = dot(PILLAR_TOP_DOT_Y); bottom_dot = dot(PILLAR_BOTTOM_DOT_Y); + qr_mark = lv_label_create(home_marks); + lv_obj_set_style_text_font(qr_mark, &ui_font_font_book16, 0); + lv_label_set_text(qr_mark, "QR"); + lv_obj_add_flag(qr_mark, LV_OBJ_FLAG_OVERFLOW_VISIBLE); + lv_obj_update_layout(qr_mark); + int32_t qr_w = lv_obj_get_width(qr_mark); + int32_t qr_h = lv_obj_get_height(qr_mark); + part(qr_mark, (STRIP_WIDTH - qr_w) / 2, PILLAR_BOTTOM_DOT_Y + PILLAR_DOT / 2 - qr_h / 2, qr_w, qr_h, + true, true); + lv_obj_set_style_transform_pivot_x(qr_mark, qr_w / 2, 0); + lv_obj_set_style_transform_pivot_y(qr_mark, qr_h / 2, 0); menu_label = lv_label_create(home_marks); lv_obj_set_style_text_font(menu_label, &ui_font_font_book16, 0); lv_obj_set_style_text_color(menu_label, lv_color_white(), 0); @@ -258,6 +285,7 @@ static void layout(void) /* Beside a vertical strip "Menu" turns a quarter around its centre and * reads downward; along a horizontal strip it reads across. */ lv_obj_set_style_transform_rotation(menu_label, vertical ? 900 : 0, 0); + lv_obj_set_style_transform_rotation(qr_mark, vertical ? 900 : 0, 0); for (unsigned i = 0; i < sizeof(screens) / sizeof(screens[0]); i++) { lv_obj_set_style_pad_left(screens[i], edge == JETKVM_SCREEN_EDGE_LEFT ? STRIP_CLEAR : EDGE_PAD, 0); lv_obj_set_style_pad_right(screens[i], edge == JETKVM_SCREEN_EDGE_RIGHT ? STRIP_CLEAR : EDGE_PAD, 0); @@ -268,10 +296,12 @@ static void layout(void) * the header and its cloud status run to the right EDGE_PAD. The rows * below it keep clear of the pillar. */ lv_obj_t *home_rows[] = {objects.home_info_container, objects.divider, - objects.home_status_container}; + objects.home_status_container, jetkvm_screen_access_point_qr_area()}; for (unsigned i = 0; i < sizeof(home_rows) / sizeof(home_rows[0]); i++) { - lv_obj_set_style_margin_right(home_rows[i], - edge == JETKVM_SCREEN_EDGE_RIGHT ? STRIP_CLEAR - EDGE_PAD : 0, 0); + if (home_rows[i] != NULL) { + lv_obj_set_style_margin_right( + home_rows[i], edge == JETKVM_SCREEN_EDGE_RIGHT ? STRIP_CLEAR - EDGE_PAD : 0, 0); + } } if (edge == JETKVM_SCREEN_EDGE_RIGHT) { lv_obj_set_style_pad_right(objects.home_screen, EDGE_PAD, 0); @@ -351,10 +381,10 @@ static void changed(lv_event_t *event) : wifi_setup_page() ? (s_wifi_setup_stoppable ? LV_SYMBOL_CLOSE : "") : LV_SYMBOL_LEFT); /* Bottom button: open the menu, step down, hold to accept, or scroll. */ - lv_label_set_text(bottom_icon, home() ? LV_SYMBOL_LIST - : wifi_setup_page() ? "" - : hold_accept ? LV_SYMBOL_OK - : LV_SYMBOL_DOWN); + lv_label_set_text(bottom_icon, home() ? LV_SYMBOL_LIST + : wifi_setup_page() || qr_view() ? "" + : hold_accept ? LV_SYMBOL_OK + : LV_SYMBOL_DOWN); /* In a menu a held bottom button accepts the entry; the small check says so. */ lv_label_set_text(hold_hint, item_count ? LV_SYMBOL_OK : ""); lv_obj_set_style_text_color(top_icon, lv_color_white(), 0); @@ -373,6 +403,9 @@ static void changed(lv_event_t *event) } lv_obj_set_style_bg_color(top_dot, lv_color_white(), 0); lv_obj_set_style_bg_color(bottom_dot, lv_color_white(), 0); + lv_obj_set_style_text_color(qr_mark, lv_color_white(), 0); + lv_obj_set_flag(bottom_dot, LV_OBJ_FLAG_HIDDEN, qr_offer()); + lv_obj_set_flag(qr_mark, LV_OBJ_FLAG_HIDDEN, !qr_offer()); if (screen == objects.boot_screen || screen == objects.rebooting_screen) { lv_obj_add_flag(strip, LV_OBJ_FLAG_HIDDEN); } else { @@ -493,6 +526,9 @@ static void buttons_press(unsigned side, unsigned button) lv_color_hex(COLOR_ACTIVE), 0); lv_obj_set_style_bg_color(side == BUTTON_TOP ? top_dot : bottom_dot, lv_color_hex(COLOR_ACTIVE), 0); + if (side == BUTTON_BOTTOM) { + lv_obj_set_style_text_color(qr_mark, lv_color_hex(COLOR_ACTIVE), 0); + } track_bottom = side == BUTTON_BOTTOM; fill_width = 2; place_track(); @@ -575,6 +611,7 @@ static void buttons_release(void) lv_obj_set_style_text_color(bottom_icon, lv_color_white(), 0); lv_obj_set_style_bg_color(top_dot, lv_color_white(), 0); lv_obj_set_style_bg_color(bottom_dot, lv_color_white(), 0); + lv_obj_set_style_text_color(qr_mark, lv_color_white(), 0); lv_obj_add_flag(track, LV_OBJ_FLAG_HIDDEN); if (press_used) { /* The hold has acted or the press lit a dark display; the release @@ -586,8 +623,16 @@ static void buttons_release(void) * accept a confirmation. */ return; } - if (home()) { + if (qr_offer() && side == BUTTON_BOTTOM) { + jetkvm_screen_access_point_qr_show(true); + changed(NULL); + } else if (home()) { action_switch_to_menu(NULL); + } else if (qr_view()) { + if (side == BUTTON_TOP) { + jetkvm_screen_access_point_qr_show(false); + changed(NULL); + } } else if (side == BUTTON_TOP) { back(); } else if (item_count) { @@ -702,6 +747,17 @@ void jetkvm_screen_buttons_set_tailscale_only(bool shown) } } +void jetkvm_screen_buttons_set_access_point(bool runs) +{ + if (runs == s_access_point) { + return; + } + s_access_point = runs; + if (strip != NULL) { + changed(NULL); + } +} + bool jetkvm_screen_buttons_poll(bool preview) { bool busy = false; diff --git a/components/jetkvm_screen/jetkvm_screen_buttons.h b/components/jetkvm_screen/jetkvm_screen_buttons.h index 6cdfc15b..1cd9b867 100644 --- a/components/jetkvm_screen/jetkvm_screen_buttons.h +++ b/components/jetkvm_screen/jetkvm_screen_buttons.h @@ -42,6 +42,11 @@ void jetkvm_screen_buttons_set_rotation(uint16_t degrees); * entries that are on the page. */ void jetkvm_screen_buttons_set_tailscale_only(bool shown); +/* The home screen shows the access point, or no longer does: while it + * `runs`, the bottom button opens the QR code of the access point there, the + * strip reads QR beside that button, and the top button closes the code. */ +void jetkvm_screen_buttons_set_access_point(bool runs); + #else static inline void jetkvm_screen_buttons_init(TaskHandle_t task, uint32_t notify_bits) @@ -72,6 +77,11 @@ static inline void jetkvm_screen_buttons_set_tailscale_only(bool shown) (void)shown; } +static inline void jetkvm_screen_buttons_set_access_point(bool runs) +{ + (void)runs; +} + #endif #ifdef __cplusplus diff --git a/components/jetkvm_screen/tests/host_renderer/lv_conf.h b/components/jetkvm_screen/tests/host_renderer/lv_conf.h index 9096cd7d..dcd1573c 100644 --- a/components/jetkvm_screen/tests/host_renderer/lv_conf.h +++ b/components/jetkvm_screen/tests/host_renderer/lv_conf.h @@ -10,5 +10,7 @@ /* The button strip draws its icons in this font, as the sdkconfig defaults of * both boards set it. */ #define LV_FONT_MONTSERRAT_16 1 +/* As sdkconfig.wifi.defaults: the QR code of the access point. */ +#define LV_USE_QRCODE 1 #endif diff --git a/components/jetkvm_screen/tests/host_renderer/render_ui_screens.c b/components/jetkvm_screen/tests/host_renderer/render_ui_screens.c index b7f20241..23b0108d 100644 --- a/components/jetkvm_screen/tests/host_renderer/render_ui_screens.c +++ b/components/jetkvm_screen/tests/host_renderer/render_ui_screens.c @@ -217,11 +217,11 @@ int main(int argc, char **argv) render_active(argv[1], SCREEN_ID_MENU_SCREEN, "menu-access-point-off") != 0) { return 1; } - if (!jetkvm_screen_access_point_apply(true, NULL) || + if (!jetkvm_screen_access_point_apply(true, NULL, NULL) || render_active(argv[1], SCREEN_ID_MENU_SCREEN, "menu-access-point-on") != 0) { return 1; } - (void)jetkvm_screen_access_point_apply(false, NULL); + (void)jetkvm_screen_access_point_apply(false, NULL, NULL); #else /* The Ethernet board has no Regulatory entry and no such page: the menu * holds Advanced, Status and About, in that order, beside the hidden @@ -275,7 +275,8 @@ int main(int argc, char **argv) * screen says so (jetkvm_screen.c sets these two texts). Once it runs, * the home screen names the mode in its header and shows the address, * the name in the Wi-Fi row and the password in the row below, here with - * a device joined and with the strip at each canvas edge. */ + * a device joined and with the strip at each canvas edge, and then with + * its QR code open. */ jetkvm_screen_buttons_set_rotation(0); lv_label_set_text(objects.no_network_title, "Hotspot Mode"); lv_label_set_text(objects.home_info_ipv6_addr_1, "Starting"); @@ -284,7 +285,8 @@ int main(int argc, char **argv) } jetkvm_screen_home_address_set("192.168.4.1"); (void)host_ui_wifi_row("JetKVM_A1B2C3", 0x22c55e); - (void)jetkvm_screen_access_point_apply(true, "kq7n-x4pd-9hue"); + (void)jetkvm_screen_access_point_apply(true, "JetKVM_A1B2C3", "kq7n-x4pd-9hue"); + jetkvm_screen_buttons_set_access_point(true); loadScreen(SCREEN_ID_HOME_SCREEN); for (size_t i = 0; i < sizeof(turns) / sizeof(turns[0]); ++i) { char name[32]; @@ -295,7 +297,21 @@ int main(int argc, char **argv) } } jetkvm_screen_buttons_set_rotation(0); - (void)jetkvm_screen_access_point_apply(false, NULL); + host_ui_tap(BUTTON_DOWN); + if (!jetkvm_screen_access_point_qr_shown()) { + return 1; + } + for (size_t i = 0; i < sizeof(turns) / sizeof(turns[0]); ++i) { + char name[32]; + snprintf(name, sizeof(name), "home-access-point-qr-%u", (unsigned)turns[i]); + jetkvm_screen_buttons_set_rotation(turns[i]); + if (render_active(argv[1], SCREEN_ID_HOME_SCREEN, name) != 0) { + return 1; + } + } + jetkvm_screen_buttons_set_rotation(0); + (void)jetkvm_screen_access_point_apply(false, NULL, NULL); + jetkvm_screen_buttons_set_access_point(false); lv_label_set_text(objects.cloud_status_label, "1 active"); #endif diff --git a/components/jetkvm_screen/tests/host_renderer/test_access_point_screen.c b/components/jetkvm_screen/tests/host_renderer/test_access_point_screen.c index 11464676..85d8b8e1 100644 --- a/components/jetkvm_screen/tests/host_renderer/test_access_point_screen.c +++ b/components/jetkvm_screen/tests/host_renderer/test_access_point_screen.c @@ -4,8 +4,10 @@ * Wi-Fi board's menu, a held bottom button on it asks for the other state, * and the home screen names the mode in its header and shows the password in * a row below the Wi-Fi row, whole and clear of the other lines, beside the - * button strip at each edge. The Ethernet board has neither the entry nor the - * row. + * button strip at each edge. While the access point runs, the strip reads QR + * beside the bottom button, which puts the QR code of the access point in the + * place of the home screen's rows; the top button puts the rows back. The + * Ethernet board has neither the entry nor the row nor the code. */ #include #include @@ -19,11 +21,17 @@ #include "jetkvm_screen_button.h" #include "jetkvm_screen_buttons.h" #include "jetkvm_screen_home_address.h" +#include "jetkvm_screen_orientation.h" #include "jetkvm_screen_regulatory.h" #include "screens.h" #include "ui.h" +#define BUTTON_BACK 0U #define BUTTON_DOWN 1U +/* A QR code module on the panel, and the least light margin around the + * symbol that phone cameras read reliably (the standard asks for 4). */ +#define QR_MODULE 4 +#define QR_LEAST_MARGIN (2 * QR_MODULE) /* The least space between the logo and the name of the mode in the header: * with less, the name reads as a part of the logo. */ #define HEADER_GAP 24 @@ -87,6 +95,64 @@ static bool hidden(lv_obj_t *obj) { return lv_obj_has_flag(obj, LV_OBJ_FLAG_HIDDEN); } + +static lv_obj_t *shown_label(lv_obj_t *parent, const char *text) +{ + for (uint32_t i = 0; i < lv_obj_get_child_count(parent); ++i) { + lv_obj_t *child = lv_obj_get_child(parent, i); + if (hidden(child)) { + continue; + } + if (lv_obj_check_type(child, &lv_label_class) && + strcmp(lv_label_get_text(child), text) == 0) { + return child; + } + lv_obj_t *found = shown_label(child, text); + if (found != NULL) { + return found; + } + } + return NULL; +} + +/* The strip is on the top layer. */ +static lv_obj_t *qr_mark(void) +{ + return shown_label(lv_layer_top(), "QR"); +} + +static bool home_shows(bool code) +{ + return lv_screen_active() == objects.home_screen && + hidden(jetkvm_screen_access_point_qr_area()) != code && + hidden(objects.home_info_container) == code && hidden(objects.divider) == code && + hidden(objects.home_status_container) == code; +} + +/* A pixel of the symbol's image: one bit a pixel behind a palette of two + * colors of 4 bytes, where a set bit is the dark color. */ +static bool dark(const lv_draw_buf_t *image, int32_t x, int32_t y) +{ + const uint8_t *row = image->data + 8 + (size_t)y * image->header.stride; + return (row[x / 8] >> (7 - x % 8) & 1U) != 0U; +} + +/* The first row of a symbol is 7 dark modules, then a light one. */ +static void expect_code(lv_obj_t *code, const char *text, const char *what) +{ + lv_obj_t *reference = lv_qrcode_create(lv_layer_sys()); + lv_qrcode_set_size(reference, lv_obj_get_width(code)); + bool same = lv_qrcode_update(reference, text, (uint32_t)strlen(text)) == LV_RESULT_OK; + const lv_draw_buf_t *have = lv_canvas_get_draw_buf(code); + const lv_draw_buf_t *want = lv_canvas_get_draw_buf(reference); + same = same && have->data_size == want->data_size && + memcmp(have->data, want->data, want->data_size) == 0; + for (int32_t x = 0; x <= 7 * QR_MODULE; ++x) { + same = same && dark(have, x, 0) == (x < 7 * QR_MODULE); + } + lv_obj_delete(reference); + expect(same, what); +} #endif int main(void) @@ -118,13 +184,19 @@ int main(void) "the hold on the entry did not ask once for setWifiAccessPoint with enabled true"); expect(lv_screen_active() == objects.menu_screen, "the hold left the menu before the mode is on"); + loadScreen(SCREEN_ID_HOME_SCREEN); + expect(qr_mark() == NULL, "the strip reads QR while no access point runs"); + host_ui_tap(BUTTON_DOWN); + expect(lv_screen_active() == objects.menu_screen, + "the bottom button does not open the menu while no access point runs"); + /* The mode is on and its access point starts: the first such state says * that the mode turned on, later ones do not. The entry reads On, and * the home screen has no password yet. */ expect(hidden(row), "the home screen shows the password row while the mode is off"); - expect(jetkvm_screen_access_point_apply(true, NULL), + expect(jetkvm_screen_access_point_apply(true, NULL, NULL), "the first state with the mode on does not report the turn-on"); - expect(!jetkvm_screen_access_point_apply(true, NULL), + expect(!jetkvm_screen_access_point_apply(true, NULL, NULL), "a later state with the mode on reports a turn-on again"); expect(strcmp(lv_label_get_text(label), "Hotspot Mode: On") == 0, "the entry does not read Hotspot Mode: On while the mode is on"); @@ -156,7 +228,7 @@ int main(void) letter, letter, letter, letter, letter, letter, letter, letter); jetkvm_screen_home_address_set("192.168.4.1"); lv_obj_t *wifi_row = host_ui_wifi_row(ssid, 0x22c55e); - expect(!jetkvm_screen_access_point_apply(true, text), + expect(!jetkvm_screen_access_point_apply(true, ssid, text), "a state with the access point running reports a turn-on"); expect(!hidden(row), "the home screen does not show the password row while the access point runs"); expect(strcmp(lv_label_get_text(objects.cloud_status_label), "Hotspot") == 0 && @@ -223,8 +295,77 @@ int main(void) } } + jetkvm_screen_buttons_set_access_point(jetkvm_screen_access_point_runs()); + loadScreen(SCREEN_ID_HOME_SCREEN); + lv_obj_t *area = jetkvm_screen_access_point_qr_area(); + lv_obj_t *tile = lv_obj_get_child(area, 0); + lv_obj_t *code = lv_obj_get_child(tile, 0); + expect(home_shows(false), "the home screen shows the QR code before a button opened it"); + expect(qr_mark() != NULL, "the strip does not read QR while the access point runs"); + host_ui_tap(BUTTON_BACK); + expect(lv_screen_active() == objects.menu_screen, + "the top button does not open the menu while the access point runs"); + loadScreen(SCREEN_ID_HOME_SCREEN); + host_ui_tap(BUTTON_DOWN); + expect(home_shows(true), "the bottom button does not open the QR code"); + expect(qr_mark() == NULL && shown_label(lv_layer_top(), "Menu") == NULL, + "the strip keeps the marks of the home screen beside the QR code"); + host_ui_tap(BUTTON_DOWN); + expect(home_shows(true), "the bottom button acts on the QR code"); + host_ui_tap(BUTTON_BACK); + expect(home_shows(false), "the top button does not close the QR code"); + + char wifi[JETKVM_SCREEN_ACCESS_POINT_QR_TEXT_CAPACITY]; + snprintf(wifi, sizeof(wifi), "WIFI:T:WPA;S:%s;P:%s;;", ssid, text); + expect_code(code, wifi, "the QR code is not the symbol of the name and the password at 4 px a module"); + jetkvm_screen_access_point_qr_text("Mini;1 \"A\"", "a:b,c\\d", wifi); + expect(strcmp(wifi, "WIFI:T:WPA;S:Mini\\;1 \\\"A\\\";P:a\\:b\\,c\\\\d;;") == 0, + "the text of the QR code does not escape the special characters of a name and a password"); + + /* The strip's part of the panel, as jetkvm_screen_buttons.c has it: 26 px + * wide, from 52 px along the button edge. */ + host_ui_tap(BUTTON_DOWN); + for (size_t i = 0; i < sizeof(turns) / sizeof(turns[0]); ++i) { + jetkvm_screen_buttons_set_rotation(turns[i]); + lv_obj_update_layout(objects.home_screen); + lv_area_t box, symbol, header, inside; + lv_obj_get_coords(tile, &box); + lv_obj_get_coords(code, &symbol); + lv_obj_get_coords(objects.home_header_container, &header); + lv_obj_get_content_coords(objects.home_screen, &inside); + const jetkvm_screen_rect_t pillar = jetkvm_screen_pillar_rect(turns[i], 0, 52, 26, 188); + const bool clear = box.x2 < pillar.x || box.x1 >= pillar.x + pillar.w || + box.y2 < pillar.y || box.y1 >= pillar.y + pillar.h; + if (!home_shows(true) || lv_area_get_width(&symbol) != 33 * QR_MODULE || + lv_area_get_height(&symbol) != 33 * QR_MODULE || + symbol.x1 - box.x1 < QR_LEAST_MARGIN || box.x2 - symbol.x2 < QR_LEAST_MARGIN || + symbol.y1 - box.y1 < QR_LEAST_MARGIN || box.y2 - symbol.y2 < QR_LEAST_MARGIN || + box.y1 <= header.y2 || box.x1 < inside.x1 || box.x2 > inside.x2 || + box.y2 > inside.y2 || !clear) { + ++s_failures; + fprintf(stderr, + "Hotspot Mode: the QR code does not fit the home screen at %u degrees (tile " + "x %d to %d, y %d to %d; symbol x %d to %d, y %d to %d; header to %d; screen " + "x %d to %d, to y %d; strip x %d, y %d, %d x %d)\n", + (unsigned)turns[i], (int)box.x1, (int)box.x2, (int)box.y1, (int)box.y2, + (int)symbol.x1, (int)symbol.x2, (int)symbol.y1, (int)symbol.y2, (int)header.y2, + (int)inside.x1, (int)inside.x2, (int)inside.y2, pillar.x, pillar.y, pillar.w, + pillar.h); + } + } + + expect(!jetkvm_screen_access_point_apply(true, NULL, NULL), + "a state with the access point stopped reports a turn-on"); + jetkvm_screen_buttons_set_access_point(jetkvm_screen_access_point_runs()); + expect(home_shows(false), "the QR code stays on the home screen after the access point stopped"); + expect(qr_mark() == NULL, "the strip reads QR after the access point stopped"); + host_ui_tap(BUTTON_DOWN); + expect(lv_screen_active() == objects.menu_screen, + "the bottom button does not open the menu after the access point stopped"); + (void)jetkvm_screen_access_point_apply(true, ssid, text); + /* Mode off: the row goes and the entry reads Off again. */ - expect(!jetkvm_screen_access_point_apply(false, text), + expect(!jetkvm_screen_access_point_apply(false, ssid, text), "a state with the mode off reports a turn-on"); expect(hidden(row), "the password row stays on the home screen after the mode went off"); expect(lv_color_eq(lv_obj_get_style_text_color(objects.cloud_status_label, LV_PART_MAIN), @@ -235,8 +376,10 @@ int main(void) #else expect(entry == NULL && row == NULL, "the Ethernet board has a Hotspot Mode entry or a password row"); - expect(!jetkvm_screen_access_point_apply(true, "kq7n-x4pd-9hue"), + expect(!jetkvm_screen_access_point_apply(true, "JetKVM_A1B2C3", "kq7n-x4pd-9hue"), "the Ethernet board reports that access point mode turned on"); + expect(jetkvm_screen_access_point_qr_area() == NULL && !jetkvm_screen_access_point_runs(), + "the Ethernet board has a QR code of an access point"); #endif if (s_failures != 0) { @@ -244,7 +387,9 @@ int main(void) } puts(JETKVM_BOARD_WIFI ? "Hotspot Mode: third menu entry, hold asks for the other state, its name in the " - "header and the password row of the home screen fit at each strip edge: PASS" - : "Hotspot Mode: no entry and no password row on the Ethernet board: PASS"); + "header and the password row of the home screen fit at each strip edge, and the " + "bottom button opens the QR code of the name and the password, which fits at each " + "strip edge: PASS" + : "Hotspot Mode: no entry, no password row and no QR code on the Ethernet board: PASS"); return 0; } diff --git a/components/jetkvm_screen/tests/run_home_address_host_test.sh b/components/jetkvm_screen/tests/run_home_address_host_test.sh index 51bf9ca3..89e9f69a 100755 --- a/components/jetkvm_screen/tests/run_home_address_host_test.sh +++ b/components/jetkvm_screen/tests/run_home_address_host_test.sh @@ -8,8 +8,9 @@ # a hold on it asks to turn the setting off # (host_renderer/test_tailscale_only_menu.c); # - Menu > Hotspot Mode on the Wi-Fi board asks for the other state on a hold, -# and the home screen's row with the access point's password fits beside -# the strip at each edge (host_renderer/test_access_point_screen.c). +# the home screen's row with the access point's password fits beside the +# strip at each edge, and the bottom button opens the QR code of the access +# point there (host_renderer/test_access_point_screen.c). # Needs cmake, ninja and managed_components/lvgl__lvgl (idf.py reconfigure). set -euo pipefail diff --git a/docs/hardware-variants.md b/docs/hardware-variants.md index 8880af39..05b527fd 100644 --- a/docs/hardware-variants.md +++ b/docs/hardware-variants.md @@ -18,7 +18,7 @@ On the Wi-Fi board the TF card and the C5 share the P4's SDMMC controller on two ## Hotspot mode (Wi-Fi board) -Where there is no Wi-Fi network to join, the Wi-Fi board hosts its own. Hold Menu > Hotspot Mode on the display. The home screen then reads Hotspot in its header and shows the address `192.168.4.1`, the network name (`JetKVM_XXXXXX`) and the password. Join the network from a computer and open the address in a browser. +Where there is no Wi-Fi network to join, the Wi-Fi board hosts its own. Hold Menu > Hotspot Mode on the display. The home screen then reads Hotspot in its header and shows the address `192.168.4.1`, the network name (`JetKVM_XXXXXX`) and the password. Join the network from a computer and open the address in a browser. The button beside QR on the display shows a QR code that joins a phone to the network. - The network uses WPA2 on 2.4 GHz channel 1, 6 or 11, whichever has the least traffic at the start. The firmware sets no country, and these are channels that every country permits for an access point. - The password is made at the first boot and stays until a factory reset. diff --git a/sdkconfig.wifi.defaults b/sdkconfig.wifi.defaults index 58dfdb87..3ec99048 100644 --- a/sdkconfig.wifi.defaults +++ b/sdkconfig.wifi.defaults @@ -51,3 +51,6 @@ CONFIG_MDNS_PREDEF_NETIF_ETH=n # and the 16 px Montserrat face supplies its icons. CONFIG_JETKVM_SCREEN_BUTTONS=y CONFIG_LV_FONT_MONTSERRAT_16=y + +# Hotspot mode shows the QR code of its network on the display. +CONFIG_LV_USE_QRCODE=y From b56a173b1a475f9a601210dacb8325896513adc0 Mon Sep 17 00:00:00 2001 From: Adam Shiervani Date: Thu, 3 Dec 2026 11:17:17 +0100 Subject: [PATCH 2/3] Close the QR code when a device joins The user needs the address next, so the home screen's rows come back when one more device has joined the access point. --- components/jetkvm_screen/README.md | 4 +- components/jetkvm_screen/jetkvm_screen.c | 3 +- .../jetkvm_screen_access_point.c | 11 ++++- .../jetkvm_screen_access_point.h | 14 +++--- .../jetkvm_screen/jetkvm_screen_buttons.c | 5 ++- .../jetkvm_screen/jetkvm_screen_buttons.h | 7 +-- .../tests/host_renderer/render_ui_screens.c | 8 ++-- .../host_renderer/test_access_point_screen.c | 44 +++++++++++++++---- docs/hardware-variants.md | 2 +- 9 files changed, 70 insertions(+), 28 deletions(-) diff --git a/components/jetkvm_screen/README.md b/components/jetkvm_screen/README.md index 8e5f9ce9..5940ae18 100644 --- a/components/jetkvm_screen/README.md +++ b/components/jetkvm_screen/README.md @@ -30,7 +30,7 @@ The menu reads Set up Wi-Fi, Regulatory and Hotspot Mode (all three on the Wi-Fi On the Wi-Fi board, Menu > Hotspot Mode turns access point mode on and off (`jetkvm_screen_access_point.c`); the display and the web UI call the mode hotspot mode. The entry is on the menu in every state of the device and reads Hotspot Mode: Off or Hotspot Mode: On. A hold on it asks the handler of `jetkvm_screen_set_wifi_access_point_handler()` for the other state, and when the mode turns on the menu gives way to the home screen of the state. Until the access point runs, the no-network screen reads Hotspot Mode and Starting. Then the home screen shows the access point as it shows a joined network: `192.168.4.1` as the address and the network name in the Wi-Fi row, whose icon is green while a device has joined. The header reads Hotspot in the place of the cloud state and the session count, and a row with a padlock below the Wi-Fi row shows the password. The Wi-Fi driver (`jetkvm_c5_wifi`) owns the mode. -While the access point runs, the strip of the home screen reads QR in the place of the dot beside the Down button, and only the other button opens the menu. The Down button puts a QR code in the place of the rows below the header: a white tile with the Wi-Fi network text `WIFI:T:WPA;S:;P:;;`, which a phone's camera reads to join the access point. The symbol has 33 modules of 4 px (LVGL's QR code library, `CONFIG_LV_USE_QRCODE` in `sdkconfig.wifi.defaults`) and a light margin of 16 px, or 11 px with the strip at the top or the bottom, where the tile has less room. On the code the strip shows Back beside the Back button, which puts the rows back; the Down button does nothing. The code also closes when the access point stops. +While the access point runs, the strip of the home screen reads QR in the place of the dot beside the Down button, and only the other button opens the menu. The Down button puts a QR code in the place of the rows below the header: a white tile with the Wi-Fi network text `WIFI:T:WPA;S:;P:;;`, which a phone's camera reads to join the access point. The symbol has 33 modules of 4 px (LVGL's QR code library, `CONFIG_LV_USE_QRCODE` in `sdkconfig.wifi.defaults`) and a light margin of 16 px, or 11 px with the strip at the top or the bottom, where the tile has less room. On the code the strip shows Back beside the Back button, which puts the rows back; the Down button does nothing. The code also closes when a device joins, because the user needs the address next, and when the access point stops. While "Web interface through Tailscale only" is on, the Advanced menu starts with the entry Tailscale Only: On (`jetkvm_screen_tailscale_only.c`). A hold on it turns the setting off, with the RPC that the web UI sends, and the entry goes with the next state. The device does not restart. This is the way back for an owner whose Tailscale path stopped working. The entry is not on the page while the setting is off. @@ -58,4 +58,4 @@ Firmware boots in H.264-only mode. SW3 (active low; GPIO17 on the Wi-Fi board, G `components/jetkvm_screen/tests/run_host_tests.sh` runs the host tests. `components/jetkvm_screen/tests/render_ui_screens.sh wifi|ethernet` renders all twelve generated pages and, for `wifi`, the Regulatory page and the screens of access point mode to PPM (and PNG with ImageMagick) using the LVGL software renderer, with no hardware. The pages are laid out by the production button code, so each one has the button strip, and the home screen is also rendered with the widest IPv4 address and the strip at each edge. -`components/jetkvm_screen/tests/run_home_address_host_test.sh` lays out the home screen in the same way and fails when an IPv4 address crosses the end of its line or an IPv6 address does not fit its two lines or breaks at another colon, without the strip and with the strip at each edge. The same script runs `test_access_point_screen.c` on both boards: Menu > Hotspot Mode is the third entry of the Wi-Fi board's menu, a hold on it asks for the other state, and the name of the mode in the header and the password row of the home screen fit beside the strip at each edge with the widest name and password. While the access point runs, the Down button opens the QR code and the Back button closes it; the code is the symbol of the name and the password at 4 px a module, fits below the header and beside the strip at each edge, and closes when the access point stops. Both scripts need cmake, ninja and `managed_components/lvgl__lvgl`. +`components/jetkvm_screen/tests/run_home_address_host_test.sh` lays out the home screen in the same way and fails when an IPv4 address crosses the end of its line or an IPv6 address does not fit its two lines or breaks at another colon, without the strip and with the strip at each edge. The same script runs `test_access_point_screen.c` on both boards: Menu > Hotspot Mode is the third entry of the Wi-Fi board's menu, a hold on it asks for the other state, and the name of the mode in the header and the password row of the home screen fit beside the strip at each edge with the widest name and password. While the access point runs, the Down button opens the QR code and the Back button closes it; the code is the symbol of the name and the password at 4 px a module, fits below the header and beside the strip at each edge, and closes when a device joins and when the access point stops. Both scripts need cmake, ninja and `managed_components/lvgl__lvgl`. diff --git a/components/jetkvm_screen/jetkvm_screen.c b/components/jetkvm_screen/jetkvm_screen.c index c5f4ea8e..822b1155 100644 --- a/components/jetkvm_screen/jetkvm_screen.c +++ b/components/jetkvm_screen/jetkvm_screen.c @@ -1112,7 +1112,8 @@ static void apply_state(const jetkvm_screen_state_t *state) state->wifi_setup_stoppable); if (jetkvm_screen_access_point_apply(state->wifi_ap, access_point ? state->wifi_ap_ssid : NULL, - access_point ? state->wifi_ap_password : NULL)) { + access_point ? state->wifi_ap_password : NULL, + state->wifi_ap_stations)) { s_wifi_access_point_turned_on = true; } jetkvm_screen_buttons_set_access_point(jetkvm_screen_access_point_runs()); diff --git a/components/jetkvm_screen/jetkvm_screen_access_point.c b/components/jetkvm_screen/jetkvm_screen_access_point.c index ad13a78d..158b6592 100644 --- a/components/jetkvm_screen/jetkvm_screen_access_point.c +++ b/components/jetkvm_screen/jetkvm_screen_access_point.c @@ -15,6 +15,7 @@ static lv_obj_t *s_entry, *s_row, *s_qr_area; #if JETKVM_BOARD_WIFI static lv_obj_t *s_entry_label, *s_password, *s_qr_tile, *s_qr; static bool s_enabled; +static uint8_t s_stations; static char s_qr_text[JETKVM_SCREEN_ACCESS_POINT_QR_TEXT_CAPACITY]; #define COLOR_ICON 0x808080 /* The text for the device's own name and password is 45 bytes, which the QR @@ -183,7 +184,8 @@ void jetkvm_screen_access_point_init(void) #endif } -bool jetkvm_screen_access_point_apply(bool enabled, const char *ssid, const char *password) +bool jetkvm_screen_access_point_apply(bool enabled, const char *ssid, const char *password, + uint8_t stations) { #if JETKVM_BOARD_WIFI if (s_entry == NULL) { @@ -200,9 +202,13 @@ bool jetkvm_screen_access_point_apply(bool enabled, const char *ssid, const char } if (shown) { qr_update(ssid != NULL ? ssid : "", password); - } else { + } + /* The code has done its work when a device joins: the user needs the + * address next. */ + if (!shown || stations > s_stations) { jetkvm_screen_access_point_qr_show(false); } + s_stations = shown ? stations : 0; if (shown == lv_obj_has_flag(s_row, LV_OBJ_FLAG_HIDDEN)) { /* The header's right side names the mode. The cloud is out of reach * from the access point's network, so its icon goes; the caller sets @@ -224,6 +230,7 @@ bool jetkvm_screen_access_point_apply(bool enabled, const char *ssid, const char (void)enabled; (void)ssid; (void)password; + (void)stations; return false; #endif } diff --git a/components/jetkvm_screen/jetkvm_screen_access_point.h b/components/jetkvm_screen/jetkvm_screen_access_point.h index b954cd89..bfc5ee1d 100644 --- a/components/jetkvm_screen/jetkvm_screen_access_point.h +++ b/components/jetkvm_screen/jetkvm_screen_access_point.h @@ -1,6 +1,7 @@ #pragma once #include +#include #include "lvgl.h" @@ -23,7 +24,8 @@ * The home screen can also show a QR code that a phone's camera reads to * join the access point. The code takes the place of the rows below the * header, which stays. The button code opens and closes it - * (jetkvm_screen_buttons.c). All calls run with LVGL owned by the caller. + * (jetkvm_screen_buttons.c), and it closes when a device joins. All calls run + * with LVGL owned by the caller. */ /* Room for the text of the QR code with the longest name, with each of its @@ -36,12 +38,14 @@ void jetkvm_screen_access_point_init(void); /* `enabled`: the mode is on. `ssid` and `password`: the name and the password * while the access point runs, else NULL; the home screen names the mode and - * shows the row only with a password. In the state after the last one with a - * password, the caller sets the header's cloud state and session count - * again, and the QR code closes. + * shows the row only with a password. `stations`: the devices that have + * joined; the QR code closes when one more has. In the state after the last + * one with a password, the caller sets the header's cloud state and session + * count again, and the QR code closes. * Returns true when the mode turned on with this call, so that the caller * leaves the menu for the home screen. */ -bool jetkvm_screen_access_point_apply(bool enabled, const char *ssid, const char *password); +bool jetkvm_screen_access_point_apply(bool enabled, const char *ssid, const char *password, + uint8_t stations); /* The home screen shows the access point: its QR code can open. */ bool jetkvm_screen_access_point_runs(void); diff --git a/components/jetkvm_screen/jetkvm_screen_buttons.c b/components/jetkvm_screen/jetkvm_screen_buttons.c index edb80759..20701cf5 100644 --- a/components/jetkvm_screen/jetkvm_screen_buttons.c +++ b/components/jetkvm_screen/jetkvm_screen_buttons.c @@ -149,6 +149,8 @@ static bool s_wifi_setup, s_wifi_setup_stoppable; /* Advanced > Tailscale Only is on the page. */ static bool s_tailscale_only; static bool s_access_point; +/* The strip as changed() drew it last: for the QR code or not. */ +static bool s_qr_strip; /* The no-network screen while Wi-Fi setup from the menu runs. */ static bool wifi_setup_page(void) @@ -353,6 +355,7 @@ static void changed(lv_event_t *event) lv_obj_t *screen = lv_screen_active(); item_count = selection = 0; hold_accept = NULL; + s_qr_strip = qr_view(); if (screen == objects.menu_screen) { /* In the order of jetkvm_screen_regulatory_init() and * jetkvm_screen_access_point_init(). */ @@ -749,7 +752,7 @@ void jetkvm_screen_buttons_set_tailscale_only(bool shown) void jetkvm_screen_buttons_set_access_point(bool runs) { - if (runs == s_access_point) { + if (runs == s_access_point && qr_view() == s_qr_strip) { return; } s_access_point = runs; diff --git a/components/jetkvm_screen/jetkvm_screen_buttons.h b/components/jetkvm_screen/jetkvm_screen_buttons.h index 1cd9b867..f72a7b12 100644 --- a/components/jetkvm_screen/jetkvm_screen_buttons.h +++ b/components/jetkvm_screen/jetkvm_screen_buttons.h @@ -42,9 +42,10 @@ void jetkvm_screen_buttons_set_rotation(uint16_t degrees); * entries that are on the page. */ void jetkvm_screen_buttons_set_tailscale_only(bool shown); -/* The home screen shows the access point, or no longer does: while it - * `runs`, the bottom button opens the QR code of the access point there, the - * strip reads QR beside that button, and the top button closes the code. */ +/* Call after each jetkvm_screen_access_point_apply(), which can close the QR + * code. While the access point `runs`, the bottom button opens the QR code on + * the home screen, the strip reads QR beside that button, and the top button + * closes the code. */ void jetkvm_screen_buttons_set_access_point(bool runs); #else diff --git a/components/jetkvm_screen/tests/host_renderer/render_ui_screens.c b/components/jetkvm_screen/tests/host_renderer/render_ui_screens.c index 23b0108d..09ef386d 100644 --- a/components/jetkvm_screen/tests/host_renderer/render_ui_screens.c +++ b/components/jetkvm_screen/tests/host_renderer/render_ui_screens.c @@ -217,11 +217,11 @@ int main(int argc, char **argv) render_active(argv[1], SCREEN_ID_MENU_SCREEN, "menu-access-point-off") != 0) { return 1; } - if (!jetkvm_screen_access_point_apply(true, NULL, NULL) || + if (!jetkvm_screen_access_point_apply(true, NULL, NULL, 0) || render_active(argv[1], SCREEN_ID_MENU_SCREEN, "menu-access-point-on") != 0) { return 1; } - (void)jetkvm_screen_access_point_apply(false, NULL, NULL); + (void)jetkvm_screen_access_point_apply(false, NULL, NULL, 0); #else /* The Ethernet board has no Regulatory entry and no such page: the menu * holds Advanced, Status and About, in that order, beside the hidden @@ -285,7 +285,7 @@ int main(int argc, char **argv) } jetkvm_screen_home_address_set("192.168.4.1"); (void)host_ui_wifi_row("JetKVM_A1B2C3", 0x22c55e); - (void)jetkvm_screen_access_point_apply(true, "JetKVM_A1B2C3", "kq7n-x4pd-9hue"); + (void)jetkvm_screen_access_point_apply(true, "JetKVM_A1B2C3", "kq7n-x4pd-9hue", 1); jetkvm_screen_buttons_set_access_point(true); loadScreen(SCREEN_ID_HOME_SCREEN); for (size_t i = 0; i < sizeof(turns) / sizeof(turns[0]); ++i) { @@ -310,7 +310,7 @@ int main(int argc, char **argv) } } jetkvm_screen_buttons_set_rotation(0); - (void)jetkvm_screen_access_point_apply(false, NULL, NULL); + (void)jetkvm_screen_access_point_apply(false, NULL, NULL, 0); jetkvm_screen_buttons_set_access_point(false); lv_label_set_text(objects.cloud_status_label, "1 active"); #endif diff --git a/components/jetkvm_screen/tests/host_renderer/test_access_point_screen.c b/components/jetkvm_screen/tests/host_renderer/test_access_point_screen.c index 85d8b8e1..a7d0880b 100644 --- a/components/jetkvm_screen/tests/host_renderer/test_access_point_screen.c +++ b/components/jetkvm_screen/tests/host_renderer/test_access_point_screen.c @@ -6,8 +6,9 @@ * a row below the Wi-Fi row, whole and clear of the other lines, beside the * button strip at each edge. While the access point runs, the strip reads QR * beside the bottom button, which puts the QR code of the access point in the - * place of the home screen's rows; the top button puts the rows back. The - * Ethernet board has neither the entry nor the row nor the code. + * place of the home screen's rows; the top button puts the rows back, and so + * does a device that joins. The Ethernet board has neither the entry nor the + * row nor the code. */ #include #include @@ -194,9 +195,9 @@ int main(void) * that the mode turned on, later ones do not. The entry reads On, and * the home screen has no password yet. */ expect(hidden(row), "the home screen shows the password row while the mode is off"); - expect(jetkvm_screen_access_point_apply(true, NULL, NULL), + expect(jetkvm_screen_access_point_apply(true, NULL, NULL, 0), "the first state with the mode on does not report the turn-on"); - expect(!jetkvm_screen_access_point_apply(true, NULL, NULL), + expect(!jetkvm_screen_access_point_apply(true, NULL, NULL, 0), "a later state with the mode on reports a turn-on again"); expect(strcmp(lv_label_get_text(label), "Hotspot Mode: On") == 0, "the entry does not read Hotspot Mode: On while the mode is on"); @@ -228,7 +229,7 @@ int main(void) letter, letter, letter, letter, letter, letter, letter, letter); jetkvm_screen_home_address_set("192.168.4.1"); lv_obj_t *wifi_row = host_ui_wifi_row(ssid, 0x22c55e); - expect(!jetkvm_screen_access_point_apply(true, ssid, text), + expect(!jetkvm_screen_access_point_apply(true, ssid, text, 0), "a state with the access point running reports a turn-on"); expect(!hidden(row), "the home screen does not show the password row while the access point runs"); expect(strcmp(lv_label_get_text(objects.cloud_status_label), "Hotspot") == 0 && @@ -354,7 +355,32 @@ int main(void) } } - expect(!jetkvm_screen_access_point_apply(true, NULL, NULL), + static const struct { + uint8_t stations; + bool code; + const char *what; + } joins[] = { + {0, true, "the QR code closed while no device has joined"}, + {1, false, "the QR code stays on the home screen after a device joined"}, + {1, true, "the QR code does not open again while a device is joined"}, + {1, true, "the QR code closed without one more device"}, + {0, true, "the QR code closed when a device left"}, + {1, false, "the QR code stays on the home screen after a device joined again"}, + }; + jetkvm_screen_buttons_set_rotation(0); + for (size_t i = 0; i < sizeof(joins) / sizeof(joins[0]); ++i) { + if (!home_shows(true)) { + host_ui_tap(BUTTON_DOWN); + } + (void)jetkvm_screen_access_point_apply(true, ssid, text, joins[i].stations); + jetkvm_screen_buttons_set_access_point(jetkvm_screen_access_point_runs()); + expect(home_shows(joins[i].code), joins[i].what); + expect((qr_mark() == NULL) == joins[i].code, + "the strip does not follow the QR code that a joined device closed"); + } + host_ui_tap(BUTTON_DOWN); + + expect(!jetkvm_screen_access_point_apply(true, NULL, NULL, 0), "a state with the access point stopped reports a turn-on"); jetkvm_screen_buttons_set_access_point(jetkvm_screen_access_point_runs()); expect(home_shows(false), "the QR code stays on the home screen after the access point stopped"); @@ -362,10 +388,10 @@ int main(void) host_ui_tap(BUTTON_DOWN); expect(lv_screen_active() == objects.menu_screen, "the bottom button does not open the menu after the access point stopped"); - (void)jetkvm_screen_access_point_apply(true, ssid, text); + (void)jetkvm_screen_access_point_apply(true, ssid, text, 0); /* Mode off: the row goes and the entry reads Off again. */ - expect(!jetkvm_screen_access_point_apply(false, ssid, text), + expect(!jetkvm_screen_access_point_apply(false, ssid, text, 0), "a state with the mode off reports a turn-on"); expect(hidden(row), "the password row stays on the home screen after the mode went off"); expect(lv_color_eq(lv_obj_get_style_text_color(objects.cloud_status_label, LV_PART_MAIN), @@ -376,7 +402,7 @@ int main(void) #else expect(entry == NULL && row == NULL, "the Ethernet board has a Hotspot Mode entry or a password row"); - expect(!jetkvm_screen_access_point_apply(true, "JetKVM_A1B2C3", "kq7n-x4pd-9hue"), + expect(!jetkvm_screen_access_point_apply(true, "JetKVM_A1B2C3", "kq7n-x4pd-9hue", 0), "the Ethernet board reports that access point mode turned on"); expect(jetkvm_screen_access_point_qr_area() == NULL && !jetkvm_screen_access_point_runs(), "the Ethernet board has a QR code of an access point"); diff --git a/docs/hardware-variants.md b/docs/hardware-variants.md index 05b527fd..f0ce9669 100644 --- a/docs/hardware-variants.md +++ b/docs/hardware-variants.md @@ -18,7 +18,7 @@ On the Wi-Fi board the TF card and the C5 share the P4's SDMMC controller on two ## Hotspot mode (Wi-Fi board) -Where there is no Wi-Fi network to join, the Wi-Fi board hosts its own. Hold Menu > Hotspot Mode on the display. The home screen then reads Hotspot in its header and shows the address `192.168.4.1`, the network name (`JetKVM_XXXXXX`) and the password. Join the network from a computer and open the address in a browser. The button beside QR on the display shows a QR code that joins a phone to the network. +Where there is no Wi-Fi network to join, the Wi-Fi board hosts its own. Hold Menu > Hotspot Mode on the display. The home screen then reads Hotspot in its header and shows the address `192.168.4.1`, the network name (`JetKVM_XXXXXX`) and the password. Join the network from a computer and open the address in a browser. The button beside QR on the display shows a QR code that joins a phone to the network; the address comes back when the phone has joined. - The network uses WPA2 on 2.4 GHz channel 1, 6 or 11, whichever has the least traffic at the start. The firmware sets no country, and these are channels that every country permits for an access point. - The password is made at the first boot and stays until a factory reset. From 42272b9a4b4589f327a471ad42232d5874a7b228 Mon Sep 17 00:00:00 2001 From: Adam Shiervani Date: Thu, 3 Dec 2026 11:25:37 +0100 Subject: [PATCH 3/3] Give the button slice tests the QR code names test_wake_press.py and test_usb_debugging_screen.py compile a slice of jetkvm_screen_buttons.c with their own stand-ins. The wake test also checks that a press on a dark display neither opens nor closes the QR code. --- .../test_usb_debugging_screen.py | 5 +++ .../tests/local_display/test_wake_press.py | 36 +++++++++++++++++-- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/components/jetkvm_screen/tests/local_display/test_usb_debugging_screen.py b/components/jetkvm_screen/tests/local_display/test_usb_debugging_screen.py index bac622a6..24fb56e5 100644 --- a/components/jetkvm_screen/tests/local_display/test_usb_debugging_screen.py +++ b/components/jetkvm_screen/tests/local_display/test_usb_debugging_screen.py @@ -105,6 +105,7 @@ def cut(source: str, start: str, end: str) -> str: static lv_obj_t icon_top, icon_bottom, dot_top, dot_bottom, track_obj, fill_obj; static lv_obj_t *top_icon = &icon_top, *bottom_icon = &icon_bottom, *top_dot = &dot_top, *bottom_dot = &dot_bottom, *track = &track_obj, *fill = &fill_obj; +static lv_obj_t mark_obj, *qr_mark = &mark_obj; static lv_obj_t *items[5]; static lv_obj_t *jetkvm_screen_regulatory_screen(void) { return NULL; } /* Advanced > Tailscale Only, which is on the page while its setting is on. */ @@ -130,6 +131,10 @@ def cut(source: str, start: str, end: str) -> str: static bool wifi_setup_page(void) { return false; } static bool wifi_setup_hold(void) { return false; } static bool home(void) { return false; } +static bool qr_offer(void) { return false; } +static bool qr_view(void) { return false; } +static void jetkvm_screen_access_point_qr_show(bool shown) { (void)shown; } +static void changed(void *event) { (void)event; } static void focus(void) {} static void action_switch_to_menu(void *event) { (void)event; } static void loadScreen(int id) { (void)id; } diff --git a/components/jetkvm_screen/tests/local_display/test_wake_press.py b/components/jetkvm_screen/tests/local_display/test_wake_press.py index 7a9016d8..5d13c2df 100644 --- a/components/jetkvm_screen/tests/local_display/test_wake_press.py +++ b/components/jetkvm_screen/tests/local_display/test_wake_press.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 """Run the production button press, hold and release handlers against a display that the off timer has made dark, one that the dim timer has dimmed, -a lit one, and the HDMI preview.""" +a lit one, the QR code of the access point, and the HDMI preview.""" from pathlib import Path import subprocess import tempfile @@ -43,6 +43,8 @@ static lv_obj_t icon_top, icon_bottom, dot_top, dot_bottom, track_obj, fill_obj; static lv_obj_t *top_icon = &icon_top, *bottom_icon = &icon_bottom, *top_dot = &dot_top, *bottom_dot = &dot_bottom, *track = &track_obj, *fill = &fill_obj; +static lv_obj_t mark_obj, *qr_mark = &mark_obj; +static bool access_point, qr_open; static lv_obj_t *items[5]; static lv_obj_t *hold_accept; static unsigned selection, item_count; @@ -67,7 +69,11 @@ static lv_obj_t *lv_screen_active(void) { return active_screen; } static bool wifi_setup_page(void) { return false; } static bool wifi_setup_hold(void) { return false; } -static bool home(void) { return active_screen == &home_screen; } +static bool qr_view(void) { return qr_open; } +static bool home(void) { return active_screen == &home_screen && !qr_open; } +static bool qr_offer(void) { return access_point && home(); } +static void jetkvm_screen_access_point_qr_show(bool shown) { qr_open = shown; } +static void changed(void *event) { (void)event; } static void focus(void) {} static void action_switch_to_menu(void *event) { (void)event; menu_opens++; } static void loadScreen(int id) { (void)id; back_loads++; } @@ -136,6 +142,32 @@ assert(wakes == 3 && backlight == LIT && menu_opens == 2); } + /* Home screen with the access point: a bottom press on a dark display + * does not open the QR code, and a top press on a dark display does not + * close it; on a dimmed display both act. No press on the code opens the + * menu. */ + active_screen = &home_screen; + item_count = 0; + access_point = true; + reset_counts(); + backlight = DARK; + press(BUTTON_BOTTOM, 50); + assert(wakes == 1 && backlight == LIT && !qr_open); + backlight = DIMMED; + press(BUTTON_BOTTOM, 50); + assert(wakes == 2 && qr_open); + press(BUTTON_BOTTOM, 50); + assert(qr_open); + backlight = DARK; + press(BUTTON_TOP, 50); + assert(wakes == 4 && qr_open); + backlight = DIMMED; + press(BUTTON_TOP, 50); + assert(wakes == 5 && !qr_open && menu_opens == 0); + press(BUTTON_TOP, 50); + assert(menu_opens == 1); + access_point = false; + /* Menu: a top tap on a dark display does not go back; on a dimmed * display it does. */ show(&menu_screen, &status_btn, &about_btn);