Browse Source

Initial support for RGB/RGBW 5050 LED strips

fastled
Xose Pérez 7 years ago
parent
commit
fb7e08ec93
7 changed files with 167 additions and 105 deletions
  1. +1
    -1
      code/build-all
  2. +60
    -60
      code/espurna/config/data.h
  3. +11
    -3
      code/espurna/config/general.h
  4. +13
    -0
      code/espurna/config/hardware.h
  5. BIN
      code/espurna/data/index.html.gz
  6. +61
    -41
      code/espurna/light.ino
  7. +21
    -0
      code/platformio.ini

+ 1
- 1
code/build-all View File

@ -1,7 +1,7 @@
#!/bin/bash
# Environments to build
ENVIRONMENTS="sonoff-debug sonoff-dht22-debug sonoff-ds18b20-debug sonoff-pow-debug sonoff-dual-debug sonoff-4ch-debug 1ch-inching-debug electrodragon-debug ecoplug-debug jangoe-debug"
ENVIRONMENTS="sonoff-debug sonoff-dht22-debug sonoff-ds18b20-debug sonoff-pow-debug sonoff-dual-debug sonoff-4ch-debug 1ch-inching-debug electrodragon-debug ecoplug-debug jangoe-debug ai-light-debug led-controller-debug"
# Get current version
version=`cat espurna/config/version.h | grep APP_VERSION | awk '{print $3}' | sed 's/"//g'`


+ 60
- 60
code/espurna/config/data.h
File diff suppressed because it is too large
View File


+ 11
- 3
code/espurna/config/general.h View File

@ -194,16 +194,24 @@
#define LIGHT_PROVIDER_NONE 0
#define LIGHT_PROVIDER_WS2812 1
#define LIGHT_PROVIDER_5050 2
#define LIGHT_PROVIDER_MY9192 3
#define LIGHT_PROVIDER_RGB 2
#define LIGHT_PROVIDER_RGBW 3
#define LIGHT_PROVIDER_MY9192 4
#define LIGHT_DEFAULT_COLOR "#C0C0C0"
#define LIGHT_DEFAULT_COLOR "#000080"
#define LIGHT_SAVE_DELAY 5
#define MY9291_DI_PIN 13
#define MY9291_DCKI_PIN 15
#define MY9291_COMMAND MY9291_COMMAND_DEFAULT
// Shared settings between RGB and RGBW lights
#define RGBW_INVERSE_LOGIC 1
#define RGBW_RED_PIN 14
#define RGBW_GREEN_PIN 5
#define RGBW_BLUE_PIN 12
#define RGBW_WHITE_PIN 13
// -----------------------------------------------------------------------------
// DOMOTICZ
// -----------------------------------------------------------------------------


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

@ -253,6 +253,19 @@
#define RELAY_PROVIDER RELAY_PROVIDER_LIGHT
#define LIGHT_PROVIDER LIGHT_PROVIDER_MY9192
// -----------------------------------------------------------------------------
// LED Controller
// -----------------------------------------------------------------------------
#elif defined(LED_CONTROLLER)
#define MANUFACTURER "MAGIC HOME"
#define DEVICE "LED CONTROLLER"
#define LED1_PIN 2
#define LED1_PIN_INVERSE 1
#define RELAY_PROVIDER RELAY_PROVIDER_LIGHT
#define LIGHT_PROVIDER LIGHT_PROVIDER_RGB
// -----------------------------------------------------------------------------
// Jan Goedeke Wifi Relay
// https://github.com/JanGoe/esp8266-wifi-relay


BIN
code/espurna/data/index.html.gz View File


+ 61
- 41
code/espurna/light.ino View File

@ -10,6 +10,8 @@ Copyright (C) 2016-2017 by Xose Pérez <xose dot perez at gmail dot com>
#include <Ticker.h>
Ticker colorTicker;
bool _lightState = false;
unsigned int _lightColor[3] = {0};
#if LIGHT_PROVIDER == LIGHT_PROVIDER_MY9192
#include <my9291.h>
@ -40,26 +42,53 @@ void color_array2rgb(unsigned int * array, char * rgb) {
}
// -----------------------------------------------------------------------------
// LIGHT MANAGEMENT
// PROVIDER
// -----------------------------------------------------------------------------
void lightColor(const char * rgb, bool save, bool forward) {
void lightColorProvider(unsigned int red, unsigned int green, unsigned int blue) {
#if LIGHT_PROVIDER == LIGHT_PROVIDER_MY9192
#if (LIGHT_PROVIDER == LIGHT_PROVIDER_MY9192) || (LIGHT_PROVIDER == LIGHT_PROVIDER_RGBW)
unsigned int white = 0;
// If all set to the same value use white instead
if ((red == green) && (green == blue)) {
white = red;
red = green = blue = 0;
}
#endif
unsigned int array[4] = {0};
color_rgb2array(rgb, array);
#if LIGHT_PROVIDER == LIGHT_PROVIDER_MY9192
_my9291->setColor((my9291_color_t) { red, green, blue, white });
#endif
// If all set to the same value use white instead
if ((array[0] == array[1]) && (array[1] == array[2])) {
array[3] = array[0];
array[0] = array[1] = array[2] = 0;
#if (LIGHT_PROVIDER == LIGHT_PROVIDER_RGB) || (LIGHT_PROVIDER == LIGHT_PROVIDER_RGBW)
if (RGBW_INVERSE_LOGIC) {
analogWrite(RGBW_RED_PIN, red);
analogWrite(RGBW_GREEN_PIN, green);
analogWrite(RGBW_BLUE_PIN, blue);
#if (LIGHT_PROVIDER == LIGHT_PROVIDER_RGBW)
analogWrite(RGBW_WHITE_PIN, white);
#endif
} else {
analogWrite(RGBW_RED_PIN, 255 - red);
analogWrite(RGBW_GREEN_PIN, 255 - green);
analogWrite(RGBW_BLUE_PIN, 255 - blue);
#if (LIGHT_PROVIDER == LIGHT_PROVIDER_RGBW)
analogWrite(RGBW_WHITE_PIN, 255 - white);
#endif
}
#endif
// Set new color (if light is open it will automatically change)
_my9291->setColor((my9291_color_t) { array[0], array[1], array[2], array[3] });
}
#endif
// -----------------------------------------------------------------------------
// LIGHT MANAGEMENT
// -----------------------------------------------------------------------------
void lightColor(const char * rgb, bool save, bool forward) {
color_rgb2array(rgb, _lightColor);
lightColorProvider(_lightColor[0], _lightColor[1], _lightColor[2]);
// Delay saving to EEPROM 5 seconds to avoid wearing it out unnecessarily
if (save) colorTicker.once(LIGHT_SAVE_DELAY, lightColorSave);
@ -72,44 +101,25 @@ void lightColor(const char * rgb, bool save, bool forward) {
sprintf(message, "{\"color\": \"%s\"}", rgb);
wsSend(message);
}
String lightColor() {
String response;
#if LIGHT_PROVIDER == LIGHT_PROVIDER_MY9192
my9291_color_t color = _my9291->getColor();
unsigned int array[3];
if (color.white > 0) {
array[0] = array[1] = array[2] = color.white;
} else {
array[0] = color.red;
array[1] = color.green;
array[2] = color.blue;
}
char rgb[8];
color_array2rgb(array, rgb);
response = String(rgb);
#endif
return response;
char rgb[8];
color_array2rgb(_lightColor, rgb);
return String(rgb);
}
void lightState(bool state) {
#if LIGHT_PROVIDER == LIGHT_PROVIDER_MY9192
_my9291->setState(state);
#endif
if (state) {
lightColorProvider(_lightColor[0], _lightColor[1], _lightColor[2]);
} else {
lightColorProvider(0, 0, 0);
}
_lightState = state;
}
bool lightState() {
bool response = false;
#if LIGHT_PROVIDER == LIGHT_PROVIDER_MY9192
response = _my9291->getState();
#endif
return response;
return _lightState;
}
// -----------------------------------------------------------------------------
@ -158,6 +168,16 @@ void lightSetup() {
_my9291 = new my9291(MY9291_DI_PIN, MY9291_DCKI_PIN, MY9291_COMMAND);
#endif
#if (LIGHT_PROVIDER == LIGHT_PROVIDER_RGB) || (LIGHT_PROVIDER == LIGHT_PROVIDER_RGBW)
pinMode(RGBW_RED_PIN, OUTPUT);
pinMode(RGBW_GREEN_PIN, OUTPUT);
pinMode(RGBW_BLUE_PIN, OUTPUT);
#if LIGHT_PROVIDER == LIGHT_PROVIDER_RGBW
pinMode(RGBW_WHITE_PIN, OUTPUT);
#endif
lightColorProvider(0, 0, 0);
#endif
lightColorRetrieve();
mqttRegister(lightMQTTCallback);


+ 21
- 0
code/platformio.ini View File

@ -406,3 +406,24 @@ build_flags = ${common.build_flags_1m128} -DAI_LIGHT
upload_speed = 115200
upload_port = "192.168.4.1"
upload_flags = --auth=fibonacci --port 8266
[env:led-controller-debug]
platform = espressif8266
framework = arduino
board = esp12e
lib_deps = ${common.lib_deps}
lib_ignore = ${common.lib_ignore}
extra_script = pio_hooks.py
build_flags = ${common.build_flags} -DLED_CONTROLLER
[env:led-controller-debug-ota]
platform = espressif8266
framework = arduino
board = esp12e
lib_deps = ${common.lib_deps}
lib_ignore = ${common.lib_ignore}
extra_script = pio_hooks.py
build_flags = ${common.build_flags} -DLED_CONTROLLER
upload_speed = 115200
upload_port = "192.168.4.1"
upload_flags = --auth=fibonacci --port 8266

Loading…
Cancel
Save