💡 Adds led service

This commit is contained in:
Rune Harlyk
2024-07-01 21:09:18 +02:00
committed by Rune Harlyk
parent 9d127230ca
commit 73019c008b
5 changed files with 80 additions and 1 deletions
+1
View File
@@ -14,4 +14,5 @@ build_flags =
-D FT_MAG=0 -D FT_MAG=0
-D FT_BMP=0 -D FT_BMP=0
-D FT_GPS=0 -D FT_GPS=0
-D FT_WS2812=0
-D FT_SERVO=1 -D FT_SERVO=1
+10 -1
View File
@@ -66,6 +66,9 @@ ESP32SvelteKit::ESP32SvelteKit(PsychicHttpServer *server,
#if FT_ENABLED(FT_IMU) || FT_ENABLED(FT_MAG) || FT_ENABLED(FT_BMP) #if FT_ENABLED(FT_IMU) || FT_ENABLED(FT_MAG) || FT_ENABLED(FT_BMP)
_imuService(&_socket), _imuService(&_socket),
#endif #endif
#if FT_ENABLED(FT_WS2812)
_ledService(&_taskManager),
#endif
#if FT_ENABLED(FT_SERVO) #if FT_ENABLED(FT_SERVO)
_servoController(server, &ESPFS, &_securitySettingsService, &_socket), _servoController(server, &ESPFS, &_securitySettingsService, &_socket),
#endif #endif
@@ -215,6 +218,9 @@ void ESP32SvelteKit::startServices() {
_servoController.begin(); _servoController.begin();
_servoController.configure(); _servoController.configure();
#endif #endif
#if FT_ENABLED(FT_WS2812)
_ledService.begin();
#endif
} }
void IRAM_ATTR ESP32SvelteKit::_loop() { void IRAM_ATTR ESP32SvelteKit::_loop() {
@@ -233,6 +239,9 @@ void IRAM_ATTR ESP32SvelteKit::_loop() {
#if FT_ENABLED(FT_SERVO) #if FT_ENABLED(FT_SERVO)
_servoController.loop(); _servoController.loop();
#endif #endif
vTaskDelay(20 / portTICK_PERIOD_MS); #if FT_ENABLED(FT_WS2812)
_ledService.loop();
#endif
delay(20);
} }
} }
@@ -29,6 +29,7 @@
#include <ServoController.h> #include <ServoController.h>
#include <ESPFS.h> #include <ESPFS.h>
#include <ESPmDNS.h> #include <ESPmDNS.h>
#include <LEDService.h>
#include <EventSocket.h> #include <EventSocket.h>
#include <FactoryResetService.h> #include <FactoryResetService.h>
#include <FeaturesService.h> #include <FeaturesService.h>
@@ -249,6 +250,9 @@ private:
#if FT_ENABLED(FT_SERVO) #if FT_ENABLED(FT_SERVO)
ServoController _servoController; ServoController _servoController;
#endif #endif
#if FT_ENABLED(FT_WS2812)
LEDService _ledService;
#endif
String _appName = APP_NAME; String _appName = APP_NAME;
+63
View File
@@ -0,0 +1,63 @@
#ifndef LEDService_h
#define LEDService_h
#include <FastLED.h>
#include <TaskManager.h>
#ifndef WS2812_PIN
#define WS2812_PIN 12
#endif
#ifndef WS2812_NUM_LEDS
#define WS2812_NUM_LEDS 1+12
#endif
#define COLOR_ORDER GRB
#define CHIPSET WS2811
class LEDService
{
private:
TaskManager *_taskManager;
unsigned long _lastUpdate = 0;
CRGB leds[WS2812_NUM_LEDS];
CRGBPalette16 currentPalette;
TBlendType currentBlending;
int _brightness = 255;
int direction = 1;
public:
LEDService(TaskManager *taskManager) :
_taskManager(taskManager)
{
FastLED.addLeds<CHIPSET, WS2812_PIN, COLOR_ORDER>(leds, WS2812_NUM_LEDS).setCorrection( TypicalLEDStrip );
currentPalette = OceanColors_p;
currentBlending = LINEARBLEND;
}
~LEDService(){}
void begin(){}
void loop(){
if (millis() - _lastUpdate < 1000 / 60) return;
if (_brightness >= 200) direction = -5;
if (_brightness <= 50) direction = 5;
_brightness += direction;
fillFromPallette(0);
FastLED.show();
_lastUpdate = millis();
}
void fillFromPallette(uint8_t colorIndex) {
CRGB color = ColorFromPalette(currentPalette, colorIndex, _brightness, currentBlending);
for( int i = 0; i < WS2812_NUM_LEDS; ++i) {
leds[i] = color;
}
}
};
#endif
+2
View File
@@ -43,6 +43,7 @@ build_flags =
${env.build_flags} ${env.build_flags}
-D FT_CAMERA=1 -D FT_CAMERA=1
-D CAMERA_MODEL_ESP32S3_EYE=1 -D CAMERA_MODEL_ESP32S3_EYE=1
-D WS2812_PIN=48
-D SDA_PIN=47 -D SDA_PIN=47
-D SCL_PIN=21 -D SCL_PIN=21
@@ -87,6 +88,7 @@ lib_deps =
adafruit/Adafruit BusIO@^1.9.3 adafruit/Adafruit BusIO@^1.9.3
adafruit/Adafruit PWM Servo Driver Library@^2.4.1 adafruit/Adafruit PWM Servo Driver Library@^2.4.1
adafruit/Adafruit ST7735 and ST7789 Library@^1.10.4 adafruit/Adafruit ST7735 and ST7789 Library@^1.10.4
fastled/FastLED@^3.7.0
SPI SPI
extra_scripts = extra_scripts =
pre:scripts/pre_build.py pre:scripts/pre_build.py