Add QR code to softAP

This commit is contained in:
fvanroie 2020-01-28 22:34:57 +01:00
parent 1db0b845bb
commit acdfa69539
5 changed files with 34 additions and 4 deletions

View File

@ -396,7 +396,7 @@ typedef uint8_t lv_obj_user_data_t;
#define LV_USE_CALENDAR (LV_HIGH_RESOURCE_MCU) #define LV_USE_CALENDAR (LV_HIGH_RESOURCE_MCU)
/*Canvas (dependencies: lv_img)*/ /*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)*/ /*Check box (dependencies: lv_btn, lv_label)*/
#define LV_USE_CB 1 #define LV_USE_CB 1

View File

@ -14,7 +14,7 @@
/********************* /*********************
* DEFINES * DEFINES
*********************/ *********************/
#define QR_SIZE 140 #define QR_SIZE 150
/********************** /**********************
* TYPEDEFS * 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; if(buf == NULL) return NULL;
lv_obj_t * canvas = lv_canvas_create(parent, 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_buffer(canvas, buf, size, size, LV_IMG_CF_INDEXED_1BIT);
lv_canvas_set_palette(canvas, 0, dark_color); 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; lv_color_t c;
c.full = 1; c.full = 1;
lv_canvas_fill_bg(qrcode, c, 0); lv_canvas_fill_bg(qrcode, c, 0);
// lv_canvas_zoom();
if(data_len > qrcodegen_BUFFER_LEN_MAX) return LV_RES_INV; if(data_len > qrcodegen_BUFFER_LEN_MAX) return LV_RES_INV;

View File

@ -8,6 +8,7 @@
#include "lv_conf.h" #include "lv_conf.h"
#include "lv_theme_hasp.h" #include "lv_theme_hasp.h"
#include "lv_objx/lv_roller.h" #include "lv_objx/lv_roller.h"
#include "lv_qrcode.h"
#include "hasp_conf.h" #include "hasp_conf.h"
@ -652,6 +653,34 @@ void haspReconnect()
lv_obj_set_hidden(obj, true);*/ 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 * Create a demo application
*/ */

View File

@ -87,6 +87,7 @@ void haspParseJson(String & strPayload);
void haspReconnect(void); void haspReconnect(void);
void haspDisconnect(void); void haspDisconnect(void);
void haspDisplayAP(const char * ssid, const char * pass);
bool haspGetConfig(const JsonObject & settings); bool haspGetConfig(const JsonObject & settings);
bool haspSetConfig(const JsonObject & settings); bool haspSetConfig(const JsonObject & settings);

View File

@ -144,7 +144,7 @@ void wifiSetup(JsonObject settings)
debugPrintln(buffer); debugPrintln(buffer);
sprintf_P(buffer, PSTR("WIFI: AP IP address : %s"), IP.toString().c_str()); sprintf_P(buffer, PSTR("WIFI: AP IP address : %s"), IP.toString().c_str());
debugPrintln(buffer); debugPrintln(buffer);
haspDisplayAP(apSsdid.c_str(), "haspadmin");
httpReconnect(); httpReconnect();
return; return;
} }