Add command ``SSerialConfig <serialconfig>`` to change Serial Bridge configuration

Add command ``SSerialConfig <serialconfig>`` to change Serial Bridge configuration
This commit is contained in:
Theo Arends 2021-12-25 12:58:24 +01:00
parent da8910b9c3
commit 4962fd229e
7 changed files with 67 additions and 14 deletions

View File

@ -3,8 +3,11 @@ All notable changes to this project will be documented in this file.
## [Unreleased] - Development
## [10.1.0.2]
## [10.1.0.3]
### Added
- Command ``SSerialConfig <serialconfig>`` to change Serial Bridge configuration
## [10.1.0.2] 20211225
### Changed
- TasmotaSerial library from v3.3.0 to v3.4.0 - reverted (#14153)
- Force initial serial configuration even if no serial GPIO's are enabled (#14153)
@ -14,7 +17,7 @@ All notable changes to this project will be documented in this file.
### Fixed
- Serial broken after #14153 - reverted
## [10.1.0.1]
## [10.1.0.1] 20211223
### Added
- PWM Dimmer two button support (#13993)
- Device Group Send full status item (#14045)

View File

@ -100,8 +100,9 @@ The latter links can be used for OTA upgrades too like ``OtaUrl http://ota.tasmo
[Complete list](BUILDS.md) of available feature and sensors.
## Changelog v10.1.0.2
## Changelog v10.1.0.3
### Added
- Command ``SSerialConfig <serialconfig>`` to change Serial Bridge configuration
- PWM Dimmer two button support [#13993](https://github.com/arendst/Tasmota/issues/13993)
- Device Group Send full status item [#14045](https://github.com/arendst/Tasmota/issues/14045)
- Support for MAX7219 Dot Matrix displays [#14091](https://github.com/arendst/Tasmota/issues/14091)

View File

@ -548,6 +548,7 @@
// Commands xdrv_08_serial_bridge.ino
#define D_CMND_SSERIALSEND "SSerialSend"
#define D_CMND_SBAUDRATE "SBaudrate"
#define D_CMND_SSERIALCONFIG "SSerialConfig"
#define D_JSON_SSERIALRECEIVED "SSerialReceived"
// Commands xdrv_09_timers.ino

View File

@ -487,8 +487,9 @@ typedef struct {
int32_t energy_kWhyesterday_ph[3]; // 320
int32_t energy_kWhtotal_ph[3]; // 32C
uint8_t free_338[7]; // 338
uint8_t free_338[6]; // 338
uint8_t sserial_config; // 33E
uint8_t tuyamcu_topic; // 33F Manage tuyaSend topic. ex_energy_power_delta on 6.6.0.20, replaced on 8.5.0.1
uint16_t domoticz_update_timer; // 340
uint16_t pwm_range; // 342
@ -595,10 +596,10 @@ typedef struct {
uint16_t influxdb_port; // 4CE
power_t interlock[MAX_INTERLOCKS_SET]; // 4D0 MAX_INTERLOCKS = MAX_RELAYS / 2
int8_t shutter_tilt_config[5][MAX_SHUTTERS]; //508
int8_t shutter_tilt_pos[MAX_SHUTTERS]; //51C
uint16_t influxdb_period; // 520
uint8_t free_522[10]; // 522
uint16_t mqtt_keepalive; // 52C

View File

@ -1472,6 +1472,9 @@ void SettingsDelta(void) {
#endif
}
}
if (Settings->version < 0x0A010003) {
Settings->sserial_config = Settings->serial_config;
}
Settings->version = VERSION;
SettingsSave(1);

View File

@ -20,6 +20,6 @@
#ifndef _TASMOTA_VERSION_H_
#define _TASMOTA_VERSION_H_
const uint32_t VERSION = 0x0A010002;
const uint32_t VERSION = 0x0A010003;
#endif // _TASMOTA_VERSION_H_

View File

@ -28,10 +28,10 @@
const uint8_t SERIAL_BRIDGE_BUFFER_SIZE = 130;
const char kSerialBridgeCommands[] PROGMEM = "|" // No prefix
D_CMND_SSERIALSEND "|" D_CMND_SBAUDRATE;
D_CMND_SSERIALSEND "|" D_CMND_SBAUDRATE "|" D_CMND_SSERIALCONFIG;
void (* const SerialBridgeCommand[])(void) PROGMEM = {
&CmndSSerialSend, &CmndSBaudrate };
&CmndSSerialSend, &CmndSBaudrate, &CmndSSerialConfig };
#include <TasmotaSerial.h>
@ -43,8 +43,32 @@ int serial_bridge_in_byte_counter = 0;
bool serial_bridge_active = true;
bool serial_bridge_raw = false;
void SerialBridgeInput(void)
{
/********************************************************************************************/
bool SetSSerialBegin(void) {
uint32_t config;
#ifdef ESP8266
config = pgm_read_byte(kTasmotaSerialConfig + Settings->sserial_config);
#endif // ESP8266
#ifdef ESP32
config = pgm_read_dword(kTasmotaSerialConfig + Settings->sserial_config);
#endif // ESP32
return SerialBridgeSerial->begin(Settings->sbaudrate * 300, config); // Reinitialize serial port with new baud rate
}
void SetSSerialConfig(uint32_t serial_config) {
if (serial_config > TS_SERIAL_8O2) {
serial_config = TS_SERIAL_8N1;
}
if (serial_config != Settings->sserial_config) {
Settings->sserial_config = serial_config;
SetSSerialBegin();
}
}
/********************************************************************************************/
void SerialBridgeInput(void) {
while (SerialBridgeSerial->available()) {
yield();
uint8_t serial_in_byte = SerialBridgeSerial->read();
@ -106,7 +130,7 @@ void SerialBridgeInit(void)
serial_bridge_active = false;
if (PinUsed(GPIO_SBR_RX) && PinUsed(GPIO_SBR_TX)) {
SerialBridgeSerial = new TasmotaSerial(Pin(GPIO_SBR_RX), Pin(GPIO_SBR_TX), HARDWARE_FALLBACK);
if (SerialBridgeSerial->begin(Settings->sbaudrate * 300)) { // Baud rate is stored div 300 so it fits into 16 bits
if (SetSSerialBegin()) {
if (SerialBridgeSerial->hardwareSerial()) {
ClaimSerial();
serial_bridge_buffer = TasmotaGlobal.serial_in_buffer; // Use idle serial buffer to save RAM
@ -168,16 +192,36 @@ void CmndSSerialSend(void)
}
}
void CmndSBaudrate(void)
{
void CmndSBaudrate(void) {
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
SetSSerialBegin();
}
ResponseCmndNumber(Settings->sbaudrate * 300);
}
void CmndSSerialConfig(void) {
// See TasmotaSerialConfig for possible options
// SSerialConfig 0..23 where 3 equals 8N1
// SSerialConfig 8N1
if (XdrvMailbox.data_len > 0) {
if (XdrvMailbox.data_len < 3) { // Use 0..23 as serial config option
if ((XdrvMailbox.payload >= TS_SERIAL_5N1) && (XdrvMailbox.payload <= TS_SERIAL_8O2)) {
SetSSerialConfig(XdrvMailbox.payload);
}
}
else if ((XdrvMailbox.payload >= 5) && (XdrvMailbox.payload <= 8)) {
int8_t serial_config = ParseSerialConfig(XdrvMailbox.data);
if (serial_config >= 0) {
SetSSerialConfig(serial_config);
}
}
}
ResponseCmndChar(GetSerialConfig(Settings->sserial_config).c_str());
}
/*********************************************************************************************\
* Interface
\*********************************************************************************************/