From 4d54cd42853da739d3e720d1bdfa5fac1721422a Mon Sep 17 00:00:00 2001 From: redfast00 Date: Tue, 15 Mar 2022 13:46:18 +0100 Subject: [PATCH] Add more robust error printing --- lib/obus_can.cpp | 4 ++++ lib/obus_can.h | 1 + lib/obus_module.cpp | 8 +++++--- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/obus_can.cpp b/lib/obus_can.cpp index eccf30e..9bf2496 100644 --- a/lib/obus_can.cpp +++ b/lib/obus_can.cpp @@ -190,6 +190,10 @@ bool is_error_condition() { return mcp2515.getInterrupts() & MCP2515::CANINTF_ERRIF; } +uint8_t get_error_flags() { + return mcp2515.getErrorFlags(); +} + void send(struct message *msg) { if (!is_init) { Serial.println(F("E Call init first")); diff --git a/lib/obus_can.h b/lib/obus_can.h index 7f23274..0836dab 100644 --- a/lib/obus_can.h +++ b/lib/obus_can.h @@ -113,6 +113,7 @@ void send(struct message *msg); bool is_error_condition(); +uint8_t get_error_flags(); /** * For internal use only diff --git a/lib/obus_module.cpp b/lib/obus_module.cpp index 20a6860..e2cd3d4 100644 --- a/lib/obus_module.cpp +++ b/lib/obus_module.cpp @@ -6,6 +6,7 @@ #define BLINK_DELAY_SLOW 1000 #define BLINK_DELAY_FAST 300 +#define BLINK_DELAY_VERY_FAST 100 #define MAX_TIME_BETWEEN_CALLS 100 @@ -79,11 +80,11 @@ void _setLedBlink(struct color color, uint16_t delay) { void blink_error(String message) { bool blink = false; + digitalWrite(PIN_LED_GREEN, LOW); while (true) { digitalWrite(PIN_LED_RED, blink); - digitalWrite(PIN_LED_GREEN, blink); blink = !blink; - delay(blink ? BLINK_DELAY_SLOW : BLINK_DELAY_FAST); + delay(BLINK_DELAY_VERY_FAST); Serial.println(message); } } @@ -132,7 +133,8 @@ bool loopPuzzle(obus_can::message* message, void (*callback_game_start)(uint8_t // We will need to fork our CAN library for this, because the needed functions are private. // Also, we can't do this by default, because the INT pin is normally not connected to the board if (obus_can::is_error_condition()) { - blink_error(F("E CAN error")); + + blink_error("E CAN error " + String(obus_can::get_error_flags(), BIN)); } // Force the user of the library to periodically call loop