Skip to content

Commit

Permalink
light: experiment with relay state provider
Browse files Browse the repository at this point in the history
* dynamic relays should not overlap with configuration
* prefer explicit relay configuration vs. dynamic addition

resolve #2568
  • Loading branch information
mcspr committed Jan 11, 2023
1 parent efaf15a commit b5a03da
Show file tree
Hide file tree
Showing 33 changed files with 12,024 additions and 11,965 deletions.
4 changes: 0 additions & 4 deletions code/espurna/config/general.h
Original file line number Diff line number Diff line change
Expand Up @@ -1214,10 +1214,6 @@
#define LIGHT_TRANSITION_TIME 500 // Time in millis from color to color
#endif

#ifndef LIGHT_RELAY_ENABLED
#define LIGHT_RELAY_ENABLED 1 // Add a virtual switch that controls the global light state. Depends on RELAY_SUPPORT
#endif

// -----------------------------------------------------------------------------
// DOMOTICZ
// -----------------------------------------------------------------------------
Expand Down
103 changes: 101 additions & 2 deletions code/espurna/config/hardware.h
Original file line number Diff line number Diff line change
Expand Up @@ -827,6 +827,9 @@
#define DEVICE "BNSZ01"
#define LIGHT_PROVIDER LIGHT_PROVIDER_DIMMER

// Relay
#define RELAY1_PROVIDER RELAY_PROVIDER_LIGHT_STATE

// LEDs
#define LED1_PIN 13
#define LED1_PIN_INVERSE 1
Expand Down Expand Up @@ -876,6 +879,9 @@
#define DEVICE "SONOFF_B1"
#define LIGHT_PROVIDER LIGHT_PROVIDER_MY92XX

// Relay
#define RELAY1_PROVIDER RELAY_PROVIDER_LIGHT_STATE

// Light

#define MY92XX_MODEL MY92XX_MODEL_MY9231
Expand All @@ -900,6 +906,9 @@
#define DEVICE "SONOFF_LED"
#define LIGHT_PROVIDER LIGHT_PROVIDER_DIMMER

// Relay
#define RELAY1_PROVIDER RELAY_PROVIDER_LIGHT_STATE

// LEDs
#define LED1_PIN 13
#define LED1_PIN_INVERSE 1
Expand Down Expand Up @@ -1304,6 +1313,9 @@
#define DEVICE "AI_LIGHT"
#define LIGHT_PROVIDER LIGHT_PROVIDER_MY92XX

// Relay
#define RELAY1_PROVIDER RELAY_PROVIDER_LIGHT_STATE

// Light
#define MY92XX_MODEL MY92XX_MODEL_MY9291
#define MY92XX_CHIPS 1
Expand All @@ -1323,6 +1335,9 @@
#define DEVICE "RGB_LED"
#define LIGHT_PROVIDER LIGHT_PROVIDER_MY92XX

// Relay
#define RELAY1_PROVIDER RELAY_PROVIDER_LIGHT_STATE

// Light
#define MY92XX_MODEL MY92XX_MODEL_MY9291
#define MY92XX_CHIPS 1
Expand All @@ -1342,6 +1357,9 @@
#define DEVICE "LED_CONTROLLER"
#define LIGHT_PROVIDER LIGHT_PROVIDER_DIMMER

// Relay
#define RELAY1_PROVIDER RELAY_PROVIDER_LIGHT_STATE

// LEDs
#define LED1_PIN 2
#define LED1_PIN_INVERSE 1
Expand All @@ -1365,6 +1383,9 @@
#define DEVICE "LED_CONTROLLER_20"
#define LIGHT_PROVIDER LIGHT_PROVIDER_DIMMER

// Relay
#define RELAY1_PROVIDER RELAY_PROVIDER_LIGHT_STATE

// LEDs
#define LED1_PIN 2
#define LED1_PIN_INVERSE 1
Expand All @@ -1388,6 +1409,9 @@
#define DEVICE "ZJ_WFMN_A_11"
#define LIGHT_PROVIDER LIGHT_PROVIDER_DIMMER

// Relay
#define RELAY1_PROVIDER RELAY_PROVIDER_LIGHT_STATE

// LEDs
#define LED1_PIN 2
#define LED1_PIN_INVERSE 1
Expand All @@ -1413,6 +1437,9 @@
#define DEVICE "ZJ_WFMN_B_11"
#define LIGHT_PROVIDER LIGHT_PROVIDER_DIMMER

// Relay
#define RELAY1_PROVIDER RELAY_PROVIDER_LIGHT_STATE

// LEDs
#define LED1_PIN 2
#define LED1_PIN_INVERSE 1
Expand All @@ -1437,6 +1464,9 @@
#define DEVICE "ZJ_WFMN_C_11"
#define LIGHT_PROVIDER LIGHT_PROVIDER_DIMMER

// Relay
#define RELAY1_PROVIDER RELAY_PROVIDER_LIGHT_STATE

// Buttons
#define BUTTON1_PIN 0
#define BUTTON1_CONFIG BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH
Expand All @@ -1456,6 +1486,9 @@
#define DEVICE "ZJ_ESPM_5CH_B_13"
#define LIGHT_PROVIDER LIGHT_PROVIDER_DIMMER

// Relay
#define RELAY1_PROVIDER RELAY_PROVIDER_LIGHT_STATE

// Buttons
#define BUTTON1_PIN 0
#define BUTTON1_CONFIG BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH
Expand All @@ -1479,6 +1512,9 @@
#define DEVICE "ZJ_LB_RGBWW_L"
#define LIGHT_PROVIDER LIGHT_PROVIDER_DIMMER

// Relay
#define RELAY1_PROVIDER RELAY_PROVIDER_LIGHT_STATE

// Light
#define LIGHT_CH1_PIN 5 // RED
#define LIGHT_CH2_PIN 4 // GREEN
Expand All @@ -1497,6 +1533,9 @@
#define DEVICE "H801"
#define LIGHT_PROVIDER LIGHT_PROVIDER_DIMMER

// Relay
#define RELAY1_PROVIDER RELAY_PROVIDER_LIGHT_STATE

// Debug
#define UART1_TX_PIN 2
#define UART2_RX_PIN GPIO_NONE
Expand All @@ -1519,6 +1558,9 @@
#define DEVICE "H802"
#define LIGHT_PROVIDER LIGHT_PROVIDER_DIMMER

// Relay
#define RELAY1_PROVIDER RELAY_PROVIDER_LIGHT_STATE

// Debug
#define UART1_TX_PIN 2
#define UART2_RX_PIN GPIO_NONE
Expand Down Expand Up @@ -1906,6 +1948,9 @@
#define DEVICE "QUINLED"
#define LIGHT_PROVIDER LIGHT_PROVIDER_DIMMER

// Relay
#define RELAY1_PROVIDER RELAY_PROVIDER_LIGHT_STATE

// LEDs
#define LED1_PIN 5
#define LED1_PIN_INVERSE 1
Expand All @@ -1925,6 +1970,9 @@
#define DEVICE "AL_LC01"
#define LIGHT_PROVIDER LIGHT_PROVIDER_DIMMER

// Relay
#define RELAY1_PROVIDER RELAY_PROVIDER_LIGHT_STATE

// Light
#define LIGHT_CH1_PIN 5 // RED
#define LIGHT_CH2_PIN 12 // GREEN
Expand All @@ -1937,6 +1985,9 @@
#define DEVICE "AL_LC02"
#define LIGHT_PROVIDER LIGHT_PROVIDER_DIMMER

// Relay
#define RELAY1_PROVIDER RELAY_PROVIDER_LIGHT_STATE

// Light
#define LIGHT_CH1_PIN 12 // RED
#define LIGHT_CH2_PIN 5 // GREEN
Expand All @@ -1950,6 +2001,9 @@
#define DEVICE "AL_LC02_V14"
#define LIGHT_PROVIDER LIGHT_PROVIDER_DIMMER

// Relay
#define RELAY1_PROVIDER RELAY_PROVIDER_LIGHT_STATE

// Light
#define LIGHT_CH1_PIN 14 // RED
#define LIGHT_CH2_PIN 5 // GREEN
Expand All @@ -1963,6 +2017,9 @@
#define DEVICE "AL_LC06"
#define LIGHT_PROVIDER LIGHT_PROVIDER_DIMMER

// Relay
#define RELAY1_PROVIDER RELAY_PROVIDER_LIGHT_STATE

// Buttons
#define BUTTON1_PIN 0
#define BUTTON1_CONFIG BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH
Expand All @@ -1982,6 +2039,9 @@
#define DEVICE "AL_LC11"
#define LIGHT_PROVIDER LIGHT_PROVIDER_DIMMER

// Relay
#define RELAY1_PROVIDER RELAY_PROVIDER_LIGHT_STATE

// Light
#define LIGHT_CH1_PIN 5 // RED
#define LIGHT_CH2_PIN 4 // GREEN
Expand All @@ -1996,6 +2056,9 @@
#define DEVICE "E27"
#define LIGHT_PROVIDER LIGHT_PROVIDER_MY92XX

// Relay
#define RELAY1_PROVIDER RELAY_PROVIDER_LIGHT_STATE

// Light
#define MY92XX_MODEL MY92XX_MODEL_MY9291
#define MY92XX_CHIPS 1
Expand Down Expand Up @@ -2064,6 +2127,9 @@
#define DEVICE "LYT8266"
#define LIGHT_PROVIDER LIGHT_PROVIDER_DIMMER

// Relay
#define RELAY1_PROVIDER RELAY_PROVIDER_LIGHT_STATE

// Light
#define LIGHT_CH1_PIN 13 // RED
#define LIGHT_CH2_PIN 12 // GREEN
Expand All @@ -2079,6 +2145,9 @@
#define DEVICE "WITTY_CLOUD"
#define LIGHT_PROVIDER LIGHT_PROVIDER_DIMMER

// Relay
#define RELAY1_PROVIDER RELAY_PROVIDER_LIGHT_STATE

// Buttons
#define BUTTON1_PIN 4
#define BUTTON1_CONFIG BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH
Expand Down Expand Up @@ -3708,6 +3777,9 @@
#define DEVICE "AG_L4"
#define LIGHT_PROVIDER LIGHT_PROVIDER_DIMMER

// Relay
#define RELAY1_PROVIDER RELAY_PROVIDER_LIGHT_STATE

// button 1: "power" button
#define BUTTON1_PIN 4
#define BUTTON1_RELAY 1
Expand Down Expand Up @@ -3749,6 +3821,9 @@
#define DEVICE "AG_L4_V3"
#define LIGHT_PROVIDER LIGHT_PROVIDER_DIMMER

// Relay
#define RELAY1_PROVIDER RELAY_PROVIDER_LIGHT_STATE

// button 1: "power" button
#define BUTTON1_PIN 13
#define BUTTON1_RELAY 1
Expand Down Expand Up @@ -4298,8 +4373,10 @@
#define BUTTON1_RELAY 1

// Relays
#define RELAY1_PIN 15
#define RELAY1_TYPE RELAY_TYPE_NORMAL
#define RELAY1_PROVIDER RELAY_PROVIDER_LIGHT_STATE

#define RELAY2_PIN 15
#define RELAY2_TYPE RELAY_TYPE_NORMAL

// LEDs
//Red LED: 0
Expand Down Expand Up @@ -4522,6 +4599,9 @@
#define DEVICE "RGBW_CONTROLLER"
#define LIGHT_PROVIDER LIGHT_PROVIDER_DIMMER

// Relay
#define RELAY1_PROVIDER RELAY_PROVIDER_LIGHT_STATE

// LEDs
#define LED1_PIN 13
#define LED1_PIN_INVERSE 1
Expand Down Expand Up @@ -4597,6 +4677,7 @@
#define TUYA_CH1_DPID 2

#define LIGHT_PROVIDER LIGHT_PROVIDER_CUSTOM
#define RELAY1_PROVIDER RELAY_PROVIDER_NONE

#define LED1_GPIO 14

Expand Down Expand Up @@ -4728,6 +4809,9 @@
#define DEVICE "MIOBULB001"
#define LIGHT_PROVIDER LIGHT_PROVIDER_DIMMER

// Relay
#define RELAY1_PROVIDER RELAY_PROVIDER_LIGHT_STATE

// Light
#define LIGHT_CH1_PIN 14 // RED
#define LIGHT_CH2_PIN 12 // GREEN
Expand Down Expand Up @@ -4857,6 +4941,9 @@
#define DEVICE "SMART_LED_LIGHT_STRIP"
#define LIGHT_PROVIDER LIGHT_PROVIDER_DIMMER

// Relay
#define RELAY1_PROVIDER RELAY_PROVIDER_LIGHT_STATE

// Light RGBW
#define LIGHT_CH1_PIN 4 // RED
#define LIGHT_CH2_PIN 12 // GREEN
Expand Down Expand Up @@ -5073,6 +5160,9 @@
#define DEVICE "E27_7W_RGBW"
#define LIGHT_PROVIDER LIGHT_PROVIDER_DIMMER

// Relay
#define RELAY1_PROVIDER RELAY_PROVIDER_LIGHT_STATE

// Light
#define LIGHT_CH1_PIN 4 // RED
#define LIGHT_CH2_PIN 12 // GREEN
Expand All @@ -5091,6 +5181,9 @@
#define DEVICE "GU53_RGBWW"
#define LIGHT_PROVIDER LIGHT_PROVIDER_DIMMER

// Relay
#define RELAY1_PROVIDER RELAY_PROVIDER_LIGHT_STATE

// Light
#define LIGHT_CH1_PIN 4 // RED
#define LIGHT_CH2_PIN 12 // GREEN
Expand All @@ -5109,6 +5202,9 @@
#define DEVICE "E27_10W_WHITE"
#define LIGHT_PROVIDER LIGHT_PROVIDER_DIMMER

// Relay
#define RELAY1_PROVIDER RELAY_PROVIDER_LIGHT_STATE

// Light
#define LIGHT_CH1_PIN 5 // WARM WHITE
#define LIGHT_CH2_PIN 4 // COLD WHITE
Expand All @@ -5127,6 +5223,9 @@
#define DEVICE "GENIO_W_A60"
#define LIGHT_PROVIDER LIGHT_PROVIDER_DIMMER

// Relay
#define RELAY1_PROVIDER RELAY_PROVIDER_LIGHT_STATE

// Light
#define LIGHT_CH1_PIN 14 // WHITE

Expand Down
1 change: 1 addition & 0 deletions code/espurna/config/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
#define RELAY_PROVIDER_GPIO RelayProvider::Gpio
#define RELAY_PROVIDER_DUAL RelayProvider::Dual
#define RELAY_PROVIDER_STM RelayProvider::Stm
#define RELAY_PROVIDER_LIGHT_STATE RelayProvider::LightState

#define RFB_PROVIDER_RCSWITCH 0
#define RFB_PROVIDER_EFM8BB1 1
Expand Down
2 changes: 1 addition & 1 deletion code/espurna/config/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@
#endif

#ifndef CFG_VERSION
#define CFG_VERSION 13
#define CFG_VERSION 14
#endif
Binary file modified code/espurna/data/index.all.html.gz
Binary file not shown.
Binary file modified code/espurna/data/index.curtain.html.gz
Binary file not shown.
Binary file modified code/espurna/data/index.garland.html.gz
Binary file not shown.
Binary file modified code/espurna/data/index.light.html.gz
Binary file not shown.
Binary file modified code/espurna/data/index.lightfox.html.gz
Binary file not shown.
Binary file modified code/espurna/data/index.rfbridge.html.gz
Binary file not shown.
Binary file modified code/espurna/data/index.rfm69.html.gz
Binary file not shown.
Binary file modified code/espurna/data/index.sensor.html.gz
Binary file not shown.
Binary file modified code/espurna/data/index.small.html.gz
Binary file not shown.
Binary file modified code/espurna/data/index.thermostat.html.gz
Binary file not shown.
4 changes: 3 additions & 1 deletion code/espurna/ifan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,9 @@ void setup() {
if (relay_pin) {
auto provider = std::make_unique<FanProvider>(
std::move(relay_pin), config, state_pins, onFanSpeedUpdate);
if (!relayAdd(std::move(provider))) {

const auto result = relayAdd(std::move(provider));
if (result) {
DEBUG_MSG_P(PSTR("[IFAN] Could not add relay provider for GPIO%d\n"), controlPin());
gpioUnlock(controlPin());
}
Expand Down
Loading

0 comments on commit b5a03da

Please sign in to comment.