Browse Source

Support for FastLED is back

fastled
Xose Pérez 6 years ago
parent
commit
58bc280eb7
5 changed files with 104 additions and 12 deletions
  1. +27
    -5
      code/espurna/config/general.h
  2. +26
    -0
      code/espurna/config/hardware.h
  3. +39
    -7
      code/espurna/light.ino
  4. +11
    -0
      code/espurna/migrate.ino
  5. +1
    -0
      code/platformio.ini

+ 27
- 5
code/espurna/config/general.h View File

@ -506,6 +506,7 @@ PROGMEM const char* const custom_reset_string[] = {
#define LIGHT_PROVIDER_NONE 0 #define LIGHT_PROVIDER_NONE 0
#define LIGHT_PROVIDER_MY92XX 1 // works with MY9291 and MY9231 #define LIGHT_PROVIDER_MY92XX 1 // works with MY9291 and MY9231
#define LIGHT_PROVIDER_DIMMER 2 #define LIGHT_PROVIDER_DIMMER 2
#define LIGHT_PROVIDER_FASTLED 3
// LIGHT_PROVIDER_DIMMER can have from 1 to 5 different channels. // LIGHT_PROVIDER_DIMMER can have from 1 to 5 different channels.
// They have to be defined for each device in the hardware.h file. // 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 #define LIGHT_SAVE_DELAY 5 // Persist color after 5 seconds to avoid wearing out
#ifndef LIGHT_MAX_PWM #ifndef LIGHT_MAX_PWM
#if LIGHT_PROVIDER == LIGHT_PROVIDER_MY92XX
#define LIGHT_MAX_PWM 255 #define LIGHT_MAX_PWM 255
#endif
#if LIGHT_PROVIDER == LIGHT_PROVIDER_DIMMER #if LIGHT_PROVIDER == LIGHT_PROVIDER_DIMMER
#undef LIGHT_MAX_PWM
#define LIGHT_MAX_PWM 10000 // 5000 * 200ns => 1 kHz #define LIGHT_MAX_PWM 10000 // 5000 * 200ns => 1 kHz
#endif #endif
#endif // LIGHT_MAX_PWM #endif // LIGHT_MAX_PWM
#ifndef LIGHT_LIMIT_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_STEP 10 // Time in millis between each transtion step
#define LIGHT_TRANSITION_STEPS 50 // Number of steps to acomplish transition #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 // DOMOTICZ
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------


+ 26
- 0
code/espurna/config/hardware.h View File

@ -64,6 +64,32 @@
#define LED1_PIN 2 #define LED1_PIN 2
#define LED1_PIN_INVERSE 1 #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 // ESPurna
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------


+ 39
- 7
code/espurna/light.ino View File

@ -12,13 +12,6 @@ Copyright (C) 2016-2017 by Xose Pérez <xose dot perez at gmail dot com>
#include <ArduinoJson.h> #include <ArduinoJson.h>
#include <vector> #include <vector>
#if LIGHT_PROVIDER == LIGHT_PROVIDER_DIMMER
#define PWM_CHANNEL_NUM_MAX LIGHT_CHANNELS
extern "C" {
#include "libs/pwm.h"
}
#endif
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
Ticker _light_save_ticker; Ticker _light_save_ticker;
@ -47,6 +40,18 @@ my92xx * _my92xx;
ARRAYINIT(unsigned char, _light_channel_map, MY92XX_MAPPING); ARRAYINIT(unsigned char, _light_channel_map, MY92XX_MAPPING);
#endif #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 <FastLED.h>
CRGB _fastleds[LIGHT_FASTLED_NUM];
#endif
// Gamma Correction lookup table (8 bit) // Gamma Correction lookup table (8 bit)
// TODO: move to PROGMEM // TODO: move to PROGMEM
const unsigned char _light_gamma_table[] = { const unsigned char _light_gamma_table[] = {
@ -413,6 +418,15 @@ void _lightProviderUpdate() {
#endif #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 #if LIGHT_PROVIDER == LIGHT_PROVIDER_DIMMER
for (unsigned int i=0; i < _light_channel.size(); i++) { for (unsigned int i=0; i < _light_channel.size(); i++) {
@ -871,6 +885,24 @@ void lightSetup() {
#endif #endif
#if LIGHT_PROVIDER == LIGHT_PROVIDER_FASTLED
#if LIGHT_FASTLED_TYPE == NEOPIXEL
FastLED.addLeds<LIGHT_FASTLED_TYPE, LIGHT_FASTLED_DATA_PIN>(_fastleds, LIGHT_FASTLED_NUM);
#else
#ifdef LIGHT_FASTLED_CLOCK_PIN
FastLED.addLeds<LIGHT_FASTLED_TYPE, LIGHT_FASTLED_DATA_PIN, LIGHT_FASTLED_CLOCK_PIN, LIGHT_FASTLED_ORDER>(_fastleds, LIGHT_FASTLED_NUM);
#else
FastLED.addLeds<LIGHT_FASTLED_TYPE, LIGHT_FASTLED_DATA_PIN, LIGHT_FASTLED_ORDER>(_fastleds, LIGHT_FASTLED_NUM);
#endif // LIGHT_FASTLED_CLOCK_PIN
#endif // LIGHT_FASTLED_TYPE == NEOPIXEL
for (unsigned char i=0; i<LIGHT_CHANNELS; i++) {
_light_channel.push_back((channel_t) {0, false, 0, 0, 0});
}
#endif
#if LIGHT_PROVIDER == LIGHT_PROVIDER_DIMMER #if LIGHT_PROVIDER == LIGHT_PROVIDER_DIMMER
#ifdef LIGHT_CH1_PIN #ifdef LIGHT_CH1_PIN


+ 11
- 0
code/espurna/migrate.ino View File

@ -683,6 +683,17 @@ void migrate() {
setSetting("chLogic", 4, 0); setSetting("chLogic", 4, 0);
setSetting("relays", 1); setSetting("relays", 1);
#elif defined(GENERIC_FASTLED)
setSetting("board", 51);
setSetting("relayProvider", RELAY_PROVIDER_LIGHT);
setSetting("lightProvider", LIGHT_PROVIDER_FASTLED);
setSetting("dataGPIO", 0, 5);
//setSetting("ledType", WS2812B);
//setSetting("ledOrder", RGB);
setSetting("ledCount", 41);
setSetting("relays", 1);
#else #else
#error "UNSUPPORTED HARDWARE!" #error "UNSUPPORTED HARDWARE!"


+ 1
- 0
code/platformio.ini View File

@ -24,6 +24,7 @@ lib_deps =
https://github.com/krosk93/espsoftwareserial#a770677 https://github.com/krosk93/espsoftwareserial#a770677
SparkFun BME280 SparkFun BME280
PMS Library PMS Library
FastLED
https://bitbucket.org/xoseperez/justwifi.git#1.1.4 https://bitbucket.org/xoseperez/justwifi.git#1.1.4
https://bitbucket.org/xoseperez/hlw8012.git#1.1.0 https://bitbucket.org/xoseperez/hlw8012.git#1.1.0
https://bitbucket.org/xoseperez/fauxmoesp.git#2.3.0 https://bitbucket.org/xoseperez/fauxmoesp.git#2.3.0


Loading…
Cancel
Save