mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-07-26 04:36:38 +00:00
Oobe setup and rename button events
This commit is contained in:
parent
0b2a4c4a9d
commit
59ce0ec960
174
src/hasp.cpp
174
src/hasp.cpp
@ -53,12 +53,13 @@ char haspZiFontPath[32];
|
|||||||
/**********************
|
/**********************
|
||||||
* STATIC PROTOTYPES
|
* STATIC PROTOTYPES
|
||||||
**********************/
|
**********************/
|
||||||
static void keyboard_event_cb(lv_obj_t * keyboard, lv_event_t event);
|
static void btn_event_handler(lv_obj_t * obj, lv_event_t event);
|
||||||
#if LV_USE_ANIMATION
|
static void toggle_event_handler(lv_obj_t * obj, lv_event_t event);
|
||||||
static void kb_hide_anim_end(lv_anim_t * a);
|
// void hasp_background(uint16_t pageid, uint16_t imageid);
|
||||||
#endif
|
|
||||||
|
|
||||||
void hasp_background(uint16_t pageid, uint16_t imageid);
|
#if LV_USE_ANIMATION
|
||||||
|
// static void kb_hide_anim_end(lv_anim_t * a);
|
||||||
|
#endif
|
||||||
|
|
||||||
/**********************
|
/**********************
|
||||||
* STATIC VARIABLES
|
* STATIC VARIABLES
|
||||||
@ -196,7 +197,7 @@ void haspProcessInput()
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void haspSendNewEvent(lv_obj_t * obj, uint8_t val)
|
void haspSendNewEvent(lv_obj_t * obj, char * val)
|
||||||
{
|
{
|
||||||
uint8_t pageid;
|
uint8_t pageid;
|
||||||
uint8_t objid;
|
uint8_t objid;
|
||||||
@ -369,6 +370,12 @@ void haspSetLabelText(lv_obj_t * obj, const char * value)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void haspSetToggle(lv_obj_t * obj, bool toggle)
|
||||||
|
{
|
||||||
|
lv_btn_set_toggle(obj, toggle);
|
||||||
|
lv_obj_set_event_cb(obj, toggle ? toggle_event_handler : btn_event_handler);
|
||||||
|
}
|
||||||
|
|
||||||
bool haspGetObjAttribute(lv_obj_t * obj, String strAttr, std::string & strPayload)
|
bool haspGetObjAttribute(lv_obj_t * obj, String strAttr, std::string & strPayload)
|
||||||
{
|
{
|
||||||
if(!obj) return false;
|
if(!obj) return false;
|
||||||
@ -587,6 +594,13 @@ void haspSetObjAttribute(lv_obj_t * obj, String strAttr, String strPayload)
|
|||||||
if(strAttr == F(".hidden")) {
|
if(strAttr == F(".hidden")) {
|
||||||
lv_obj_set_hidden(obj, val == 0);
|
lv_obj_set_hidden(obj, val == 0);
|
||||||
return;
|
return;
|
||||||
|
} else if(strAttr == F(".toggle")) {
|
||||||
|
lv_obj_type_t list;
|
||||||
|
lv_obj_get_type(obj, &list);
|
||||||
|
if(check_obj_type(list.type[0], LV_HASP_BUTTON)) {
|
||||||
|
haspSetToggle(obj, strPayload.toInt() > 0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 8:
|
case 8:
|
||||||
@ -689,6 +703,8 @@ void haspDisconnect()
|
|||||||
|
|
||||||
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);
|
||||||
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_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);
|
||||||
@ -701,6 +717,7 @@ 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_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);
|
||||||
@ -724,7 +741,7 @@ void haspDisplayAP(const char * ssid, const char * pass)
|
|||||||
txt.reserve(64);
|
txt.reserve(64);
|
||||||
|
|
||||||
char buffer[127];
|
char buffer[127];
|
||||||
sprintf_P(buffer, PSTR("WIFI:S:%s;T:WPA;P:%s;;"), ssid, pass);
|
snprintf_P(buffer, sizeof(buffer), PSTR("WIFI:S:%s;T:WPA;P:%s;;"), ssid, pass);
|
||||||
|
|
||||||
/*Clear all screens*/
|
/*Clear all screens*/
|
||||||
for(uint8_t i = 0; i < (sizeof pages / sizeof *pages); i++) {
|
for(uint8_t i = 0; i < (sizeof pages / sizeof *pages); i++) {
|
||||||
@ -733,13 +750,13 @@ void haspDisplayAP(const char * ssid, const char * pass)
|
|||||||
|
|
||||||
#if HASP_USE_QRCODE != 0
|
#if HASP_USE_QRCODE != 0
|
||||||
lv_obj_t * qr = lv_qrcode_create(pages[0], 120, LV_COLOR_BLACK, LV_COLOR_WHITE);
|
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, 10);
|
lv_obj_align(qr, NULL, LV_ALIGN_CENTER, 0, 50);
|
||||||
lv_qrcode_update(qr, buffer, strlen(buffer));
|
lv_qrcode_update(qr, buffer, strlen(buffer));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
lv_obj_t * panel = lv_cont_create(pages[0], NULL);
|
lv_obj_t * panel = lv_cont_create(pages[0], NULL);
|
||||||
lv_obj_set_style(panel, &lv_style_pretty);
|
lv_obj_set_style(panel, &lv_style_pretty);
|
||||||
lv_obj_align(panel, qr, LV_ALIGN_OUT_TOP_MID, 0, 0);
|
lv_obj_align(panel, qr, LV_ALIGN_OUT_TOP_MID, 0, -20);
|
||||||
lv_label_set_align(panel, LV_LABEL_ALIGN_CENTER);
|
lv_label_set_align(panel, LV_LABEL_ALIGN_CENTER);
|
||||||
lv_cont_set_fit(panel, LV_FIT_TIGHT);
|
lv_cont_set_fit(panel, LV_FIT_TIGHT);
|
||||||
lv_cont_set_layout(panel, LV_LAYOUT_COL_M);
|
lv_cont_set_layout(panel, LV_LAYOUT_COL_M);
|
||||||
@ -797,11 +814,13 @@ static void kb_event_cb(lv_obj_t * event_kb, lv_event_t event)
|
|||||||
} else if(event == LV_EVENT_CANCEL) {
|
} else if(event == LV_EVENT_CANCEL) {
|
||||||
haspSetPage(0);
|
haspSetPage(0);
|
||||||
lv_obj_set_click(lv_disp_get_layer_sys(NULL), true);
|
lv_obj_set_click(lv_disp_get_layer_sys(NULL), true);
|
||||||
// dispatchReboot(false);
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
/* prevent double presses, swipes and ghost press on tiny keyboard */
|
||||||
|
if(event == LV_EVENT_RELEASED) lv_kb_def_event_cb(event_kb, LV_EVENT_VALUE_CHANGED);
|
||||||
|
|
||||||
/* Just call the regular event handler */
|
/* Just call the regular event handler */
|
||||||
lv_kb_def_event_cb(event_kb, event);
|
// lv_kb_def_event_cb(event_kb, event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
static void ta_event_cb(lv_obj_t * ta, lv_event_t event)
|
static void ta_event_cb(lv_obj_t * ta, lv_event_t event)
|
||||||
@ -816,65 +835,81 @@ static void ta_event_cb(lv_obj_t * ta, lv_event_t event)
|
|||||||
if(str[0] == '\n') {
|
if(str[0] == '\n') {
|
||||||
printf("Ready\n");
|
printf("Ready\n");
|
||||||
} else {
|
} else {
|
||||||
printf("%s\n", lv_ta_get_text(ta));
|
// printf("%s\n", lv_ta_get_text(ta));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void haspFirstSetup(void)
|
void haspFirstSetup(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
/*Create styles for the keyboard*/
|
/*Create styles for the keyboard*/
|
||||||
static lv_style_t rel_style, pr_style;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
lv_style_copy(&rel_style, &lv_style_btn_rel);
|
lv_style_copy(&rel_style, &lv_style_btn_rel);
|
||||||
rel_style.body.radius = 0;
|
rel_style.body.radius = 0;
|
||||||
rel_style.body.border.width = 1;
|
rel_style.body.border.width = 1;
|
||||||
|
rel_style.text.font = LV_FONT_DEFAULT;
|
||||||
|
|
||||||
lv_style_copy(&pr_style, &lv_style_btn_pr);
|
lv_style_copy(&pr_style, &lv_style_btn_pr);
|
||||||
pr_style.body.radius = 0;
|
pr_style.body.radius = 0;
|
||||||
pr_style.body.border.width = 1;
|
pr_style.body.border.width = 1;
|
||||||
|
rel_style.text.font = LV_FONT_DEFAULT;
|
||||||
|
|
||||||
/* Create the password box */
|
/* Create the password box */
|
||||||
lv_obj_t * pwd_ta = lv_ta_create(pages[1], NULL);
|
lv_obj_t * pwd_ta = lv_ta_create(pages[1], NULL);
|
||||||
lv_ta_set_text(pwd_ta, "");
|
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_pwd_mode(pwd_ta, true);
|
||||||
lv_ta_set_one_line(pwd_ta, true);
|
lv_ta_set_one_line(pwd_ta, true);
|
||||||
lv_obj_set_user_data(pwd_ta, 20);
|
lv_obj_set_user_data(pwd_ta, 20);
|
||||||
lv_obj_set_width(pwd_ta, LV_HOR_RES - 20);
|
lv_obj_set_width(pwd_ta, disp->driver.hor_res - leftmargin - 20);
|
||||||
lv_obj_set_pos(pwd_ta, 5, 20);
|
|
||||||
lv_obj_set_event_cb(pwd_ta, ta_event_cb);
|
lv_obj_set_event_cb(pwd_ta, ta_event_cb);
|
||||||
lv_obj_align(pwd_ta, NULL, LV_ALIGN_OUT_TOP_MID, 0, 140);
|
lv_obj_align(pwd_ta, NULL, LV_ALIGN_CENTER, leftmargin / 2, topmargin - voffset);
|
||||||
|
|
||||||
/* Create the one-line mode text area */
|
/* Create the one-line mode text area */
|
||||||
lv_obj_t * oneline_ta = lv_ta_create(pages[1], pwd_ta);
|
lv_obj_t * oneline_ta = lv_ta_create(pages[1], pwd_ta);
|
||||||
lv_ta_set_pwd_mode(oneline_ta, false);
|
lv_ta_set_pwd_mode(oneline_ta, false);
|
||||||
lv_obj_set_user_data(oneline_ta, 10);
|
lv_obj_set_user_data(oneline_ta, 10);
|
||||||
lv_ta_set_cursor_type(oneline_ta, LV_CURSOR_LINE | LV_CURSOR_HIDDEN);
|
lv_ta_set_cursor_type(oneline_ta, LV_CURSOR_LINE | LV_CURSOR_HIDDEN);
|
||||||
lv_obj_align(oneline_ta, NULL, LV_ALIGN_OUT_TOP_MID, 0, 100);
|
lv_obj_align(oneline_ta, pwd_ta, LV_ALIGN_OUT_TOP_MID, 0, topmargin);
|
||||||
|
|
||||||
/* Create a label and position it above the text box */
|
/* Create a label and position it above the text box */
|
||||||
lv_obj_t * pwd_label = lv_label_create(pages[1], NULL);
|
lv_obj_t * pwd_label = lv_label_create(pages[1], NULL);
|
||||||
lv_label_set_text(pwd_label, "Password:");
|
lv_label_set_text(pwd_label, "Password:");
|
||||||
lv_obj_align(pwd_label, pwd_ta, LV_ALIGN_OUT_TOP_LEFT, 0, 0);
|
lv_obj_align(pwd_label, pwd_ta, labelpos, 0, 0);
|
||||||
|
|
||||||
/* Create a label and position it above the text box */
|
/* Create a label and position it above the text box */
|
||||||
lv_obj_t * oneline_label = lv_label_create(pages[1], NULL);
|
lv_obj_t * oneline_label = lv_label_create(pages[1], NULL);
|
||||||
lv_label_set_text(oneline_label, "Ssid:");
|
lv_label_set_text(oneline_label, "Ssid:");
|
||||||
lv_obj_align(oneline_label, oneline_ta, LV_ALIGN_OUT_TOP_LEFT, 0, 0);
|
lv_obj_align(oneline_label, oneline_ta, labelpos, 0, 0);
|
||||||
|
|
||||||
/* Create a keyboard and make it fill the width of the above text areas */
|
/* Create a keyboard and make it fill the width of the above text areas */
|
||||||
kb = lv_kb_create(pages[1], NULL);
|
kb = lv_kb_create(pages[1], NULL);
|
||||||
// lv_obj_set_pos(kb, 5, 90);
|
// lv_obj_set_pos(kb, 5, 90);
|
||||||
lv_obj_set_event_cb(kb,
|
lv_obj_set_event_cb(kb,
|
||||||
kb_event_cb); /* Setting a custom event handler stops the keyboard from closing automatically */
|
kb_event_cb); /* Setting a custom event handler stops the keyboard from closing automatically */
|
||||||
// lv_obj_set_size(kb, LV_HOR_RES, 140);
|
|
||||||
lv_kb_set_style(kb, LV_KB_STYLE_BG, &lv_style_transp_tight);
|
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_REL, &rel_style);
|
||||||
lv_kb_set_style(kb, LV_KB_STYLE_BTN_PR, &pr_style);
|
lv_kb_set_style(kb, LV_KB_STYLE_BTN_PR, &pr_style);
|
||||||
|
|
||||||
lv_kb_set_ta(kb, pwd_ta); /* Focus it on one of the text areas to start */
|
lv_kb_set_ta(kb, oneline_ta); /* Focus it on one of the text areas to start */
|
||||||
lv_kb_set_cursor_manage(kb, true); /* Automatically show/hide cursors on text areas */
|
lv_kb_set_cursor_manage(oneline_ta, true); /* Automatically show/hide cursors on text areas */
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1098,10 +1133,9 @@ void haspSetup(JsonObject settings)
|
|||||||
**********************/
|
**********************/
|
||||||
|
|
||||||
void haspLoop(void)
|
void haspLoop(void)
|
||||||
{
|
{}
|
||||||
/* idle detection and dim */
|
|
||||||
}
|
|
||||||
|
|
||||||
|
/*
|
||||||
void hasp_background(uint16_t pageid, uint16_t imageid)
|
void hasp_background(uint16_t pageid, uint16_t imageid)
|
||||||
{
|
{
|
||||||
lv_obj_t * page = get_page(pageid);
|
lv_obj_t * page = get_page(pageid);
|
||||||
@ -1114,7 +1148,8 @@ void hasp_background(uint16_t pageid, uint16_t imageid)
|
|||||||
|
|
||||||
if(!thisobj) return;
|
if(!thisobj) return;
|
||||||
|
|
||||||
/*
|
|
||||||
|
|
||||||
switch (imageid)
|
switch (imageid)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
@ -1143,13 +1178,13 @@ void hasp_background(uint16_t pageid, uint16_t imageid)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
//printf("Image set to %u\n", imageid);
|
//printf("Image set to %u\n", imageid);
|
||||||
*/
|
|
||||||
lv_img_set_auto_size(thisobj, false);
|
lv_img_set_auto_size(thisobj, false);
|
||||||
lv_obj_set_width(thisobj, lv_disp_get_hor_res(NULL));
|
lv_obj_set_width(thisobj, lv_disp_get_hor_res(NULL));
|
||||||
lv_obj_set_height(thisobj, lv_disp_get_ver_res(NULL));
|
lv_obj_set_height(thisobj, lv_disp_get_ver_res(NULL));
|
||||||
// lv_obj_set_protect(wp, LV_PROTECT_POS);
|
// lv_obj_set_protect(wp, LV_PROTECT_POS);
|
||||||
// lv_obj_invalidate(thisobj);
|
// lv_obj_invalidate(thisobj);
|
||||||
}
|
}*/
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
@ -1162,54 +1197,62 @@ static void btn_event_handler(lv_obj_t * obj, lv_event_t event)
|
|||||||
{
|
{
|
||||||
// int16_t id = get_obj_id(obj);
|
// int16_t id = get_obj_id(obj);
|
||||||
|
|
||||||
uint8_t eventid = 0;
|
// uint8_t eventid = 0;
|
||||||
uint8_t pageid = 0;
|
uint8_t pageid = 0;
|
||||||
lv_obj_user_data_t objid;
|
lv_obj_user_data_t objid;
|
||||||
|
|
||||||
char buffer[127];
|
char buffer[127];
|
||||||
sprintf(buffer, PSTR("HASP: "));
|
sprintf(buffer, PSTR("HASP: "));
|
||||||
|
|
||||||
if(!FindIdFromObj(obj, &pageid, &objid)) {
|
if(obj != lv_disp_get_layer_sys(NULL)) {
|
||||||
errorPrintln(F("HASP: %sEvent for unknown object"));
|
if(!FindIdFromObj(obj, &pageid, &objid)) {
|
||||||
return;
|
errorPrintln(F("HASP: %sEvent for unknown object"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(event) {
|
switch(event) {
|
||||||
case LV_EVENT_PRESSED:
|
case LV_EVENT_PRESSED:
|
||||||
strcat_P(buffer, PSTR("Pressed Down"));
|
// strcat_P(buffer, PSTR("Pressed Down"));
|
||||||
debugPrintln(buffer);
|
// debugPrintln(buffer);
|
||||||
eventid = 1;
|
// eventid = 1;
|
||||||
|
memcpy_P(buffer, PSTR("DOWN"), sizeof(buffer));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LV_EVENT_CLICKED:
|
case LV_EVENT_CLICKED:
|
||||||
strcat_P(buffer, PSTR("Released Up"));
|
// strcat_P(buffer, PSTR("Released Up"));
|
||||||
debugPrintln(buffer);
|
// debugPrintln(buffer);
|
||||||
// UP = the same object was release then was pressed and press was not lost!
|
// UP = the same object was release then was pressed and press was not lost!
|
||||||
eventid = 0;
|
// eventid = 0;
|
||||||
|
memcpy_P(buffer, PSTR("UP"), sizeof(buffer));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LV_EVENT_SHORT_CLICKED:
|
case LV_EVENT_SHORT_CLICKED:
|
||||||
strcat_P(buffer, PSTR("Short Click"));
|
// strcat_P(buffer, PSTR("Short Click"));
|
||||||
debugPrintln(buffer);
|
// debugPrintln(buffer);
|
||||||
eventid = 2;
|
// eventid = 2;
|
||||||
|
memcpy_P(buffer, PSTR("SHORT"), sizeof(buffer));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LV_EVENT_LONG_PRESSED:
|
case LV_EVENT_LONG_PRESSED:
|
||||||
strcat_P(buffer, PSTR("Long Press"));
|
// strcat_P(buffer, PSTR("Long Press"));
|
||||||
debugPrintln(buffer);
|
// debugPrintln(buffer);
|
||||||
eventid = 3;
|
// eventid = 3;
|
||||||
|
memcpy_P(buffer, PSTR("LONG"), sizeof(buffer));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LV_EVENT_LONG_PRESSED_REPEAT:
|
case LV_EVENT_LONG_PRESSED_REPEAT:
|
||||||
strcat_P(buffer, PSTR("Long Hold"));
|
// strcat_P(buffer, PSTR("Long Hold"));
|
||||||
debugPrintln(buffer);
|
// debugPrintln(buffer);
|
||||||
eventid = 4;
|
// eventid = 4;
|
||||||
|
memcpy_P(buffer, PSTR("HOLD"), sizeof(buffer));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LV_EVENT_PRESS_LOST:
|
case LV_EVENT_PRESS_LOST:
|
||||||
strcat_P(buffer, PSTR("Lost Press"));
|
// strcat_P(buffer, PSTR("Lost Press"));
|
||||||
debugPrintln(buffer);
|
// debugPrintln(buffer);
|
||||||
eventid = 9;
|
// eventid = 9;
|
||||||
|
memcpy_P(buffer, PSTR("LOST"), sizeof(buffer));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LV_EVENT_PRESSING:
|
case LV_EVENT_PRESSING:
|
||||||
@ -1230,7 +1273,11 @@ static void btn_event_handler(lv_obj_t * obj, lv_event_t event)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// printf("p[%u].b[%u].val = %u ", pageid, objid, eventid);
|
// printf("p[%u].b[%u].val = %u ", pageid, objid, eventid);
|
||||||
mqttSendNewEvent(pageid, objid, eventid);
|
if(obj == lv_disp_get_layer_sys(NULL)) {
|
||||||
|
mqttSendState("wakeuptouch", buffer);
|
||||||
|
} else {
|
||||||
|
mqttSendNewEvent(pageid, objid, buffer);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void btnmap_event_handler(lv_obj_t * obj, lv_event_t event)
|
static void btnmap_event_handler(lv_obj_t * obj, lv_event_t event)
|
||||||
@ -1238,6 +1285,12 @@ static void btnmap_event_handler(lv_obj_t * obj, lv_event_t event)
|
|||||||
if(event == LV_EVENT_VALUE_CHANGED) haspSendNewValue(obj, lv_btnm_get_pressed_btn(obj));
|
if(event == LV_EVENT_VALUE_CHANGED) haspSendNewValue(obj, lv_btnm_get_pressed_btn(obj));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void toggle_event_handler(lv_obj_t * obj, lv_event_t event)
|
||||||
|
{
|
||||||
|
bool toggled = lv_btn_get_state(obj) == LV_BTN_STATE_TGL_PR || lv_btn_get_state(obj) == LV_BTN_STATE_TGL_REL;
|
||||||
|
if(event == LV_EVENT_VALUE_CHANGED) haspSendNewValue(obj, toggled);
|
||||||
|
}
|
||||||
|
|
||||||
static void slider_event_handler(lv_obj_t * obj, lv_event_t event)
|
static void slider_event_handler(lv_obj_t * obj, lv_event_t event)
|
||||||
{
|
{
|
||||||
if(event == LV_EVENT_VALUE_CHANGED) haspSendNewValue(obj, lv_slider_get_value(obj));
|
if(event == LV_EVENT_VALUE_CHANGED) haspSendNewValue(obj, lv_slider_get_value(obj));
|
||||||
@ -1369,14 +1422,15 @@ void haspNewObject(const JsonObject & config)
|
|||||||
case LV_HASP_BUTTON: {
|
case LV_HASP_BUTTON: {
|
||||||
obj = lv_btn_create(parent_obj, NULL);
|
obj = lv_btn_create(parent_obj, NULL);
|
||||||
bool toggle = config[F("toggle")].as<bool>();
|
bool toggle = config[F("toggle")].as<bool>();
|
||||||
lv_btn_set_toggle(obj, toggle);
|
haspSetToggle(obj, toggle);
|
||||||
if(config[F("txt")]) {
|
// lv_btn_set_toggle(obj, toggle);
|
||||||
label = lv_label_create(obj, NULL);
|
// if(config[F("txt")]) {
|
||||||
lv_label_set_text(label, config[F("txt")].as<String>().c_str());
|
label = lv_label_create(obj, NULL);
|
||||||
lv_obj_set_opa_scale_enable(label, true);
|
lv_label_set_text(label, config[F("txt")].as<String>().c_str());
|
||||||
lv_obj_set_opa_scale(label, LV_OPA_COVER);
|
lv_obj_set_opa_scale_enable(label, true);
|
||||||
}
|
lv_obj_set_opa_scale(label, LV_OPA_COVER);
|
||||||
lv_obj_set_event_cb(obj, btn_event_handler);
|
//}
|
||||||
|
// lv_obj_set_event_cb(obj, btn_event_handler);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case LV_HASP_CHECKBOX: {
|
case LV_HASP_CHECKBOX: {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user