Intergated changes of original projects
This commit is contained in:
@@ -49,6 +49,7 @@
|
|||||||
2017-02-02 removed "blackout" on mode, speed or color-change
|
2017-02-02 removed "blackout" on mode, speed or color-change
|
||||||
2017-09-26 implemented segment and reverse features
|
2017-09-26 implemented segment and reverse features
|
||||||
2017-11-16 changed speed calc, reduced memory footprint
|
2017-11-16 changed speed calc, reduced memory footprint
|
||||||
|
2018-02-24 added hooks for user created custom effects
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "WS2812FX.h"
|
#include "WS2812FX.h"
|
||||||
@@ -223,7 +224,7 @@ const __FlashStringHelper* WS2812FX::getModeName(uint8_t m) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void WS2812FX::setSegment(uint8_t n, uint16_t start, uint16_t stop, uint8_t mode, uint32_t color, uint16_t speed, bool reverse) {
|
void WS2812FX::setSegment(uint8_t n, uint16_t start, uint16_t stop, uint8_t mode, uint32_t color, uint16_t speed, bool reverse) {
|
||||||
if(n < MAX_NUM_SEGMENTS) {
|
if(n < (sizeof(_segments) / sizeof(_segments[0]))) {
|
||||||
if(n + 1 > _num_segments) _num_segments = n + 1;
|
if(n + 1 > _num_segments) _num_segments = n + 1;
|
||||||
_segments[n].start = start;
|
_segments[n].start = start;
|
||||||
_segments[n].stop = stop;
|
_segments[n].stop = stop;
|
||||||
@@ -235,7 +236,7 @@ void WS2812FX::setSegment(uint8_t n, uint16_t start, uint16_t stop, uint8_t mode
|
|||||||
}
|
}
|
||||||
|
|
||||||
void WS2812FX::setSegment(uint8_t n, uint16_t start, uint16_t stop, uint8_t mode, const uint32_t colors[], uint16_t speed, bool reverse) {
|
void WS2812FX::setSegment(uint8_t n, uint16_t start, uint16_t stop, uint8_t mode, const uint32_t colors[], uint16_t speed, bool reverse) {
|
||||||
if(n < MAX_NUM_SEGMENTS) {
|
if(n < (sizeof(_segments) / sizeof(_segments[0]))) {
|
||||||
if(n + 1 > _num_segments) _num_segments = n + 1;
|
if(n + 1 > _num_segments) _num_segments = n + 1;
|
||||||
_segments[n].start = start;
|
_segments[n].start = start;
|
||||||
_segments[n].stop = stop;
|
_segments[n].stop = stop;
|
||||||
@@ -252,9 +253,10 @@ void WS2812FX::setSegment(uint8_t n, uint16_t start, uint16_t stop, uint8_t mode
|
|||||||
void WS2812FX::resetSegments() {
|
void WS2812FX::resetSegments() {
|
||||||
memset(_segments, 0, sizeof(_segments));
|
memset(_segments, 0, sizeof(_segments));
|
||||||
memset(_segment_runtimes, 0, sizeof(_segment_runtimes));
|
memset(_segment_runtimes, 0, sizeof(_segment_runtimes));
|
||||||
_segment_index = 0;
|
|
||||||
|
_segment_index = 0;
|
||||||
_num_segments = 1;
|
_num_segments = 1;
|
||||||
setSegment(0, 0, 7, FX_MODE_STATIC, {DEFAULT_COLOR}, DEFAULT_SPEED, false);
|
setSegment(0, 0, 7, FX_MODE_STATIC, DEFAULT_COLOR, DEFAULT_SPEED, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* #####################################################
|
/* #####################################################
|
||||||
@@ -618,7 +620,7 @@ uint16_t WS2812FX::mode_rainbow(void) {
|
|||||||
*/
|
*/
|
||||||
uint16_t WS2812FX::mode_rainbow_cycle(void) {
|
uint16_t WS2812FX::mode_rainbow_cycle(void) {
|
||||||
for(uint16_t i=0; i < SEGMENT_LENGTH; i++) {
|
for(uint16_t i=0; i < SEGMENT_LENGTH; i++) {
|
||||||
uint32_t color = color_wheel(((i * 256 / SEGMENT_LENGTH) + SEGMENT_RUNTIME.counter_mode_step) & 0xFF);
|
uint32_t color = color_wheel(((i * 256 / SEGMENT_LENGTH) + SEGMENT_RUNTIME.counter_mode_step) & 0xFF);
|
||||||
Adafruit_NeoPixel::setPixelColor(SEGMENT.start + i, color);
|
Adafruit_NeoPixel::setPixelColor(SEGMENT.start + i, color);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1353,3 +1355,23 @@ uint16_t WS2812FX::mode_icu() {
|
|||||||
|
|
||||||
return (SEGMENT.speed / SEGMENT_LENGTH);
|
return (SEGMENT.speed / SEGMENT_LENGTH);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Custom mode
|
||||||
|
*/
|
||||||
|
uint16_t (*customMode)(void) = NULL;
|
||||||
|
uint16_t WS2812FX::mode_custom() {
|
||||||
|
if(customMode == NULL) {
|
||||||
|
return 1000; // if custom mode not set, do nothing
|
||||||
|
} else {
|
||||||
|
return customMode();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Custom mode helper
|
||||||
|
*/
|
||||||
|
void WS2812FX::setCustomMode(uint16_t (*p)()) {
|
||||||
|
setMode(FX_MODE_CUSTOM);
|
||||||
|
customMode = p;
|
||||||
|
}
|
||||||
@@ -50,6 +50,8 @@
|
|||||||
#define BRIGHTNESS_MIN 0
|
#define BRIGHTNESS_MIN 0
|
||||||
#define BRIGHTNESS_MAX 255
|
#define BRIGHTNESS_MAX 255
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#define MAX_NUM_SEGMENTS 10
|
#define MAX_NUM_SEGMENTS 10
|
||||||
#define NUM_COLORS 4 /* number of colors per segment */
|
#define NUM_COLORS 4 /* number of colors per segment */
|
||||||
#define SEGMENT _segments[_segment_index]
|
#define SEGMENT _segments[_segment_index]
|
||||||
@@ -70,7 +72,7 @@
|
|||||||
#define ORANGE 0x00FF3000
|
#define ORANGE 0x00FF3000
|
||||||
#define ULTRAWHITE 0xFFFFFFFF
|
#define ULTRAWHITE 0xFFFFFFFF
|
||||||
|
|
||||||
#define MODE_COUNT 56
|
#define MODE_COUNT 57
|
||||||
|
|
||||||
#define FX_MODE_STATIC 0
|
#define FX_MODE_STATIC 0
|
||||||
#define FX_MODE_BLINK 1
|
#define FX_MODE_BLINK 1
|
||||||
@@ -128,6 +130,7 @@
|
|||||||
#define FX_MODE_BICOLOR_CHASE 53
|
#define FX_MODE_BICOLOR_CHASE 53
|
||||||
#define FX_MODE_TRICOLOR_CHASE 54
|
#define FX_MODE_TRICOLOR_CHASE 54
|
||||||
#define FX_MODE_ICU 55
|
#define FX_MODE_ICU 55
|
||||||
|
#define FX_MODE_CUSTOM 56
|
||||||
|
|
||||||
class WS2812FX : public Adafruit_NeoPixel {
|
class WS2812FX : public Adafruit_NeoPixel {
|
||||||
|
|
||||||
@@ -219,6 +222,7 @@ class WS2812FX : public Adafruit_NeoPixel {
|
|||||||
_mode[FX_MODE_RUNNING_LIGHTS] = &WS2812FX::mode_running_lights;
|
_mode[FX_MODE_RUNNING_LIGHTS] = &WS2812FX::mode_running_lights;
|
||||||
_mode[FX_MODE_ICU] = &WS2812FX::mode_icu;
|
_mode[FX_MODE_ICU] = &WS2812FX::mode_icu;
|
||||||
#endif
|
#endif
|
||||||
|
_mode[FX_MODE_CUSTOM] = &WS2812FX::mode_custom;
|
||||||
|
|
||||||
_name[FX_MODE_STATIC] = F("Static");
|
_name[FX_MODE_STATIC] = F("Static");
|
||||||
_name[FX_MODE_BLINK] = F("Blink");
|
_name[FX_MODE_BLINK] = F("Blink");
|
||||||
@@ -276,6 +280,7 @@ class WS2812FX : public Adafruit_NeoPixel {
|
|||||||
_name[FX_MODE_BICOLOR_CHASE] = F("Bicolor Chase");
|
_name[FX_MODE_BICOLOR_CHASE] = F("Bicolor Chase");
|
||||||
_name[FX_MODE_TRICOLOR_CHASE] = F("Tricolor Chase");
|
_name[FX_MODE_TRICOLOR_CHASE] = F("Tricolor Chase");
|
||||||
_name[FX_MODE_ICU] = F("ICU");
|
_name[FX_MODE_ICU] = F("ICU");
|
||||||
|
_name[FX_MODE_CUSTOM] = F("Custom");
|
||||||
|
|
||||||
_brightness = DEFAULT_BRIGHTNESS;
|
_brightness = DEFAULT_BRIGHTNESS;
|
||||||
_running = false;
|
_running = false;
|
||||||
@@ -294,6 +299,7 @@ class WS2812FX : public Adafruit_NeoPixel {
|
|||||||
start(void),
|
start(void),
|
||||||
stop(void),
|
stop(void),
|
||||||
setMode(uint8_t m),
|
setMode(uint8_t m),
|
||||||
|
setCustomMode(uint16_t (*p)()),
|
||||||
setSpeed(uint16_t s),
|
setSpeed(uint16_t s),
|
||||||
increaseSpeed(uint8_t s),
|
increaseSpeed(uint8_t s),
|
||||||
decreaseSpeed(uint8_t s),
|
decreaseSpeed(uint8_t s),
|
||||||
@@ -405,7 +411,8 @@ class WS2812FX : public Adafruit_NeoPixel {
|
|||||||
tricolor_chase(uint32_t, uint32_t, uint32_t),
|
tricolor_chase(uint32_t, uint32_t, uint32_t),
|
||||||
mode_bicolor_chase(void),
|
mode_bicolor_chase(void),
|
||||||
mode_tricolor_chase(void),
|
mode_tricolor_chase(void),
|
||||||
mode_icu(void);
|
mode_icu(void),
|
||||||
|
mode_custom(void);
|
||||||
|
|
||||||
boolean
|
boolean
|
||||||
_running,
|
_running,
|
||||||
|
|||||||
@@ -611,9 +611,15 @@ void shortKeyPress() {
|
|||||||
if (buttonState == false) {
|
if (buttonState == false) {
|
||||||
setModeByStateString(BTN_MODE_SHORT);
|
setModeByStateString(BTN_MODE_SHORT);
|
||||||
buttonState = true;
|
buttonState = true;
|
||||||
|
#ifdef ENABLE_MQTT
|
||||||
|
mqtt_client.publish(mqtt_outtopic, String("OK =static white").c_str());
|
||||||
|
#endif
|
||||||
} else {
|
} else {
|
||||||
mode = OFF;
|
mode = OFF;
|
||||||
buttonState = false;
|
buttonState = false;
|
||||||
|
#ifdef ENABLE_MQTT
|
||||||
|
mqtt_client.publish(mqtt_outtopic, String("OK =off").c_str());
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -621,12 +627,20 @@ void shortKeyPress() {
|
|||||||
void mediumKeyPress() {
|
void mediumKeyPress() {
|
||||||
DBG_OUTPUT_PORT.printf("Medium button press\n");
|
DBG_OUTPUT_PORT.printf("Medium button press\n");
|
||||||
setModeByStateString(BTN_MODE_MEDIUM);
|
setModeByStateString(BTN_MODE_MEDIUM);
|
||||||
|
buttonState = true;
|
||||||
|
#ifdef ENABLE_MQTT
|
||||||
|
mqtt_client.publish(mqtt_outtopic, String("OK =fire flicker").c_str());
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// called when button is kept pressed for 2 seconds or more
|
// called when button is kept pressed for 2 seconds or more
|
||||||
void longKeyPress() {
|
void longKeyPress() {
|
||||||
DBG_OUTPUT_PORT.printf("Long button press\n");
|
DBG_OUTPUT_PORT.printf("Long button press\n");
|
||||||
setModeByStateString(BTN_MODE_LONG);
|
setModeByStateString(BTN_MODE_LONG);
|
||||||
|
buttonState = true;
|
||||||
|
#ifdef ENABLE_MQTT
|
||||||
|
mqtt_client.publish(mqtt_outtopic, String("OK =fireworks random").c_str());
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void button() {
|
void button() {
|
||||||
|
|||||||
@@ -7,6 +7,10 @@
|
|||||||
> Because of it's open architecture and APIs it's easy to build new clients for different platforms (iOS, Android, Windows Universal Apps, Siri/Cortana integration, ...).
|
> Because of it's open architecture and APIs it's easy to build new clients for different platforms (iOS, Android, Windows Universal Apps, Siri/Cortana integration, ...).
|
||||||
|
|
||||||
___
|
___
|
||||||
|
Update 17.02.2018:
|
||||||
|
User @debsahu contributed code for integration with homeassistant. It's currently in a separate branch (https://github.com/toblum/McLighting/tree/feature/ha_integration). If you're using Homeassistant, please try it out and give feedback.
|
||||||
|
A thank you goes to all contributors.
|
||||||
|
|
||||||
Update 31.01.2018:
|
Update 31.01.2018:
|
||||||
User @codmpm did a very professional McLighting installation and even designed his own PCBs. He has a great writeup for his project at: https://allgeek.de/2018/01/29/esp8266-neopixel-controller/ (in german).
|
User @codmpm did a very professional McLighting installation and even designed his own PCBs. He has a great writeup for his project at: https://allgeek.de/2018/01/29/esp8266-neopixel-controller/ (in german).
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user