Skip to content

Commit

Permalink
fix: lock lcd on clear
Browse files Browse the repository at this point in the history
fix: do not update lastTimerState to ST_Unknown
chore: add stackmat state change debug print
  • Loading branch information
filipton committed May 23, 2024
1 parent 47ce104 commit c84db26
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
8 changes: 7 additions & 1 deletion firmware/src/lcd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,13 @@ void printLcdBuff(bool force) {
// Clears screen and sets cursor on (0, 0)
void lcdClear() {
waitForLock();
lcdWriteLock = true;

memset(&lcdBuff, ' ', LCD_SIZE_X * LCD_SIZE_Y);
lcdBuff[LCD_SIZE_Y-1][LCD_SIZE_X] = '\0';

x = y = 0;
lcdWriteLock = false;
lcdHasChanged = true;
}

Expand All @@ -105,6 +107,7 @@ void lcdClearLine(int line) {
if (line < 0 || line >= LCD_SIZE_Y) return;

waitForLock();
lcdWriteLock = true;

memset(&lcdBuff[line], ' ', LCD_SIZE_X);
lcdBuff[line][LCD_SIZE_X] = '\0';
Expand All @@ -115,6 +118,9 @@ void lcdClearLine(int line) {
if (line == scrollerLine) {
scrollerLine = -1;
}

lcdWriteLock = false;
lcdHasChanged = true;
}

void scrollLoop() {
Expand Down Expand Up @@ -214,8 +220,8 @@ void printToScreen(char *str, bool fillBlank = true, PrintAligment aligment = AL

x = leftOffset + strl;
if (x >= LCD_SIZE_X) x = LCD_SIZE_X;
if (!forceUnlock) lcdWriteLock = false;

if (!forceUnlock) lcdWriteLock = false;
lcdHasChanged = true;
}

Expand Down
12 changes: 8 additions & 4 deletions firmware/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,12 @@ void sleepDetection() {
}

void stackmatLoop() {
if (stackmat.state() != state.lastTimerState && stackmat.state() != ST_Unknown && state.lastTimerState != ST_Unknown) {
switch (stackmat.state()) {
StackmatTimerState stackmatState = stackmat.state();

if (stackmatState != state.lastTimerState && stackmatState != ST_Unknown) {
Logger.printf("Stackmat state change to: %d\n", stackmatState);

switch (stackmatState) {
case ST_Stopped:
if (state.solveTime > 0) break;
if (state.competitorCardId == 0) {
Expand Down Expand Up @@ -195,11 +199,11 @@ void stackmatLoop() {
stateHasChanged = true;
}

if (stackmat.state() == StackmatTimerState::ST_Running && state.currentScene == SCENE_TIMER_TIME) {
if (stackmatState == StackmatTimerState::ST_Running && state.currentScene == SCENE_TIMER_TIME) {
lcdPrintf(0, true, ALIGN_CENTER, "%s", displayTime(stackmat.displayMinutes(), stackmat.displaySeconds(), stackmat.displayMilliseconds()).c_str());
displayStr(displayTime(stackmat.displayMinutes(), stackmat.displaySeconds(), stackmat.displayMilliseconds(), false));
lcdClearLine(1);
}

state.lastTimerState = stackmat.state();
if(stackmatState != ST_Unknown) state.lastTimerState = stackmatState;
}

0 comments on commit c84db26

Please sign in to comment.