Skip to content

Commit

Permalink
v5.10.0c
Browse files Browse the repository at this point in the history
5.10.0c
 * Consolidate device serial (MH-Z19, SenseAir and Pzem004T)
into TasmotaSerial library
 * Consolidate PWM device recognition
 * Fix
Wemo Emulation (#1357)
 * Add support for Arilux LC06 (#1414)
  • Loading branch information
arendst committed Dec 25, 2017
1 parent 7723d52 commit 67d8fa0
Show file tree
Hide file tree
Showing 39 changed files with 760 additions and 821 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
## Sonoff-Tasmota
Provide ESP8266 based Sonoff by [iTead Studio](https://www.itead.cc/) and ElectroDragon IoT Relay with Serial, Web and MQTT control allowing 'Over the Air' or OTA firmware updates using Arduino IDE.

Current version is **5.10.0b** - See [sonoff/_releasenotes.ino](https://github.com/arendst/Sonoff-Tasmota/blob/development/sonoff/_releasenotes.ino) for change information.
Current version is **5.10.0c** - See [sonoff/_releasenotes.ino](https://github.com/arendst/Sonoff-Tasmota/blob/development/sonoff/_releasenotes.ino) for change information.

### ATTENTION All versions

Expand Down
8 changes: 8 additions & 0 deletions lib/TasmotaSerial-1.0.0/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# TasmotaSerial

Implementation of software serial library for the ESP8266 at 9600 baud

Allows for several instances to be active at the same time.

Please note that due to the fact that the ESP always have other activities ongoing, there will be some inexactness in interrupt
timings. This may lead to bit errors when having heavy data traffic.
27 changes: 27 additions & 0 deletions lib/TasmotaSerial-1.0.0/examples/swsertest/swsertest.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

#include <TasmotaSerial.h>

TasmotaSerial swSer(14, 12);

void setup() {
Serial.begin(115200);
swSer.begin();

Serial.println("\nTasmota serial test started");

for (char ch = ' '; ch <= 'z'; ch++) {
swSer.write(ch);
}
swSer.println("");

}

void loop() {
while (swSer.available() > 0) {
Serial.write(swSer.read());
}
while (Serial.available() > 0) {
swSer.write(Serial.read());
}

}
26 changes: 26 additions & 0 deletions lib/TasmotaSerial-1.0.0/keywords.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#######################################
# Syntax Coloring Map for TasmotaSerial
# (esp8266)
#######################################

#######################################
# Datatypes (KEYWORD1)
#######################################

TasmotaSerial KEYWORD1

#######################################
# Methods and Functions (KEYWORD2)
#######################################

begin KEYWORD2
read KEYWORD2
write KEYWORD2
available KEYWORD2
flush KEYWORD2
peek KEYWORD2

#######################################
# Constants (LITERAL1)
#######################################

15 changes: 15 additions & 0 deletions lib/TasmotaSerial-1.0.0/library.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "TasmotaSerial",
"version": "1.0.0",
"keywords": [
"serial", "io", "TasmotaSerial"
],
"description": "Implementation of software serial for ESP8266 at 9600 baud.",
"repository":
{
"type": "git",
"url": "https://github.com/arendst/Sonoff-Tasmota/lib/TasmotaSerial"
},
"frameworks": "arduino",
"platforms": "espressif8266"
}
9 changes: 9 additions & 0 deletions lib/TasmotaSerial-1.0.0/library.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name=TasmotaSerial
version=1.0
author=Theo Arends
maintainer=Theo Arends <theo@arends.com>
sentence=Implementation of software serial for ESP8266 at 9600 baud.
paragraph=
category=Signal Input/Output
url=
architectures=esp8266
193 changes: 193 additions & 0 deletions lib/TasmotaSerial-1.0.0/src/TasmotaSerial.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
/*
TasmotaSerial.cpp - Minimal implementation of software serial for Tasmota
Copyright (C) 2018 Theo Arends
This library is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include <Arduino.h>

// The Arduino standard GPIO routines are not enough,
// must use some from the Espressif SDK as well
extern "C" {
#include "gpio.h"
}

#include <TasmotaSerial.h>

// As the Arduino attachInterrupt has no parameter, lists of objects
// and callbacks corresponding to each possible GPIO pins have to be defined
TasmotaSerial *ObjList[16];

#ifdef TM_SERIAL_USE_IRAM
void ICACHE_RAM_ATTR sws_isr_0() { ObjList[0]->rxRead(); };
void ICACHE_RAM_ATTR sws_isr_1() { ObjList[1]->rxRead(); };
void ICACHE_RAM_ATTR sws_isr_2() { ObjList[2]->rxRead(); };
void ICACHE_RAM_ATTR sws_isr_3() { ObjList[3]->rxRead(); };
void ICACHE_RAM_ATTR sws_isr_4() { ObjList[4]->rxRead(); };
void ICACHE_RAM_ATTR sws_isr_5() { ObjList[5]->rxRead(); };
// Pin 6 to 11 can not be used
void ICACHE_RAM_ATTR sws_isr_12() { ObjList[12]->rxRead(); };
void ICACHE_RAM_ATTR sws_isr_13() { ObjList[13]->rxRead(); };
void ICACHE_RAM_ATTR sws_isr_14() { ObjList[14]->rxRead(); };
void ICACHE_RAM_ATTR sws_isr_15() { ObjList[15]->rxRead(); };
#else
void sws_isr_0() { ObjList[0]->rxRead(); };
void sws_isr_1() { ObjList[1]->rxRead(); };
void sws_isr_2() { ObjList[2]->rxRead(); };
void sws_isr_3() { ObjList[3]->rxRead(); };
void sws_isr_4() { ObjList[4]->rxRead(); };
void sws_isr_5() { ObjList[5]->rxRead(); };
// Pin 6 to 11 can not be used
void sws_isr_12() { ObjList[12]->rxRead(); };
void sws_isr_13() { ObjList[13]->rxRead(); };
void sws_isr_14() { ObjList[14]->rxRead(); };
void sws_isr_15() { ObjList[15]->rxRead(); };
#endif // TM_SERIAL_USE_IRAM

static void (*ISRList[16])() = {
sws_isr_0,
sws_isr_1,
sws_isr_2,
sws_isr_3,
sws_isr_4,
sws_isr_5,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
sws_isr_12,
sws_isr_13,
sws_isr_14,
sws_isr_15
};

TasmotaSerial::TasmotaSerial(int receive_pin, int transmit_pin)
{
m_valid = false;
if (!((isValidGPIOpin(receive_pin)) && (isValidGPIOpin(transmit_pin) || transmit_pin == 16))) {
return;
}
m_buffer = (uint8_t*)malloc(TM_SERIAL_BUFFER_SIZE);
if (m_buffer == NULL) {
return;
}
m_valid = true;
m_rx_pin = receive_pin;
m_tx_pin = transmit_pin;
m_in_pos = m_out_pos = 0;
// Use getCycleCount() loop to get as exact timing as possible
m_bit_time = ESP.getCpuFreqMHz() *1000000 /TM_SERIAL_BAUDRATE;
pinMode(m_rx_pin, INPUT);
ObjList[m_rx_pin] = this;
attachInterrupt(m_rx_pin, ISRList[m_rx_pin], FALLING);
pinMode(m_tx_pin, OUTPUT);
digitalWrite(m_tx_pin, HIGH);
}

bool TasmotaSerial::isValidGPIOpin(int pin)
{
return (pin >= 0 && pin <= 5) || (pin >= 12 && pin <= 15);
}

bool TasmotaSerial::begin() {
return m_valid;
}

int TasmotaSerial::read()
{
if (m_in_pos == m_out_pos) {
return -1;
}
uint8_t ch = m_buffer[m_out_pos];
m_out_pos = (m_out_pos +1) % TM_SERIAL_BUFFER_SIZE;
return ch;
}

int TasmotaSerial::available()
{
int avail = m_in_pos - m_out_pos;
if (avail < 0) {
avail += TM_SERIAL_BUFFER_SIZE;
}
return avail;
}

//#define TM_SERIAL_WAIT { while (ESP.getCycleCount()-start < wait) optimistic_yield(1); wait += m_bit_time; } // Watchdog timeouts
#define TM_SERIAL_WAIT { while (ESP.getCycleCount()-start < wait); wait += m_bit_time; }

size_t TasmotaSerial::txWrite(uint8_t b)
{
unsigned long wait = m_bit_time;
digitalWrite(m_tx_pin, HIGH);
unsigned long start = ESP.getCycleCount();
// Start bit;
digitalWrite(m_tx_pin, LOW);
TM_SERIAL_WAIT;
for (int i = 0; i < 8; i++) {
digitalWrite(m_tx_pin, (b & 1) ? HIGH : LOW);
TM_SERIAL_WAIT;
b >>= 1;
}
// Stop bit
digitalWrite(m_tx_pin, HIGH);
TM_SERIAL_WAIT;
return 1;
}

size_t TasmotaSerial::write(const uint8_t *buffer, size_t size)
{
size_t n = 0;
// Flush input buffer on every write
m_in_pos = m_out_pos = 0;
while(size--) {
n += txWrite(*buffer++);
}
return n;
}

#ifdef TM_SERIAL_USE_IRAM
void ICACHE_RAM_ATTR TasmotaSerial::rxRead()
{
#else
void TasmotaSerial::rxRead()
{
#endif
// Advance the starting point for the samples but compensate for the
// initial delay which occurs before the interrupt is delivered
unsigned long wait = m_bit_time + m_bit_time/3 - 500;
unsigned long start = ESP.getCycleCount();
uint8_t rec = 0;
for (int i = 0; i < 8; i++) {
TM_SERIAL_WAIT;
rec >>= 1;
if (digitalRead(m_rx_pin)) {
rec |= 0x80;
}
}
// Stop bit
TM_SERIAL_WAIT;
// Store the received value in the buffer unless we have an overflow
int next = (m_in_pos+1) % TM_SERIAL_BUFFER_SIZE;
if (next != m_out_pos) {
m_buffer[m_in_pos] = rec;
m_in_pos = next;
}
// Must clear this bit in the interrupt register,
// it gets set even when interrupts are disabled
GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, 1 << m_rx_pin);
}
56 changes: 56 additions & 0 deletions lib/TasmotaSerial-1.0.0/src/TasmotaSerial.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
TasmotaSerial.h - Minimal implementation of software serial for Tasmota
Copyright (C) 2018 Theo Arends
This library is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef TasmotaSerial_h
#define TasmotaSerial_h
/*********************************************************************************************\
* TasmotaSerial supports 9600 baud with fixed buffer size of 20 bytes using optional no iram
*
* Based on EspSoftwareSerial v3.3.1 by Peter Lerup (https://github.com/plerup/espsoftwareserial)
\*********************************************************************************************/

#define TM_SERIAL_BAUDRATE 9600
#define TM_SERIAL_BUFFER_SIZE 20
//#define TM_SERIAL_USE_IRAM // Enable to use iram (+368 bytes)

class TasmotaSerial {
public:
TasmotaSerial(int receive_pin, int transmit_pin);
bool begin();
size_t write(const uint8_t *buffer, size_t size = 1);
int read();
int available();

void rxRead();

private:
bool isValidGPIOpin(int pin);
size_t txWrite(uint8_t byte);

// Member variables
bool m_valid;
int m_rx_pin;
int m_tx_pin;
unsigned long m_bit_time;
unsigned int m_in_pos;
unsigned int m_out_pos;
uint8_t *m_buffer;
};

#endif // TasmotaSerial_h
10 changes: 8 additions & 2 deletions sonoff/_releasenotes.ino
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
/* 5.10.0b
/* 5.10.0c
* Consolidate device serial (MH-Z19, SenseAir and Pzem004T) into TasmotaSerial library
* Consolidate PWM device recognition
* Fix Wemo Emulation (#1357)
* Add support for Arilux LC06 (#1414)
*
* 5.10.0b
* Add support for PZEM004T energy sensor to be enabled with define USE_PZEM004T in user_config.h
* Change Sonoff Pow Energy MQTT data message and consolidate Status 8 into Status 10
* Change Wemo SetBinaryState to distinguish from GetBinaryState (#1357)
* Change output of HTTP command to valid JSON and Array only (#1363)
* Add support for MH-Z19(B) CO2 sensor to be enabled with define USE_MHZ19 in user_config.h (#561, #1248)
* Add support for senseair S8 CO2 sensor to be enabled with define USE_SENSEAIR in user_config.h
* Add support for SenseAir S8 CO2 sensor to be enabled with define USE_SENSEAIR in user_config.h
* Add support for Domoticz Air Quality sensor to be used by MH-Z19(B) and SenseAir sensors
*
* 5.10.0a
Expand Down
2 changes: 1 addition & 1 deletion sonoff/settings.ino
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ void SettingsSaveAll()
} else {
Settings.power = 0;
}
XsnsCall(FUNC_XSNS_SAVE_BEFORE_RESTART);
XsnsCall(FUNC_SAVE_BEFORE_RESTART);
SettingsSave(0);
}

Expand Down
2 changes: 1 addition & 1 deletion sonoff/sonoff.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ enum LightTypes {LT_BASIC, LT_PWM1, LT_PWM2, LT_PWM3, LT_PWM4, LT_PWM5, LT_PWM6,
enum LichtSubtypes {LST_NONE, LST_SINGLE, LST_COLDWARM, LST_RGB, LST_RGBW, LST_RGBWC};
enum LichtSchemes {LS_POWER, LS_WAKEUP, LS_CYCLEUP, LS_CYCLEDN, LS_RANDOM, LS_MAX};

enum XsnsFunctions {FUNC_XSNS_INIT, FUNC_XSNS_EVERY_SECOND, FUNC_XSNS_PREP_BEFORE_TELEPERIOD, FUNC_XSNS_JSON_APPEND, FUNC_XSNS_WEB_APPEND, FUNC_XSNS_SAVE_BEFORE_RESTART};
enum XsnsFunctions {FUNC_INIT, FUNC_EVERY_50_MSECOND, FUNC_EVERY_SECOND, FUNC_PREP_BEFORE_TELEPERIOD, FUNC_JSON_APPEND, FUNC_WEB_APPEND, FUNC_SAVE_BEFORE_RESTART};

const uint8_t kDefaultRfCode[9] PROGMEM = { 0x21, 0x16, 0x01, 0x0E, 0x03, 0x48, 0x2E, 0x1A, 0x00 };

Expand Down
Loading

0 comments on commit 67d8fa0

Please sign in to comment.