mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-07-28 13:46:36 +00:00
Remember last pageid for mqtt messages
This commit is contained in:
parent
f96e88d63c
commit
ec616daa80
@ -51,6 +51,7 @@ uint8_t nCommands = 0;
|
||||
haspCommand_t commands[26];
|
||||
|
||||
moodlight_t moodlight = {.brightness = 255};
|
||||
uint8_t saved_jsonl_page = 0;
|
||||
|
||||
/* Sends the payload out on the state/subtopic
|
||||
*/
|
||||
@ -628,12 +629,12 @@ void dispatch_parse_json(const char*, const char* payload, uint8_t source)
|
||||
}
|
||||
|
||||
#ifdef ARDUINO
|
||||
void dispatch_parse_jsonl(Stream& stream)
|
||||
void dispatch_parse_jsonl(Stream& stream, uint8_t& saved_page_id)
|
||||
#else
|
||||
void dispatch_parse_jsonl(std::istream& stream)
|
||||
void dispatch_parse_jsonl(std::istream& stream, uint8_t& saved_page_id)
|
||||
#endif
|
||||
{
|
||||
uint8_t savedPage = haspPages.get();
|
||||
// uint8_t savedPage = haspPages.get();
|
||||
uint16_t line = 1;
|
||||
DynamicJsonDocument jsonl(MQTT_MAX_PACKET_SIZE / 2 + 128);
|
||||
DeserializationError jsonError = deserializeJson(jsonl, stream);
|
||||
@ -644,30 +645,33 @@ void dispatch_parse_jsonl(std::istream& stream)
|
||||
|
||||
// guiStop();
|
||||
while(jsonError == DeserializationError::Ok) {
|
||||
hasp_new_object(jsonl.as<JsonObject>(), savedPage);
|
||||
hasp_new_object(jsonl.as<JsonObject>(), saved_page_id);
|
||||
jsonError = deserializeJson(jsonl, stream);
|
||||
line++;
|
||||
}
|
||||
// guiStart();
|
||||
|
||||
/* For debugging pourposes */
|
||||
/* For debugging purposes */
|
||||
if(jsonError == DeserializationError::EmptyInput) {
|
||||
LOG_INFO(TAG_MSGR, F(D_JSONL_SUCCEEDED));
|
||||
|
||||
} else {
|
||||
LOG_ERROR(TAG_MSGR, F(D_JSONL_FAILED ": %s"), line, jsonError.c_str());
|
||||
}
|
||||
|
||||
saved_jsonl_page = saved_page_id;
|
||||
}
|
||||
|
||||
void dispatch_parse_jsonl(const char*, const char* payload, uint8_t source)
|
||||
{
|
||||
if(source != TAG_MQTT) saved_jsonl_page = haspPages.get();
|
||||
#if HASP_USE_CONFIG > 0
|
||||
CharStream stream((char*)payload);
|
||||
// stream.setTimeout(10);
|
||||
dispatch_parse_jsonl(stream);
|
||||
dispatch_parse_jsonl(stream, saved_jsonl_page);
|
||||
#else
|
||||
std::istringstream stream((char*)payload);
|
||||
dispatch_parse_jsonl(stream);
|
||||
dispatch_parse_jsonl(stream, saved_jsonl_page);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -50,9 +50,9 @@ void dispatch_topic_payload(const char* topic, const char* payload, bool update,
|
||||
void dispatch_text_line(const char* cmnd, uint8_t source);
|
||||
|
||||
#ifdef ARDUINO
|
||||
void dispatch_parse_jsonl(Stream& stream);
|
||||
void dispatch_parse_jsonl(Stream& stream, uint8_t& saved_page_id);
|
||||
#else
|
||||
void dispatch_parse_jsonl(std::istream& stream);
|
||||
void dispatch_parse_jsonl(std::istream& stream, uint8_t& saved_page_id);
|
||||
#endif
|
||||
|
||||
void dispatch_clear_page(const char* page);
|
||||
|
@ -33,33 +33,46 @@ uint8_t Page::count()
|
||||
return (uint8_t)(sizeof(_pages) / sizeof(*_pages));
|
||||
}
|
||||
|
||||
void Page::swap(lv_obj_t* page, uint8_t id)
|
||||
{
|
||||
if(id > count()) {
|
||||
LOG_WARNING(TAG_HASP, "Invalid page id %d", id);
|
||||
return;
|
||||
}
|
||||
|
||||
// Swap page objects
|
||||
lv_obj_t* prev_page_obj = _pages[id];
|
||||
_pages[id] = page;
|
||||
_pages[id]->user_data.objid = LV_HASP_SCREEN;
|
||||
_pages[id]->user_data.id = 0;
|
||||
|
||||
/**< If the `indev` was pressing this object but swiped out while pressing do not search other object.*/
|
||||
lv_obj_add_protect(_pages[id], LV_PROTECT_PRESS_LOST);
|
||||
lv_obj_set_event_cb(_pages[id], generic_event_handler);
|
||||
|
||||
// Delete previous page object
|
||||
if(prev_page_obj) {
|
||||
if(prev_page_obj == lv_scr_act()) {
|
||||
lv_scr_load_anim(_pages[id], LV_SCR_LOAD_ANIM_NONE, 500, 0, false); // update page screen obj
|
||||
lv_obj_del_async(prev_page_obj);
|
||||
} else
|
||||
lv_obj_del(prev_page_obj);
|
||||
}
|
||||
}
|
||||
|
||||
void Page::init(uint8_t start_page)
|
||||
{
|
||||
lv_obj_t* scr_act = lv_scr_act();
|
||||
lv_obj_clean(lv_layer_top());
|
||||
|
||||
for(int i = 0; i < count(); i++) {
|
||||
lv_obj_t* prev_page_obj = _pages[i];
|
||||
|
||||
_pages[i] = lv_obj_create(NULL, NULL);
|
||||
_pages[i]->user_data.objid = LV_HASP_SCREEN;
|
||||
lv_obj_set_event_cb(_pages[i], generic_event_handler);
|
||||
|
||||
/**< If the `indev` was pressing this object but swiped out while pressing do not search other object.*/
|
||||
lv_obj_add_protect(_pages[i], LV_PROTECT_PRESS_LOST);
|
||||
lv_obj_t* page = lv_obj_create(NULL, NULL);
|
||||
Page::swap(page, i);
|
||||
|
||||
uint16_t thispage = i + PAGE_START_INDEX;
|
||||
_meta_data[i].prev = thispage == PAGE_START_INDEX ? HASP_NUM_PAGES : thispage - PAGE_START_INDEX;
|
||||
_meta_data[i].next = thispage == HASP_NUM_PAGES ? PAGE_START_INDEX : thispage + PAGE_START_INDEX;
|
||||
_meta_data[i].back = start_page;
|
||||
|
||||
if(prev_page_obj) {
|
||||
if(scr_act == prev_page_obj) {
|
||||
lv_scr_load_anim(_pages[i], LV_SCR_LOAD_ANIM_NONE, 500, 0, false); // update page screen obj
|
||||
lv_obj_del_async(prev_page_obj);
|
||||
} else
|
||||
lv_obj_del(prev_page_obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -150,6 +163,7 @@ uint8_t Page::get()
|
||||
|
||||
void Page::load_jsonl(const char* pagesfile)
|
||||
{
|
||||
uint8_t savedPage = haspPages.get();
|
||||
#if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0
|
||||
if(pagesfile[0] == '\0') return;
|
||||
|
||||
@ -170,7 +184,7 @@ void Page::load_jsonl(const char* pagesfile)
|
||||
LOG_ERROR(TAG_HASP, F(D_FILE_LOAD_FAILED), pagesfile);
|
||||
return;
|
||||
}
|
||||
dispatch_parse_jsonl(file);
|
||||
dispatch_parse_jsonl(file, savedPage);
|
||||
file.close();
|
||||
|
||||
LOG_INFO(TAG_HASP, F(D_FILE_LOADED), pagesfile);
|
||||
@ -178,7 +192,7 @@ void Page::load_jsonl(const char* pagesfile)
|
||||
#elif HASP_USE_EEPROM > 0
|
||||
LOG_TRACE(TAG_HASP, F("Loading jsonl from EEPROM..."));
|
||||
EepromStream eepromStream(4096, 1024);
|
||||
dispatch_parse_jsonl(eepromStream);
|
||||
dispatch_parse_jsonl(eepromStream, savedPage);
|
||||
LOG_INFO(TAG_HASP, F("Loaded jsonl from EEPROM"));
|
||||
|
||||
#else
|
||||
@ -192,7 +206,7 @@ void Page::load_jsonl(const char* pagesfile)
|
||||
LOG_TRACE(TAG_HASP, F("Loading %s from disk..."), path);
|
||||
std::ifstream f(path); // taking file as inputstream
|
||||
if(f) {
|
||||
dispatch_parse_jsonl(f);
|
||||
dispatch_parse_jsonl(f, savedPage);
|
||||
}
|
||||
f.close();
|
||||
LOG_INFO(TAG_HASP, F("Loaded %s from disk"), path);
|
||||
@ -211,7 +225,7 @@ void Page::load_jsonl(const char* pagesfile)
|
||||
// LOG_ERROR(TAG_HASP, F("TEST Opening %q from FS failed %d"), path, res);
|
||||
// }
|
||||
|
||||
// dispatch_parse_jsonl(file);
|
||||
// dispatch_parse_jsonl(file, savedPage);
|
||||
// res = lv_fs_close(&file);
|
||||
// if(res == LV_FS_RES_OK) {
|
||||
// LOG_VERBOSE(TAG_HASP, F("Closing %s OK"), path);
|
||||
|
@ -37,6 +37,7 @@ class Page {
|
||||
void clear(uint8_t pageid);
|
||||
// void set(uint8_t pageid);
|
||||
void set(uint8_t pageid, lv_scr_load_anim_t animation);
|
||||
void swap(lv_obj_t* page, uint8_t id);
|
||||
|
||||
void next(lv_scr_load_anim_t animation);
|
||||
void prev(lv_scr_load_anim_t animation);
|
||||
|
Loading…
x
Reference in New Issue
Block a user