1
0
mirror of https://github.com/thooge/esp32-nmea2000-obp60.git synced 2025-12-13 05:53:06 +01:00

add led handling for m5atom

This commit is contained in:
andreas
2021-11-06 16:02:30 +01:00
parent 33b2810f97
commit 62151f9c3c
6 changed files with 118 additions and 2 deletions

60
lib/led/GwLeds.cpp Normal file
View File

@@ -0,0 +1,60 @@
#include "GwLeds.h"
#include "GwHardware.h"
#include "GwApi.h"
#include "FastLED.h"
static GwLedMode mode=LED_OFF;
void setLedMode(GwLedMode newMode){
//we consider the mode to an atomic item...
mode=newMode;
}
static CRGB::HTMLColorCode colorFromMode(GwLedMode cmode){
switch(cmode){
case LED_BLUE:
return CRGB::Blue;
case LED_GREEN:
return CRGB::Green;
case LED_RED:
return CRGB::Red;
case LED_WHITE:
return CRGB::White;
default:
return CRGB::Black;
}
}
void handleLeds(void *param){
GwApi *api=(GwApi*)param;
GwLog *logger=api->getLogger();
#ifndef GWLED_FASTLED
LOG_DEBUG(GwLog::LOG,"currently only fastled handling");
vTaskDelete(NULL);
return;
#else
CRGB leds[1];
#ifdef GWLED_SCHEMA
FastLED.addLeds<GWLED_TYPE,GWLED_PIN,GWLED_SCHEMA>(leds,1);
#else
FastLED.addLeds<GWLED_TYPE,GWLED_PIN>(leds,1);
#endif
#ifdef GWLED_BRIGHTNESS
uint8_t brightness=GWLED_BRIGHTNESS;
#else
uint8_t brightness=128; //50%
#endif
GwLedMode currentMode=mode;
leds[0]=colorFromMode(currentMode);
FastLED.setBrightness(brightness);
FastLED.show();
while(true){
delay(50);
GwLedMode newMode=mode;
if (newMode != currentMode){
leds[0]=colorFromMode(newMode);
FastLED.show();
currentMode=newMode;
}
}
vTaskDelete(NULL);
#endif
}

13
lib/led/GwLeds.h Normal file
View File

@@ -0,0 +1,13 @@
#ifndef _GWLEDS_H
#define _GWLEDS_H
//task function
void handleLeds(void *param);
typedef enum {
LED_OFF,
LED_GREEN,
LED_BLUE,
LED_RED,
LED_WHITE
} GwLedMode;
void setLedMode(GwLedMode mode);
#endif