Merge pull request #63 from FabLab-Luenen/beta

Beta
This commit is contained in:
bpohvoodoo
2019-12-16 21:06:05 +01:00
committed by GitHub
9 changed files with 97 additions and 83 deletions
+3 -2
View File
@@ -604,6 +604,7 @@ void loop() {
WiFi.disconnect(); WiFi.disconnect();
WiFi.setSleepMode(WIFI_NONE_SLEEP); WiFi.setSleepMode(WIFI_NONE_SLEEP);
WiFi.mode(WIFI_STA); WiFi.mode(WIFI_STA);
WiFi.hostname(HOSTNAME);
WiFi.begin(); WiFi.begin();
} else { } else {
if ((strlen(mqtt_host) != 0) && (mqtt_port != 0) && (mqtt_reconnect_retries < MQTT_MAX_RECONNECT_TRIES)) { if ((strlen(mqtt_host) != 0) && (mqtt_port != 0) && (mqtt_reconnect_retries < MQTT_MAX_RECONNECT_TRIES)) {
@@ -658,7 +659,7 @@ void loop() {
snprintf(mqtt_buf, sizeof(mqtt_buf), "OK =off", ""); snprintf(mqtt_buf, sizeof(mqtt_buf), "OK =off", "");
#endif #endif
#if defined(POWER_SUPPLY) #if defined(POWER_SUPPLY)
digitalWrite(POWER_SUPPLY, LOW); // power off -> external power supply digitalWrite(POWER_SUPPLY, !POWER_ON); // power off -> external power supply
#endif #endif
if (Config.transEffect) { if (Config.transEffect) {
brightness_trans = 0; brightness_trans = 0;
@@ -667,7 +668,7 @@ void loop() {
} }
#if defined(POWER_SUPPLY) #if defined(POWER_SUPPLY)
if (State.mode != OFF) { if (State.mode != OFF) {
if (prevmode != State.mode) {digitalWrite(POWER_SUPPLY, HIGH); } // power on -> external power supply if (prevmode != State.mode) {digitalWrite(POWER_SUPPLY, POWER_ON); } // power on -> external power supply
} }
#endif #endif
+15 -10
View File
@@ -21,10 +21,13 @@ char HOSTNAME[65] = "McLightingRGBW"; // Friedly hostname is configurable just
#define ENABLE_HOMEASSISTANT // If defined, enable Homeassistant integration, ENABLE_MQTT must be active #define ENABLE_HOMEASSISTANT // If defined, enable Homeassistant integration, ENABLE_MQTT must be active
#define MQTT_HOME_ASSISTANT_SUPPORT // If defined, use AMQTT and select Tools -> IwIP Variant -> Higher Bandwidth #define MQTT_HOME_ASSISTANT_SUPPORT // If defined, use AMQTT and select Tools -> IwIP Variant -> Higher Bandwidth
#define ENABLE_BUTTON 14 // If defined, enable button handling code, see: https://github.com/toblum/McLighting/wiki/Button-control, the value defines the input pin (14 / D5) for switching the LED strip on / off, connect this PIN to ground to trigger button. //#define ENABLE_BUTTON 14 // If defined, enable button handling code, see: https://github.com/toblum/McLighting/wiki/Button-control, the value defines the input pin (14 / D5) for switching the LED strip on / off, connect this PIN to ground to trigger button.
//#define ENABLE_BUTTON_GY33 12 // If defined, enable button handling code for GY-33 color sensor to scan color. The value defines the input pin (12 / D6) for read color data with RGB sensor, connect this PIN to ground to trigger button. //#define ENABLE_BUTTON_GY33 12 // If defined, enable button handling code for GY-33 color sensor to scan color. The value defines the input pin (12 / D6) for read color data with RGB sensor, connect this PIN to ground to trigger button.
//#define POWER_SUPPLY 12 // PIN (12 / D6) If defined, enable output to control external power supply //#define POWER_SUPPLY 12 // PIN (12 / D6) If defined, enable output to control external power supply
//#define ENABLE_REMOTE 13 // If defined, enable Remote Control via TSOP31238. The value defines the input pin (13 / D7) for TSOP31238 Out #if defined(POWER_SUPPLY)
#define POWER_ON HIGH // Define the output state to turn on the power supply, either HIGH or LOW. Opposite will be uses for power off.
#endif
#define ENABLE_REMOTE 13 // If defined, enable Remote Control via TSOP31238. The value defines the input pin (13 / D7) for TSOP31238 Out
#if defined(ENABLE_BUTTON_GY33) #if defined(ENABLE_BUTTON_GY33)
#define GAMMA 2.5 // Gamma correction for GY-33 sensor #define GAMMA 2.5 // Gamma correction for GY-33 sensor
@@ -57,7 +60,7 @@ uint8_t prevsegment = 0;
#if defined(ENABLE_REMOTE) #if defined(ENABLE_REMOTE)
uint8_t selected_color = 1; uint8_t selected_color = 1;
uint64_t last_remote_cmd; uint64_t last_remote_cmd;
enum RMT_BTN {ON_OFF, MODE_UP, MODE_DOWN, RED_UP, RED_DOWN, GREEN_UP, GREEN_DOWN, BLUE_UP, BLUE_DOWN, WHITE_UP, WHITE_DOWN, BRIGHTNESS_UP, BRIGHTNESS_DOWN, SPEED_UP, SPEED_DOWN, COL_M, COL_B, COL_X, AUTOMODE, CUST_1, CUST_2, CUST_3, CUST_4, CUST_5, REPEATCMD, BTN_CNT}; enum RMT_BTN {ON_OFF, MODE_UP, MODE_DOWN, RED_UP, RED_DOWN, GREEN_UP, GREEN_DOWN, BLUE_UP, BLUE_DOWN, WHITE_UP, WHITE_DOWN, BRIGHTNESS_UP, BRIGHTNESS_DOWN, SPEED_UP, SPEED_DOWN, COL_M, COL_B, COL_X, AUTOMODE, CUST_1, CUST_2, CUST_3, SEG_UP, SEG_DOWN, REPEATCMD, BTN_CNT};
// Change your IR Commands here. You can see them in console, after you pressed a button on the remote // Change your IR Commands here. You can see them in console, after you pressed a button on the remote
uint64_t rmt_commands[BTN_CNT] = {0xF7C03F, 0xF7708F, 0xF7F00F, 0xF720DF, 0xF710EF, 0xF7A05F, 0xF7906F, 0xF7609F, 0xF750AF, 0xF7E01F, 0xF7D02F, 0xF730CF, 0xF7B04F, 0xF748B7, 0xF7C837, 0xF700FF, 0xF7807F, 0xF740BF, 0xF708F7, 0xF78877, 0xF728D7, 0xF7A857, 0xF76897, 0xF7E817, 0xFFFFFFFFFFFFFFFF}; uint64_t rmt_commands[BTN_CNT] = {0xF7C03F, 0xF7708F, 0xF7F00F, 0xF720DF, 0xF710EF, 0xF7A05F, 0xF7906F, 0xF7609F, 0xF750AF, 0xF7E01F, 0xF7D02F, 0xF730CF, 0xF7B04F, 0xF748B7, 0xF7C837, 0xF700FF, 0xF7807F, 0xF740BF, 0xF708F7, 0xF78877, 0xF728D7, 0xF7A857, 0xF76897, 0xF7E817, 0xFFFFFFFFFFFFFFFF};
#endif #endif
@@ -207,13 +210,16 @@ bool updateConfig = false; // For WiFiManger custom config and config
// Button handling // Button handling
#if defined(ENABLE_BUTTON) #if defined(ENABLE_BUTTON) || defined(ENABLE_BUTTON_GY33)
//#define BTN_MODE_SHORT "STA|mo|fxm| b| s| r1| g1| b1| w1| r2| g2| b2| w2| r3| g3| b3| w3" // Example
#define BTN_MODE_SHORT "STA| 5| 0|255|196| 0| 0| 0|255| 0| 0| 0| 0| 0| 0| 0| 0" // Static white
#define BTN_MODE_MEDIUM "STA| 5| 48|200|196|255|102| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0" // Fire flicker
#define BTN_MODE_LONG "STA| 5| 46|200|196|255|102| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0" // Fireworks random
unsigned long keyPrevMillis = 0;
const unsigned long keySampleIntervalMs = 25; const unsigned long keySampleIntervalMs = 25;
#endif
#if defined(ENABLE_BUTTON)
//#define BTN_MODE_SHORT "STA|mo|fxm| s| b| r1| g1| b1| w1| r2| g2| b2| w2| r3| g3| b3| w3" // Example
#define BTN_MODE_SHORT "STA| 5| 0|196|255| 0| 0| 0|255| 0| 0| 0| 0| 0| 0| 0| 0" // Static white
#define BTN_MODE_MEDIUM "STA| 5| 48|196|200|255|102| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0" // Fire flicker
#define BTN_MODE_LONG "STA| 5| 46|196|200|255|102| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0" // Fireworks random
unsigned long keyPrevMillis = 0;
byte longKeyPressCountMax = 80; // 80 * 25 = 2000 ms byte longKeyPressCountMax = 80; // 80 * 25 = 2000 ms
byte mediumKeyPressCountMin = 20; // 20 * 25 = 500 ms byte mediumKeyPressCountMin = 20; // 20 * 25 = 500 ms
byte KeyPressCount = 0; byte KeyPressCount = 0;
@@ -222,7 +228,6 @@ bool updateConfig = false; // For WiFiManger custom config and config
#if defined(ENABLE_BUTTON_GY33) #if defined(ENABLE_BUTTON_GY33)
unsigned long keyPrevMillis_gy33 = 0; unsigned long keyPrevMillis_gy33 = 0;
const unsigned long keySampleIntervalMs_gy33 = 25;
byte longKeyPressCountMax_gy33 = 80; // 80 * 25 = 2000 ms byte longKeyPressCountMax_gy33 = 80; // 80 * 25 = 2000 ms
byte mediumKeyPressCountMin_gy33 = 20; // 20 * 25 = 500 ms byte mediumKeyPressCountMin_gy33 = 20; // 20 * 25 = 500 ms
byte KeyPressCount_gy33 = 0; byte KeyPressCount_gy33 = 0;
+12 -12
View File
@@ -22,13 +22,13 @@ uint16_t convertSpeed(uint8_t _mcl_speed) {
if (_mcl_speed < 50) { if (_mcl_speed < 50) {
_fx_speed = 65535 - (_mcl_speed * 1000); _fx_speed = 65535 - (_mcl_speed * 1000);
} else if (_mcl_speed < 100) { } else if (_mcl_speed < 100) {
_fx_speed = 16535 - ((_mcl_speed-49) * 250); _fx_speed = 16675 - ((_mcl_speed-49) * 250);
} else if (_mcl_speed < 150) { } else if (_mcl_speed < 150) {
_fx_speed = 4035 - ((_mcl_speed-99) * 50); _fx_speed = 4075 - ((_mcl_speed-99) * 50);
} else if (_mcl_speed < 200) { } else if (_mcl_speed < 200) {
_fx_speed = 1535 - ((_mcl_speed-149) * 25); _fx_speed = 1550 - ((_mcl_speed-149) * 25);
} else { } else {
_fx_speed = 285 - ((_mcl_speed-199) * 5); _fx_speed = 280 - ((_mcl_speed-199) * 5);
} }
_fx_speed = constrain(_fx_speed, SPEED_MIN, SPEED_MAX); _fx_speed = constrain(_fx_speed, SPEED_MIN, SPEED_MAX);
return _fx_speed; return _fx_speed;
@@ -36,14 +36,14 @@ uint16_t convertSpeed(uint8_t _mcl_speed) {
/*uint8_t unconvertSpeed(uint16_t _fx_speed) { /*uint8_t unconvertSpeed(uint16_t _fx_speed) {
uint16_t _mcl_speed = 0; uint16_t _mcl_speed = 0;
if (_fx_speed <= 285) { if (_fx_speed <= 280) {
_mcl_speed = ((285 - _fx_speed)/5) + 199; _mcl_speed = ((280 - _fx_speed)/5) + 199;
} else if (_fx_speed < 1535) { } else if (_fx_speed < 1550) {
_mcl_speed = ((1535 - _fx_speed)/25) + 149; _mcl_speed = ((1550 - _fx_speed)/25) + 149;
} else if (_fx_speed < 4035) { } else if (_fx_speed < 4075) {
_mcl_speed = ((4035 - _fx_speed)/50) + 99; _mcl_speed = ((4075 - _fx_speed)/50) + 99;
} else if (_mcl_speed < 16535) { } else if (_mcl_speed < 16500) {
_mcl_speed = ((16535 - _fx_speed)/250) + 49; _mcl_speed = ((16675 - _fx_speed)/250) + 49;
} else { } else {
_mcl_speed = ((65535 - _fx_speed)/1000); _mcl_speed = ((65535 - _fx_speed)/1000);
} }
@@ -19,13 +19,13 @@ uint16_t handleSegmentOFF(void) {
// *************************************************************************** // ***************************************************************************
void handleAutoPlay(uint8_t _seg) { void handleAutoPlay(uint8_t _seg) {
//WS2812FX::Segment* _seg = strip->getSegment(); //WS2812FX::Segment* _seg = strip->getSegment();
if (autoDelay[_seg] <= millis()) { if (autoDelay[_seg] <= millis()) {
uint32_t _hex_colors[3] = {}; uint32_t _hex_colors[3] = {};
//if (_seg == //if (_seg ==
_hex_colors[0] = autoParams[autoCount[_seg]][0]; _hex_colors[0] = autoParams[autoCount[_seg]][0];
_hex_colors[1] = autoParams[autoCount[_seg]][1]; _hex_colors[1] = autoParams[autoCount[_seg]][1];
_hex_colors[2] = autoParams[autoCount[_seg]][2]; _hex_colors[2] = autoParams[autoCount[_seg]][2];
//} //}
strip->setColors(_seg, _hex_colors); strip->setColors(_seg, _hex_colors);
strip->setSpeed(_seg, convertSpeed((uint16_t)autoParams[autoCount[_seg]][3])); strip->setSpeed(_seg, convertSpeed((uint16_t)autoParams[autoCount[_seg]][3]));
strip->setMode(_seg, (uint8_t)autoParams[autoCount[_seg]][4]); strip->setMode(_seg, (uint8_t)autoParams[autoCount[_seg]][4]);
@@ -60,8 +60,8 @@ uint16_t handleCustomWS(void) {
uint8_t twitch[10]= {50,50,50,50,50,50,50,50,50,50}; uint8_t twitch[10]= {50,50,50,50,50,50,50,50,50,50};
uint8_t dipCount[10] = {0,0,0,0,0,0,0,0,0,0}; uint8_t dipCount[10] = {0,0,0,0,0,0,0,0,0,0};
bool timeToDip[10] = {false,false,false,false,false,false,false,false,false,false}; bool timeToDip[10] = {false,false,false,false,false,false,false,false,false,false};
void hsb2rgbAN1(uint16_t index, uint8_t sat, uint8_t bright, uint16_t led) { void hsb2rgbAN1(uint16_t index, uint8_t sat, uint8_t bright, uint16_t led) {
// Source: https://blog.adafruit.com/2012/03/14/constant-brightness-hsb-to-rgb-algorithm/ // Source: https://blog.adafruit.com/2012/03/14/constant-brightness-hsb-to-rgb-algorithm/
uint8_t temp[5], n = (index >> 8) % 3; uint8_t temp[5], n = (index >> 8) % 3;
@@ -70,7 +70,7 @@ uint16_t handleCustomWS(void) {
temp[2] = (uint8_t)(((((((index & 255) ^ 255) * sat) / 255) + (sat ^ 255)) * bright) / 255); temp[2] = (uint8_t)(((((((index & 255) ^ 255) * sat) / 255) + (sat ^ 255)) * bright) / 255);
strip->setPixelColor(led, temp[n + 2], temp[n + 1], temp[n], 0); strip->setPixelColor(led, temp[n + 2], temp[n + 1], temp[n], 0);
} }
uint16_t handleTV(void) { uint16_t handleTV(void) {
WS2812FX::Segment* _seg = strip->getSegment(); WS2812FX::Segment* _seg = strip->getSegment();
@@ -85,28 +85,28 @@ uint16_t handleCustomWS(void) {
} }
if((millis() - previousMillis[_seg_num]) < twitch[_seg_num]) { if((millis() - previousMillis[_seg_num]) < twitch[_seg_num]) {
uint16_t led=random(_seg->start, _seg->stop); uint16_t led=random(_seg->start, _seg->stop);
ledState[_seg_num] = ledState[_seg_num] == LOW ? HIGH : LOW; // if the LED is off turn it on and vice-versa: ledState[_seg_num] = ledState[_seg_num] == LOW ? HIGH : LOW; // if the LED is off turn it on and vice-versa:
ledstates[led] = ((ledState[_seg_num]) ? 255 : 0); ledstates[led] = ((ledState[_seg_num]) ? 255 : 0);
for (uint16_t j=_seg->start; j<=_seg->stop; j++) { for (uint16_t j=_seg->start; j<=_seg->stop; j++) {
uint16_t index = (j%3 == 0) ? 400 : random(0,767); uint16_t index = (j%3 == 0) ? 400 : random(0,767);
hsb2rgbAN1(index, 200, ledstates[j], j); hsb2rgbAN1(index, 200, ledstates[j], j);
} }
if (dipCount[_seg_num] > dipInterval[_seg_num]) { if (dipCount[_seg_num] > dipInterval[_seg_num]) {
timeToDip[_seg_num] = true; timeToDip[_seg_num] = true;
dipCount[_seg_num] = 0; dipCount[_seg_num] = 0;
dipStartTime[_seg_num] = millis(); dipStartTime[_seg_num] = millis();
darkTime[_seg_num] = random(50,150); darkTime[_seg_num] = random(50,150);
dipInterval[_seg_num] = random(5,250);// cycles of flicker dipInterval[_seg_num] = random(5,250);// cycles of flicker
} }
} }
} else { } else {
if (millis() - dipStartTime[_seg_num] < darkTime[_seg_num]) { if (millis() - dipStartTime[_seg_num] < darkTime[_seg_num]) {
for (uint16_t i=(_seg->start + 3); i<= _seg->stop; i++) { for (uint16_t i=(_seg->start + 3); i<= _seg->stop; i++) {
ledstates[i] = 0; ledstates[i] = 0;
for (uint16_t j=_seg->start; j<=_seg->stop; j++) { for (uint16_t j=_seg->start; j<=_seg->stop; j++) {
uint16_t index = (j%3 == 0) ? 400 : random(0,767); uint16_t index = (j%3 == 0) ? 400 : random(0,767);
hsb2rgbAN1(index, 200, ledstates[j], j); hsb2rgbAN1(index, 200, ledstates[j], j);
} }
} }
} else { } else {
timeToDip[_seg_num] = false; timeToDip[_seg_num] = false;
@@ -116,18 +116,18 @@ uint16_t handleCustomWS(void) {
} }
// *************************************************************************** // ***************************************************************************
// E1.31 mode // E1.31 mode
// *************************************************************************** // ***************************************************************************
uint16_t handleE131(void) { uint16_t handleE131(void) {
WS2812FX::Segment* _seg = strip->getSegment(); WS2812FX::Segment* _seg = strip->getSegment();
if (!e131->isEmpty()) { if (!e131->isEmpty()) {
e131_packet_t packet; e131_packet_t packet;
e131->pull(&packet); // Pull packet from ring buffer e131->pull(&packet); // Pull packet from ring buffer
uint16_t universe = htons(packet.universe); uint16_t universe = htons(packet.universe);
uint8_t *data = packet.property_values + 1; uint8_t *data = packet.property_values + 1;
if (universe < START_UNIVERSE || universe > END_UNIVERSE) return _seg->speed/(_seg->stop - _seg->start); //async will take care about filling the buffer if (universe < START_UNIVERSE || universe > END_UNIVERSE) return _seg->speed/(_seg->stop - _seg->start); //async will take care about filling the buffer
// Serial.printf("Universe %u / %u Channels | Packet#: %u / Errors: %u / CH1: %u\n", // Serial.printf("Universe %u / %u Channels | Packet#: %u / Errors: %u / CH1: %u\n",
// htons(packet.universe), // The Universe for this packet // htons(packet.universe), // The Universe for this packet
// htons(packet.property_value_count) - 1, // Start code is ignored, we're interested in dimmer data // htons(packet.property_value_count) - 1, // Start code is ignored, we're interested in dimmer data
@@ -136,7 +136,7 @@ uint16_t handleCustomWS(void) {
// packet.property_values[1]); // Dimmer data for Channel 1 // packet.property_values[1]); // Dimmer data for Channel 1
/* #if defined(RGBW) /* #if defined(RGBW)
uint16_t multipacketOffset = (universe - START_UNIVERSE) * 128; //if more than 128 LEDs * 4 colors = 512 channels, client will send in next higher universe uint16_t multipacketOffset = (universe - START_UNIVERSE) * 128; //if more than 128 LEDs * 4 colors = 512 channels, client will send in next higher universe
if (NUMLEDS <= multipacketOffset) return; if (Config.stripSize <= multipacketOffset) return _seg->speed/(_seg->stop - _seg->start);
uint16_t len = (128 + multipacketOffset > Config.stripSize) ? (Config.stripSize - multipacketOffset) : 128; uint16_t len = (128 + multipacketOffset > Config.stripSize) ? (Config.stripSize - multipacketOffset) : 128;
#else*/ #else*/
uint16_t multipacketOffset = (universe - START_UNIVERSE) * 170; //if more than 170 LEDs * 3 colors = 510 channels, client will send in next higher universe uint16_t multipacketOffset = (universe - START_UNIVERSE) * 170; //if more than 170 LEDs * 3 colors = 510 channels, client will send in next higher universe
@@ -156,18 +156,18 @@ uint16_t handleCustomWS(void) {
} }
return _seg->speed/(_seg->stop - _seg->start); return _seg->speed/(_seg->stop - _seg->start);
} }
/* /*
* paste in the Fire2012 code with a small edit at the end which uses the * paste in the Fire2012 code with a small edit at the end which uses the
* setPixelColor() function to copy the color data to the ws2812fx instance. * setPixelColor() function to copy the color data to the ws2812fx instance.
*/ */
#include <FastLED.h> //https://github.com/FastLED/FastLED #include <FastLED.h> //https://github.com/FastLED/FastLED
// Fire2012 by Mark Kriegsman, July 2012 // Fire2012 by Mark Kriegsman, July 2012
// as part of "Five Elements" shown here: http://youtu.be/knWiGsmgycY // as part of "Five Elements" shown here: http://youtu.be/knWiGsmgycY
//// ////
// This basic one-dimensional 'fire' simulation works roughly as follows: // This basic one-dimensional 'fire' simulation works roughly as follows:
// There's a underlying array of 'heat' cells, that model the temperature // There's a underlying array of 'heat' cells, that model the temperature
// at each point along the line. Every cycle through the simulation, // at each point along the line. Every cycle through the simulation,
// four steps are performed: // four steps are performed:
// 1) All cells cool down a little bit, losing heat to the air // 1) All cells cool down a little bit, losing heat to the air
// 2) The heat from each cell drifts 'up' and diffuses a little // 2) The heat from each cell drifts 'up' and diffuses a little
@@ -178,7 +178,7 @@ uint16_t handleCustomWS(void) {
// Temperature is in arbitrary units from 0 (cold black) to 255 (white hot). // Temperature is in arbitrary units from 0 (cold black) to 255 (white hot).
// //
// This simulation scales it self a bit depending on NUM_LEDS; it should look // This simulation scales it self a bit depending on NUM_LEDS; it should look
// "OK" on anywhere from 20 to 100 LEDs without too much tweaking. // "OK" on anywhere from 20 to 100 LEDs without too much tweaking.
// //
// I recommend running this simulation at anywhere from 30-100 frames per second, // I recommend running this simulation at anywhere from 30-100 frames per second,
// meaning an interframe delay of about 10-35 milliseconds. // meaning an interframe delay of about 10-35 milliseconds.
@@ -192,34 +192,34 @@ uint16_t handleCustomWS(void) {
// //
// COOLING: How much does the air cool as it rises? // COOLING: How much does the air cool as it rises?
// Less cooling = taller flames. More cooling = shorter flames. // Less cooling = taller flames. More cooling = shorter flames.
// Default 50, suggested range 20-100 // Default 50, suggested range 20-100
#define COOLING 70 #define COOLING 70
// SPARKING: What chance (out of 255) is there that a new spark will be lit? // SPARKING: What chance (out of 255) is there that a new spark will be lit?
// Higher chance = more roaring fire. Lower chance = more flickery fire. // Higher chance = more roaring fire. Lower chance = more flickery fire.
// Default 120, suggested range 50-200. // Default 120, suggested range 50-200.
#define SPARKING 120 #define SPARKING 120
uint16_t handleFire2012(void) { uint16_t handleFire2012(void) {
// Array of temperature readings at each simulation cell // Array of temperature readings at each simulation cell
WS2812FX::Segment* _seg = strip->getSegment(); WS2812FX::Segment* _seg = strip->getSegment();
// Step 1. Cool down every cell a little // Step 1. Cool down every cell a little
for( uint16_t i = _seg->start; i <= _seg->stop; i++) { for( uint16_t i = _seg->start; i <= _seg->stop; i++) {
ledstates[i] = qsub8(ledstates[i], random8(0, ((COOLING * 10) / (_seg->stop - _seg->start)+1) + 2)); ledstates[i] = qsub8(ledstates[i], random8(0, ((COOLING * 10) / (_seg->stop - _seg->start)+1) + 2));
} }
// Step 2. Heat from each cell drifts 'up' and diffuses a little // Step 2. Heat from each cell drifts 'up' and diffuses a little
for( uint16_t k= _seg->stop; k >= (_seg->start + 2); k--) { for( uint16_t k= _seg->stop; k >= (_seg->start + 2); k--) {
ledstates[k] = (ledstates[k - 1] + ledstates[k - 2] + ledstates[k - 2]) / 3; ledstates[k] = (ledstates[k - 1] + ledstates[k - 2] + ledstates[k - 2]) / 3;
} }
// Step 3. Randomly ignite new 'sparks' of heat near the bottom // Step 3. Randomly ignite new 'sparks' of heat near the bottom
if( random8() < SPARKING ) { if( random8() < SPARKING ) {
uint8_t y = random8(7) + _seg->start; uint8_t y = random8(7) + _seg->start;
ledstates[y] = qadd8(ledstates[y], random8(160,255) ); ledstates[y] = qadd8(ledstates[y], random8(160,255) );
} }
// Step 4. Map from heat cells to LED colors // Step 4. Map from heat cells to LED colors
for( uint16_t j = _seg->start; j <= _seg->stop; j++) { for( uint16_t j = _seg->start; j <= _seg->stop; j++) {
CRGB color = HeatColor(ledstates[j]); CRGB color = HeatColor(ledstates[j]);
@@ -233,7 +233,7 @@ uint16_t handleCustomWS(void) {
} }
return _seg->speed/(_seg->stop - _seg->start); return _seg->speed/(_seg->stop - _seg->start);
} }
uint16_t handleGradient(void) { uint16_t handleGradient(void) {
WS2812FX::Segment* _seg = strip->getSegment(); WS2812FX::Segment* _seg = strip->getSegment();
for(uint16_t j = 0; j <= (_seg->stop - _seg->start); j++) { for(uint16_t j = 0; j <= (_seg->stop - _seg->start); j++) {
+20 -17
View File
@@ -432,12 +432,10 @@ void checkpayload(uint8_t * _payload, bool mqtt = false, uint8_t num = 0) {
} }
#if defined(ENABLE_STATE_SAVE) #if defined(ENABLE_STATE_SAVE)
if (_updateState) { if (_updateState) {
DBG_OUTPUT_PORT.println("Saving stripstate.json!");
if(!save_state.active()) save_state.once(3, tickerSaveState); if(!save_state.active()) save_state.once(3, tickerSaveState);
} }
if (_updateSegState) { if (_updateSegState) {
State.mode = SET; State.mode = SET;
DBG_OUTPUT_PORT.println("Saving stripstate_segment.json!");
if(!save_seg_state.active()) save_seg_state.once(3, tickerSaveSegmentState); if(!save_seg_state.active()) save_seg_state.once(3, tickerSaveSegmentState);
} }
@@ -549,11 +547,9 @@ void checkpayload(uint8_t * _payload, bool mqtt = false, uint8_t num = 0) {
} }
#if defined(ENABLE_STATE_SAVE) #if defined(ENABLE_STATE_SAVE)
if (_updateStrip || _updateConfig) { if (_updateStrip || _updateConfig) {
DBG_OUTPUT_PORT.println("Saving config.json!");
if(!save_conf.active()) save_conf.once(3, tickerSaveConfig); if(!save_conf.active()) save_conf.once(3, tickerSaveConfig);
} }
if (_updateState) { if (_updateState) {
DBG_OUTPUT_PORT.println("Saving stripstate.json!");
if(!save_state.active()) save_state.once(3, tickerSaveState); if(!save_state.active()) save_state.once(3, tickerSaveState);
} }
#endif #endif
@@ -867,12 +863,10 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght
} }
#if defined(ENABLE_STATE_SAVE) #if defined(ENABLE_STATE_SAVE)
if (_updateState) { if (_updateState) {
DBG_OUTPUT_PORT.println("Saving stripstate.json!");
if(!save_state.active()) save_state.once(3, tickerSaveState); if(!save_state.active()) save_state.once(3, tickerSaveState);
} }
if (_updateSegState) { if (_updateSegState) {
State.mode = SET; State.mode = SET;
DBG_OUTPUT_PORT.println("Saving stripstate_segment.json!");
if(!save_seg_state.active()) save_seg_state.once(3, tickerSaveSegmentState); if(!save_seg_state.active()) save_seg_state.once(3, tickerSaveSegmentState);
} }
#endif #endif
@@ -1000,6 +994,7 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght
DBG_OUTPUT_PORT.println("Re-connecting to Wi-Fi..."); DBG_OUTPUT_PORT.println("Re-connecting to Wi-Fi...");
WiFi.setSleepMode(WIFI_NONE_SLEEP); WiFi.setSleepMode(WIFI_NONE_SLEEP);
WiFi.mode(WIFI_STA); WiFi.mode(WIFI_STA);
WiFi.hostname(HOSTNAME);
WiFi.begin(); WiFi.begin();
} }
@@ -1189,7 +1184,7 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght
} }
void button_gy33() { void button_gy33() {
if (millis() - keyPrevMillis_gy33 >= keySampleIntervalMs_gy33) { if (millis() - keyPrevMillis_gy33 >= keySampleIntervalMs) {
keyPrevMillis_gy33 = millis(); keyPrevMillis_gy33 = millis();
byte currKeyState_gy33 = digitalRead(ENABLE_BUTTON_GY33); byte currKeyState_gy33 = digitalRead(ENABLE_BUTTON_GY33);
@@ -1250,6 +1245,7 @@ void handleRemote() {
last_remote_cmd = results.value; last_remote_cmd = results.value;
if (State.brightness + chng <= 255) { if (State.brightness + chng <= 255) {
State.brightness = State.brightness + chng; State.brightness = State.brightness + chng;
brightness_trans = State.brightness;
_updateState = true; _updateState = true;
} }
} }
@@ -1257,6 +1253,7 @@ void handleRemote() {
last_remote_cmd = results.value; last_remote_cmd = results.value;
if (State.brightness - chng >= 0) { if (State.brightness - chng >= 0) {
State.brightness = State.brightness - chng; State.brightness = State.brightness - chng;
brightness_trans = State.brightness;
_updateState = true; _updateState = true;
} }
} }
@@ -1475,46 +1472,52 @@ void handleRemote() {
} }
if (results.value == rmt_commands[AUTOMODE]) { // Toggle Automode if (results.value == rmt_commands[AUTOMODE]) { // Toggle Automode
last_remote_cmd = 0; last_remote_cmd = 0;
fx_mode = 56; fx_mode = FX_MODE_CUSTOM_0;
_updateSegState = true; _updateSegState = true;
} }
#if defined(CUSTOM_WS2812FX_ANIMATIONS) #if defined(CUSTOM_WS2812FX_ANIMATIONS)
if (results.value == rmt_commands[CUST_1]) { // Select TV Mode if (results.value == rmt_commands[CUST_1]) { // Select TV Mode
last_remote_cmd = 0; last_remote_cmd = 0;
fx_mode = 57; fx_mode = FX_MODE_CUSTOM_2;
_updateSegState = true; _updateSegState = true;
} }
#endif #endif
if (results.value == rmt_commands[CUST_2]) { // Select Custom Mode 2 if (results.value == rmt_commands[CUST_2]) { // Select Custom Mode 2
last_remote_cmd = 0; last_remote_cmd = 0;
fx_mode = 12; fx_mode = FX_MODE_RAINBOW_CYCLE;
_updateSegState = true; _updateSegState = true;
} }
if (results.value == rmt_commands[CUST_3]) { // Select Custom Mode 3 if (results.value == rmt_commands[CUST_3]) { // Select Custom Mode 3
last_remote_cmd = 0; last_remote_cmd = 0;
fx_mode = 48; fx_mode = FX_MODE_FIRE_FLICKER;
_updateSegState = true; _updateSegState = true;
} }
if (results.value == rmt_commands[CUST_4]) { // Select Custom Mode 4 if (results.value == rmt_commands[SEG_UP]) { // Select segment up
last_remote_cmd = 0; last_remote_cmd = 0;
fx_mode = 21; if ((State.segment < Config.segments - 1) && (State.mode == HOLD)) {
prevsegment = State.segment;
State.segment = State.segment + 1;
getSegmentParams(State.segment);
}
_updateSegState = true; _updateSegState = true;
} }
if (results.value == rmt_commands[CUST_5]) { // Select Custom Mode 5 if (results.value == rmt_commands[SEG_DOWN]) { // Select segment down
last_remote_cmd = 0; last_remote_cmd = 0;
fx_mode = 46; if ((State.segment > 0) && (State.mode == HOLD)) {
prevsegment = State.segment;
State.segment = State.segment - 1;
getSegmentParams(State.segment);
}
_updateSegState = true; _updateSegState = true;
} }
irrecv.resume(); // Receive the next value irrecv.resume(); // Receive the next value
} }
#if defined(ENABLE_STATE_SAVE) #if defined(ENABLE_STATE_SAVE)
if (_updateState) { if (_updateState) {
DBG_OUTPUT_PORT.println("Saving stripstate.json!");
if(!save_state.active()) save_state.once(3, tickerSaveState); if(!save_state.active()) save_state.once(3, tickerSaveState);
} }
if (_updateSegState) { if (_updateSegState) {
State.mode = SET; State.mode = SET;
DBG_OUTPUT_PORT.println("Saving stripstate_segment.json!");
if(!save_seg_state.active()) save_seg_state.once(3, tickerSaveSegmentState); if(!save_seg_state.active()) save_seg_state.once(3, tickerSaveSegmentState);
} }
#endif #endif
-6
View File
@@ -294,11 +294,9 @@ server.on("/config", []() {
#if defined(ENABLE_STATE_SAVE) #if defined(ENABLE_STATE_SAVE)
if (_updateStrip || _updateConfig) { if (_updateStrip || _updateConfig) {
DBG_OUTPUT_PORT.println("Saving config.json!");
if(!save_conf.active()) save_conf.once(3, tickerSaveConfig); if(!save_conf.active()) save_conf.once(3, tickerSaveConfig);
} }
if (_updateState) { if (_updateState) {
DBG_OUTPUT_PORT.println("Saving stripstate.json!");
if(!save_state.active()) save_state.once(3, tickerSaveState); if(!save_state.active()) save_state.once(3, tickerSaveState);
} }
#endif #endif
@@ -312,7 +310,6 @@ server.on("/off", []() {
if (State.mode == OFF) { State.mode = SET; } else { State.mode = OFF; }; if (State.mode == OFF) { State.mode = SET; } else { State.mode = OFF; };
getStateJSON(); getStateJSON();
#if defined(ENABLE_STATE_SAVE) #if defined(ENABLE_STATE_SAVE)
DBG_OUTPUT_PORT.println("Saving stripstate.json!");
if(!save_state.active()) save_state.once(3, tickerSaveState); if(!save_state.active()) save_state.once(3, tickerSaveState);
#endif #endif
}); });
@@ -322,7 +319,6 @@ server.on("/on", []() {
State.mode = SET; State.mode = SET;
getStateJSON(); getStateJSON();
#if defined(ENABLE_STATE_SAVE) #if defined(ENABLE_STATE_SAVE)
DBG_OUTPUT_PORT.println("Saving stripstate.json!");
if(!save_state.active()) save_state.once(3, tickerSaveState); if(!save_state.active()) save_state.once(3, tickerSaveState);
#endif #endif
} else { } else {
@@ -491,11 +487,9 @@ server.on("/set", []() {
#if defined(ENABLE_STATE_SAVE) #if defined(ENABLE_STATE_SAVE)
if (_updateState) { if (_updateState) {
DBG_OUTPUT_PORT.println("Saving stripstate.json!");
if(!save_state.active()) save_state.once(3, tickerSaveState); if(!save_state.active()) save_state.once(3, tickerSaveState);
} }
if (_updateSegState) { if (_updateSegState) {
DBG_OUTPUT_PORT.println("Saving stripstate_segment.json!");
State.mode = SET; State.mode = SET;
if(!save_seg_state.active()) save_seg_state.once(3, tickerSaveSegmentState); if(!save_seg_state.active()) save_seg_state.once(3, tickerSaveSegmentState);
} }
+1 -1
View File
@@ -1 +1 @@
#define SKETCH_VERSION "3.1.0.BETA5" #define SKETCH_VERSION "3.1.0.BETA6"
+10
View File
@@ -237,4 +237,14 @@
* Homeassistant will allways use active segment * Homeassistant will allways use active segment
* E1.31 is only working for one segment at the moment * E1.31 is only working for one segment at the moment
* *
* 09 December
* Version Bump to 3.1.0.BETA6
* bugfixes for IR remote control
* Implemented segments to IR Remote
* Power supply update
* bugfix for Button definitions as speed and brightness were interchanged
* adressed issue #59
* known problems:
* Homeassistant will allways use active segment
* E1.31 is only working for one segment at the moment
*/ */
+7 -6
View File
@@ -1,6 +1,6 @@
# McLighting v3 - The ESP8266 based multi-client lighting gadget # McLighting v3 - The ESP8266 based multi-client lighting gadget
[![Gitter](https://badges.gitter.im/mclighting/Lobby.svg)](https://gitter.im/mclighting/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) [![Build Status](https://travis-ci.com/toblum/McLighting.svg?branch=master)](https://travis-ci.com/toblum/McLighting) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![version](https://img.shields.io/badge/version-v3.0.0-blue.svg)](https://github.com/FabLab-Luenen/McLighting/blob/master/Arduino/McLighting/version.h) [![Gitter](https://badges.gitter.im/mclighting/Lobby.svg)](https://gitter.im/mclighting/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) [![Build Status](https://travis-ci.com/toblum/McLighting.svg?branch=master)](https://travis-ci.com/toblum/McLighting) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![version](https://img.shields.io/badge/version-v3.1.0-blue.svg)](https://github.com/FabLab-Luenen/McLighting/blob/master/Arduino/McLighting/version.h)
McLighting (the multi-client lighting gadget) is a very cheap internet-controllable lighting solution based on the famous ESP8266 microcontroller and WS2811/2812 led strips. It features among other things a web-interface, a REST-API and a websocket connector. McLighting (the multi-client lighting gadget) is a very cheap internet-controllable lighting solution based on the famous ESP8266 microcontroller and WS2811/2812 led strips. It features among other things a web-interface, a REST-API and a websocket connector.
@@ -67,16 +67,17 @@ I hope I didn't miss any sources and mentioned every author. In case I forgot so
## Todos ## Todos
- [ ] Redesign of Code and bump to V3 - [ ] Redesign of Code and bump to V3
- [ ] Support multiple strips and control them separately or together [Issue](https://github.com/toblum/McLighting/issues/118)
- [ ] Support for up to ten segments
- [ ] Customer profile to define segments of (in)active areas on the strip [Issue](https://github.com/toblum/McLighting/issues/37) - [ ] Customer profile to define segments of (in)active areas on the strip [Issue](https://github.com/toblum/McLighting/issues/37)
- [ ] Remove old / wrong EEPROM settings completely [Issue]
- [ ] Additional clients - [ ] Additional clients
- [ ] If no wifi, at least enable button mode. - [x] If no wifi, at least enable button mode.
- [ ] Also enable McLighting in Wifi AP mode. - [x] Also enable McLighting in Wifi AP mode.
- [ ] Search a non-blocking alternative for wifiManager
- [ ] Multiple buttons/GPIO Inputs. [Issue](https://github.com/toblum/McLighting/issues/119) - [ ] Multiple buttons/GPIO Inputs. [Issue](https://github.com/toblum/McLighting/issues/119)
- [ ] Music visualizer / Bring back ArtNet [Issue](https://github.com/toblum/McLighting/issues/111) - [ ] Music visualizer / Bring back ArtNet [Issue](https://github.com/toblum/McLighting/issues/111)
- [ ] Display version and parameters (Number of LEDs, definition settings, ..) in the web UI [Issue](https://github.com/toblum/McLighting/issues/150) - [ ] Display version and parameters (Number of LEDs, definition settings, ..) in the web UI [Issue](https://github.com/toblum/McLighting/issues/150)
- [x] Remove old / wrong EEPROM settings completely [Issue] EEPROM saving discarded
- [x] Support multiple strips and control them separately or together [Issue](https://github.com/toblum/McLighting/issues/118)
- [x] Support for up to ten segments
- [x] Removal of LEGACY_ANIMATIONS - [x] Removal of LEGACY_ANIMATIONS
- [x] Include ws2812fx library to code due to modifications in library - [x] Include ws2812fx library to code due to modifications in library
- [x] Add TV, E1.31 and AUTO to CUSTOM_WS2812FX_ANIMATIONS - [x] Add TV, E1.31 and AUTO to CUSTOM_WS2812FX_ANIMATIONS