Browse Source

Support for multiple buttons on board

fastled
Xose Pérez 7 years ago
parent
commit
d17f8259fe
9 changed files with 93 additions and 51 deletions
  1. +7
    -0
      CHANGELOG.md
  2. BIN
      code/data/script.js.gz
  3. +1
    -1
      code/html/custom.js
  4. +21
    -28
      code/platformio.ini
  5. +32
    -7
      code/src/button.ino
  6. +27
    -11
      code/src/config/hardware.h
  7. +1
    -1
      code/src/config/version.h
  8. +2
    -3
      code/src/main.ino
  9. +2
    -0
      code/src/relay.ino

+ 7
- 0
CHANGELOG.md View File

@ -4,8 +4,15 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).
## [Unreleased]
### Added
- Added last-modified header to static contents
- Added support for multi-button boards (SONOFF_4CH)
- Force password changing if it's the default one
- Comment out hardware selection in hardware.h if using Arduino IDE
### Changed
- Using unreleased AsyncMqttClient with stability improvements
- Better decoupling between MQTT and relays/websockets
## [1.1.0] 2016-12-06
### Added


BIN
code/data/script.js.gz View File


+ 1
- 1
code/html/custom.js View File

@ -70,7 +70,7 @@ function createRelays(count) {
$(line).find("input").each(function() {
$(this).attr("data", relayID);
});
if (count > 1) $(".relay_id", line).html(" " + relayID);
if (count > 1) $(".relay_id", line).html(" " + (relayID+1));
line.appendTo("#relays");
$(":checkbox", line).iphoneStyle({
onChange: doToggle,


+ 21
- 28
code/platformio.ini View File

@ -127,6 +127,27 @@ upload_speed = 115200
upload_port = "192.168.4.1"
upload_flags = --auth=fibonacci --port 8266
[env:sonoff-4ch-debug]
platform = espressif8266
framework = arduino
board = esp01_1m
lib_deps = ${common.lib_deps}
lib_ignore = ${common.lib_ignore}
extra_script = pio_hooks.py
build_flags = -g -Wl,-Tesp8266.flash.1m128.ld -DDEBUG_PORT=Serial -DSONOFF_4CH
[env:sonoff-4ch-debug-ota]
platform = espressif8266
framework = arduino
board = esp01_1m
lib_deps = ${common.lib_deps}
lib_ignore = ${common.lib_ignore}
extra_script = pio_hooks.py
build_flags = -g -Wl,-Tesp8266.flash.1m128.ld -DDEBUG_PORT=Serial -DSONOFF_4CH
upload_speed = 115200
upload_port = "192.168.4.1"
upload_flags = --auth=fibonacci --port 8266
[env:slampher-debug]
platform = espressif8266
framework = arduino
@ -189,31 +210,3 @@ build_flags = -g -DDEBUG_PORT=Serial -DDEBUG_PORT=Serial -DESP_RELAY_BOARD -DENA
upload_speed = 115200
upload_port = "192.168.4.1"
upload_flags = --auth=fibonacci --port 8266
# ------------------------------------------------------------------------------
[env:studio-lamp-device]
topic = /home/studio/lamp/ip
platform = espressif8266_stage
framework = arduino
board = esp01_1m
lib_deps = ${common.lib_deps}
lib_ignore =
extra_script = pio_hooks.py
build_flags = -g -Wl,-Tesp8266.flash.1m128.ld -DDEBUG_PORT=Serial -DSONOFF -DENABLE_FAUXMO=1
upload_speed = 115200
upload_port = "192.168.4.1"
upload_flags = --auth=fibonacci --port 8266
[env:living-lamp-device]
topic = /home/living/lamp/ip
platform = espressif8266_stage
framework = arduino
board = esp01_1m
lib_deps = ${common.lib_deps}
lib_ignore =
extra_script = pio_hooks.py
build_flags = -g -Wl,-Tesp8266.flash.1m128.ld -DDEBUG_PORT=Serial -DSONOFF -DENABLE_FAUXMO=1
upload_speed = 115200
upload_port = "192.168.4.1"
upload_flags = --auth=fibonacci --port 8266

+ 32
- 7
code/src/button.ino View File

@ -55,21 +55,46 @@ void buttonLoop() {
}
#else
#ifdef BUTTON_PIN
#ifdef BUTTON1_PIN
#include <DebounceEvent.h>
DebounceEvent button1 = false;
#include <vector>
std::vector<DebounceEvent *> _buttons;
void buttonSetup() {
button1 = DebounceEvent(BUTTON_PIN);
#ifdef BUTTON1_PIN
_buttons.push_back(new DebounceEvent(BUTTON1_PIN));
#endif
#ifdef BUTTON2_PIN
_buttons.push_back(new DebounceEvent(BUTTON2_PIN));
#endif
#ifdef BUTTON3_PIN
_buttons.push_back(new DebounceEvent(BUTTON3_PIN));
#endif
#ifdef BUTTON4_PIN
_buttons.push_back(new DebounceEvent(BUTTON4_PIN));
#endif
DEBUG_MSG("[BUTTON] Number of buttons: %d\n", _buttons.size());
}
void buttonLoop() {
if (button1.loop()) {
if (button1.getEvent() == EVENT_SINGLE_CLICK) relayToggle(0);
if (button1.getEvent() == EVENT_DOUBLE_CLICK) createAP();
if (button1.getEvent() == EVENT_LONG_CLICK) ESP.reset();
for (unsigned int i=0; i < _buttons.size(); i++) {
if (_buttons[i]->loop()) {
uint8_t event = _buttons[i]->getEvent();
DEBUG_MSG("[BUTTON] Pressed #%d, event: %d\n", i, event);
if (i == 0) {
if (event == EVENT_DOUBLE_CLICK) createAP();
if (event == EVENT_LONG_CLICK) ESP.reset();
}
if (event == EVENT_SINGLE_CLICK) relayToggle(i);
}
}
}
#else


+ 27
- 11
code/src/config/hardware.h View File

@ -6,7 +6,7 @@
#define MANUFACTURER "NODEMCU"
#define DEVICE "LOLIN"
#define BUTTON_PIN 0
#define BUTTON1_PIN 0
#define RELAY1_PIN 12
#define LED_PIN 2
#define LED_PIN_INVERSE 0
@ -19,7 +19,7 @@
#define MANUFACTURER "ITEAD"
#define DEVICE "SONOFF"
#define BUTTON_PIN 0
#define BUTTON1_PIN 0
#define RELAY1_PIN 12
#define LED_PIN 13
#define LED_PIN_INVERSE 0
@ -28,7 +28,7 @@
#define MANUFACTURER "ITEAD"
#define DEVICE "SONOFF_TH"
#define BUTTON_PIN 0
#define BUTTON1_PIN 0
#define RELAY1_PIN 12
#define LED_PIN 13
#define LED_PIN_INVERSE 0
@ -37,7 +37,7 @@
#define MANUFACTURER "ITEAD"
#define DEVICE "SONOFF_TOUCH"
#define BUTTON_PIN 0
#define BUTTON1_PIN 0
#define RELAY1_PIN 12
#define LED_PIN 13
#define LED_PIN_INVERSE 1
@ -46,7 +46,7 @@
#define MANUFACTURER "ITEAD"
#define DEVICE "SONOFF_POW"
#define BUTTON_PIN 0
#define BUTTON1_PIN 0
#define RELAY1_PIN 12
#define LED_PIN 15
#define LED_PIN_INVERSE 1
@ -56,17 +56,32 @@
#define MANUFACTURER "ITEAD"
#define DEVICE "SONOFF_DUAL"
#define BUTTON_PIN 0
#define BUTTON1_PIN 0
#define LED_PIN 13
#define LED_PIN_INVERSE 0
#undef SERIAL_BAUDRATE
#define SERIAL_BAUDRATE 19230
#elif defined(SONOFF_4CH)
#define MANUFACTURER "ITEAD"
#define DEVICE "SONOFF_4CH"
#define BUTTON1_PIN 0
#define BUTTON2_PIN 9
#define BUTTON3_PIN 10
#define BUTTON4_PIN 14
#define RELAY1_PIN 12
#define RELAY2_PIN 5
#define RELAY3_PIN 4
#define RELAY4_PIN 15
#define LED_PIN 13
#define LED_PIN_INVERSE 1
#elif defined(SLAMPHER)
#define MANUFACTURER "ITEAD"
#define DEVICE "SLAMPHER"
#define BUTTON_PIN 0
#define BUTTON1_PIN 0
#define RELAY1_PIN 12
#define LED_PIN 13
#define LED_PIN_INVERSE 0
@ -75,7 +90,7 @@
#define MANUFACTURER "ITEAD"
#define DEVICE "S20"
#define BUTTON_PIN 0
#define BUTTON1_PIN 0
#define RELAY1_PIN 12
#define LED_PIN 13
#define LED_PIN_INVERSE 0
@ -88,7 +103,8 @@
#define MANUFACTURER "ELECTRODRAGON"
#define DEVICE "ESP_RELAY_BOARD"
#define BUTTON_PIN 2
#define BUTTON1_PIN 0
#define BUTTON2_PIN 2
#define RELAY1_PIN 12
#define RELAY2_PIN 13
#define LED_PIN 16
@ -102,7 +118,7 @@
#define MANUFACTURER "WORKCHOICE"
#define DEVICE "ECOPLUG"
#define BUTTON_PIN 13
#define BUTTON1_PIN 13
#define RELAY_PIN 15
#define LED_PIN 2
#define LED_PIN_INVERSE 1
@ -115,7 +131,7 @@
#define MANUFACTURER "TINKERMAN"
#define DEVICE "ESPURNA"
#define BUTTON_PIN 0
#define BUTTON1_PIN 0
#define RELAY1_PIN 12
#define LED_PIN 13
#define LED_PIN_INVERSE 0


+ 1
- 1
code/src/config/version.h View File

@ -1,4 +1,4 @@
#define APP_NAME "ESPurna"
#define APP_VERSION "1.1.0"
#define APP_VERSION "1.2.0"
#define APP_AUTHOR "xose.perez@gmail.com"
#define APP_WEBSITE "http://tinkerman.cat"

+ 2
- 3
code/src/main.ino View File

@ -104,9 +104,6 @@ void welcome() {
void setup() {
hardwareSetup();
buttonSetup();
ledSetup();
welcome();
settingsSetup();
@ -116,6 +113,8 @@ void setup() {
}
relaySetup();
buttonSetup();
ledSetup();
wifiSetup();
otaSetup();
mqttSetup();


+ 2
- 0
code/src/relay.ino View File

@ -239,4 +239,6 @@ void relaySetup() {
mqttRegister(relayMQTTCallback);
DEBUG_MSG("[RELAY] Number of relays: %d\n", _relays.size());
}

Loading…
Cancel
Save