From 4c93854524db00be44d88b393ad8ee9670c16da6 Mon Sep 17 00:00:00 2001 From: bpohvoodoo Date: Mon, 16 Dec 2019 21:04:10 +0100 Subject: [PATCH] Bumpt to 3.1.0BETA6 * 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 --- Arduino/McLighting/McLighting.ino | 5 ++- Arduino/McLighting/definitions.h | 25 ++++++++----- Arduino/McLighting/helper_functions.h | 24 ++++++------ .../mode_custom_ws2812fx_animations.h | 2 +- Arduino/McLighting/request_handlers.h | 37 ++++++++++--------- Arduino/McLighting/rest_api.h | 6 --- Arduino/McLighting/version.h | 2 +- Arduino/McLighting/version_info.ino | 10 +++++ 8 files changed, 62 insertions(+), 49 deletions(-) diff --git a/Arduino/McLighting/McLighting.ino b/Arduino/McLighting/McLighting.ino index 12473cd..c257359 100644 --- a/Arduino/McLighting/McLighting.ino +++ b/Arduino/McLighting/McLighting.ino @@ -604,6 +604,7 @@ void loop() { WiFi.disconnect(); WiFi.setSleepMode(WIFI_NONE_SLEEP); WiFi.mode(WIFI_STA); + WiFi.hostname(HOSTNAME); WiFi.begin(); } else { 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", ""); #endif #if defined(POWER_SUPPLY) - digitalWrite(POWER_SUPPLY, LOW); // power off -> external power supply + digitalWrite(POWER_SUPPLY, !POWER_ON); // power off -> external power supply #endif if (Config.transEffect) { brightness_trans = 0; @@ -667,7 +668,7 @@ void loop() { } #if defined(POWER_SUPPLY) 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 diff --git a/Arduino/McLighting/definitions.h b/Arduino/McLighting/definitions.h index 07b8bc8..435f685 100644 --- a/Arduino/McLighting/definitions.h +++ b/Arduino/McLighting/definitions.h @@ -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 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 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) #define GAMMA 2.5 // Gamma correction for GY-33 sensor @@ -57,7 +60,7 @@ uint8_t prevsegment = 0; #if defined(ENABLE_REMOTE) uint8_t selected_color = 1; 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 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 @@ -207,13 +210,16 @@ bool updateConfig = false; // For WiFiManger custom config and config // Button handling -#if defined(ENABLE_BUTTON) -//#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; +#if defined(ENABLE_BUTTON) || defined(ENABLE_BUTTON_GY33) 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 mediumKeyPressCountMin = 20; // 20 * 25 = 500 ms byte KeyPressCount = 0; @@ -222,7 +228,6 @@ bool updateConfig = false; // For WiFiManger custom config and config #if defined(ENABLE_BUTTON_GY33) unsigned long keyPrevMillis_gy33 = 0; - const unsigned long keySampleIntervalMs_gy33 = 25; byte longKeyPressCountMax_gy33 = 80; // 80 * 25 = 2000 ms byte mediumKeyPressCountMin_gy33 = 20; // 20 * 25 = 500 ms byte KeyPressCount_gy33 = 0; diff --git a/Arduino/McLighting/helper_functions.h b/Arduino/McLighting/helper_functions.h index 9b60bc2..bf874ca 100644 --- a/Arduino/McLighting/helper_functions.h +++ b/Arduino/McLighting/helper_functions.h @@ -22,13 +22,13 @@ uint16_t convertSpeed(uint8_t _mcl_speed) { if (_mcl_speed < 50) { _fx_speed = 65535 - (_mcl_speed * 1000); } else if (_mcl_speed < 100) { - _fx_speed = 16535 - ((_mcl_speed-49) * 250); + _fx_speed = 16675 - ((_mcl_speed-49) * 250); } else if (_mcl_speed < 150) { - _fx_speed = 4035 - ((_mcl_speed-99) * 50); + _fx_speed = 4075 - ((_mcl_speed-99) * 50); } else if (_mcl_speed < 200) { - _fx_speed = 1535 - ((_mcl_speed-149) * 25); + _fx_speed = 1550 - ((_mcl_speed-149) * 25); } else { - _fx_speed = 285 - ((_mcl_speed-199) * 5); + _fx_speed = 280 - ((_mcl_speed-199) * 5); } _fx_speed = constrain(_fx_speed, SPEED_MIN, SPEED_MAX); return _fx_speed; @@ -36,14 +36,14 @@ uint16_t convertSpeed(uint8_t _mcl_speed) { /*uint8_t unconvertSpeed(uint16_t _fx_speed) { uint16_t _mcl_speed = 0; - if (_fx_speed <= 285) { - _mcl_speed = ((285 - _fx_speed)/5) + 199; - } else if (_fx_speed < 1535) { - _mcl_speed = ((1535 - _fx_speed)/25) + 149; - } else if (_fx_speed < 4035) { - _mcl_speed = ((4035 - _fx_speed)/50) + 99; - } else if (_mcl_speed < 16535) { - _mcl_speed = ((16535 - _fx_speed)/250) + 49; + if (_fx_speed <= 280) { + _mcl_speed = ((280 - _fx_speed)/5) + 199; + } else if (_fx_speed < 1550) { + _mcl_speed = ((1550 - _fx_speed)/25) + 149; + } else if (_fx_speed < 4075) { + _mcl_speed = ((4075 - _fx_speed)/50) + 99; + } else if (_mcl_speed < 16500) { + _mcl_speed = ((16675 - _fx_speed)/250) + 49; } else { _mcl_speed = ((65535 - _fx_speed)/1000); } diff --git a/Arduino/McLighting/mode_custom_ws2812fx_animations.h b/Arduino/McLighting/mode_custom_ws2812fx_animations.h index 222c9d3..d72d475 100644 --- a/Arduino/McLighting/mode_custom_ws2812fx_animations.h +++ b/Arduino/McLighting/mode_custom_ws2812fx_animations.h @@ -136,7 +136,7 @@ uint16_t handleCustomWS(void) { // packet.property_values[1]); // Dimmer data for Channel 1 /* #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 - 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; #else*/ uint16_t multipacketOffset = (universe - START_UNIVERSE) * 170; //if more than 170 LEDs * 3 colors = 510 channels, client will send in next higher universe diff --git a/Arduino/McLighting/request_handlers.h b/Arduino/McLighting/request_handlers.h index 3e85956..6b311e8 100644 --- a/Arduino/McLighting/request_handlers.h +++ b/Arduino/McLighting/request_handlers.h @@ -432,12 +432,10 @@ void checkpayload(uint8_t * _payload, bool mqtt = false, uint8_t num = 0) { } #if defined(ENABLE_STATE_SAVE) if (_updateState) { - DBG_OUTPUT_PORT.println("Saving stripstate.json!"); if(!save_state.active()) save_state.once(3, tickerSaveState); } if (_updateSegState) { State.mode = SET; - DBG_OUTPUT_PORT.println("Saving stripstate_segment.json!"); 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 (_updateStrip || _updateConfig) { - DBG_OUTPUT_PORT.println("Saving config.json!"); if(!save_conf.active()) save_conf.once(3, tickerSaveConfig); } if (_updateState) { - DBG_OUTPUT_PORT.println("Saving stripstate.json!"); if(!save_state.active()) save_state.once(3, tickerSaveState); } #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 (_updateState) { - DBG_OUTPUT_PORT.println("Saving stripstate.json!"); if(!save_state.active()) save_state.once(3, tickerSaveState); } if (_updateSegState) { State.mode = SET; - DBG_OUTPUT_PORT.println("Saving stripstate_segment.json!"); if(!save_seg_state.active()) save_seg_state.once(3, tickerSaveSegmentState); } #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..."); WiFi.setSleepMode(WIFI_NONE_SLEEP); WiFi.mode(WIFI_STA); + WiFi.hostname(HOSTNAME); WiFi.begin(); } @@ -1189,7 +1184,7 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght } void button_gy33() { - if (millis() - keyPrevMillis_gy33 >= keySampleIntervalMs_gy33) { + if (millis() - keyPrevMillis_gy33 >= keySampleIntervalMs) { keyPrevMillis_gy33 = millis(); byte currKeyState_gy33 = digitalRead(ENABLE_BUTTON_GY33); @@ -1250,6 +1245,7 @@ void handleRemote() { last_remote_cmd = results.value; if (State.brightness + chng <= 255) { State.brightness = State.brightness + chng; + brightness_trans = State.brightness; _updateState = true; } } @@ -1257,6 +1253,7 @@ void handleRemote() { last_remote_cmd = results.value; if (State.brightness - chng >= 0) { State.brightness = State.brightness - chng; + brightness_trans = State.brightness; _updateState = true; } } @@ -1475,46 +1472,52 @@ void handleRemote() { } if (results.value == rmt_commands[AUTOMODE]) { // Toggle Automode last_remote_cmd = 0; - fx_mode = 56; + fx_mode = FX_MODE_CUSTOM_0; _updateSegState = true; } #if defined(CUSTOM_WS2812FX_ANIMATIONS) if (results.value == rmt_commands[CUST_1]) { // Select TV Mode last_remote_cmd = 0; - fx_mode = 57; + fx_mode = FX_MODE_CUSTOM_2; _updateSegState = true; } #endif if (results.value == rmt_commands[CUST_2]) { // Select Custom Mode 2 last_remote_cmd = 0; - fx_mode = 12; + fx_mode = FX_MODE_RAINBOW_CYCLE; _updateSegState = true; } if (results.value == rmt_commands[CUST_3]) { // Select Custom Mode 3 last_remote_cmd = 0; - fx_mode = 48; + fx_mode = FX_MODE_FIRE_FLICKER; _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; - 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; } - 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; - fx_mode = 46; + if ((State.segment > 0) && (State.mode == HOLD)) { + prevsegment = State.segment; + State.segment = State.segment - 1; + getSegmentParams(State.segment); + } _updateSegState = true; } irrecv.resume(); // Receive the next value } #if defined(ENABLE_STATE_SAVE) if (_updateState) { - DBG_OUTPUT_PORT.println("Saving stripstate.json!"); if(!save_state.active()) save_state.once(3, tickerSaveState); } if (_updateSegState) { State.mode = SET; - DBG_OUTPUT_PORT.println("Saving stripstate_segment.json!"); if(!save_seg_state.active()) save_seg_state.once(3, tickerSaveSegmentState); } #endif diff --git a/Arduino/McLighting/rest_api.h b/Arduino/McLighting/rest_api.h index cf05637..d424322 100644 --- a/Arduino/McLighting/rest_api.h +++ b/Arduino/McLighting/rest_api.h @@ -294,11 +294,9 @@ server.on("/config", []() { #if defined(ENABLE_STATE_SAVE) if (_updateStrip || _updateConfig) { - DBG_OUTPUT_PORT.println("Saving config.json!"); if(!save_conf.active()) save_conf.once(3, tickerSaveConfig); } if (_updateState) { - DBG_OUTPUT_PORT.println("Saving stripstate.json!"); if(!save_state.active()) save_state.once(3, tickerSaveState); } #endif @@ -312,7 +310,6 @@ server.on("/off", []() { if (State.mode == OFF) { State.mode = SET; } else { State.mode = OFF; }; getStateJSON(); #if defined(ENABLE_STATE_SAVE) - DBG_OUTPUT_PORT.println("Saving stripstate.json!"); if(!save_state.active()) save_state.once(3, tickerSaveState); #endif }); @@ -322,7 +319,6 @@ server.on("/on", []() { State.mode = SET; getStateJSON(); #if defined(ENABLE_STATE_SAVE) - DBG_OUTPUT_PORT.println("Saving stripstate.json!"); if(!save_state.active()) save_state.once(3, tickerSaveState); #endif } else { @@ -491,11 +487,9 @@ server.on("/set", []() { #if defined(ENABLE_STATE_SAVE) if (_updateState) { - DBG_OUTPUT_PORT.println("Saving stripstate.json!"); if(!save_state.active()) save_state.once(3, tickerSaveState); } if (_updateSegState) { - DBG_OUTPUT_PORT.println("Saving stripstate_segment.json!"); State.mode = SET; if(!save_seg_state.active()) save_seg_state.once(3, tickerSaveSegmentState); } diff --git a/Arduino/McLighting/version.h b/Arduino/McLighting/version.h index 077c528..06a4e60 100644 --- a/Arduino/McLighting/version.h +++ b/Arduino/McLighting/version.h @@ -1 +1 @@ -#define SKETCH_VERSION "3.1.0.BETA5" +#define SKETCH_VERSION "3.1.0.BETA6" diff --git a/Arduino/McLighting/version_info.ino b/Arduino/McLighting/version_info.ino index 26d37f9..befc5d5 100644 --- a/Arduino/McLighting/version_info.ino +++ b/Arduino/McLighting/version_info.ino @@ -237,4 +237,14 @@ * Homeassistant will allways use active segment * 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 */