From 20681bcd041b804559f658a37971842e3ec3feb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xose=20P=C3=A9rez?= Date: Mon, 22 May 2017 09:34:26 +0200 Subject: [PATCH] Fix no relay control bug for Sonoff Dual devices --- CHANGELOG.md | 4 ++++ README.md | 2 +- code/espurna/config/version.h | 2 +- code/espurna/espurna.ino | 3 +++ code/espurna/relay.ino | 6 ++++-- 5 files changed, 13 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ff30d6f8..9a09ad15 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [1.8.1] 2017-05-22 +### Fix +- Issue #140. Fix no relay control bug in Sonoff Dual + ## [1.8.0] 2017-05-21 ### Added - Added gamma correction to RGB strips. Thanks to Chris Ward. diff --git a/README.md b/README.md index 4987b8bf..52e05155 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ ESPurna ("spark" in Catalan) is a custom firmware for ESP8266 based smart switch It was originally developed with the **[IteadStudio Sonoff](https://www.itead.cc/sonoff-wifi-wireless-switch.html)** in mind but now it supports a growing number of ESP8266-based boards. It uses the Arduino Core for ESP8266 framework and a number of 3rd party libraries. -**Current Release Version is 1.8.0**, read the [changelog](https://bitbucket.org/xoseperez/espurna/src/master/CHANGELOG.md). +**Current Release Version is 1.8.1**, read the [changelog](https://bitbucket.org/xoseperez/espurna/src/master/CHANGELOG.md). ## Features diff --git a/code/espurna/config/version.h b/code/espurna/config/version.h index f562061f..6442fe19 100644 --- a/code/espurna/config/version.h +++ b/code/espurna/config/version.h @@ -1,4 +1,4 @@ #define APP_NAME "ESPurna" -#define APP_VERSION "1.8.0" +#define APP_VERSION "1.8.1" #define APP_AUTHOR "xose.perez@gmail.com" #define APP_WEBSITE "http://tinkerman.cat" diff --git a/code/espurna/espurna.ino b/code/espurna/espurna.ino index 6d48e100..e8bc0341 100644 --- a/code/espurna/espurna.ino +++ b/code/espurna/espurna.ino @@ -102,6 +102,9 @@ void hardwareSetup() { #ifdef DEBUG_PORT DEBUG_PORT.begin(SERIAL_BAUDRATE); #endif + #if SONOFF_DUAL + Serial.begin(SERIAL_BAUDRATE); + #endif #if not EMBEDDED_WEB SPIFFS.begin(); #endif diff --git a/code/espurna/relay.ino b/code/espurna/relay.ino index 262f0b53..dbb2f635 100644 --- a/code/espurna/relay.ino +++ b/code/espurna/relay.ino @@ -36,6 +36,8 @@ unsigned char _dual_status = 0; void relayProviderStatus(unsigned char id, bool status) { + if (id >= _relays.size()) return; + #if RELAY_PROVIDER == RELAY_PROVIDER_DUAL _dual_status ^= (1 << id); Serial.flush(); @@ -58,8 +60,9 @@ void relayProviderStatus(unsigned char id, bool status) { bool relayProviderStatus(unsigned char id) { + if (id >= _relays.size()) return false; + #if RELAY_PROVIDER == RELAY_PROVIDER_DUAL - if (id >= 2) return false; return ((_dual_status & (1 << id)) > 0); #endif @@ -68,7 +71,6 @@ bool relayProviderStatus(unsigned char id) { #endif #if RELAY_PROVIDER == RELAY_PROVIDER_RELAY - if (id >= _relays.size()) return false; bool status = (digitalRead(_relays[id].pin) == HIGH); return _relays[id].reverse ? !status : status; #endif