diff --git a/code/espurna/config/general.h b/code/espurna/config/general.h index b97117b8..1564247f 100644 --- a/code/espurna/config/general.h +++ b/code/espurna/config/general.h @@ -506,6 +506,7 @@ PROGMEM const char* const custom_reset_string[] = { #define LIGHT_PROVIDER_NONE 0 #define LIGHT_PROVIDER_MY92XX 1 // works with MY9291 and MY9231 #define LIGHT_PROVIDER_DIMMER 2 +#define LIGHT_PROVIDER_FASTLED 3 // LIGHT_PROVIDER_DIMMER can have from 1 to 5 different channels. // They have to be defined for each device in the hardware.h file. @@ -524,15 +525,11 @@ PROGMEM const char* const custom_reset_string[] = { #define LIGHT_SAVE_DELAY 5 // Persist color after 5 seconds to avoid wearing out #ifndef LIGHT_MAX_PWM - -#if LIGHT_PROVIDER == LIGHT_PROVIDER_MY92XX #define LIGHT_MAX_PWM 255 -#endif - #if LIGHT_PROVIDER == LIGHT_PROVIDER_DIMMER +#undef LIGHT_MAX_PWM #define LIGHT_MAX_PWM 10000 // 5000 * 200ns => 1 kHz #endif - #endif // LIGHT_MAX_PWM #ifndef LIGHT_LIMIT_PWM @@ -555,6 +552,31 @@ PROGMEM const char* const custom_reset_string[] = { #define LIGHT_TRANSITION_STEP 10 // Time in millis between each transtion step #define LIGHT_TRANSITION_STEPS 50 // Number of steps to acomplish transition +// ----------------------------------------------------------------------------- + +#ifndef LIGHT_FASTLED_TYPE +#define LIGHT_FASTLED_TYPE NEOPIXEL // LED chipset +#endif + +#ifndef LIGHT_FASTLED_NUM +#define LIGHT_FASTLED_NUM 10 // Number of LEDs +#endif + +#ifndef LIGHT_FASTLED_DATA_PIN +#define LIGHT_FASTLED_DATA_PIN 4 // Data GPIO +#endif + +//#define LIGHT_FASTLED_CLOCK_PIN 2 // Clock GPIO, only for SPI based chipsets + +#ifndef LIGHT_FASTLED_ORDER +#define LIGHT_FASTLED_ORDER GRB // Channel order +#endif + +#if LIGHT_PROVIDER == LIGHT_PROVIDER_FASTLED +#undef LIGHT_CHANNELS +#define LIGHT_CHANNELS 3 +#endif + // ----------------------------------------------------------------------------- // DOMOTICZ // ----------------------------------------------------------------------------- diff --git a/code/espurna/config/hardware.h b/code/espurna/config/hardware.h index 971740c8..c5abe456 100644 --- a/code/espurna/config/hardware.h +++ b/code/espurna/config/hardware.h @@ -64,6 +64,32 @@ #define LED1_PIN 2 #define LED1_PIN_INVERSE 1 +#elif defined(GENERIC_FASTLED) + + // Info + #define MANUFACTURER "GENERIC" + #define DEVICE "FASTLED" + + // Buttons + #define BUTTON1_PIN 13 // Connect a pushbutton between D3 and GND, + // it's the same as using a Wemos one button shield + #define BUTTON1_MODE BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH | BUTTON_SET_PULLUP + #define BUTTON1_RELAY 1 + + // Relays + #define RELAY_PROVIDER RELAY_PROVIDER_LIGHT + #define DUMMY_RELAY_COUNT 1 + + // LEDs + #define LED1_PIN 2 + #define LED1_PIN_INVERSE 1 + + #define LIGHT_PROVIDER LIGHT_PROVIDER_FASTLED + #define LIGHT_FASTLED_TYPE WS2812B + #define LIGHT_FASTLED_ORDER RGB + #define LIGHT_FASTLED_NUM 41 + #define LIGHT_FASTLED_DATA_PIN 5 + // ----------------------------------------------------------------------------- // ESPurna // ----------------------------------------------------------------------------- diff --git a/code/espurna/light.ino b/code/espurna/light.ino index 3200fcd2..8fad82f7 100644 --- a/code/espurna/light.ino +++ b/code/espurna/light.ino @@ -12,13 +12,6 @@ Copyright (C) 2016-2017 by Xose PĂ©rez #include #include -#if LIGHT_PROVIDER == LIGHT_PROVIDER_DIMMER -#define PWM_CHANNEL_NUM_MAX LIGHT_CHANNELS -extern "C" { - #include "libs/pwm.h" -} -#endif - // ----------------------------------------------------------------------------- Ticker _light_save_ticker; @@ -47,6 +40,18 @@ my92xx * _my92xx; ARRAYINIT(unsigned char, _light_channel_map, MY92XX_MAPPING); #endif +#if LIGHT_PROVIDER == LIGHT_PROVIDER_DIMMER +#define PWM_CHANNEL_NUM_MAX LIGHT_CHANNELS +extern "C" { + #include "libs/pwm.h" +} +#endif + +#if LIGHT_PROVIDER == LIGHT_PROVIDER_FASTLED +#include +CRGB _fastleds[LIGHT_FASTLED_NUM]; +#endif + // Gamma Correction lookup table (8 bit) // TODO: move to PROGMEM const unsigned char _light_gamma_table[] = { @@ -413,6 +418,15 @@ void _lightProviderUpdate() { #endif + #if LIGHT_PROVIDER == LIGHT_PROVIDER_FASTLED + + for (CRGB & pixel : _fastleds) { + pixel = CRGB(_toPWM(0), _toPWM(1), _toPWM(2)); + } + FastLED.show(); + + #endif + #if LIGHT_PROVIDER == LIGHT_PROVIDER_DIMMER for (unsigned int i=0; i < _light_channel.size(); i++) { @@ -871,6 +885,24 @@ void lightSetup() { #endif + #if LIGHT_PROVIDER == LIGHT_PROVIDER_FASTLED + + #if LIGHT_FASTLED_TYPE == NEOPIXEL + FastLED.addLeds(_fastleds, LIGHT_FASTLED_NUM); + #else + #ifdef LIGHT_FASTLED_CLOCK_PIN + FastLED.addLeds(_fastleds, LIGHT_FASTLED_NUM); + #else + FastLED.addLeds(_fastleds, LIGHT_FASTLED_NUM); + #endif // LIGHT_FASTLED_CLOCK_PIN + #endif // LIGHT_FASTLED_TYPE == NEOPIXEL + + for (unsigned char i=0; i