Reduced code duplication and fixed adjust cursor bug
This commit is contained in:
parent
e08a3a5291
commit
d2f3bba544
1 changed files with 23 additions and 18 deletions
|
@ -158,10 +158,14 @@ static void drawAdjustBase(const char* title, bool all) {
|
||||||
drawAdjCursor(WHITE);
|
drawAdjCursor(WHITE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void drawLineCursor(uint16_t hPos, uint16_t vPos, int color) {
|
||||||
|
display.drawLine(hPos, vPos,hPos, vPos+6, color);
|
||||||
|
}
|
||||||
|
|
||||||
static bool updateAdjustLineCursor(uint32_t timeNow, uint16_t hPos, uint16_t vPos ) {
|
static bool updateAdjustLineCursor(uint32_t timeNow, uint16_t hPos, uint16_t vPos ) {
|
||||||
if ((timeNow - cursorBlinkTime) > cursorBlinkInterval) {
|
if ((timeNow - cursorBlinkTime) > cursorBlinkInterval) {
|
||||||
if (cursorNow == WHITE) cursorNow = BLACK; else cursorNow = WHITE;
|
if (cursorNow == WHITE) cursorNow = BLACK; else cursorNow = WHITE;
|
||||||
display.drawLine(hPos, vPos,hPos, vPos+6, cursorNow);;
|
drawLineCursor(hPos, vPos, cursorNow);
|
||||||
cursorBlinkTime = timeNow;
|
cursorBlinkTime = timeNow;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -282,6 +286,21 @@ static bool updateAdjustCursor(uint32_t timeNow) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool handleInput(const AdjustMenuEntry *currentMenu, uint32_t timeNow, uint8_t buttons, uint16_t *xpos, int ypos, int index) {
|
||||||
|
if (buttons) {
|
||||||
|
drawAdjustBar( buttons, ypos, ¤tMenu->entries[index], xpos );
|
||||||
|
int last = adjustCurrent;
|
||||||
|
if(buttons == BTN_ENTER) adjustCurrent += 1;
|
||||||
|
else if( buttons == BTN_MENU) adjustCurrent = 0;
|
||||||
|
|
||||||
|
if(last != adjustCurrent) drawLineCursor(*xpos, ypos, WHITE);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return updateAdjustLineCursor(timeNow, *xpos, ypos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int updateAdjustMenu(uint32_t timeNow, KeyState &input, bool firstRun, bool drawSensor) {
|
int updateAdjustMenu(uint32_t timeNow, KeyState &input, bool firstRun, bool drawSensor) {
|
||||||
bool redraw = false;
|
bool redraw = false;
|
||||||
int result = 0;
|
int result = 0;
|
||||||
|
@ -327,27 +346,13 @@ int updateAdjustMenu(uint32_t timeNow, KeyState &input, bool firstRun, bool draw
|
||||||
currentMenu->saveFunc(*currentMenu);
|
currentMenu->saveFunc(*currentMenu);
|
||||||
|
|
||||||
} else if( adjustCurrent == 1) {
|
} else if( adjustCurrent == 1) {
|
||||||
if (buttons) {
|
handleInput(currentMenu, timeNow, buttons, &pos1, 20, 0);
|
||||||
drawAdjustBar( buttons, 20, ¤tMenu->entries[0], &pos1 );
|
|
||||||
if(buttons == BTN_ENTER) adjustCurrent += 1;
|
|
||||||
else if( buttons == BTN_MENU) adjustCurrent = 0;
|
|
||||||
redraw = true;
|
|
||||||
} else {
|
|
||||||
redraw |= updateAdjustLineCursor( timeNow, pos1, 20 );
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if (buttons) {
|
handleInput(currentMenu, timeNow, buttons, &pos2, 50, 1);
|
||||||
drawAdjustBar( buttons, 50, ¤tMenu->entries[1], &pos2 );
|
|
||||||
if(buttons == BTN_ENTER) adjustCurrent += 1;
|
|
||||||
else if( buttons == BTN_MENU) adjustCurrent = 0;
|
|
||||||
redraw = true;
|
|
||||||
} else {
|
|
||||||
redraw |= updateAdjustLineCursor( timeNow, pos2, 50 );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Keep adjustCurrent in range
|
// Keep adjustCurrent in range
|
||||||
if( adjustCurrent > 2 || (adjustCurrent == 2 && currentMenu->entries[1].value == nullptr))
|
if( (adjustCurrent > 2) || ((adjustCurrent == 2) && (currentMenu->entries[1].value == nullptr)))
|
||||||
adjustCurrent = 0;
|
adjustCurrent = 0;
|
||||||
|
|
||||||
// Keep adjust option in range.
|
// Keep adjust option in range.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue