mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-07-28 13:46:36 +00:00
Add oobe setup
This commit is contained in:
parent
41b81d398d
commit
71c2b943f9
226
src/hasp.cpp
226
src/hasp.cpp
@ -13,10 +13,6 @@
|
|||||||
|
|
||||||
//#include "../lib/lvgl/src/lv_widgets/lv_roller.h"
|
//#include "../lib/lvgl/src/lv_widgets/lv_roller.h"
|
||||||
|
|
||||||
#if HASP_USE_QRCODE != 0
|
|
||||||
#include "lv_qrcode.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if HASP_USE_SPIFFS
|
#if HASP_USE_SPIFFS
|
||||||
#if defined(ARDUINO_ARCH_ESP32)
|
#if defined(ARDUINO_ARCH_ESP32)
|
||||||
#include "lv_zifont.h"
|
#include "lv_zifont.h"
|
||||||
@ -69,9 +65,9 @@ char haspZiFontPath[32];
|
|||||||
/**********************
|
/**********************
|
||||||
* STATIC VARIABLES
|
* STATIC VARIABLES
|
||||||
**********************/
|
**********************/
|
||||||
static lv_style_t style_mbox_bg; /*Black bg. style with opacity*/
|
lv_style_t style_mbox_bg; /*Black bg. style with opacity*/
|
||||||
static lv_obj_t * kb;
|
lv_obj_t * kb;
|
||||||
static lv_font_t * defaultFont;
|
lv_font_t * defaultFont;
|
||||||
|
|
||||||
#if LV_DEMO_WALLPAPER
|
#if LV_DEMO_WALLPAPER
|
||||||
LV_IMG_DECLARE(img_bubble_pattern)
|
LV_IMG_DECLARE(img_bubble_pattern)
|
||||||
@ -97,7 +93,7 @@ static const char * btnm_map2[] = {"0", "1", "\n", "2", "3", "\n", "4", "5",
|
|||||||
"\n", "6", "7", "\n", "P1", "P2", "P3", ""};
|
"\n", "6", "7", "\n", "P1", "P2", "P3", ""};
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static lv_obj_t * pages[HASP_NUM_PAGES];
|
lv_obj_t * pages[HASP_NUM_PAGES];
|
||||||
#if defined(ARDUINO_ARCH_ESP8266)
|
#if defined(ARDUINO_ARCH_ESP8266)
|
||||||
static lv_font_t * haspFonts[4];
|
static lv_font_t * haspFonts[4];
|
||||||
// static lv_style_t labelStyles[4];
|
// static lv_style_t labelStyles[4];
|
||||||
@ -321,20 +317,21 @@ void haspWakeUp()
|
|||||||
|
|
||||||
void haspDisconnect()
|
void haspDisconnect()
|
||||||
{
|
{
|
||||||
#if LVGL7
|
|
||||||
|
|
||||||
#else
|
|
||||||
/* Create a dark plain style for a message box's background (modal)*/
|
/* Create a dark plain style for a message box's background (modal)*/
|
||||||
lv_style_copy(&style_mbox_bg, &lv_style_plain);
|
// lv_style_copy(&style_mbox_bg, &lv_style_plain);
|
||||||
style_mbox_bg.body.main_color = LV_COLOR_BLACK;
|
// style_mbox_bg.body.main_color = LV_COLOR_BLACK;
|
||||||
style_mbox_bg.body.grad_color = LV_COLOR_BLACK;
|
// style_mbox_bg.body.grad_color = LV_COLOR_BLACK;
|
||||||
style_mbox_bg.body.opa = LV_OPA_60;
|
// style_mbox_bg.body.opa = LV_OPA_60;
|
||||||
|
|
||||||
lv_obj_set_style(lv_disp_get_layer_sys(NULL), &style_mbox_bg);
|
// lv_obj_set_style(lv_disp_get_layer_sys(NULL), &style_mbox_bg);
|
||||||
#endif
|
|
||||||
|
/*
|
||||||
lv_obj_set_click(lv_disp_get_layer_sys(NULL), true);
|
lv_obj_set_click(lv_disp_get_layer_sys(NULL), true);
|
||||||
lv_obj_set_event_cb(lv_disp_get_layer_sys(NULL), NULL);
|
lv_obj_set_event_cb(lv_disp_get_layer_sys(NULL), NULL);
|
||||||
lv_obj_set_user_data(lv_disp_get_layer_sys(NULL), 255);
|
lv_obj_set_user_data(lv_disp_get_layer_sys(NULL), 255);
|
||||||
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
lv_obj_t * obj = lv_obj_get_child(lv_disp_get_layer_sys(NULL), NULL);
|
lv_obj_t * obj = lv_obj_get_child(lv_disp_get_layer_sys(NULL), NULL);
|
||||||
lv_obj_set_hidden(obj, false);
|
lv_obj_set_hidden(obj, false);
|
||||||
@ -346,8 +343,8 @@ void haspReconnect()
|
|||||||
{
|
{
|
||||||
/*Revert the top layer to not block*/
|
/*Revert the top layer to not block*/
|
||||||
// lv_obj_set_style(lv_disp_get_layer_sys(NULL), &lv_style_transp);
|
// lv_obj_set_style(lv_disp_get_layer_sys(NULL), &lv_style_transp);
|
||||||
lv_obj_set_click(lv_disp_get_layer_sys(NULL), false);
|
// lv_obj_set_click(lv_disp_get_layer_sys(NULL), false);
|
||||||
lv_obj_set_event_cb(lv_disp_get_layer_sys(NULL), btn_event_handler);
|
// lv_obj_set_event_cb(lv_disp_get_layer_sys(NULL), btn_event_handler);
|
||||||
/*
|
/*
|
||||||
lv_obj_t * obj = lv_obj_get_child(lv_disp_get_layer_sys(NULL), NULL);
|
lv_obj_t * obj = lv_obj_get_child(lv_disp_get_layer_sys(NULL), NULL);
|
||||||
lv_obj_set_hidden(obj, true);
|
lv_obj_set_hidden(obj, true);
|
||||||
@ -355,201 +352,10 @@ void haspReconnect()
|
|||||||
lv_obj_set_hidden(obj, true);*/
|
lv_obj_set_hidden(obj, true);*/
|
||||||
}
|
}
|
||||||
|
|
||||||
void gotoPage1(lv_obj_t * event_kb, lv_event_t event)
|
|
||||||
{
|
|
||||||
if(event == LV_EVENT_RELEASED) {
|
|
||||||
lv_obj_set_click(lv_disp_get_layer_sys(NULL), false);
|
|
||||||
haspSetPage(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void haspDisplayAP(const char * ssid, const char * pass)
|
|
||||||
{
|
|
||||||
guiSetDim(100);
|
|
||||||
|
|
||||||
String txt((char *)0);
|
|
||||||
txt.reserve(64);
|
|
||||||
|
|
||||||
char buffer[128];
|
|
||||||
snprintf_P(buffer, sizeof(buffer), PSTR("WIFI:S:%s;T:WPA;P:%s;;"), ssid, pass);
|
|
||||||
|
|
||||||
/*Clear all screens*/
|
|
||||||
for(uint8_t i = 0; i < (sizeof pages / sizeof *pages); i++) {
|
|
||||||
lv_obj_clean(pages[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
#if HASP_USE_QRCODE != 0
|
|
||||||
lv_obj_t * qr = lv_qrcode_create(pages[0], 120, LV_COLOR_BLACK, LV_COLOR_WHITE);
|
|
||||||
lv_obj_align(qr, NULL, LV_ALIGN_CENTER, 0, 50);
|
|
||||||
lv_qrcode_update(qr, buffer, strlen(buffer));
|
|
||||||
#endif
|
|
||||||
|
|
||||||
lv_obj_t * panel = lv_cont_create(pages[0], NULL);
|
|
||||||
// lv_obj_set_style(panel, &lv_style_pretty);
|
|
||||||
#if HASP_USE_QRCODE != 0
|
|
||||||
lv_obj_align(panel, qr, LV_ALIGN_OUT_TOP_MID, 0, -20);
|
|
||||||
#endif
|
|
||||||
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, txt.c_str());
|
|
||||||
|
|
||||||
lv_obj_t * password = lv_label_create(panel, NULL);
|
|
||||||
txt = String(F("\xef\x80\xA3")) + String(pass);
|
|
||||||
lv_label_set_text(password, txt.c_str());
|
|
||||||
|
|
||||||
haspSetPage(0);
|
|
||||||
lv_obj_set_click(lv_disp_get_layer_sys(NULL), true);
|
|
||||||
lv_obj_set_event_cb(lv_disp_get_layer_sys(NULL), gotoPage1);
|
|
||||||
|
|
||||||
haspFirstSetup();
|
|
||||||
// lv_obj_set_style(lv_disp_get_layer_sys(NULL), &lv_style_transp);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void kb_event_cb(lv_obj_t * event_kb, lv_event_t event)
|
|
||||||
{
|
|
||||||
if(event == LV_EVENT_APPLY) {
|
|
||||||
char ssid[32];
|
|
||||||
char pass[32];
|
|
||||||
|
|
||||||
DynamicJsonDocument settings(256);
|
|
||||||
|
|
||||||
lv_obj_t * child;
|
|
||||||
child = lv_obj_get_child(pages[1], NULL);
|
|
||||||
while(child) {
|
|
||||||
if(child->user_data) {
|
|
||||||
lv_obj_user_data_t objid = 10;
|
|
||||||
if(objid == child->user_data) {
|
|
||||||
strncpy(ssid, lv_textarea_get_text(child), sizeof(ssid));
|
|
||||||
settings[FPSTR(F_CONFIG_SSID)] = ssid;
|
|
||||||
// if(kb != NULL) lv_keyboard_set_ta(kb, child);
|
|
||||||
}
|
|
||||||
objid = 20;
|
|
||||||
if(objid == child->user_data) {
|
|
||||||
strncpy(pass, lv_textarea_get_text(child), sizeof(pass));
|
|
||||||
settings[FPSTR(F_CONFIG_PASS)] = pass;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* next sibling */
|
|
||||||
child = lv_obj_get_child(pages[1], child);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(strlen(ssid) > 0) {
|
|
||||||
wifiSetConfig(settings.as<JsonObject>());
|
|
||||||
dispatchReboot(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
} else if(event == LV_EVENT_CANCEL) {
|
|
||||||
haspSetPage(0);
|
|
||||||
lv_obj_set_click(lv_disp_get_layer_sys(NULL), true);
|
|
||||||
} else {
|
|
||||||
|
|
||||||
/* prevent double presses, swipes and ghost press on tiny keyboard */
|
|
||||||
if(event == LV_EVENT_RELEASED) lv_keyboard_def_event_cb(event_kb, LV_EVENT_VALUE_CHANGED);
|
|
||||||
/* Just call the regular event handler */
|
|
||||||
// lv_kb_def_event_cb(event_kb, event);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
static void ta_event_cb(lv_obj_t * ta, lv_event_t event)
|
|
||||||
{
|
|
||||||
if(event == LV_EVENT_CLICKED) {
|
|
||||||
/* Focus on the clicked text area */
|
|
||||||
// if(kb != NULL) lv_keyboard_set_ta(kb, ta);
|
|
||||||
}
|
|
||||||
|
|
||||||
else if(event == LV_EVENT_INSERT) {
|
|
||||||
const char * str = (const char *)lv_event_get_data();
|
|
||||||
if(str[0] == '\n') {
|
|
||||||
// printf("Ready\n");
|
|
||||||
} else {
|
|
||||||
// printf("%s\n", lv_ta_get_text(ta));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void haspFirstSetup(void)
|
|
||||||
{
|
|
||||||
/*Create styles for the keyboard*/
|
|
||||||
static lv_style_t rel_style, pr_style;
|
|
||||||
|
|
||||||
lv_coord_t leftmargin, topmargin, voffset;
|
|
||||||
lv_align_t labelpos;
|
|
||||||
|
|
||||||
lv_disp_t * disp = lv_disp_get_default();
|
|
||||||
if(disp->driver.hor_res <= disp->driver.ver_res) {
|
|
||||||
leftmargin = 0;
|
|
||||||
topmargin = -35;
|
|
||||||
voffset = 12;
|
|
||||||
labelpos = LV_ALIGN_OUT_TOP_LEFT;
|
|
||||||
} else {
|
|
||||||
leftmargin = 100;
|
|
||||||
topmargin = -14;
|
|
||||||
voffset = 20;
|
|
||||||
labelpos = LV_ALIGN_OUT_LEFT_MID;
|
|
||||||
}
|
|
||||||
|
|
||||||
#if LVGL7
|
|
||||||
#else
|
|
||||||
lv_style_copy(&rel_style, &lv_style_btn_rel);
|
|
||||||
rel_style.body.radius = 0;
|
|
||||||
rel_style.body.border.width = 1;
|
|
||||||
rel_style.text.font = LV_FONT_DEFAULT;
|
|
||||||
|
|
||||||
lv_style_copy(&pr_style, &lv_style_btn_pr);
|
|
||||||
pr_style.body.radius = 0;
|
|
||||||
pr_style.body.border.width = 1;
|
|
||||||
rel_style.text.font = LV_FONT_DEFAULT;
|
|
||||||
|
|
||||||
/* Create the password box */
|
|
||||||
lv_obj_t * pwd_ta = lv_ta_create(pages[1], NULL);
|
|
||||||
lv_ta_set_text(pwd_ta, "");
|
|
||||||
lv_ta_set_max_length(pwd_ta, 32);
|
|
||||||
lv_ta_set_pwd_mode(pwd_ta, true);
|
|
||||||
lv_ta_set_one_line(pwd_ta, true);
|
|
||||||
lv_obj_set_user_data(pwd_ta, 20);
|
|
||||||
lv_obj_set_width(pwd_ta, disp->driver.hor_res - leftmargin - 20);
|
|
||||||
lv_obj_set_event_cb(pwd_ta, ta_event_cb);
|
|
||||||
lv_obj_align(pwd_ta, NULL, LV_ALIGN_CENTER, leftmargin / 2, topmargin - voffset);
|
|
||||||
|
|
||||||
/* Create the one-line mode text area */
|
|
||||||
lv_obj_t * oneline_ta = lv_ta_create(pages[1], pwd_ta);
|
|
||||||
lv_ta_set_pwd_mode(oneline_ta, false);
|
|
||||||
lv_obj_set_user_data(oneline_ta, 10);
|
|
||||||
lv_ta_set_cursor_type(oneline_ta, LV_CURSOR_LINE | LV_CURSOR_HIDDEN);
|
|
||||||
lv_obj_align(oneline_ta, pwd_ta, LV_ALIGN_OUT_TOP_MID, 0, topmargin);
|
|
||||||
|
|
||||||
/* Create a label and position it above the text box */
|
|
||||||
lv_obj_t * pwd_label = lv_label_create(pages[1], NULL);
|
|
||||||
lv_label_set_text(pwd_label, "Password:");
|
|
||||||
lv_obj_align(pwd_label, pwd_ta, labelpos, 0, 0);
|
|
||||||
|
|
||||||
/* Create a label and position it above the text box */
|
|
||||||
lv_obj_t * oneline_label = lv_label_create(pages[1], NULL);
|
|
||||||
lv_label_set_text(oneline_label, "Ssid:");
|
|
||||||
lv_obj_align(oneline_label, oneline_ta, labelpos, 0, 0);
|
|
||||||
|
|
||||||
/* Create a keyboard and make it fill the width of the above text areas */
|
|
||||||
kb = lv_kb_create(pages[1], NULL);
|
|
||||||
// lv_obj_set_pos(kb, 5, 90);
|
|
||||||
lv_obj_set_event_cb(kb,
|
|
||||||
kb_event_cb); /* Setting a custom event handler stops the keyboard from closing automatically */
|
|
||||||
lv_kb_set_style(kb, LV_KB_STYLE_BG, &lv_style_transp_tight);
|
|
||||||
lv_kb_set_style(kb, LV_KB_STYLE_BTN_REL, &rel_style);
|
|
||||||
lv_kb_set_style(kb, LV_KB_STYLE_BTN_PR, &pr_style);
|
|
||||||
|
|
||||||
lv_kb_set_ta(kb, oneline_ta); /* Focus it on one of the text areas to start */
|
|
||||||
lv_kb_set_cursor_manage(oneline_ta, true); /* Automatically show/hide cursors on text areas */
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a demo application
|
* Create a demo application
|
||||||
*/
|
*/
|
||||||
void haspSetup(JsonObject settings)
|
void haspSetup()
|
||||||
{
|
{
|
||||||
guiSetDim(haspStartDim);
|
guiSetDim(haspStartDim);
|
||||||
|
|
||||||
|
@ -61,7 +61,6 @@ enum lv_hasp_obj_type_t {
|
|||||||
*/
|
*/
|
||||||
void haspSetup();
|
void haspSetup();
|
||||||
void haspLoop(void);
|
void haspLoop(void);
|
||||||
void haspFirstSetup(void);
|
|
||||||
|
|
||||||
void haspSetPage(uint8_t id);
|
void haspSetPage(uint8_t id);
|
||||||
uint8_t haspGetPage();
|
uint8_t haspGetPage();
|
||||||
@ -82,7 +81,6 @@ void haspNewObject(const JsonObject & config, uint8_t & saved_page_id);
|
|||||||
|
|
||||||
void haspReconnect(void);
|
void haspReconnect(void);
|
||||||
void haspDisconnect(void);
|
void haspDisconnect(void);
|
||||||
void haspDisplayAP(const char * ssid, const char * pass);
|
|
||||||
void haspWakeUp(void);
|
void haspWakeUp(void);
|
||||||
|
|
||||||
bool haspGetConfig(const JsonObject & settings);
|
bool haspGetConfig(const JsonObject & settings);
|
||||||
|
@ -125,7 +125,7 @@ void dispatchAttribute(String strTopic, const char * payload)
|
|||||||
dispatchWebUpdate(payload);
|
dispatchWebUpdate(payload);
|
||||||
|
|
||||||
} else if(strTopic == F("setupap")) {
|
} else if(strTopic == F("setupap")) {
|
||||||
haspDisplayAP(String(F("HASP-ABC123")).c_str(), String(F("haspadmin")).c_str());
|
// haspDisplayAP(String(F("HASP-ABC123")).c_str(), String(F("haspadmin")).c_str());
|
||||||
|
|
||||||
} else if(strTopic.length() == 7 && strTopic.startsWith(F("output"))) {
|
} else if(strTopic.length() == 7 && strTopic.startsWith(F("output"))) {
|
||||||
dispatchOutput(strTopic, payload);
|
dispatchOutput(strTopic, payload);
|
||||||
@ -189,7 +189,7 @@ void dispatchBacklight(String strPayload)
|
|||||||
|
|
||||||
void dispatchCommand(String cmnd)
|
void dispatchCommand(String cmnd)
|
||||||
{
|
{
|
||||||
dispatchPrintln(F("CMND"), cmnd);
|
// dispatchPrintln(F("CMND"), cmnd);
|
||||||
|
|
||||||
if(cmnd.startsWith(F("page "))) {
|
if(cmnd.startsWith(F("page "))) {
|
||||||
cmnd = cmnd.substring(5, cmnd.length());
|
cmnd = cmnd.substring(5, cmnd.length());
|
||||||
@ -260,7 +260,7 @@ void dispatchJsonl(char * payload)
|
|||||||
stream.print(payload);
|
stream.print(payload);
|
||||||
while(deserializeJson(config, stream) == DeserializationError::Ok) {
|
while(deserializeJson(config, stream) == DeserializationError::Ok) {
|
||||||
serializeJson(config, Serial);
|
serializeJson(config, Serial);
|
||||||
// Serial.println();
|
Serial.println();
|
||||||
haspNewObject(config.as<JsonObject>(), savedPage);
|
haspNewObject(config.as<JsonObject>(), savedPage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
128
src/hasp_gui.cpp
128
src/hasp_gui.cpp
@ -12,8 +12,12 @@
|
|||||||
#include "hasp_config.h"
|
#include "hasp_config.h"
|
||||||
#include "hasp_dispatch.h"
|
#include "hasp_dispatch.h"
|
||||||
#include "hasp_gui.h"
|
#include "hasp_gui.h"
|
||||||
|
#include "hasp_oobe.h"
|
||||||
#include "hasp.h"
|
#include "hasp.h"
|
||||||
|
|
||||||
|
#include "lv_ex_conf.h"
|
||||||
|
//#include "tpcal.h"
|
||||||
|
|
||||||
#if HASP_USE_PNGDECODE
|
#if HASP_USE_PNGDECODE
|
||||||
#include "png_decoder.h"
|
#include "png_decoder.h"
|
||||||
#endif
|
#endif
|
||||||
@ -54,7 +58,6 @@ static bool guiShowPointer = false;
|
|||||||
static bool guiBacklightIsOn = true;
|
static bool guiBacklightIsOn = true;
|
||||||
static int8_t guiDimLevel = -1;
|
static int8_t guiDimLevel = -1;
|
||||||
static int8_t guiBacklightPin = TFT_BCKL;
|
static int8_t guiBacklightPin = TFT_BCKL;
|
||||||
static bool guiAutoCalibrate = true;
|
|
||||||
static uint16_t guiSleepTime1 = 60; // 1 second resolution
|
static uint16_t guiSleepTime1 = 60; // 1 second resolution
|
||||||
static uint16_t guiSleepTime2 = 120; // 1 second resolution
|
static uint16_t guiSleepTime2 = 120; // 1 second resolution
|
||||||
static uint8_t guiSleeping = 0; // 0 = off, 1 = short, 2 = long
|
static uint8_t guiSleeping = 0; // 0 = off, 1 = short, 2 = long
|
||||||
@ -161,7 +164,7 @@ static void gui_take_screenshot(uint8_t * data_p, size_t len)
|
|||||||
res = pFileOut.write(data_p, len);
|
res = pFileOut.write(data_p, len);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
len = webClient->client().write(data_p, len);
|
res = webClient->client().write(data_p, len);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
res = 0; // nothing to do
|
res = 0; // nothing to do
|
||||||
@ -297,12 +300,83 @@ static void IRAM_ATTR lv_tick_handler(void)
|
|||||||
return false;
|
return false;
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
void guiFirstCalibration()
|
#define _RAWERR 20 // Deadband error allowed in successive position samples
|
||||||
|
uint8_t validTouch(uint16_t * x, uint16_t * y, uint16_t threshold)
|
||||||
{
|
{
|
||||||
guiSetDim(100);
|
uint16_t x_tmp, y_tmp, x_tmp2, y_tmp2;
|
||||||
dispatchCommand(F("calibrate"));
|
|
||||||
guiAutoCalibrate = false;
|
// Wait until pressure stops increasing to debounce pressure
|
||||||
// haspFirstSetup();
|
uint16_t z1 = 1;
|
||||||
|
uint16_t z2 = 0;
|
||||||
|
while(z1 > z2) {
|
||||||
|
z2 = z1;
|
||||||
|
z1 = tft.getTouchRawZ();
|
||||||
|
delay(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Serial.print("Z = ");Serial.println(z1);
|
||||||
|
|
||||||
|
if(z1 <= threshold) return false;
|
||||||
|
|
||||||
|
tft.getTouchRaw(&x_tmp, &y_tmp);
|
||||||
|
|
||||||
|
// Serial.print("Sample 1 x,y = "); Serial.print(x_tmp);Serial.print(",");Serial.print(y_tmp);
|
||||||
|
// Serial.print(", Z = ");Serial.println(z1);
|
||||||
|
|
||||||
|
delay(1); // Small delay to the next sample
|
||||||
|
if(tft.getTouchRawZ() <= threshold) return false;
|
||||||
|
|
||||||
|
delay(2); // Small delay to the next sample
|
||||||
|
tft.getTouchRaw(&x_tmp2, &y_tmp2);
|
||||||
|
|
||||||
|
// Serial.print("Sample 2 x,y = "); Serial.print(x_tmp2);Serial.print(",");Serial.println(y_tmp2);
|
||||||
|
// Serial.print("Sample difference = ");Serial.print(abs(x_tmp -
|
||||||
|
// x_tmp2));Serial.print(",");Serial.println(abs(y_tmp - y_tmp2));
|
||||||
|
|
||||||
|
if(abs(x_tmp - x_tmp2) > _RAWERR) return false;
|
||||||
|
if(abs(y_tmp - y_tmp2) > _RAWERR) return false;
|
||||||
|
|
||||||
|
*x = x_tmp;
|
||||||
|
*y = y_tmp;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool my_touchpad_read_raw(lv_indev_drv_t * indev_driver, lv_indev_data_t * data)
|
||||||
|
{
|
||||||
|
#ifdef TOUCH_CS
|
||||||
|
uint16_t touchX, touchY;
|
||||||
|
|
||||||
|
bool touched = validTouch(&touchX, &touchY, 600u / 2);
|
||||||
|
if(!touched) return false;
|
||||||
|
|
||||||
|
// if(touchCounter < 255) {
|
||||||
|
// touchCounter++;
|
||||||
|
|
||||||
|
// // Store the raw touches
|
||||||
|
// if(touchCounter >= 8) {
|
||||||
|
// touchPoints[touchCorner].x /= touchCounter;
|
||||||
|
// touchPoints[touchCorner].y /= touchCounter;
|
||||||
|
// touchCounter = 255;
|
||||||
|
// } else {
|
||||||
|
// touchPoints[touchCorner].x += touchX;
|
||||||
|
// touchPoints[touchCorner].y += touchY;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
if(guiSleeping > 0) guiCheckSleep(); // update Idle
|
||||||
|
|
||||||
|
/*Save the state and save the pressed coordinate*/
|
||||||
|
// lv_disp_t * disp = lv_disp_get_default();
|
||||||
|
data->state = touched ? LV_INDEV_STATE_PR : LV_INDEV_STATE_REL;
|
||||||
|
data->point.x = touchX; // 20 + (disp->driver.hor_res - 40) * (touchCorner % 2);
|
||||||
|
data->point.y = touchY; // 20 + (disp->driver.ver_res - 40) * (touchCorner / 2);
|
||||||
|
|
||||||
|
Log.trace(F("Calibrate touch %u / %u"), touchX, touchY);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return false; /*Return `false` because we are not buffering and no more data to read*/
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IRAM_ATTR my_touchpad_read(lv_indev_drv_t * indev_driver, lv_indev_data_t * data)
|
bool IRAM_ATTR my_touchpad_read(lv_indev_drv_t * indev_driver, lv_indev_data_t * data)
|
||||||
@ -313,11 +387,6 @@ bool IRAM_ATTR my_touchpad_read(lv_indev_drv_t * indev_driver, lv_indev_data_t *
|
|||||||
bool touched = tft.getTouch(&touchX, &touchY, 600);
|
bool touched = tft.getTouch(&touchX, &touchY, 600);
|
||||||
if(!touched) return false;
|
if(!touched) return false;
|
||||||
|
|
||||||
if(guiAutoCalibrate) {
|
|
||||||
guiFirstCalibration();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(guiSleeping > 0) guiCheckSleep(); // update Idle
|
if(guiSleeping > 0) guiCheckSleep(); // update Idle
|
||||||
|
|
||||||
// Ignore first press?
|
// Ignore first press?
|
||||||
@ -368,7 +437,7 @@ void guiCalibrate()
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void guiSetup(const JsonObject & settings)
|
void guiSetup()
|
||||||
{
|
{
|
||||||
/* TFT init */
|
/* TFT init */
|
||||||
tft.begin();
|
tft.begin();
|
||||||
@ -406,7 +475,7 @@ void guiSetup(const JsonObject & settings)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Dump TFT Cofiguration */
|
/* Dump TFT Cofiguration */
|
||||||
tftSetup(tft, settings[F("tft")]);
|
tftSetup(tft);
|
||||||
|
|
||||||
/* Load User Settings */
|
/* Load User Settings */
|
||||||
// guiSetConfig(settings);
|
// guiSetConfig(settings);
|
||||||
@ -425,7 +494,6 @@ void guiSetup(const JsonObject & settings)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// char buffer[128];
|
|
||||||
Log.verbose(F("LVGL: Version : %u.%u.%u %s"), LVGL_VERSION_MAJOR, LVGL_VERSION_MINOR, LVGL_VERSION_PATCH,
|
Log.verbose(F("LVGL: Version : %u.%u.%u %s"), LVGL_VERSION_MAJOR, LVGL_VERSION_MINOR, LVGL_VERSION_PATCH,
|
||||||
PSTR(LVGL_VERSION_INFO));
|
PSTR(LVGL_VERSION_INFO));
|
||||||
Log.verbose(F("LVGL: Rotation : %d"), guiRotation);
|
Log.verbose(F("LVGL: Rotation : %d"), guiRotation);
|
||||||
@ -445,12 +513,12 @@ void guiSetup(const JsonObject & settings)
|
|||||||
if(guiRotation == 0 || guiRotation == 2 || guiRotation == 4 || guiRotation == 6) {
|
if(guiRotation == 0 || guiRotation == 2 || guiRotation == 4 || guiRotation == 6) {
|
||||||
/* 1/3=Landscape or 0/2=Portrait orientation */
|
/* 1/3=Landscape or 0/2=Portrait orientation */
|
||||||
// Normal width & height
|
// Normal width & height
|
||||||
disp_drv.hor_res = TFT_WIDTH; // From User_Setup.h
|
disp_drv.hor_res = TFT_WIDTH;
|
||||||
disp_drv.ver_res = TFT_HEIGHT; // From User_Setup.h
|
disp_drv.ver_res = TFT_HEIGHT;
|
||||||
} else {
|
} else {
|
||||||
// Swapped width & height
|
// Swapped width & height
|
||||||
disp_drv.hor_res = TFT_HEIGHT; // From User_Setup.h
|
disp_drv.hor_res = TFT_HEIGHT;
|
||||||
disp_drv.ver_res = TFT_WIDTH; // From User_Setup.h
|
disp_drv.ver_res = TFT_WIDTH;
|
||||||
}
|
}
|
||||||
lv_disp_drv_register(&disp_drv);
|
lv_disp_drv_register(&disp_drv);
|
||||||
|
|
||||||
@ -463,10 +531,17 @@ void guiSetup(const JsonObject & settings)
|
|||||||
indev_drv.read_cb = my_touchpad_read;
|
indev_drv.read_cb = my_touchpad_read;
|
||||||
lv_indev_t * mouse_indev = lv_indev_drv_register(&indev_drv);
|
lv_indev_t * mouse_indev = lv_indev_drv_register(&indev_drv);
|
||||||
|
|
||||||
if(guiShowPointer) {
|
if(guiShowPointer || true) {
|
||||||
lv_obj_t * label = lv_label_create(lv_layer_sys(), NULL);
|
// lv_obj_t * label = lv_label_create(lv_layer_sys(), NULL);
|
||||||
lv_label_set_text(label, "<");
|
// lv_label_set_text(label, "<");
|
||||||
lv_indev_set_cursor(mouse_indev, label); // connect the object to the driver
|
// lv_indev_set_cursor(mouse_indev, label); // connect the object to the driver
|
||||||
|
|
||||||
|
/*Set a cursor for the mouse*/
|
||||||
|
LV_IMG_DECLARE(mouse_cursor_icon); /*Declare the image file.*/
|
||||||
|
lv_obj_t * cursor_obj =
|
||||||
|
lv_img_create(lv_disp_get_scr_act(NULL), NULL); /*Create an image object for the cursor */
|
||||||
|
lv_img_set_src(cursor_obj, &mouse_cursor_icon); /*Set the image source*/
|
||||||
|
lv_indev_set_cursor(mouse_indev, cursor_obj); /*Connect the image object to the driver*/
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -616,10 +691,13 @@ bool guiSetConfig(const JsonObject & settings)
|
|||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(status) {
|
if(calData[0] != 0 || calData[1] != 65535 || calData[2] != 0 || calData[3] != 65535) {
|
||||||
Log.trace(F("calData set [%u, %u, %u, %u, %u]"), calData[0], calData[1], calData[2], calData[3],
|
Log.trace(F("calData set [%u, %u, %u, %u, %u]"), calData[0], calData[1], calData[2], calData[3],
|
||||||
calData[4]);
|
calData[4]);
|
||||||
guiAutoCalibrate = false;
|
oobeSetAutoCalibrate(true);
|
||||||
|
} else {
|
||||||
|
Log.notice(F("First Touch Calibration enabled"));
|
||||||
|
oobeSetAutoCalibrate(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
changed |= status;
|
changed |= status;
|
||||||
|
@ -136,26 +136,9 @@ void wifiSetup()
|
|||||||
char buffer[128];
|
char buffer[128];
|
||||||
|
|
||||||
if(strlen(wifiSsid) == 0) {
|
if(strlen(wifiSsid) == 0) {
|
||||||
String apSsdid = F("HASP-");
|
|
||||||
apSsdid += wifiGetMacAddress(3, "");
|
|
||||||
snprintf_P(buffer, sizeof(buffer), PSTR("haspadmin"));
|
|
||||||
|
|
||||||
WiFi.mode(WIFI_AP);
|
WiFi.mode(WIFI_AP);
|
||||||
WiFi.softAP(apSsdid.c_str(), buffer);
|
|
||||||
// haspDisplayAP(apSsdid.c_str(), buffer);
|
|
||||||
|
|
||||||
/* Setup the DNS server redirecting all the domains to the apIP */
|
|
||||||
// dnsServer.setErrorReplyCode(DNSReplyCode::NoError);
|
|
||||||
// dnsServer.start(DNS_PORT, "*", apIP);
|
|
||||||
|
|
||||||
IPAddress IP = WiFi.softAPIP();
|
|
||||||
Log.warning(F("WIFI: Temporary Access Point %s password: %s"), apSsdid.c_str(), PSTR("haspadmin"));
|
|
||||||
Log.warning(F("WIFI: AP IP address : %s"), IP.toString().c_str());
|
|
||||||
// httpReconnect();
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
WiFi.mode(WIFI_STA);
|
WiFi.mode(WIFI_STA);
|
||||||
Log.notice(F("WIFI: Connecting to : %s"), wifiSsid);
|
|
||||||
|
|
||||||
#if defined(ARDUINO_ARCH_ESP8266)
|
#if defined(ARDUINO_ARCH_ESP8266)
|
||||||
// wifiEventHandler[0] = WiFi.onStationModeConnected(wifiSTAConnected);
|
// wifiEventHandler[0] = WiFi.onStationModeConnected(wifiSTAConnected);
|
||||||
@ -167,11 +150,38 @@ void wifiSetup()
|
|||||||
WiFi.onEvent(wifi_callback);
|
WiFi.onEvent(wifi_callback);
|
||||||
WiFi.setSleep(false);
|
WiFi.setSleep(false);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
WiFi.begin(wifiSsid, wifiPassword);
|
WiFi.begin(wifiSsid, wifiPassword);
|
||||||
|
Log.notice(F("WIFI: Connecting to : %s"), wifiSsid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool wifiConfigured()
|
||||||
|
{
|
||||||
|
return (strlen(wifiSsid) >= 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wifiShowAP(char * ssid, char * pass)
|
||||||
|
{
|
||||||
|
// if(WiFi.mode != WIFI_AP) return false;
|
||||||
|
|
||||||
|
byte mac[6];
|
||||||
|
WiFi.macAddress(mac);
|
||||||
|
sprintf_P(ssid, PSTR("HASP-%02x%02x%02x"), mac[3], mac[4], mac[5]);
|
||||||
|
sprintf_P(pass, PSTR("haspadmin"));
|
||||||
|
|
||||||
|
// WiFi.softAP(ssid, pass);
|
||||||
|
|
||||||
|
/* Setup the DNS server redirecting all the domains to the apIP */
|
||||||
|
// dnsServer.setErrorReplyCode(DNSReplyCode::NoError);
|
||||||
|
// dnsServer.start(DNS_PORT, "*", apIP);
|
||||||
|
|
||||||
|
Log.warning(F("WIFI: Temporary Access Point %s password: %s"), ssid, pass);
|
||||||
|
Log.warning(F("WIFI: AP IP address : %s"), WiFi.softAPIP().toString().c_str());
|
||||||
|
// httpReconnect();}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool wifiEvery5Seconds()
|
bool wifiEvery5Seconds()
|
||||||
{
|
{
|
||||||
if(WiFi.getMode() == WIFI_AP || WiFi.status() == WL_CONNECTED) {
|
if(WiFi.getMode() == WIFI_AP || WiFi.status() == WL_CONNECTED) {
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#include "ArduinoJson.h"
|
#include "ArduinoJson.h"
|
||||||
|
|
||||||
void wifiSetup();
|
void wifiSetup();
|
||||||
|
bool wifiShowAP(char * ssid, char * pass);
|
||||||
bool wifiEvery5Seconds(void);
|
bool wifiEvery5Seconds(void);
|
||||||
void wifiStop(void);
|
void wifiStop(void);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user