diff --git a/code/espurna/config/general.h b/code/espurna/config/general.h index 3432b3a3..3354931e 100644 --- a/code/espurna/config/general.h +++ b/code/espurna/config/general.h @@ -775,6 +775,9 @@ #define LIGHT_SAVE_DELAY 5 // Persist color after 5 seconds to avoid wearing out #endif +#ifndef LIGHT_MAX_CHANNELS +#define LIGHT_MAX_CHANNELS 6 +#endif #ifndef LIGHT_MAX_PWM diff --git a/code/espurna/config/hardware.h b/code/espurna/config/hardware.h index 3d2cb18d..6705e503 100644 --- a/code/espurna/config/hardware.h +++ b/code/espurna/config/hardware.h @@ -194,6 +194,32 @@ enum boards { // ----------------------------------------------------------------------------- +#elif \ + defined(ARILUX_AL_LC01) || \ + defined(ARILUX_AL_LC02) || \ + defined(ARILUX_AL_LC06) || \ + defined(ARILUX_AL_LC11) || \ + defined(AUTHOMETION_LYT8266) || \ + defined(GENERIC_AG_L4) || \ + defined(HUACANXING_H801) || \ + defined(HUACANXING_H802) || \ + defined(INTERMITTECH_QUINLED) || \ + defined(ITEAD_BNSZ01) || \ + defined(ITEAD_SONOFF_LED) + + #define ESPURNA_IMAGE ESPURNA_DIMMER + +// ----------------------------------------------------------------------------- + +#elif \ + defined(AITHINKER_AI_LIGHT) || \ + defined(ARILUX_E27) || \ + defined(ITEAD_SONOFF_B1) + + #define ESPURNA_IMAGE ESPURNA_MY92XX + +// ----------------------------------------------------------------------------- + #elif \ defined(GENERIC_ESP01S_DHT11_V10) || \ defined(GENERIC_ESP01S_DS18B20_V10) || \ @@ -283,69 +309,10 @@ enum boards { // ----------------------------------------------------------------------------- -#elif defined(ITEAD_BNSZ01) - - #define ESPURNA_IMAGE ESPURNA_DIMMER - - // Info - #define LIGHT_CHANNELS 1 - #define LIGHT_CH1_PIN 12 - #define LIGHT_CH1_INVERSE 0 - -#elif defined(ITEAD_SONOFF_B1) - - #define ESPURNA_IMAGE ESPURNA_MY92XX - - // Info - #define LIGHT_CHANNELS 5 - #define MY92XX_MODEL MY92XX_MODEL_MY9231 - #define MY92XX_CHIPS 2 - #define MY92XX_DI_PIN 12 - #define MY92XX_DCKI_PIN 14 - #define MY92XX_COMMAND MY92XX_COMMAND_DEFAULT - #define MY92XX_MAPPING 4, 3, 5, 0, 1 - #define LIGHT_WHITE_FACTOR (0.1) // White LEDs are way more bright in the B1 - -#elif defined(ITEAD_SONOFF_LED) - - #define ESPURNA_IMAGE ESPURNA_DIMMER - - // Info - #define LIGHT_CHANNELS 2 - #define LIGHT_CH1_PIN 12 // Cold white - #define LIGHT_CH2_PIN 14 // Warm white - #define LIGHT_CH1_INVERSE 0 - #define LIGHT_CH2_INVERSE 0 - -#elif defined(AITHINKER_AI_LIGHT) - - #define ESPURNA_IMAGE ESPURNA_MY92XX - - // Info - #define LIGHT_CHANNELS 4 - #define MY92XX_MODEL MY92XX_MODEL_MY9291 - #define MY92XX_CHIPS 1 - #define MY92XX_DI_PIN 13 - #define MY92XX_DCKI_PIN 15 - #define MY92XX_COMMAND MY92XX_COMMAND_DEFAULT - #define MY92XX_MAPPING 0, 1, 2, 3 - #elif defined(MAGICHOME_LED_CONTROLLER) #define ESPURNA_IMAGE ESPURNA_DIMMER - // Info - #define DUMMY_RELAY_COUNT 1 - #define LIGHT_CHANNELS 4 - #define LIGHT_CH1_PIN 14 // RED - #define LIGHT_CH2_PIN 5 // GREEN - #define LIGHT_CH3_PIN 12 // BLUE - #define LIGHT_CH4_PIN 13 // WHITE - #define LIGHT_CH1_INVERSE 0 - #define LIGHT_CH2_INVERSE 0 - #define LIGHT_CH3_INVERSE 0 - #define LIGHT_CH4_INVERSE 0 - // IR #define IR_SUPPORT 1 #define IR_RECEIVER_PIN 4 @@ -355,188 +322,17 @@ enum boards { #define ESPURNA_IMAGE ESPURNA_DIMMER - // Info - #define LIGHT_CHANNELS 4 - #define LIGHT_CH1_PIN 5 // RED - #define LIGHT_CH2_PIN 12 // GREEN - #define LIGHT_CH3_PIN 13 // BLUE - #define LIGHT_CH4_PIN 15 // WHITE - #define LIGHT_CH1_INVERSE 0 - #define LIGHT_CH2_INVERSE 0 - #define LIGHT_CH3_INVERSE 0 - #define LIGHT_CH4_INVERSE 0 - // IR #define IR_SUPPORT 1 #define IR_RECEIVER_PIN 4 #define IR_BUTTON_SET 1 -#elif defined(HUACANXING_H801) - - #define ESPURNA_IMAGE ESPURNA_DIMMER - - // Info - #define DEBUG_PORT Serial1 - #define SERIAL_RX_ENABLED 1 - #define LIGHT_CHANNELS 5 - #define LIGHT_CH1_PIN 15 // RED - #define LIGHT_CH2_PIN 13 // GREEN - #define LIGHT_CH3_PIN 12 // BLUE - #define LIGHT_CH4_PIN 14 // WHITE1 - #define LIGHT_CH5_PIN 4 // WHITE2 - #define LIGHT_CH1_INVERSE 0 - #define LIGHT_CH2_INVERSE 0 - #define LIGHT_CH3_INVERSE 0 - #define LIGHT_CH4_INVERSE 0 - #define LIGHT_CH5_INVERSE 0 - -#elif defined(HUACANXING_H802) - - #define ESPURNA_IMAGE ESPURNA_DIMMER - - // Info - #define DEBUG_PORT Serial1 - #define SERIAL_RX_ENABLED 1 - #define LIGHT_CHANNELS 4 - #define LIGHT_CH1_PIN 12 // RED - #define LIGHT_CH2_PIN 14 // GREEN - #define LIGHT_CH3_PIN 13 // BLUE - #define LIGHT_CH4_PIN 15 // WHITE - #define LIGHT_CH1_INVERSE 0 - #define LIGHT_CH2_INVERSE 0 - #define LIGHT_CH3_INVERSE 0 - #define LIGHT_CH4_INVERSE 0 - -#elif defined(INTERMITTECH_QUINLED) - - #define ESPURNA_IMAGE ESPURNA_DIMMER - - // Info - #define LIGHT_CHANNELS 2 - #define LIGHT_CH1_PIN 0 - #define LIGHT_CH2_PIN 2 - #define LIGHT_CH1_INVERSE 0 - #define LIGHT_CH2_INVERSE 0 - -#elif defined(ARILUX_AL_LC01) - - #define ESPURNA_IMAGE ESPURNA_DIMMER - - // Info - #define LIGHT_CHANNELS 3 - #define LIGHT_CH1_PIN 5 // RED - #define LIGHT_CH2_PIN 12 // GREEN - #define LIGHT_CH3_PIN 13 // BLUE - #define LIGHT_CH1_INVERSE 0 - #define LIGHT_CH2_INVERSE 0 - #define LIGHT_CH3_INVERSE 0 - -#elif defined(ARILUX_AL_LC02) - - #define ESPURNA_IMAGE ESPURNA_DIMMER - - // Info - #define LIGHT_CHANNELS 4 - #define LIGHT_CH1_PIN 12 // RED - #define LIGHT_CH2_PIN 5 // GREEN - #define LIGHT_CH3_PIN 13 // BLUE - #define LIGHT_CH4_PIN 15 // WHITE1 - #define LIGHT_CH1_INVERSE 0 - #define LIGHT_CH2_INVERSE 0 - #define LIGHT_CH3_INVERSE 0 - #define LIGHT_CH4_INVERSE 0 - -#elif defined(ARILUX_AL_LC06) - - #define ESPURNA_IMAGE ESPURNA_DIMMER - - // Info - #define LIGHT_CHANNELS 5 - #define LIGHT_CH1_PIN 14 // RED - #define LIGHT_CH2_PIN 12 // GREEN - #define LIGHT_CH3_PIN 13 // BLUE - #define LIGHT_CH4_PIN 15 // WHITE1 - #define LIGHT_CH5_PIN 5 // WHITE2 - #define LIGHT_CH1_INVERSE 0 - #define LIGHT_CH2_INVERSE 0 - #define LIGHT_CH3_INVERSE 0 - #define LIGHT_CH4_INVERSE 0 - #define LIGHT_CH5_INVERSE 0 - -#elif defined(ARILUX_AL_LC11) - - #define ESPURNA_IMAGE ESPURNA_DIMMER - - // Info - #define LIGHT_CHANNELS 5 - #define LIGHT_CH1_PIN 5 // RED - #define LIGHT_CH2_PIN 4 // GREEN - #define LIGHT_CH3_PIN 14 // BLUE - #define LIGHT_CH4_PIN 13 // WHITE1 - #define LIGHT_CH5_PIN 12 // WHITE1 - #define LIGHT_CH1_INVERSE 0 - #define LIGHT_CH2_INVERSE 0 - #define LIGHT_CH3_INVERSE 0 - #define LIGHT_CH4_INVERSE 0 - #define LIGHT_CH5_INVERSE 0 - -#elif defined(ARILUX_E27) - - #define ESPURNA_IMAGE ESPURNA_MY92XX - - // Info - #define LIGHT_CHANNELS 4 - #define MY92XX_MODEL MY92XX_MODEL_MY9291 - #define MY92XX_CHIPS 1 - #define MY92XX_DI_PIN 13 - #define MY92XX_DCKI_PIN 15 - #define MY92XX_COMMAND MY92XX_COMMAND_DEFAULT - #define MY92XX_MAPPING 0, 1, 2, 3 - -#elif defined(AUTHOMETION_LYT8266) - - #define ESPURNA_IMAGE ESPURNA_DIMMER - - // Info - #define LIGHT_CHANNELS 4 - #define LIGHT_CH1_PIN 13 // RED - #define LIGHT_CH2_PIN 12 // GREEN - #define LIGHT_CH3_PIN 14 // BLUE - #define LIGHT_CH4_PIN 2 // WHITE - #define LIGHT_CH1_INVERSE 0 - #define LIGHT_CH2_INVERSE 0 - #define LIGHT_CH3_INVERSE 0 - #define LIGHT_CH4_INVERSE 0 - #define LIGHT_ENABLE_PIN 15 - #elif defined(GIZWITS_WITTY_CLOUD) #define ESPURNA_IMAGE ESPURNA_DIMMER - // Info - #define LIGHT_CHANNELS 3 - #define LIGHT_CH1_PIN 15 // RED - #define LIGHT_CH2_PIN 12 // GREEN - #define LIGHT_CH3_PIN 13 // BLUE - #define LIGHT_CH1_INVERSE 0 - #define LIGHT_CH2_INVERSE 0 - #define LIGHT_CH3_INVERSE 0 - #define ANALOG_SUPPORT 1 // TODO: specific or generic? -#elif defined(GENERIC_AG_L4) - - #define ESPURNA_IMAGE ESPURNA_DIMMER - - // Info - #define LIGHT_CHANNELS 3 - #define LIGHT_CH1_PIN 14 // RED - #define LIGHT_CH2_PIN 13 // GREEN - #define LIGHT_CH3_PIN 12 // BLUE - #define LIGHT_CH1_INVERSE 0 - #define LIGHT_CH2_INVERSE 0 - #define LIGHT_CH3_INVERSE 0 - // ----------------------------------------------------------------------------- // TEST boards (do not use!!) // ----------------------------------------------------------------------------- @@ -743,6 +539,7 @@ enum boards { #define RELAY_PROVIDER RELAY_PROVIDER_LIGHT #define LIGHT_PROVIDER LIGHT_PROVIDER_MY92XX + #define MY92XX_COMMAND MY92XX_COMMAND_DEFAULT #elif ESPURNA_IMAGE == ESPURNA_EMON diff --git a/code/espurna/config/prototypes.h b/code/espurna/config/prototypes.h index f7ab84b4..cde74200 100644 --- a/code/espurna/config/prototypes.h +++ b/code/espurna/config/prototypes.h @@ -129,8 +129,6 @@ void settingsRegisterKeyCheck(setting_key_check_callback_f callback); char * ltrim(char * s); void nice_delay(unsigned long ms); -#define ARRAYINIT(type, name, ...) type name[] = {__VA_ARGS__}; - // ----------------------------------------------------------------------------- // WebServer // ----------------------------------------------------------------------------- diff --git a/code/espurna/hardware.ino b/code/espurna/hardware.ino index 844ed125..5bfd2667 100644 --- a/code/espurna/hardware.ino +++ b/code/espurna/hardware.ino @@ -375,7 +375,7 @@ void _hardwareLoad() { setSetting("litProvider", LIGHT_PROVIDER_MY92XX); - setSetting("myModel", MY92XX_MODEL_MY9291); // 4 channels per chip + setSetting("myModel", 0); // 4 channels per chip setSetting("myChips", 1); setSetting("myDIGPIO", 13); setSetting("myDCKIGPIO", 15); @@ -578,7 +578,7 @@ void _hardwareLoad() { setSetting("litChFactor", 4, 0.1); // White LEDs are way more bright in the B1 setSetting("litChFactor", 5, 0.1); // White LEDs are way more bright in the B1 - setSetting("myModel", MY92XX_MODEL_MY9231); // 3 channels per chip + setSetting("myModel", 1); // 3 channels per chip setSetting("myChips", 2); setSetting("myDIGPIO", 12); setSetting("myDCKIGPIO", 14); @@ -945,7 +945,7 @@ void _hardwareLoad() { setSetting("litProvider", LIGHT_PROVIDER_MY92XX); - setSetting("myModel", MY92XX_MODEL_MY9291); // 4 channels per chip + setSetting("myModel", 0); // 4 channels per chip setSetting("myChips", 1); setSetting("myDIGPIO", 13); setSetting("myDCKIGPIO", 15); diff --git a/code/espurna/ir.ino b/code/espurna/ir.ino index 02eda546..ebe16142 100644 --- a/code/espurna/ir.ino +++ b/code/espurna/ir.ino @@ -14,6 +14,7 @@ Module key prefix: ir #include #include +bool _ir_enabled = true; IRrecv * _ir_recv; decode_results _ir_results; unsigned long _ir_last_toggle = 0; @@ -113,15 +114,21 @@ bool _irKeyCheck(const char * key) { void irSetup() { - _ir_recv = new IRrecv(IR_RECEIVER_PIN); - _ir_recv->enableIRIn(); + _ir_enabled = (getSetting("irEnabled", 1).toInt() == 1); + + if (_ir_enabled) { + + _ir_recv = new IRrecv(getSetting("irGPIO", IR_RECEIVER_PIN).toInt()); + _ir_recv->enableIRIn(); + + // Register loop + espurnaRegisterLoop(irLoop); + + } // Key Check settingsRegisterKeyCheck(_irKeyCheck); - // Register loop - espurnaRegisterLoop(irLoop); - } void irLoop() { diff --git a/code/espurna/light.ino b/code/espurna/light.ino index 6ecfa79a..f322f5e1 100644 --- a/code/espurna/light.ino +++ b/code/espurna/light.ino @@ -19,7 +19,7 @@ extern "C" { } #if LIGHT_PROVIDER == LIGHT_PROVIDER_DIMMER -#define PWM_CHANNEL_NUM_MAX LIGHT_CHANNELS +#define PWM_CHANNEL_NUM_MAX LIGHT_MAX_CHANNELS extern "C" { #include "libs/pwm.h" } @@ -32,12 +32,14 @@ Ticker _light_transition_ticker; typedef struct { unsigned char pin; - bool reverse; + bool inverse; bool state; unsigned char inputValue; // value that has been inputted unsigned char value; // normalized value including brightness unsigned char shadow; // represented value double current; // transition value + double factor; // correction factor + unsigned char mapping; // channel mapping for MY90XX } channel_t; std::vector _light_channel; @@ -55,7 +57,6 @@ unsigned int _light_mireds = round((LIGHT_COLDWHITE_MIRED+LIGHT_WARMWHITE_MIRED) #if LIGHT_PROVIDER == LIGHT_PROVIDER_MY92XX #include my92xx * _my92xx; -ARRAYINIT(unsigned char, _light_channel_map, MY92XX_MAPPING); #endif // Gamma Correction lookup table (8 bit) @@ -131,12 +132,12 @@ void _generateBrightness() { double factor = (max_out > 0) ? (double) (max_in / max_out) : 0; for (unsigned char i=0; i < channelSize; i++) { - _light_channel[i].value = round((double) _light_channel[i].value * factor * brightness); + _light_channel[i].value = round((double) _light_channel[i].value * factor * _light_channel[i].factor * brightness); } // Scale white channel to match brightness for (unsigned char i=3; i < channelSize; i++) { - _light_channel[i].value = constrain(_light_channel[i].value * LIGHT_WHITE_FACTOR, 0, LIGHT_MAX_BRIGHTNESS); + _light_channel[i].value = constrain(_light_channel[i].value * _light_channel[i].factor, 0, LIGHT_MAX_BRIGHTNESS); } // For the rest of channels, don't apply brightness, it is already in the inputValue @@ -394,18 +395,18 @@ void _toCSV(char * buffer, size_t len, bool applyBrightness) { // PROVIDER // ----------------------------------------------------------------------------- -unsigned int _toPWM(unsigned long value, bool gamma, bool reverse) { +unsigned int _toPWM(unsigned long value, bool gamma, bool inverse) { value = constrain(value, 0, LIGHT_MAX_VALUE); if (gamma) value = _light_gamma_table[value]; if (LIGHT_MAX_VALUE != LIGHT_LIMIT_PWM) value = map(value, 0, LIGHT_MAX_VALUE, 0, LIGHT_LIMIT_PWM); - if (reverse) value = LIGHT_LIMIT_PWM - value; + if (inverse) value = LIGHT_LIMIT_PWM - value; return value; } // Returns a PWM value for the given channel ID unsigned int _toPWM(unsigned char id) { bool useGamma = _light_use_gamma && _light_has_color && (id < 3); - return _toPWM(_light_channel[id].shadow, useGamma, _light_channel[id].reverse); + return _toPWM(_light_channel[id].shadow, useGamma, _light_channel[id].inverse); } void _shadow() { @@ -440,7 +441,7 @@ void _lightProviderUpdate() { #if LIGHT_PROVIDER == LIGHT_PROVIDER_MY92XX for (unsigned char i=0; i<_light_channel.size(); i++) { - _my92xx->setChannel(_light_channel_map[i], _toPWM(i)); + _my92xx->setChannel(_light_channel[i].mapping, _toPWM(i)); } _my92xx->setState(true); _my92xx->update(); @@ -1007,6 +1008,11 @@ void _lightConfigure() { _light_use_transitions = getSetting("litTrans", LIGHT_USE_TRANSITIONS).toInt() == 1; _light_transition_time = getSetting("litTime", LIGHT_TRANSITION_TIME).toInt(); + for (unsigned char i=0; i<_light_channel.size(); i++) { + channel_t channel = _light_channel[i]; + channel.factor = getSetting("litChFactor", i, 1).toFloat(); + } + } bool _lightKeyCheck(const char * key) { @@ -1033,41 +1039,44 @@ void lightSetup() { _lightBackwards(); - #ifdef LIGHT_ENABLE_PIN - pinMode(LIGHT_ENABLE_PIN, OUTPUT); - digitalWrite(LIGHT_ENABLE_PIN, HIGH); - #endif + { + unsigned char gpio = getSetting("litEnableGPIO", GPIO_NONE).toInt(); + if (GPIO_NONE != gpio) { + pinMode(gpio, OUTPUT); + digitalWrite(gpio, getSetting("litEnableLogic", GPIO_LOGIC_DIRECT).toInt() == GPIO_LOGIC_DIRECT ? HIGH : LOW); + } + } #if LIGHT_PROVIDER == LIGHT_PROVIDER_MY92XX - - _my92xx = new my92xx(MY92XX_MODEL, MY92XX_CHIPS, MY92XX_DI_PIN, MY92XX_DCKI_PIN, MY92XX_COMMAND); - for (unsigned char i=0; i