Skip to content

Commit

Permalink
Add start message timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
flxkrmr committed Nov 4, 2022
1 parent fe7c480 commit 3499a4b
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
platform = atmelavr
board = uno
framework = arduino
monitor_speed = 19200
lib_deps =
evert-arias/EasyButton@^2.0.1
olikraus/U8g2@^2.34.4
Expand Down
8 changes: 8 additions & 0 deletions src/EecIv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,17 @@ void EecIv::setModeLiveData() {
int EecIv::mainLoop() {
switch(currentState) {
case IDLE:
startMessageCounter = 0;
break;

case SEND_START_MESSAGE:
if(startMessageCounter >= startMessageCounterMax) {
onStartMessageTimeout();
currentState = IDLE;
break;
}
sendStartMessage();
startMessageCounter++;
debugPrint("Send start message");
currentState = ENABLE_READING_FAST_SYNC;
break;
Expand All @@ -92,6 +99,7 @@ int EecIv::mainLoop() {
currentState = WAIT_FAST_SYNC;
case WAIT_FAST_SYNC:
if (waitSyncLoop()) {
startMessageCounter = 0;
currentState = ANSWER_FAST_SYNC;
} else {
if(exceededTimeout()) {
Expand Down
3 changes: 3 additions & 0 deletions src/EecIv.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class EecIv {
callback_t onFaultCodeFinished;
callback_t onKoeoReadCode;
callback_empty_t onKoeoFinished;
callback_empty_t onStartMessageTimeout;

enum OperationMode {
READ_FAULTS,
Expand Down Expand Up @@ -72,6 +73,8 @@ class EecIv {
int koeoCounter = 0;
unsigned long timeoutTimer = 0L;
const unsigned long timeoutMax = 2000UL;
unsigned short startMessageCounter = 0;
const unsigned short startMessageCounterMax = 5;

char out_buf[90];

Expand Down
10 changes: 10 additions & 0 deletions src/EecIvReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ void onFaultCodeFinished(char message[]);
void onKoeoReadCode(char message[]);
void onKoeoFinished();
void onFaultCodeFinished(char message[]);
void onStartMessageTimeout();

void onButtonUp();
void onButtonDown();
Expand All @@ -69,6 +70,7 @@ int mode = FAULT_CODE;

enum SCREEN_MODE {
SELECT_MODE,
START_MESSAGE_TIMEOUT,
READING_FAULT_CODE,
RESULT_FAULT_CODE,
RUNNING_KOEO,
Expand Down Expand Up @@ -99,6 +101,8 @@ void setup() {
eecIv.onFaultCodeFinished = &onFaultCodeFinished;
eecIv.onKoeoReadCode = &onKoeoReadCode;
eecIv.onKoeoFinished = &onKoeoFinished;
eecIv.onStartMessageTimeout = &onStartMessageTimeout;

eecIv.setup();

initSelectMode();
Expand Down Expand Up @@ -162,6 +166,7 @@ void onButtonSelect() {
case SELECT_MODE:
selectMode();
break;
case START_MESSAGE_TIMEOUT:
case RESULT_KOEO:
case RESULT_FAULT_CODE:
initSelectMode();
Expand Down Expand Up @@ -217,6 +222,11 @@ void onKoeoReadCode(char message[]) {
koeo_counter++;
}

void onStartMessageTimeout() {
screenMode = RESULT_FAULT_CODE;
drawMenuScreen(BACK_SIGN, NO_SIGN, NO_SIGN, "Timeout Error", "Is the igni-", "tion on?", "");
}

void onKoeoFinished() {
koeo_counter = 0;
koeo_code = 0;
Expand Down

0 comments on commit 3499a4b

Please sign in to comment.