handle the leds as user task

This commit is contained in:
andreas 2023-10-24 15:23:54 +02:00
parent 155c7a8d1c
commit 91c1e6f85c
4 changed files with 9 additions and 8 deletions

View File

@ -1,7 +1,7 @@
#include "GwButtons.h" #include "GwButtons.h"
#include "GwHardware.h" #include "GwHardware.h"
#include "GwApi.h" #include "GwApi.h"
#include "GwLeds.h" #include "GwLedTask.h"
class FactoryResetRequest: public GwMessage{ class FactoryResetRequest: public GwMessage{
private: private:

View File

@ -1,4 +1,4 @@
#include "GwLeds.h" #include "GwLedTask.h"
#include "GwHardware.h" #include "GwHardware.h"
#include "GwApi.h" #include "GwApi.h"
#include "FastLED.h" #include "FastLED.h"
@ -23,8 +23,7 @@ static CRGB::HTMLColorCode colorFromMode(GwLedMode cmode){
return CRGB::Black; return CRGB::Black;
} }
} }
void handleLeds(void *param){ void handleLeds(GwApi *api){
GwApi *api=(GwApi*)param;
GwLog *logger=api->getLogger(); GwLog *logger=api->getLogger();
#ifndef GWLED_FASTLED #ifndef GWLED_FASTLED
LOG_DEBUG(GwLog::LOG,"currently only fastled handling"); LOG_DEBUG(GwLog::LOG,"currently only fastled handling");
@ -43,6 +42,7 @@ void handleLeds(void *param){
leds[0]=colorFromMode(currentMode); leds[0]=colorFromMode(currentMode);
FastLED.setBrightness(brightness); FastLED.setBrightness(brightness);
FastLED.show(); FastLED.show();
LOG_DEBUG(GwLog::LOG,"led task started with mode %d",(int)currentMode);
while(true){ while(true){
delay(50); delay(50);
GwLedMode newMode=mode; GwLedMode newMode=mode;

View File

@ -1,7 +1,8 @@
#ifndef _GWLEDS_H #ifndef _GWLEDS_H
#define _GWLEDS_H #define _GWLEDS_H
#include "GwApi.h"
//task function //task function
void handleLeds(void *param); void handleLeds(GwApi *param);
typedef enum { typedef enum {
LED_OFF, LED_OFF,
LED_GREEN, LED_GREEN,
@ -10,4 +11,5 @@ typedef enum {
LED_WHITE LED_WHITE
} GwLedMode; } GwLedMode;
void setLedMode(GwLedMode mode); void setLedMode(GwLedMode mode);
DECLARE_USERTASK(handleLeds);
#endif #endif

View File

@ -54,7 +54,7 @@ const unsigned long HEAP_REPORT_TIME=2000; //set to 0 to disable heap reporting
#include "GwWebServer.h" #include "GwWebServer.h"
#include "NMEA0183DataToN2K.h" #include "NMEA0183DataToN2K.h"
#include "GwButtons.h" #include "GwButtons.h"
#include "GwLeds.h" #include "GwLedTask.h"
#include "GwCounter.h" #include "GwCounter.h"
#include "GwXDRMappings.h" #include "GwXDRMappings.h"
#include "GwSynchronized.h" #include "GwSynchronized.h"
@ -852,9 +852,8 @@ void setup() {
NMEA2000.Open(); NMEA2000.Open();
logger.logDebug(GwLog::LOG,"starting addon tasks"); logger.logDebug(GwLog::LOG,"starting addon tasks");
logger.flush(); logger.flush();
userCodeHandler.startAddonTask(F("handleButtons"),handleButtons,100);
setLedMode(LED_GREEN); setLedMode(LED_GREEN);
userCodeHandler.startAddonTask(F("handleLeds"),handleLeds,101); userCodeHandler.startAddonTask(F("handleButtons"),handleButtons,100);
{ {
GWSYNCHRONIZED(&mainLock); GWSYNCHRONIZED(&mainLock);
userCodeHandler.startUserTasks(MIN_USER_TASK); userCodeHandler.startUserTasks(MIN_USER_TASK);