Skip to content

Commit

Permalink
Merge pull request #2 from arendst/development
Browse files Browse the repository at this point in the history
Update to 6.6.0.9
  • Loading branch information
Jason2866 authored Aug 28, 2019
2 parents 5df12ad + 9af67a5 commit f916dbf
Show file tree
Hide file tree
Showing 13 changed files with 71 additions and 54 deletions.
14 changes: 7 additions & 7 deletions lib/TasmotaSerial-2.3.2/src/TasmotaSerial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ static void (*ISRList[16])() = {
tms_isr_15
};

TasmotaSerial::TasmotaSerial(int receive_pin, int transmit_pin, int hardware_fallback, int nwmode)
TasmotaSerial::TasmotaSerial(int receive_pin, int transmit_pin, int hardware_fallback, int nwmode, int buffer_size)
{
m_valid = false;
m_hardserial = 0;
Expand All @@ -98,7 +98,7 @@ TasmotaSerial::TasmotaSerial(int receive_pin, int transmit_pin, int hardware_fal
}
else {
if (m_rx_pin > -1) {
m_buffer = (uint8_t*)malloc(TM_SERIAL_BUFFER_SIZE);
m_buffer = (uint8_t*)malloc(serial_buffer_size);
if (m_buffer == NULL) return;
// Use getCycleCount() loop to get as exact timing as possible
m_bit_time = ESP.getCpuFreqMHz() * 1000000 / TM_SERIAL_BAUDRATE;
Expand Down Expand Up @@ -185,7 +185,7 @@ int TasmotaSerial::read()
} else {
if ((-1 == m_rx_pin) || (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;
m_out_pos = (m_out_pos +1) % serial_buffer_size;
return ch;
}
}
Expand All @@ -196,7 +196,7 @@ int TasmotaSerial::available()
return Serial.available();
} else {
int avail = m_in_pos - m_out_pos;
if (avail < 0) avail += TM_SERIAL_BUFFER_SIZE;
if (avail < 0) avail += serial_buffer_size;
return avail;
}
}
Expand Down Expand Up @@ -260,7 +260,7 @@ if (!m_nwmode) {
TM_SERIAL_WAIT;
}
// Store the received value in the buffer unless we have an overflow
unsigned int next = (m_in_pos+1) % TM_SERIAL_BUFFER_SIZE;
unsigned int next = (m_in_pos+1) % serial_buffer_size;
if (next != (int)m_out_pos) {
m_buffer[m_in_pos] = rec;
m_in_pos = next;
Expand Down Expand Up @@ -297,7 +297,7 @@ if (!m_nwmode) {
ss_byte|=(1<<i);
}
//stobyte(0,ssp->ss_byte>>1);
unsigned int next = (m_in_pos+1) % TM_SERIAL_BUFFER_SIZE;
unsigned int next = (m_in_pos+1) % serial_buffer_size;
if (next != (int)m_out_pos) {
m_buffer[m_in_pos] = ss_byte>>1;
m_in_pos = next;
Expand All @@ -311,7 +311,7 @@ if (!m_nwmode) {
if (diff>=LASTBIT) {
// bit zero was 0,
//stobyte(0,ssp->ss_byte>>1);
unsigned int next = (m_in_pos+1) % TM_SERIAL_BUFFER_SIZE;
unsigned int next = (m_in_pos+1) % serial_buffer_size;
if (next != (int)m_out_pos) {
m_buffer[m_in_pos] = ss_byte>>1;
m_in_pos = next;
Expand Down
3 changes: 2 additions & 1 deletion lib/TasmotaSerial-2.3.2/src/TasmotaSerial.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

class TasmotaSerial : public Stream {
public:
TasmotaSerial(int receive_pin, int transmit_pin, int hardware_fallback = 0,int nwmode = 0);
TasmotaSerial(int receive_pin, int transmit_pin, int hardware_fallback = 0,int nwmode = 0, int buffer_size = TM_SERIAL_BUFFER_SIZE);
virtual ~TasmotaSerial();

bool begin(long speed, int stop_bits = 1);
Expand Down Expand Up @@ -75,6 +75,7 @@ class TasmotaSerial : public Stream {
unsigned int m_in_pos;
unsigned int m_out_pos;
uint8_t *m_buffer;
int serial_buffer_size;
};

#endif // TasmotaSerial_h
3 changes: 3 additions & 0 deletions sonoff/_changelog.ino
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
/*********************************************************************************************\
* 6.6.0.9 20190828
* Change theoretical baudrate range to 300..19660500 bps in 300 increments (#6294)
*
* 6.6.0.8 20190827
* Add Tuya Energy monitoring by Shantur Rathore
* Add phase 1 Domoticz P1 Smart Meter support using energy sensors handled by xdrv_03_energy.ino based on an idea by pablozg
Expand Down
10 changes: 4 additions & 6 deletions sonoff/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ struct SYSCFG {
int8_t timezone; // 016
char ota_url[101]; // 017
char mqtt_prefix[3][11]; // 07C
uint8_t baudrate; // 09D
uint8_t ex_baudrate; // 09D - Free since 6.6.0.9
uint8_t seriallog_level; // 09E
uint8_t sta_config; // 09F
uint8_t sta_active; // 0A0
Expand Down Expand Up @@ -288,7 +288,7 @@ struct SYSCFG {
char friendlyname[MAX_FRIENDLYNAMES][33]; // 3AC
char switch_topic[33]; // 430
char serial_delimiter; // 451
uint8_t sbaudrate; // 452
uint8_t ex_sbaudrate; // 452 - Free since 6.6.0.9
uint8_t sleep; // 453
uint16_t domoticz_switch_idx[MAX_DOMOTICZ_IDX]; // 454
uint16_t domoticz_sensor_idx[MAX_DOMOTICZ_SNS_IDX]; // 45C
Expand Down Expand Up @@ -345,11 +345,9 @@ struct SYSCFG {
uint8_t web_color[18][3]; // 73E
uint16_t display_width; // 774
uint16_t display_height; // 776

uint8_t free_778[4]; // 778

uint16_t baudrate; // 778
uint16_t sbaudrate; // 77A
EnergyUsage energy_usage; // 77C

// uint32_t drivers[3]; // 794 - 6.5.0.12 replaced by below three entries
uint32_t adc_param1; // 794
uint32_t adc_param2; // 798
Expand Down
12 changes: 8 additions & 4 deletions sonoff/settings.ino
Original file line number Diff line number Diff line change
Expand Up @@ -596,8 +596,8 @@ void SettingsDefaultSet2(void)
// for (uint32_t i = 1; i < MAX_PULSETIMERS; i++) { Settings.pulse_timer[i] = 0; }

// Serial
Settings.baudrate = APP_BAUDRATE / 1200;
Settings.sbaudrate = SOFT_BAUDRATE / 1200;
Settings.baudrate = APP_BAUDRATE / 300;
Settings.sbaudrate = SOFT_BAUDRATE / 300;
Settings.serial_delimiter = 0xff;
Settings.seriallog_level = SERIAL_LOG_LEVEL;

Expand Down Expand Up @@ -960,10 +960,10 @@ void SettingsDelta(void)
}
}
if (Settings.version < 0x050C0007) {
Settings.baudrate = APP_BAUDRATE / 1200;
Settings.baudrate = APP_BAUDRATE / 300;
}
if (Settings.version < 0x050C0008) {
Settings.sbaudrate = SOFT_BAUDRATE / 1200;
Settings.sbaudrate = SOFT_BAUDRATE / 300;
Settings.serial_delimiter = 0xff;
}
if (Settings.version < 0x050C000A) {
Expand Down Expand Up @@ -1091,6 +1091,10 @@ void SettingsDelta(void)
Settings.param[P_ENERGY_TARIFF2] = ENERGY_TARIFF2_HOUR;
Settings.flag3.energy_weekend = ENERGY_TARIFF_WEEKEND;
}
if (Settings.version < 0x06060009) {
Settings.baudrate = Settings.ex_baudrate * 4;
Settings.sbaudrate = Settings.ex_sbaudrate * 4;
}

Settings.version = VERSION;
SettingsSave(1);
Expand Down
2 changes: 1 addition & 1 deletion sonoff/sonoff.ino
Original file line number Diff line number Diff line change
Expand Up @@ -1476,7 +1476,7 @@ void setup(void)
XdrvCall(FUNC_SETTINGS_OVERRIDE);
}

baudrate = Settings.baudrate * 1200;
baudrate = Settings.baudrate * 300;
// mdns_delayed_start = Settings.param[P_MDNS_DELAYED_START];
seriallog_level = Settings.seriallog_level;
seriallog_timer = SERIALLOG_TIMER;
Expand Down
2 changes: 1 addition & 1 deletion sonoff/sonoff_version.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@
#ifndef _SONOFF_VERSION_H_
#define _SONOFF_VERSION_H_

const uint32_t VERSION = 0x06060008;
const uint32_t VERSION = 0x06060009;

#endif // _SONOFF_VERSION_H_
4 changes: 2 additions & 2 deletions sonoff/support.ino
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,7 @@ int GetStateNumber(char *state_text)

void SetSerialBaudrate(int baudrate)
{
Settings.baudrate = baudrate / 1200;
Settings.baudrate = baudrate / 300;
if (Serial.baudRate() != baudrate) {
if (seriallog_level) {
AddLog_P2(LOG_LEVEL_INFO, PSTR(D_LOG_APPLICATION D_SET_BAUDRATE_TO " %d"), baudrate);
Expand All @@ -793,7 +793,7 @@ void ClaimSerial(void)
AddLog_P(LOG_LEVEL_INFO, PSTR("SNS: Hardware Serial"));
SetSeriallog(LOG_LEVEL_NONE);
baudrate = Serial.baudRate();
Settings.baudrate = baudrate / 1200;
Settings.baudrate = baudrate / 300;
}

void SerialSendRaw(char *codes)
Expand Down
8 changes: 4 additions & 4 deletions sonoff/support_command.ino
Original file line number Diff line number Diff line change
Expand Up @@ -961,12 +961,12 @@ void CmndSwitchDebounce(void)

void CmndBaudrate(void)
{
if (XdrvMailbox.payload > 1200) {
XdrvMailbox.payload /= 1200; // Make it a valid baudrate
baudrate = (XdrvMailbox.payload & 0xFF) * 1200;
if (XdrvMailbox.payload >= 300) {
XdrvMailbox.payload /= 300; // Make it a valid baudrate
baudrate = (XdrvMailbox.payload & 0xFFFF) * 300;
SetSerialBaudrate(baudrate);
}
ResponseCmndNumber(Settings.baudrate * 1200);
ResponseCmndNumber(Settings.baudrate * 300);
}

void CmndSerialSend(void)
Expand Down
2 changes: 2 additions & 0 deletions sonoff/xdrv_03_energy.ino
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,12 @@ void Energy200ms(void)
Settings.energy_kWhtotal += Energy.kWhtoday;
RtcSettings.energy_kWhtotal = Settings.energy_kWhtotal;
Energy.kWhtoday = 0;
RtcSettings.energy_kWhtoday = 0;

Settings.energy_usage.usage1_kWhtotal += Energy.kWhtoday1;
RtcSettings.energy_usage.usage1_kWhtotal = Settings.energy_usage.usage1_kWhtotal;
Energy.kWhtoday1 = 0;
RtcSettings.energy_usage.usage1_kWhtoday = 0;

Energy.kWhtoday_delta = 0;
Energy.period = Energy.kWhtoday;
Expand Down
11 changes: 6 additions & 5 deletions sonoff/xdrv_08_serial_bridge.ino
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ void SerialBridgeInit(void)
serial_bridge_active = false;
if ((pin[GPIO_SBR_RX] < 99) && (pin[GPIO_SBR_TX] < 99)) {
SerialBridgeSerial = new TasmotaSerial(pin[GPIO_SBR_RX], pin[GPIO_SBR_TX]);
if (SerialBridgeSerial->begin(Settings.sbaudrate * 1200)) { // Baud rate is stored div 1200 so it fits into one byte
if (SerialBridgeSerial->begin(Settings.sbaudrate * 300)) { // Baud rate is stored div 300 so it fits into 16 bits
if (SerialBridgeSerial->hardwareSerial()) {
ClaimSerial();
serial_bridge_buffer = serial_in_buffer; // Use idle serial buffer to save RAM
Expand Down Expand Up @@ -141,11 +141,12 @@ void CmndSSerialSend(void)

void CmndSBaudrate(void)
{
if (XdrvMailbox.payload > 1200) {
Settings.sbaudrate /= 1200; // Make it a valid baudrate
SerialBridgeSerial->begin(Settings.sbaudrate * 1200); // Reinitialize serial port with new baud rate
if (XdrvMailbox.payload >= 300) {
XdrvMailbox.payload /= 300; // Make it a valid baudrate
Settings.sbaudrate = XdrvMailbox.payload;
SerialBridgeSerial->begin(Settings.sbaudrate * 300); // Reinitialize serial port with new baud rate
}
ResponseCmndNumber(Settings.sbaudrate * 1200);
ResponseCmndNumber(Settings.sbaudrate * 300);
}

/*********************************************************************************************\
Expand Down
51 changes: 28 additions & 23 deletions sonoff/xdrv_16_tuyadimmer.ino
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,34 @@ void TuyaSetWifiLed(void)
TuyaSendCmd(TUYA_CMD_WIFI_STATE, &wifi_state, 1);
}

#ifdef USE_ENERGY_SENSOR
/*********************************************************************************************\
* Energy Interface
\*********************************************************************************************/

int Xnrg08(uint8_t function)
{
int result = 0;

if (TUYA_DIMMER == my_module_type) {
if (FUNC_PRE_INIT == function) {
if (!energy_flg) {
if (Settings.param[P_TUYA_POWER_ID] != 0) {
if (Settings.param[P_TUYA_CURRENT_ID] == 0) {
Energy.current_available = false;
}
if (Settings.param[P_TUYA_VOLTAGE_ID] == 0) {
Energy.voltage_available = false;
}
energy_flg = XNRG_08;
}
}
}
}
return result;
}
#endif // USE_ENERGY_SENSOR

/*********************************************************************************************\
* Interface
\*********************************************************************************************/
Expand Down Expand Up @@ -463,28 +491,5 @@ bool Xdrv16(uint8_t function)
return result;
}

#ifdef USE_ENERGY_SENSOR
/*********************************************************************************************\
* Energy Interface
\*********************************************************************************************/

int Xnrg08(uint8_t function)
{
int result = 0;
if (FUNC_PRE_INIT == function) {
if (Settings.param[P_TUYA_POWER_ID] != 0) {
energy_flg = XNRG_08;
}
if (Settings.param[P_TUYA_CURRENT_ID] == 0) {
Energy.current_available = false;
}
if (Settings.param[P_TUYA_VOLTAGE_ID] == 0) {
Energy.voltage_available = false;
}
}
return result;
}
#endif // USE_ENERGY_SENSOR

#endif // USE_TUYA_DIMMER
#endif // USE_LIGHT
3 changes: 3 additions & 0 deletions sonoff/xdrv_20_hue.ino
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,9 @@ uint32_t findEchoGeneration(void) {
break;
}
}
if (0 == user_agent.length()) {
gen = 1; // if no user-agent, also revert to gen v1
}

AddLog_P2(LOG_LEVEL_DEBUG_MORE, D_LOG_HTTP D_HUE " User-Agent: %s, gen=%d", user_agent.c_str(), gen); // Header collection is set in xdrv_01_webserver.ino, in StartWebserver()

Expand Down

0 comments on commit f916dbf

Please sign in to comment.