Browse Source

Merge branch 'toggle-switch' into dev

fastled
Xose Pérez 7 years ago
parent
commit
5ac123f5f1
2 changed files with 52 additions and 8 deletions
  1. +10
    -8
      code/espurna/button.ino
  2. +42
    -0
      code/espurna/config/hardware.h

+ 10
- 8
code/espurna/button.ino View File

@ -82,28 +82,28 @@ typedef struct {
std::vector<button_t> _buttons; std::vector<button_t> _buttons;
#ifdef MQTT_BUTTON_TOPIC #ifdef MQTT_BUTTON_TOPIC
void buttonMQTT(unsigned char id) {
void buttonMQTT(unsigned char id, const char * payload) {
if (id >= _buttons.size()) return; if (id >= _buttons.size()) return;
String mqttGetter = getSetting("mqttGetter", MQTT_USE_GETTER); String mqttGetter = getSetting("mqttGetter", MQTT_USE_GETTER);
char buffer[strlen(MQTT_BUTTON_TOPIC) + mqttGetter.length() + 3]; char buffer[strlen(MQTT_BUTTON_TOPIC) + mqttGetter.length() + 3];
sprintf(buffer, "%s/%d%s", MQTT_BUTTON_TOPIC, id, mqttGetter.c_str()); sprintf(buffer, "%s/%d%s", MQTT_BUTTON_TOPIC, id, mqttGetter.c_str());
mqttSend(buffer, _buttons[id].button->pressed() ? "1" : "0");
mqttSend(buffer, payload);
} }
#endif #endif
void buttonSetup() { void buttonSetup() {
#ifdef BUTTON1_PIN #ifdef BUTTON1_PIN
_buttons.push_back({new DebounceEvent(BUTTON1_PIN), BUTTON1_RELAY});
_buttons.push_back({new DebounceEvent(BUTTON1_PIN, BUTTON1_MODE), BUTTON1_RELAY});
#endif #endif
#ifdef BUTTON2_PIN #ifdef BUTTON2_PIN
_buttons.push_back({new DebounceEvent(BUTTON2_PIN), BUTTON2_RELAY});
_buttons.push_back({new DebounceEvent(BUTTON2_PIN, BUTTON2_MODE), BUTTON2_RELAY});
#endif #endif
#ifdef BUTTON3_PIN #ifdef BUTTON3_PIN
_buttons.push_back({new DebounceEvent(BUTTON3_PIN), BUTTON3_RELAY});
_buttons.push_back({new DebounceEvent(BUTTON3_PIN, BUTTON3_MODE), BUTTON3_RELAY});
#endif #endif
#ifdef BUTTON4_PIN #ifdef BUTTON4_PIN
_buttons.push_back({new DebounceEvent(BUTTON4_PIN), BUTTON4_RELAY});
_buttons.push_back({new DebounceEvent(BUTTON4_PIN, BUTTON4_MODE), BUTTON4_RELAY});
#endif #endif
#ifdef LED_PULSE #ifdef LED_PULSE
@ -125,7 +125,7 @@ void buttonLoop() {
DEBUG_MSG("[BUTTON] Pressed #%d, event: %d\n", i, event); DEBUG_MSG("[BUTTON] Pressed #%d, event: %d\n", i, event);
#ifdef MQTT_BUTTON_TOPIC #ifdef MQTT_BUTTON_TOPIC
buttonMQTT(i);
buttonMQTT(i, (event == EVENT_CHANGED || event == EVENT_PRESSED) ? "1" : "0");
#endif #endif
if (i == 0) { if (i == 0) {
@ -140,7 +140,9 @@ void buttonLoop() {
} }
#endif #endif
if (event == EVENT_SINGLE_CLICK) {
// Here we can have EVENT_CHANGED only when using BUTTON_SWITCH
// and EVENT_SINGLE_CLICK only when using BUTTON_PUSHBUTTON
if (event == EVENT_SINGLE_CLICK || event == EVENT_CHANGED) {
if (_buttons[i].relayID > 0) { if (_buttons[i].relayID > 0) {
relayToggle(_buttons[i].relayID - 1); relayToggle(_buttons[i].relayID - 1);
} }


+ 42
- 0
code/espurna/config/hardware.h View File

@ -1,3 +1,21 @@
// -----------------------------------------------------------------------------
// Configuration HELP
// -----------------------------------------------------------------------------
//
// MANUFACTURER: Name of the manufacturer of the board ("string")
// DEVICE: Name of the device ("string")
// BUTTON#_PIN: GPIO for the n-th button (1-based, up to 4 buttons)
// BUTTON#_RELAY: Relay number that will be bind to the n-th button (1-based)
// BUTTON#_MODE: A mask of options (BUTTON_PUSHBUTTON and BUTTON_SWITCH cannot be together)
// - BUTTON_PUSHBUTTON: button event is fired when released
// - BUTTON_SWITCH: button event is fired when pressed or released
// - BUTTON_DEFAULT_HIGH: there is a pull up in place
// - BUTTON_SET_PULLUP: set pullup by software
// RELAY#_PIN: GPIO for the n-th relay (1-based, up to 4 relays)
// RELAY#_PIN_INVERSE: Relay has inversed logic (closed or ON when pulled down)
// LED#_PIN: GPIO for the n-th LED (1-based, up to 4 LEDs)
// LED#_PIN_INVERSE: LED has inversed logic (lit when pulled down)
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// Development boards // Development boards
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
@ -8,6 +26,7 @@
#define DEVICE "LOLIN" #define DEVICE "LOLIN"
#define BUTTON1_PIN 0 #define BUTTON1_PIN 0
#define BUTTON1_RELAY 1 #define BUTTON1_RELAY 1
#define BUTTON1_MODE BUTTON_SWITCH | BUTTON_DEFAULT_HIGH
#define RELAY1_PIN 12 #define RELAY1_PIN 12
#define RELAY1_PIN_INVERSE 0 #define RELAY1_PIN_INVERSE 0
#define LED1_PIN 2 #define LED1_PIN 2
@ -32,6 +51,7 @@
#define DEVICE "SONOFF" #define DEVICE "SONOFF"
#define BUTTON1_PIN 0 #define BUTTON1_PIN 0
#define BUTTON1_RELAY 1 #define BUTTON1_RELAY 1
#define BUTTON1_MODE BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH
#define RELAY1_PIN 12 #define RELAY1_PIN 12
#define RELAY1_PIN_INVERSE 0 #define RELAY1_PIN_INVERSE 0
#define LED1_PIN 13 #define LED1_PIN 13
@ -43,6 +63,7 @@
#define DEVICE "SONOFF_TH" #define DEVICE "SONOFF_TH"
#define BUTTON1_PIN 0 #define BUTTON1_PIN 0
#define BUTTON1_RELAY 1 #define BUTTON1_RELAY 1
#define BUTTON1_MODE BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH
#define RELAY1_PIN 12 #define RELAY1_PIN 12
#define RELAY1_PIN_INVERSE 0 #define RELAY1_PIN_INVERSE 0
#define LED1_PIN 13 #define LED1_PIN 13
@ -54,6 +75,7 @@
#define DEVICE "SONOFF_SV" #define DEVICE "SONOFF_SV"
#define BUTTON1_PIN 0 #define BUTTON1_PIN 0
#define BUTTON1_RELAY 1 #define BUTTON1_RELAY 1
#define BUTTON1_MODE BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH
#define RELAY1_PIN 12 #define RELAY1_PIN 12
#define RELAY1_PIN_INVERSE 0 #define RELAY1_PIN_INVERSE 0
#define LED1_PIN 13 #define LED1_PIN 13
@ -65,6 +87,7 @@
#define DEVICE "SLAMPHER" #define DEVICE "SLAMPHER"
#define BUTTON1_PIN 0 #define BUTTON1_PIN 0
#define BUTTON1_RELAY 1 #define BUTTON1_RELAY 1
#define BUTTON1_MODE BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH
#define RELAY1_PIN 12 #define RELAY1_PIN 12
#define RELAY1_PIN_INVERSE 0 #define RELAY1_PIN_INVERSE 0
#define LED1_PIN 13 #define LED1_PIN 13
@ -76,6 +99,7 @@
#define DEVICE "S20" #define DEVICE "S20"
#define BUTTON1_PIN 0 #define BUTTON1_PIN 0
#define BUTTON1_RELAY 1 #define BUTTON1_RELAY 1
#define BUTTON1_MODE BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH
#define RELAY1_PIN 12 #define RELAY1_PIN 12
#define RELAY1_PIN_INVERSE 0 #define RELAY1_PIN_INVERSE 0
#define LED1_PIN 13 #define LED1_PIN 13
@ -87,6 +111,7 @@
#define DEVICE "SONOFF_TOUCH" #define DEVICE "SONOFF_TOUCH"
#define BUTTON1_PIN 0 #define BUTTON1_PIN 0
#define BUTTON1_RELAY 1 #define BUTTON1_RELAY 1
#define BUTTON1_MODE BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH
#define RELAY1_PIN 12 #define RELAY1_PIN 12
#define RELAY1_PIN_INVERSE 0 #define RELAY1_PIN_INVERSE 0
#define LED1_PIN 13 #define LED1_PIN 13
@ -98,6 +123,7 @@
#define DEVICE "SONOFF_POW" #define DEVICE "SONOFF_POW"
#define BUTTON1_PIN 0 #define BUTTON1_PIN 0
#define BUTTON1_RELAY 1 #define BUTTON1_RELAY 1
#define BUTTON1_MODE BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH
#define RELAY1_PIN 12 #define RELAY1_PIN 12
#define RELAY1_PIN_INVERSE 0 #define RELAY1_PIN_INVERSE 0
#define LED1_PIN 15 #define LED1_PIN 15
@ -120,12 +146,16 @@
#define DEVICE "SONOFF_4CH" #define DEVICE "SONOFF_4CH"
#define BUTTON1_PIN 0 #define BUTTON1_PIN 0
#define BUTTON1_RELAY 1 #define BUTTON1_RELAY 1
#define BUTTON1_MODE BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH
#define BUTTON2_PIN 9 #define BUTTON2_PIN 9
#define BUTTON2_RELAY 2 #define BUTTON2_RELAY 2
#define BUTTON2_MODE BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH
#define BUTTON3_PIN 10 #define BUTTON3_PIN 10
#define BUTTON3_RELAY 3 #define BUTTON3_RELAY 3
#define BUTTON3_MODE BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH
#define BUTTON4_PIN 14 #define BUTTON4_PIN 14
#define BUTTON4_RELAY 4 #define BUTTON4_RELAY 4
#define BUTTON4_MODE BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH
#define RELAY1_PIN 12 #define RELAY1_PIN 12
#define RELAY1_PIN_INVERSE 0 #define RELAY1_PIN_INVERSE 0
#define RELAY2_PIN 5 #define RELAY2_PIN 5
@ -147,12 +177,16 @@
#define DEVICE "1CH_INCHING" #define DEVICE "1CH_INCHING"
#define BUTTON1_PIN 0 #define BUTTON1_PIN 0
#define BUTTON1_RELAY 1 #define BUTTON1_RELAY 1
#define BUTTON1_MODE BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH
#define BUTTON2_PIN 15 #define BUTTON2_PIN 15
#define BUTTON2_RELAY 0 #define BUTTON2_RELAY 0
#define BUTTON2_MODE BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH
#define RELAY1_PIN 12 #define RELAY1_PIN 12
#define RELAY1_PIN_INVERSE 0 #define RELAY1_PIN_INVERSE 0
#define LED1_PIN 13 #define LED1_PIN 13
#define LED1_PIN_INVERSE 0 #define LED1_PIN_INVERSE 0
// Special LED that shows pulse mode status
#define LED_PULSE 14 #define LED_PULSE 14
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
@ -165,8 +199,10 @@
#define DEVICE "ESP_RELAY_BOARD" #define DEVICE "ESP_RELAY_BOARD"
#define BUTTON1_PIN 0 #define BUTTON1_PIN 0
#define BUTTON1_RELAY 1 #define BUTTON1_RELAY 1
#define BUTTON1_MODE BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH
#define BUTTON2_PIN 2 #define BUTTON2_PIN 2
#define BUTTON2_RELAY 2 #define BUTTON2_RELAY 2
#define BUTTON2_MODE BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH
#define RELAY1_PIN 12 #define RELAY1_PIN 12
#define RELAY1_PIN_INVERSE 0 #define RELAY1_PIN_INVERSE 0
#define RELAY2_PIN 13 #define RELAY2_PIN 13
@ -184,6 +220,7 @@
#define DEVICE "ECOPLUG" #define DEVICE "ECOPLUG"
#define BUTTON1_PIN 13 #define BUTTON1_PIN 13
#define BUTTON1_RELAY 1 #define BUTTON1_RELAY 1
#define BUTTON1_MODE BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH
#define RELAY1_PIN 15 #define RELAY1_PIN 15
#define RELAY1_PIN_INVERSE 0 #define RELAY1_PIN_INVERSE 0
#define LED1_PIN 2 #define LED1_PIN 2
@ -199,8 +236,10 @@
#define DEVICE "WIFI_RELAY_NC" #define DEVICE "WIFI_RELAY_NC"
#define BUTTON1_PIN 12 #define BUTTON1_PIN 12
#define BUTTON1_RELAY 1 #define BUTTON1_RELAY 1
#define BUTTON1_MODE BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH
#define BUTTON2_PIN 13 #define BUTTON2_PIN 13
#define BUTTON2_RELAY 2 #define BUTTON2_RELAY 2
#define BUTTON2_MODE BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH
#define RELAY1_PIN 2 #define RELAY1_PIN 2
#define RELAY1_PIN_INVERSE 1 #define RELAY1_PIN_INVERSE 1
#define RELAY2_PIN 14 #define RELAY2_PIN 14
@ -212,8 +251,10 @@
#define DEVICE "WIFI_RELAY_NO" #define DEVICE "WIFI_RELAY_NO"
#define BUTTON1_PIN 12 #define BUTTON1_PIN 12
#define BUTTON1_RELAY 1 #define BUTTON1_RELAY 1
#define BUTTON1_MODE BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH
#define BUTTON2_PIN 13 #define BUTTON2_PIN 13
#define BUTTON2_RELAY 2 #define BUTTON2_RELAY 2
#define BUTTON2_MODE BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH
#define RELAY1_PIN 2 #define RELAY1_PIN 2
#define RELAY1_PIN_INVERSE 0 #define RELAY1_PIN_INVERSE 0
#define RELAY2_PIN 14 #define RELAY2_PIN 14
@ -229,6 +270,7 @@
#define DEVICE "ESPURNA" #define DEVICE "ESPURNA"
#define BUTTON1_PIN 0 #define BUTTON1_PIN 0
#define BUTTON1_RELAY 1 #define BUTTON1_RELAY 1
#define BUTTON1_MODE BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH
#define RELAY1_PIN 12 #define RELAY1_PIN 12
#define RELAY1_PIN_INVERSE 0 #define RELAY1_PIN_INVERSE 0
#define LED1_PIN 13 #define LED1_PIN 13


Loading…
Cancel
Save