From d5ac1ee5534710e105b699d2069b6b6f9b6869d3 Mon Sep 17 00:00:00 2001 From: Gediminas Jakutis Date: Fri, 27 Apr 2018 13:53:54 +0300 Subject: tempmodule: report error state by turning on all temperatre LEDs. --- src/tempmodule/indicator.c | 16 +++++++++------- src/tempmodule/indicator.h | 6 +++--- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/tempmodule/indicator.c b/src/tempmodule/indicator.c index 4c1b958..2968958 100644 --- a/src/tempmodule/indicator.c +++ b/src/tempmodule/indicator.c @@ -28,8 +28,8 @@ struct indicator { unsigned int red; unsigned int green; unsigned int blue; - unsigned int current_temp; - unsigned int calibration[4]; + int current_temp; + int calibration[4]; }; static struct indicator state; @@ -39,9 +39,9 @@ static const unsigned int blueled = 14; /* D5 */ static void indicator_set_state(unsigned int red, unsigned int green, unsigned int blue); -void indicator_init(unsigned int temp, unsigned int const * const calibration) +void indicator_init(int temp, unsigned int const * const calibration) { - static const unsigned int default_calibration[] = {3430, 3330, 3230, 3130}; + static const int default_calibration[] = {3430, 3330, 3230, 3130}; pinMode(redled, OUTPUT); pinMode(greenled, OUTPUT); @@ -57,14 +57,16 @@ void indicator_init(unsigned int temp, unsigned int const * const calibration) } -void indicator_update(const unsigned int temp, const unsigned int on) +void indicator_update(const int temp, const unsigned int on) { if (!on) { indicator_set_state(0, 0, 0); return; } - if (temp > state.calibration[0]) { + if (temp == -1) { + indicator_set_state(1, 1, 1); + } else if (temp > state.calibration[0]) { indicator_set_state(1, 0, 0); } else if (temp > state.calibration[1]) { indicator_set_state(1, 1, 0); @@ -77,7 +79,7 @@ void indicator_update(const unsigned int temp, const unsigned int on) } } -void indicator_calibrate(unsigned int const * const calibration) +void indicator_calibrate(int const * const calibration) { memcpy(state.calibration, calibration, sizeof(state.calibration)); indicator_update(state.current_temp, 1); diff --git a/src/tempmodule/indicator.h b/src/tempmodule/indicator.h index d44b7fe..99f4e1c 100644 --- a/src/tempmodule/indicator.h +++ b/src/tempmodule/indicator.h @@ -25,9 +25,9 @@ extern "C" { #endif -void indicator_init(unsigned int temp, unsigned int const * const calibration); -void indicator_update(const unsigned int temp, const unsigned int on); -void indicator_calibrate(unsigned int const * const calibration); +void indicator_init(int temp, unsigned int const * const calibration); +void indicator_update(const int temp, const unsigned int on); +void indicator_calibrate(int const * const calibration); #ifdef __cplusplus } -- cgit v1.2.3