From acdfa695392a628d3e65b8e4ab98a433998b41c5 Mon Sep 17 00:00:00 2001 From: fvanroie Date: Tue, 28 Jan 2020 22:34:57 +0100 Subject: [PATCH] Add QR code to softAP --- include/lv_conf.h | 2 +- lib/lv_lib_qrcode/lv_qrcode.c | 4 ++-- src/hasp.cpp | 29 +++++++++++++++++++++++++++++ src/hasp.h | 1 + src/hasp_wifi.cpp | 2 +- 5 files changed, 34 insertions(+), 4 deletions(-) diff --git a/include/lv_conf.h b/include/lv_conf.h index 9c31524a..4ebdb107 100644 --- a/include/lv_conf.h +++ b/include/lv_conf.h @@ -396,7 +396,7 @@ typedef uint8_t lv_obj_user_data_t; #define LV_USE_CALENDAR (LV_HIGH_RESOURCE_MCU) /*Canvas (dependencies: lv_img)*/ -#define LV_USE_CANVAS (LV_HIGH_RESOURCE_MCU) +#define LV_USE_CANVAS 1 // needed for QR code /*Check box (dependencies: lv_btn, lv_label)*/ #define LV_USE_CB 1 diff --git a/lib/lv_lib_qrcode/lv_qrcode.c b/lib/lv_lib_qrcode/lv_qrcode.c index 2517b569..638e488f 100644 --- a/lib/lv_lib_qrcode/lv_qrcode.c +++ b/lib/lv_lib_qrcode/lv_qrcode.c @@ -14,7 +14,7 @@ /********************* * DEFINES *********************/ -#define QR_SIZE 140 +#define QR_SIZE 150 /********************** * TYPEDEFS @@ -52,7 +52,6 @@ lv_obj_t * lv_qrcode_create(lv_obj_t * parent, lv_coord_t size, lv_color_t dark_ if(buf == NULL) return NULL; lv_obj_t * canvas = lv_canvas_create(parent, NULL); - if(canvas == NULL) return NULL; lv_canvas_set_buffer(canvas, buf, size, size, LV_IMG_CF_INDEXED_1BIT); lv_canvas_set_palette(canvas, 0, dark_color); @@ -73,6 +72,7 @@ lv_res_t lv_qrcode_update(lv_obj_t * qrcode, const void * data, uint32_t data_le lv_color_t c; c.full = 1; lv_canvas_fill_bg(qrcode, c, 0); + // lv_canvas_zoom(); if(data_len > qrcodegen_BUFFER_LEN_MAX) return LV_RES_INV; diff --git a/src/hasp.cpp b/src/hasp.cpp index 0d7179bd..e69f78ae 100644 --- a/src/hasp.cpp +++ b/src/hasp.cpp @@ -8,6 +8,7 @@ #include "lv_conf.h" #include "lv_theme_hasp.h" #include "lv_objx/lv_roller.h" +#include "lv_qrcode.h" #include "hasp_conf.h" @@ -652,6 +653,34 @@ void haspReconnect() lv_obj_set_hidden(obj, true);*/ } +void haspDisplayAP(const char * ssid, const char * pass) +{ + String txt((char *)0); + txt.reserve(64); + + char buffer[64]; + sprintf_P(buffer, PSTR("WIFI:S:%s;T:WPA;P:%s;;"), ssid, pass); + + lv_obj_t * qr = lv_qrcode_create(lv_disp_get_layer_sys(NULL), 150, LV_COLOR_BLACK, LV_COLOR_WHITE); + lv_obj_align(qr, NULL, LV_ALIGN_CENTER, 0, 20); + lv_qrcode_update(qr, buffer, strlen(buffer)); + + lv_obj_t * panel = lv_cont_create(lv_disp_get_layer_sys(NULL), NULL); + lv_obj_set_style(panel, &lv_style_pretty); + lv_obj_align(panel, qr, LV_ALIGN_OUT_TOP_MID, 0, 10); + lv_label_set_align(panel, LV_LABEL_ALIGN_CENTER); + lv_cont_set_fit(panel, LV_FIT_TIGHT); + lv_cont_set_layout(panel, LV_LAYOUT_COL_M); + + txt = String(LV_SYMBOL_WIFI) + String(ssid); + lv_obj_t * network = lv_label_create(panel, NULL); + lv_label_set_text(network, ssid); + + lv_obj_t * password = lv_label_create(panel, NULL); + txt = String(LV_SYMBOL_WIFI) + String(pass); + lv_label_set_text(password, txt.c_str()); +} + /** * Create a demo application */ diff --git a/src/hasp.h b/src/hasp.h index 2919812b..99a8a3c4 100644 --- a/src/hasp.h +++ b/src/hasp.h @@ -87,6 +87,7 @@ void haspParseJson(String & strPayload); void haspReconnect(void); void haspDisconnect(void); +void haspDisplayAP(const char * ssid, const char * pass); bool haspGetConfig(const JsonObject & settings); bool haspSetConfig(const JsonObject & settings); diff --git a/src/hasp_wifi.cpp b/src/hasp_wifi.cpp index 18aab909..d7fab967 100644 --- a/src/hasp_wifi.cpp +++ b/src/hasp_wifi.cpp @@ -144,7 +144,7 @@ void wifiSetup(JsonObject settings) debugPrintln(buffer); sprintf_P(buffer, PSTR("WIFI: AP IP address : %s"), IP.toString().c_str()); debugPrintln(buffer); - + haspDisplayAP(apSsdid.c_str(), "haspadmin"); httpReconnect(); return; }