From 5c2dd19c3f31d4dba629e4c6400a358845cf6cff Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Thu, 10 Dec 2020 21:46:41 -0800 Subject: [PATCH] blink fault codes --- firmware/fault.h | 6 ++++-- firmware/main.cpp | 41 ++++++++++++++++++++++++++--------------- 2 files changed, 30 insertions(+), 17 deletions(-) diff --git a/firmware/fault.h b/firmware/fault.h index 9062984..f5ae19e 100644 --- a/firmware/fault.h +++ b/firmware/fault.h @@ -2,8 +2,10 @@ enum class Fault { - None, - SensorDidntHeat, + None = 0, + + // First fault code at 3 so it's easier to see + SensorDidntHeat = 3, }; void setFault(Fault fault); diff --git a/firmware/main.cpp b/firmware/main.cpp index 06a3a05..b857d4f 100644 --- a/firmware/main.cpp +++ b/firmware/main.cpp @@ -25,8 +25,6 @@ static const UARTConfig uartCfg = .cr3 = 0, }; -char strBuffer[200]; - /* * Application entry point. */ @@ -46,30 +44,43 @@ int main() { while(true) { + if (!hasFault()) + { + // blue is off + palClearPad(GPIOB, 5); + + // Green is blinking + palTogglePad(GPIOB, 6); + + // Fast blink if closed loop, slow if not + chThdSleepMilliseconds(IsRunningClosedLoop() ? 50 : 400); + + continue; + } + auto fault = getCurrentFault(); switch (fault) { case Fault::None: - // blue is off - palClearPad(GPIOB, 5); - - // Green is blinking - palTogglePad(GPIOB, 6); - - // Fast blink if closed loop, slow if not - chThdSleepMilliseconds(IsRunningClosedLoop() ? 50 : 400); break; case Fault::SensorDidntHeat: - // Blue is blinking - palTogglePad(GPIOB, 5); - // green is off palClearPad(GPIOB, 6); - // fast blink - chThdSleepMilliseconds(50); + // Blink out the error code + for (int i = 0; i < 2 * static_cast(fault); i++) + { + // Blue is blinking + palTogglePad(GPIOB, 5); + + // fast blink + chThdSleepMilliseconds(300); + } + break; } + + chThdSleepMilliseconds(2000); } }