aboutsummaryrefslogtreecommitdiffstats
path: root/usr/space_light
diff options
context:
space:
mode:
Diffstat (limited to 'usr/space_light')
-rw-r--r--usr/space_light/src/space_light.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/usr/space_light/src/space_light.c b/usr/space_light/src/space_light.c
index eb82c5a..807d9d0 100644
--- a/usr/space_light/src/space_light.c
+++ b/usr/space_light/src/space_light.c
@@ -41,7 +41,7 @@
#define GREEN BK_PWM_4
#define BLUE BK_PWM_5
-TimerHandle_t xOneShotTimer;
+TimerHandle_t xOneShotTimer = NULL;
void power_save_mode() {
// Turn your lights down low
@@ -198,9 +198,18 @@ void set_rgbcw(struct RGBCW *rgbcw) {
static void oneShotTimerCallback(TimerHandle_t xTimer) { power_save_mode(); }
void set_timer(uint16_t seconds) {
- // TODO: reset or disable timer!
- xOneShotTimer =
- xTimerCreate("OneShot", seconds * 1000, pdFALSE, 0, oneShotTimerCallback);
+ // FIXME: restructure the code
+ if (xOneShotTimer == NULL && seconds == 0) {
+ return;
+ }
+ if (seconds == 0) {
+ xTimerStop(xOneShotTimer, 0);
+ }
+
+ if (xOneShotTimer == NULL) {
+ xOneShotTimer = xTimerCreate("OneShot", seconds * 1000, pdFALSE, 0,
+ oneShotTimerCallback);
+ }
if ((xOneShotTimer != NULL)) {
xTimerStart(xOneShotTimer, 0);
}