From 91c1e6f85cb497bd80d4d6c91d65039efb79042b Mon Sep 17 00:00:00 2001 From: andreas Date: Tue, 24 Oct 2023 15:23:54 +0200 Subject: [PATCH] handle the leds as user task --- lib/buttons/GwButtons.cpp | 2 +- lib/{led/GwLeds.cpp => ledtask/GwLedTask.cpp} | 6 +++--- lib/{led/GwLeds.h => ledtask/GwLedTask.h} | 4 +++- src/main.cpp | 5 ++--- 4 files changed, 9 insertions(+), 8 deletions(-) rename lib/{led/GwLeds.cpp => ledtask/GwLedTask.cpp} (91%) rename lib/{led/GwLeds.h => ledtask/GwLedTask.h} (67%) diff --git a/lib/buttons/GwButtons.cpp b/lib/buttons/GwButtons.cpp index c169e48..b810f4f 100644 --- a/lib/buttons/GwButtons.cpp +++ b/lib/buttons/GwButtons.cpp @@ -1,7 +1,7 @@ #include "GwButtons.h" #include "GwHardware.h" #include "GwApi.h" -#include "GwLeds.h" +#include "GwLedTask.h" class FactoryResetRequest: public GwMessage{ private: diff --git a/lib/led/GwLeds.cpp b/lib/ledtask/GwLedTask.cpp similarity index 91% rename from lib/led/GwLeds.cpp rename to lib/ledtask/GwLedTask.cpp index 36de526..54c28bd 100644 --- a/lib/led/GwLeds.cpp +++ b/lib/ledtask/GwLedTask.cpp @@ -1,4 +1,4 @@ -#include "GwLeds.h" +#include "GwLedTask.h" #include "GwHardware.h" #include "GwApi.h" #include "FastLED.h" @@ -23,8 +23,7 @@ static CRGB::HTMLColorCode colorFromMode(GwLedMode cmode){ return CRGB::Black; } } -void handleLeds(void *param){ - GwApi *api=(GwApi*)param; +void handleLeds(GwApi *api){ GwLog *logger=api->getLogger(); #ifndef GWLED_FASTLED LOG_DEBUG(GwLog::LOG,"currently only fastled handling"); @@ -43,6 +42,7 @@ void handleLeds(void *param){ leds[0]=colorFromMode(currentMode); FastLED.setBrightness(brightness); FastLED.show(); + LOG_DEBUG(GwLog::LOG,"led task started with mode %d",(int)currentMode); while(true){ delay(50); GwLedMode newMode=mode; diff --git a/lib/led/GwLeds.h b/lib/ledtask/GwLedTask.h similarity index 67% rename from lib/led/GwLeds.h rename to lib/ledtask/GwLedTask.h index 0d25a9e..a868537 100644 --- a/lib/led/GwLeds.h +++ b/lib/ledtask/GwLedTask.h @@ -1,7 +1,8 @@ #ifndef _GWLEDS_H #define _GWLEDS_H +#include "GwApi.h" //task function -void handleLeds(void *param); +void handleLeds(GwApi *param); typedef enum { LED_OFF, LED_GREEN, @@ -10,4 +11,5 @@ typedef enum { LED_WHITE } GwLedMode; void setLedMode(GwLedMode mode); +DECLARE_USERTASK(handleLeds); #endif \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 94825ac..52f37ef 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -54,7 +54,7 @@ const unsigned long HEAP_REPORT_TIME=2000; //set to 0 to disable heap reporting #include "GwWebServer.h" #include "NMEA0183DataToN2K.h" #include "GwButtons.h" -#include "GwLeds.h" +#include "GwLedTask.h" #include "GwCounter.h" #include "GwXDRMappings.h" #include "GwSynchronized.h" @@ -852,9 +852,8 @@ void setup() { NMEA2000.Open(); logger.logDebug(GwLog::LOG,"starting addon tasks"); logger.flush(); - userCodeHandler.startAddonTask(F("handleButtons"),handleButtons,100); setLedMode(LED_GREEN); - userCodeHandler.startAddonTask(F("handleLeds"),handleLeds,101); + userCodeHandler.startAddonTask(F("handleButtons"),handleButtons,100); { GWSYNCHRONIZED(&mainLock); userCodeHandler.startUserTasks(MIN_USER_TASK);