Fix page rollover crash on screenshot page

This commit is contained in:
fvanroie 2020-03-30 00:25:41 +02:00
parent 946c372ce9
commit 50f8761c3e
3 changed files with 22 additions and 7 deletions

View File

@ -27,4 +27,10 @@
#define HASP_NUM_INPUTS 3 // Buttons #define HASP_NUM_INPUTS 3 // Buttons
#define HASP_NUM_OUTPUTS 3 #define HASP_NUM_OUTPUTS 3
#if defined(ARDUINO_ARCH_ESP32)
#define HASP_NUM_PAGES 12
#else
#define HASP_NUM_PAGES 4
#endif
#endif #endif

View File

@ -105,18 +105,17 @@ 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];
#if defined(ARDUINO_ARCH_ESP8266) #if defined(ARDUINO_ARCH_ESP8266)
static lv_obj_t * pages[4];
// static lv_font_t * haspFonts[4]; // static lv_font_t * haspFonts[4];
// static lv_style_t labelStyles[4]; // static lv_style_t labelStyles[4];
// static lv_style_t rollerStyles[4]; // static lv_style_t rollerStyles[4];
#else #else
static lv_obj_t * pages[12];
// static lv_font_t * haspFonts[8]; // static lv_font_t * haspFonts[8];
// static lv_style_t labelStyles[8]; // static lv_style_t labelStyles[8];
// static lv_style_t rollerStyles[8]; // static lv_style_t rollerStyles[8];
#endif #endif
uint16_t current_page = 0; uint8_t current_page = 0;
// uint16_t current_style = 0; // uint16_t current_style = 0;
/********************** /**********************
@ -963,12 +962,12 @@ void haspClearPage(uint16_t pageid)
} }
} }
uint16_t haspGetPage() uint8_t haspGetPage()
{ {
return current_page; return current_page;
} }
void haspSetPage(uint16_t pageid) void haspSetPage(uint8_t pageid)
{ {
lv_obj_t * page = get_page(pageid); lv_obj_t * page = get_page(pageid);
if(!page) { if(!page) {

View File

@ -689,11 +689,21 @@ void webHandleScreenshot()
if(webServer.hasArg(F("a")) && webServer.arg(F("a")) == F("next")) { if(webServer.hasArg(F("a")) && webServer.arg(F("a")) == F("next")) {
uint8_t page = haspGetPage(); uint8_t page = haspGetPage();
haspSetPage(page + 1); if(page + 1 == HASP_NUM_PAGES) {
page = 0;
} else {
page++;
}
haspSetPage(page);
} }
if(webServer.hasArg(F("a")) && webServer.arg(F("a")) == F("prev")) { if(webServer.hasArg(F("a")) && webServer.arg(F("a")) == F("prev")) {
uint8_t page = haspGetPage(); uint8_t page = haspGetPage();
haspSetPage(page - 1); if(page == 0) {
page = HASP_NUM_PAGES - 1;
} else {
page--;
}
haspSetPage(page);
} }
if(webServer.hasArg(F("q"))) { if(webServer.hasArg(F("q"))) {