From b8a577a4ef339eaed3553bdcae4d1df8817e4dbd Mon Sep 17 00:00:00 2001 From: mverch67 Date: Sun, 24 Nov 2024 21:37:58 +0100 Subject: [PATCH] add qr code, auto channel name for primary --- generated/ui_320x240/images.c | 3 +- generated/ui_320x240/images.h | 3 +- generated/ui_320x240/screens.c | 51 ++++++++- generated/ui_320x240/screens.h | 3 + .../ui_320x240/ui_image_key_generate_image.c | 73 ++++++++++++ include/TFTView_320x240.h | 5 + include/lv_conf.h | 4 +- source/TFTView_320x240.cpp | 107 ++++++++++++++++-- 8 files changed, 232 insertions(+), 17 deletions(-) create mode 100644 generated/ui_320x240/ui_image_key_generate_image.c diff --git a/generated/ui_320x240/images.c b/generated/ui_320x240/images.c index 3d9af63..6b92cdf 100644 --- a/generated/ui_320x240/images.c +++ b/generated/ui_320x240/images.c @@ -1,6 +1,6 @@ #include "images.h" -const ext_img_desc_t images[61] = { +const ext_img_desc_t images[62] = { { "meshtastic_boot_logo_image", &img_meshtastic_boot_logo_image }, { "settings_button_image", &img_settings_button_image }, { "map_button_image", &img_map_button_image }, @@ -62,4 +62,5 @@ const ext_img_desc_t images[61] = { { "top_lora_image", &img_top_lora_image }, { "home_bell_image", &img_home_bell_image }, { "home_bell_slash_image", &img_home_bell_slash_image }, + { "key_generate_image", &img_key_generate_image }, }; diff --git a/generated/ui_320x240/images.h b/generated/ui_320x240/images.h index aa6ad96..03fb913 100644 --- a/generated/ui_320x240/images.h +++ b/generated/ui_320x240/images.h @@ -68,6 +68,7 @@ extern const lv_img_dsc_t img_home_lora_image; extern const lv_img_dsc_t img_top_lora_image; extern const lv_img_dsc_t img_home_bell_image; extern const lv_img_dsc_t img_home_bell_slash_image; +extern const lv_img_dsc_t img_key_generate_image; #ifndef EXT_IMG_DESC_T #define EXT_IMG_DESC_T @@ -77,7 +78,7 @@ typedef struct _ext_img_desc_t { } ext_img_desc_t; #endif -extern const ext_img_desc_t images[61]; +extern const ext_img_desc_t images[62]; #ifdef __cplusplus diff --git a/generated/ui_320x240/screens.c b/generated/ui_320x240/screens.c index d7d2b2e..49c6299 100644 --- a/generated/ui_320x240/screens.c +++ b/generated/ui_320x240/screens.c @@ -2093,6 +2093,7 @@ void create_screen_main_screen() { lv_obj_set_pos(obj, -5, 0); lv_obj_set_size(obj, 24, 24); lv_img_set_pivot(obj, 0, 0); + lv_obj_clear_flag(obj, LV_OBJ_FLAG_SCROLLABLE); add_style_top_image_style(obj); lv_obj_set_style_bg_image_src(obj, &img_top_map_image, LV_PART_MAIN | LV_STATE_DEFAULT); lv_obj_set_style_align(obj, LV_ALIGN_LEFT_MID, LV_PART_MAIN | LV_STATE_DEFAULT); @@ -3937,6 +3938,18 @@ void create_screen_main_screen() { lv_obj_set_style_pad_left(obj, 0, LV_PART_MAIN | LV_STATE_DEFAULT); lv_obj_set_style_pad_right(obj, 0, LV_PART_MAIN | LV_STATE_DEFAULT); } + { + // SettingsModifyChannelKeyGenerateButton + lv_obj_t *obj = lv_btn_create(parent_obj); + objects.settings_modify_channel_key_generate_button = obj; + lv_obj_set_pos(obj, 224, 54); + lv_obj_set_size(obj, 25, 24); + lv_obj_set_style_align(obj, LV_ALIGN_DEFAULT, LV_PART_MAIN | LV_STATE_DEFAULT); + lv_obj_set_style_bg_color(obj, lv_color_hex(0xffffffff), LV_PART_MAIN | LV_STATE_DEFAULT); + lv_obj_set_style_bg_image_src(obj, &img_key_generate_image, LV_PART_MAIN | LV_STATE_DEFAULT); + lv_obj_set_style_bg_image_recolor(obj, lv_color_hex(0xff373737), LV_PART_MAIN | LV_STATE_DEFAULT); + lv_obj_set_style_bg_image_recolor_opa(obj, 255, LV_PART_MAIN | LV_STATE_DEFAULT); + } { // KeyboardButton_4 lv_obj_t *obj = lv_btn_create(parent_obj); @@ -3972,9 +3985,43 @@ void create_screen_main_screen() { lv_obj_set_style_pad_bottom(obj, 0, LV_PART_MAIN | LV_STATE_DEFAULT); lv_obj_set_style_bg_opa(obj, 0, LV_PART_MAIN | LV_STATE_DEFAULT); lv_obj_set_style_border_width(obj, 0, LV_PART_MAIN | LV_STATE_DEFAULT); - create_user_widget_ok_cancel_widget(obj, 323); + create_user_widget_ok_cancel_widget(obj, 324); lv_obj_set_style_align(obj, LV_ALIGN_BOTTOM_MID, LV_PART_MAIN | LV_STATE_DEFAULT); } + { + // SettingsModifyChannelQrPanel + lv_obj_t *obj = lv_obj_create(parent_obj); + objects.settings_modify_channel_qr_panel = obj; + lv_obj_set_pos(obj, 0, 0); + lv_obj_set_size(obj, LV_PCT(80), LV_PCT(100)); + lv_obj_add_flag(obj, LV_OBJ_FLAG_HIDDEN); + lv_obj_clear_flag(obj, LV_OBJ_FLAG_SCROLLABLE); + lv_obj_set_scrollbar_mode(obj, LV_SCROLLBAR_MODE_OFF); + lv_obj_set_style_align(obj, LV_ALIGN_TOP_MID, LV_PART_MAIN | LV_STATE_DEFAULT); + lv_obj_set_style_max_width(obj, 300, LV_PART_MAIN | LV_STATE_DEFAULT); + lv_obj_set_style_max_height(obj, 300, LV_PART_MAIN | LV_STATE_DEFAULT); + lv_obj_set_style_border_width(obj, 0, LV_PART_MAIN | LV_STATE_DEFAULT); + lv_obj_set_style_bg_opa(obj, 0, LV_PART_MAIN | LV_STATE_DEFAULT); + lv_obj_set_style_pad_top(obj, 0, LV_PART_MAIN | LV_STATE_DEFAULT); + lv_obj_set_style_pad_bottom(obj, 0, LV_PART_MAIN | LV_STATE_DEFAULT); + lv_obj_set_style_pad_left(obj, 0, LV_PART_MAIN | LV_STATE_DEFAULT); + lv_obj_set_style_pad_right(obj, 0, LV_PART_MAIN | LV_STATE_DEFAULT); + { + lv_obj_t *parent_obj = obj; + { + // SettingsModifyChannelQrButton + lv_obj_t *obj = lv_btn_create(parent_obj); + objects.settings_modify_channel_qr_button = obj; + lv_obj_set_pos(obj, 0, 0); + lv_obj_set_size(obj, LV_PCT(100), LV_PCT(100)); + lv_obj_set_style_bg_opa(obj, 0, LV_PART_MAIN | LV_STATE_DEFAULT); + lv_obj_set_style_pad_top(obj, 0, LV_PART_MAIN | LV_STATE_DEFAULT); + lv_obj_set_style_pad_bottom(obj, 0, LV_PART_MAIN | LV_STATE_DEFAULT); + lv_obj_set_style_pad_left(obj, 0, LV_PART_MAIN | LV_STATE_DEFAULT); + lv_obj_set_style_pad_right(obj, 0, LV_PART_MAIN | LV_STATE_DEFAULT); + } + } + } } } { @@ -5408,7 +5455,7 @@ void tick_screen_main_screen() { tick_user_widget_ok_cancel_widget(298); tick_user_widget_ok_cancel_widget(305); tick_user_widget_ok_cancel_widget(311); - tick_user_widget_ok_cancel_widget(323); + tick_user_widget_ok_cancel_widget(324); } void create_screen_blank_screen() { diff --git a/generated/ui_320x240/screens.h b/generated/ui_320x240/screens.h index df4ec18..81a054a 100644 --- a/generated/ui_320x240/screens.h +++ b/generated/ui_320x240/screens.h @@ -386,12 +386,15 @@ typedef struct _objects_t { lv_obj_t *keyboard_button_3; lv_obj_t *obj18; lv_obj_t *settings_modify_channel_psk_textarea; + lv_obj_t *settings_modify_channel_key_generate_button; lv_obj_t *keyboard_button_4; lv_obj_t *settings_modify_trash_button; lv_obj_t *obj19; lv_obj_t *obj19__ok_cancel_panel_w; lv_obj_t *obj19__ok_button_w; lv_obj_t *obj19__cancel_button_w; + lv_obj_t *settings_modify_channel_qr_panel; + lv_obj_t *settings_modify_channel_qr_button; lv_obj_t *node_options_panel; lv_obj_t *node_options_tab_view; lv_obj_t *tab_page_filter; diff --git a/generated/ui_320x240/ui_image_key_generate_image.c b/generated/ui_320x240/ui_image_key_generate_image.c new file mode 100644 index 0000000..832571c --- /dev/null +++ b/generated/ui_320x240/ui_image_key_generate_image.c @@ -0,0 +1,73 @@ +#ifdef __has_include + #if __has_include("lvgl.h") + #ifndef LV_LVGL_H_INCLUDE_SIMPLE + #define LV_LVGL_H_INCLUDE_SIMPLE + #endif + #endif +#endif + +#if defined(LV_LVGL_H_INCLUDE_SIMPLE) +#include "lvgl.h" +#elif defined(LV_BUILD_TEST) +#include "../lvgl.h" +#else +#include "lvgl/lvgl.h" +#endif + + +#ifndef LV_ATTRIBUTE_MEM_ALIGN +#define LV_ATTRIBUTE_MEM_ALIGN +#endif + +#ifndef LV_ATTRIBUTE_IMG_KEY_GENERATE_IMAGE +#define LV_ATTRIBUTE_IMG_KEY_GENERATE_IMAGE +#endif + +static const +LV_ATTRIBUTE_MEM_ALIGN LV_ATTRIBUTE_LARGE_CONST LV_ATTRIBUTE_IMG_KEY_GENERATE_IMAGE +uint8_t img_key_generate_image_map[] = { + + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xdb,0xde,0x41,0x08,0xfb,0xde,0xfb,0xde,0xfb,0xde,0xfb,0xde,0x45,0x29,0xdb,0xde,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0xba,0xd6,0xfb,0xde,0xfb,0xde,0xfb,0xde,0x1c,0xe7,0xfb,0xde,0xfb,0xde,0xfb,0xde,0xfb,0xde,0x1c,0xe7,0xfb,0xde,0xfb,0xde,0xfb,0xde,0xba,0xd6,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0xdb,0xde,0x1c,0xe7,0xfb,0xde,0x1c,0xe7,0xfb,0xde,0xfb,0xde,0xfb,0xde,0x1c,0xe7,0x1c,0xe7,0x1c,0xe7,0x1c,0xe7,0xfb,0xde,0xfb,0xde,0xfb,0xde,0x1c,0xe7,0xfb,0xde,0x1c,0xe7,0xdb,0xde,0x00,0x00, + 0x00,0x00,0x1c,0xe7,0x1c,0xe7,0xfb,0xde,0xfb,0xde,0x1c,0xe7,0x1c,0xe7,0x1c,0xe7,0x1c,0xe7,0xfb,0xde,0x1c,0xe7,0x1c,0xe7,0x1c,0xe7,0x1c,0xe7,0x1c,0xe7,0xfb,0xde,0xfb,0xde,0x1c,0xe7,0x1c,0xe7,0x00,0x00, + 0x00,0x00,0xfb,0xde,0xfb,0xde,0x1c,0xe7,0x1c,0xe7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0xfb,0xde,0xfb,0xde,0xfb,0xde,0x1c,0xe7,0x1c,0xe7,0xfb,0xde,0xfb,0xde,0xfb,0xde,0xfb,0xde,0x1c,0xe7,0x1c,0xe7,0xfb,0xde,0xfb,0xde,0xfb,0xde,0xfb,0xde,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0xb6,0xb5,0xfb,0xde,0xfb,0xde,0xfb,0xde,0xfb,0xde,0x1c,0xe7,0x1c,0xe7,0x1c,0xe7,0x1c,0xe7,0x1c,0xe7,0x1c,0xe7,0xfb,0xde,0xfb,0xde,0xfb,0xde,0xfb,0xde,0x96,0xb5,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x75,0xad,0xfb,0xde,0xfb,0xde,0x1c,0xe7,0xfb,0xde,0x1c,0xe7,0x1c,0xe7,0x1c,0xe7,0x1c,0xe7,0xfb,0xde,0x1c,0xe7,0xfb,0xde,0xfb,0xde,0x55,0xad,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xfb,0xde,0xdb,0xde,0xfb,0xde,0xfb,0xde,0xfb,0xde,0xfb,0xde,0xfb,0xde,0xfb,0xde,0xdb,0xde,0xfb,0xde,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x9a,0xd6,0xfb,0xde,0xfb,0xde,0xfb,0xde,0xfb,0xde,0xfb,0xde,0xfb,0xde,0x9a,0xd6,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0e,0x3b,0x3b,0x0e,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x05,0x2c,0x75,0xc5,0xf6,0xf6,0xc5,0x75,0x2c,0x05,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x12,0x5a,0xac,0xeb,0xfd,0xda,0x93,0x93,0xda,0xfd,0xec,0xac,0x5a,0x12,0x00,0x00,0x00, + 0x00,0x00,0x19,0xb3,0xfd,0xec,0xac,0x5b,0x1b,0x00,0x00,0x1b,0x5b,0xac,0xec,0xfd,0xb4,0x19,0x00,0x00,0x00,0x00,0x64,0xfe,0x96,0x2b,0x05,0x00,0x00,0x02,0x02,0x00,0x00,0x05,0x2b,0x96,0xfe,0x65,0x00,0x00, + 0x00,0x00,0x80,0xf7,0x39,0x00,0x00,0x01,0x48,0xa7,0xa7,0x48,0x01,0x00,0x00,0x39,0xf7,0x80,0x00,0x00,0x00,0x00,0x80,0xf6,0x39,0x00,0x00,0x38,0xe7,0xf0,0xf0,0xe7,0x38,0x00,0x00,0x39,0xf6,0x80,0x00,0x00, + 0x00,0x00,0x80,0xf6,0x39,0x00,0x00,0x77,0xfe,0x5a,0x5a,0xfd,0x78,0x00,0x00,0x39,0xf6,0x80,0x00,0x00,0x00,0x00,0x80,0xf6,0x39,0x00,0x00,0x60,0xfd,0xa5,0xa5,0xfd,0x60,0x00,0x00,0x39,0xf6,0x81,0x00,0x00, + 0x00,0x00,0x78,0xfa,0x43,0x00,0x00,0x13,0xa5,0xfd,0xfd,0xa5,0x13,0x00,0x00,0x43,0xfa,0x78,0x00,0x00,0x00,0x00,0x50,0xfc,0x7d,0x00,0x00,0x00,0x16,0xd1,0xd1,0x16,0x00,0x00,0x00,0x7c,0xfc,0x50,0x00,0x00, + 0x00,0x00,0x17,0xd0,0xdd,0x29,0x00,0x00,0x0b,0xcb,0xcb,0x0b,0x00,0x00,0x29,0xdd,0xd0,0x17,0x00,0x00,0x00,0x00,0x00,0x5d,0xfa,0xb5,0x18,0x00,0x03,0x75,0x75,0x03,0x00,0x18,0xb5,0xfa,0x5d,0x00,0x00,0x00, + 0x00,0x00,0x00,0x05,0x88,0xfe,0xb6,0x27,0x00,0x00,0x00,0x00,0x27,0xb6,0xfe,0x88,0x05,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0a,0x87,0xfa,0xd6,0x56,0x06,0x06,0x56,0xd6,0xfa,0x87,0x0a,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x05,0x63,0xe1,0xf9,0xab,0xab,0xf9,0xe2,0x63,0x05,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x2d,0xa0,0xf1,0xf1,0xa0,0x2d,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x05,0x33,0x33,0x05,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + +}; + +const lv_image_dsc_t img_key_generate_image = { + .header.magic = LV_IMAGE_HEADER_MAGIC, + .header.cf = LV_COLOR_FORMAT_RGB565A8, + .header.flags = 0, + .header.w = 20, + .header.h = 20, + .header.stride = 40, + .data_size = sizeof(img_key_generate_image_map), + .data = img_key_generate_image_map, +}; + diff --git a/include/TFTView_320x240.h b/include/TFTView_320x240.h index c6ecd13..4ea8faf 100644 --- a/include/TFTView_320x240.h +++ b/include/TFTView_320x240.h @@ -190,6 +190,7 @@ class TFTView_320x240 : public MeshtasticView void ui_events_init(void); void ui_set_active(lv_obj_t *b, lv_obj_t *p, lv_obj_t *tp); void showKeyboard(lv_obj_t *textArea); + lv_obj_t *showQrCode(lv_obj_t *parent, const char *data); void enablePanel(lv_obj_t *panel); void disablePanel(lv_obj_t *panel); @@ -216,6 +217,7 @@ class TFTView_320x240 : public MeshtasticView void storeNodeOptions(void); void showLoRaFrequency(const meshtastic_Config_LoRaConfig &cfg); void setBellText(bool banner, bool sound); + void setChannelName(const meshtastic_Channel &ch); // lvgl event callbacks // static void ui_event_HomeButton(lv_event_t * e); @@ -269,6 +271,8 @@ class TFTView_320x240 : public MeshtasticView static void ui_event_shutdown_button(lv_event_t *e); static void ui_event_modify_channel(lv_event_t *e); static void ui_event_delete_channel(lv_event_t *e); + static void ui_event_generate_psk(lv_event_t *e); + static void ui_event_qr_code(lv_event_t *e); static void ui_event_screen_timeout_slider(lv_event_t *e); static void ui_event_brightness_slider(lv_event_t *e); @@ -338,6 +342,7 @@ class TFTView_320x240 : public MeshtasticView char old_val1_scratch[64], old_val2_scratch[64]; // temporary scratch buffers for settings strings std::array ch_label; // indexable label list for settings meshtastic_Channel *channel_scratch; // temporary scratch copy of channel db + lv_obj_t *qr; // qr code // extended default device profile struct with additional required data struct meshtastic_DeviceProfile_ext : meshtastic_DeviceProfile { diff --git a/include/lv_conf.h b/include/lv_conf.h index 202d15f..f53bfe6 100644 --- a/include/lv_conf.h +++ b/include/lv_conf.h @@ -526,7 +526,7 @@ #define LV_USE_CALENDAR_HEADER_DROPDOWN 1 #endif /*LV_USE_CALENDAR*/ -#define LV_USE_CANVAS 0 +#define LV_USE_CANVAS 1 #define LV_USE_CHART 0 @@ -703,7 +703,7 @@ #define LV_USE_RLE 0 /*QR code library*/ -#define LV_USE_QRCODE 0 +#define LV_USE_QRCODE 1 /*Barcode code library*/ #define LV_USE_BARCODE 0 diff --git a/source/TFTView_320x240.cpp b/source/TFTView_320x240.cpp index 7325f89..d9beb29 100644 --- a/source/TFTView_320x240.cpp +++ b/source/TFTView_320x240.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #ifdef ARCH_PORTDUINO #include "LinuxHelper.h" @@ -83,7 +84,8 @@ TFTView_320x240 *TFTView_320x240::instance(const DisplayDriverConfig &cfg) TFTView_320x240::TFTView_320x240(const DisplayDriverConfig *cfg, DisplayDriver *driver) : MeshtasticView(cfg, driver, new ViewController), screensInitialised(false), nodesFiltered(0), processingFilter(false), packetLogEnabled(false), detectorRunning(false), packetCounter(0), actTime(0), uptime(0), hasPosition(false), - topNodeLL(nullptr), scans(0), selectedHops(0), chooseNodeSignalScanner(false), chooseNodeTraceRoute(false), db{} + topNodeLL(nullptr), scans(0), selectedHops(0), chooseNodeSignalScanner(false), chooseNodeTraceRoute(false), qr(nullptr), + db{} { filter.active = false; highlight.active = false; @@ -608,6 +610,9 @@ void TFTView_320x240::ui_events_init(void) lv_obj_add_event_cb(objects.settings_channel7_button, ui_event_modify_channel, LV_EVENT_ALL, (void *)7); // delete channel button lv_obj_add_event_cb(objects.settings_modify_trash_button, ui_event_delete_channel, LV_EVENT_CLICKED, NULL); + // generate PSK + lv_obj_add_event_cb(objects.settings_modify_channel_key_generate_button, ui_event_generate_psk, LV_EVENT_CLICKED, NULL); + lv_obj_add_event_cb(objects.settings_modify_channel_qr_button, ui_event_qr_code, LV_EVENT_CLICKED, NULL); // screen lv_obj_add_event_cb(objects.calibration_screen, ui_event_calibration_screen_loaded, LV_EVENT_SCREEN_LOADED, (void *)7); @@ -1553,6 +1558,45 @@ void TFTView_320x240::ui_event_modify_channel(lv_event_t *e) } } +void TFTView_320x240::ui_event_generate_psk(lv_event_t *e) +{ + std::string base64 = lv_textarea_get_text(objects.settings_modify_channel_psk_textarea); + if (base64.size() == 0 || THIS->qr) { + meshtastic_ChannelSettings_psk_t psk{.size = 32}; + std::mt19937 generator(millis() + psk.bytes[7]); // Mersenne Twister number generator + for (int i = 0; i < 8; i++) { + int r = generator(); + memcpy(&psk.bytes[i * 4], &r, 4); + } + base64 = THIS->pskToBase64(psk); + lv_textarea_set_text(objects.settings_modify_channel_psk_textarea, base64.c_str()); + } + + std::string base64Https = base64; + for (char &c : base64Https) { + if (c == '+') + c = '-'; + else if (c == '/') + c = '_'; + else if (c == '=') + c = '\0'; // remove paddings at the end of the url + } + std::string qr = "https://meshtastic.org/e/#" + base64Https; + lv_obj_remove_flag(objects.settings_modify_channel_qr_panel, LV_OBJ_FLAG_HIDDEN); + THIS->qr = THIS->showQrCode(objects.settings_modify_channel_qr_panel, qr.c_str()); + lv_obj_add_state(objects.keyboard_button_3, LV_STATE_DISABLED); + lv_obj_add_state(objects.keyboard_button_4, LV_STATE_DISABLED); +} + +void TFTView_320x240::ui_event_qr_code(lv_event_t *e) +{ + lv_obj_remove_state(objects.keyboard_button_3, LV_STATE_DISABLED); + lv_obj_remove_state(objects.keyboard_button_4, LV_STATE_DISABLED); + lv_obj_add_flag(objects.settings_modify_channel_qr_panel, LV_OBJ_FLAG_HIDDEN); + lv_obj_delete(THIS->qr); + THIS->qr = nullptr; +} + void TFTView_320x240::ui_event_delete_channel(lv_event_t *e) { lv_textarea_set_text(objects.settings_modify_channel_psk_textarea, ""); @@ -4237,15 +4281,7 @@ void TFTView_320x240::updateChannelConfig(const meshtastic_Channel &ch) db.channel[ch.index] = ch; if (ch.role != meshtastic_Channel_Role_DISABLED) { - if (ch.role == meshtastic_Channel_Role_PRIMARY) { - char buf[32]; - lv_snprintf(buf, sizeof(buf), _("Channel: %s"), strlen(ch.settings.name) ? ch.settings.name : _("")); - lv_label_set_text(objects.basic_settings_channel_label, buf); - lv_snprintf(buf, sizeof(buf), "*%s", strlen(ch.settings.name) ? ch.settings.name : _("")); - lv_label_set_text(channel[ch.index], buf); - } else { - lv_label_set_text(channel[ch.index], ch.settings.name); - } + setChannelName(ch); lv_obj_set_width(btn[ch.index], lv_pct(70)); lv_obj_set_style_pad_left(btn[ch.index], 8, LV_PART_MAIN | LV_STATE_DEFAULT); @@ -4347,7 +4383,7 @@ void TFTView_320x240::updateLoRaConfig(const meshtastic_Config_LoRaConfig &cfg) lv_snprintf(region, sizeof(region), _("Region: %s"), LoRaPresets::loRaRegionToString(cfg.region)); lv_label_set_text(objects.basic_settings_region_label, region); - char buf1[16], buf2[32]; + char buf1[20], buf2[32]; lv_dropdown_set_selected(objects.settings_modem_preset_dropdown, cfg.modem_preset); lv_dropdown_get_selected_str(objects.settings_modem_preset_dropdown, buf1, sizeof(buf1)); lv_snprintf(buf2, sizeof(buf2), _("Modem Preset: %s"), buf1); @@ -4360,6 +4396,15 @@ void TFTView_320x240::updateLoRaConfig(const meshtastic_Config_LoRaConfig &cfg) db.config.lora.channel_num = LoRaPresets::getDefaultSlot(db.config.lora.region, THIS->db.config.lora.modem_preset); } lv_slider_set_value(objects.frequency_slot_slider, db.config.lora.channel_num, LV_ANIM_OFF); + + if (db.config.lora.region != meshtastic_Config_LoRaConfig_RegionCode_UNSET) { + // update primary channel name if region is known + for (int i = 0; i < c_max_channels; i++) { + if (db.channel[i].has_settings && db.channel[i].role == meshtastic_Channel_Role_PRIMARY) { + setChannelName(db.channel[i]); + } + } + } } void TFTView_320x240::showLoRaFrequency(const meshtastic_Config_LoRaConfig &cfg) @@ -4404,6 +4449,30 @@ void TFTView_320x240::setBellText(bool banner, bool sound) Themes::recolorText(objects.home_bell_label, banner || sound); } +/** + * auto set primary channel name (based on region) + */ +void TFTView_320x240::setChannelName(const meshtastic_Channel &ch) +{ + if (ch.role == meshtastic_Channel_Role_PRIMARY) { + char buf[40]; + sprintf(buf, _("Channel: %s"), + strlen(ch.settings.name) ? ch.settings.name + : db.config.lora.region == meshtastic_Config_LoRaConfig_RegionCode_UNSET + ? ("") + : LoRaPresets::modemPresetToString(db.config.lora.modem_preset)); + lv_label_set_text(objects.basic_settings_channel_label, buf); + sprintf(buf, "*%s", + strlen(ch.settings.name) ? ch.settings.name + : db.config.lora.region == meshtastic_Config_LoRaConfig_RegionCode_UNSET + ? ("") + : LoRaPresets::modemPresetToString(db.config.lora.modem_preset)); + lv_label_set_text(channel[ch.index], buf); + } else { + lv_label_set_text(channel[ch.index], ch.settings.name); + } +} + void TFTView_320x240::updateBluetoothConfig(const meshtastic_Config_BluetoothConfig &cfg) { db.config.bluetooth = cfg; @@ -4859,6 +4928,22 @@ void TFTView_320x240::showKeyboard(lv_obj_t *textArea) lv_keyboard_set_textarea(objects.keyboard, textArea); } +lv_obj_t *TFTView_320x240::showQrCode(lv_obj_t *parent, const char *data) +{ + lv_color_t bg_color = lv_color_hex(0x67EA94); + lv_color_t fg_color = lv_palette_darken(LV_PALETTE_BLUE, 4); + qr = lv_qrcode_create(parent); + int32_t size = std::min(lv_obj_get_width(parent), lv_obj_get_height(parent)) - 8; + lv_qrcode_set_size(qr, size); + lv_qrcode_set_dark_color(qr, fg_color); + lv_qrcode_set_light_color(qr, bg_color); + lv_qrcode_update(qr, data, strlen(data)); + lv_obj_center(qr); + lv_obj_set_style_border_color(qr, fg_color, 0); + lv_obj_set_style_border_width(qr, 4, 0); + return qr; +} + /** * Enable underlying panel, buttons and scrollbar after it was disabled */