mirror of
https://github.com/arendst/Tasmota.git
synced 2025-08-01 23:17:43 +00:00
Add dynamic buffer space
Make serial buffer space reservation dynamic
This commit is contained in:
parent
33a158fb0c
commit
a360ac4ef6
@ -53,7 +53,7 @@ uint8_t tuya_cmd_checksum = 0; // Checksum of tuya command
|
|||||||
uint8_t tuya_data_len = 0; // Data lenght of command
|
uint8_t tuya_data_len = 0; // Data lenght of command
|
||||||
int8_t tuya_wifi_state = -2; // Keep MCU wifi-status in sync with WifiState()
|
int8_t tuya_wifi_state = -2; // Keep MCU wifi-status in sync with WifiState()
|
||||||
|
|
||||||
char tuya_buffer[TUYA_BUFFER_SIZE]; // Serial receive buffer
|
char *tuya_buffer = NULL; // Serial receive buffer
|
||||||
int tuya_byte_counter = 0; // Index in serial receive buffer
|
int tuya_byte_counter = 0; // Index in serial receive buffer
|
||||||
|
|
||||||
/*********************************************************************************************\
|
/*********************************************************************************************\
|
||||||
@ -285,14 +285,17 @@ void TuyaInit(void)
|
|||||||
if (!Settings.param[P_TUYA_DIMMER_ID]) {
|
if (!Settings.param[P_TUYA_DIMMER_ID]) {
|
||||||
Settings.param[P_TUYA_DIMMER_ID] = TUYA_DIMMER_ID;
|
Settings.param[P_TUYA_DIMMER_ID] = TUYA_DIMMER_ID;
|
||||||
}
|
}
|
||||||
TuyaSerial = new TasmotaSerial(pin[GPIO_TUYA_RX], pin[GPIO_TUYA_TX], 2);
|
tuya_buffer = reinterpret_cast<char*>(malloc(TUYA_BUFFER_SIZE));
|
||||||
if (TuyaSerial->begin(9600)) {
|
if (tuya_buffer != NULL) {
|
||||||
if (TuyaSerial->hardwareSerial()) { ClaimSerial(); }
|
TuyaSerial = new TasmotaSerial(pin[GPIO_TUYA_RX], pin[GPIO_TUYA_TX], 2);
|
||||||
// Get MCU Configuration
|
if (TuyaSerial->begin(9600)) {
|
||||||
snprintf_P(log_data, sizeof(log_data), "TYA: Request MCU configuration");
|
if (TuyaSerial->hardwareSerial()) { ClaimSerial(); }
|
||||||
AddLog(LOG_LEVEL_DEBUG);
|
// Get MCU Configuration
|
||||||
|
snprintf_P(log_data, sizeof(log_data), "TYA: Request MCU configuration");
|
||||||
|
AddLog(LOG_LEVEL_DEBUG);
|
||||||
|
|
||||||
TuyaSendCmd(TUYA_CMD_MCU_CONF);
|
TuyaSendCmd(TUYA_CMD_MCU_CONF);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,8 +33,8 @@ boolean ps16dz_power = false;
|
|||||||
uint8_t ps16dz_bright = 0;
|
uint8_t ps16dz_bright = 0;
|
||||||
//uint64_t ps16dz_seq = 0;
|
//uint64_t ps16dz_seq = 0;
|
||||||
|
|
||||||
char ps16dz_tx_buffer[PS16DZ_BUFFER_SIZE]; // Serial transmit buffer
|
char *ps16dz_tx_buffer = NULL; // Serial transmit buffer
|
||||||
char ps16dz_rx_buffer[PS16DZ_BUFFER_SIZE]; // Serial receive buffer
|
char *ps16dz_rx_buffer = NULL; // Serial receive buffer
|
||||||
int ps16dz_byte_counter = 0;
|
int ps16dz_byte_counter = 0;
|
||||||
|
|
||||||
/*********************************************************************************************\
|
/*********************************************************************************************\
|
||||||
@ -60,7 +60,7 @@ boolean PS16DZSetPower(void)
|
|||||||
snprintf_P(ps16dz_tx_buffer, sizeof(ps16dz_tx_buffer), PSTR( "%s\",\"switch\":\"%s\""), ps16dz_tx_buffer, rpower?"on":"off");
|
snprintf_P(ps16dz_tx_buffer, sizeof(ps16dz_tx_buffer), PSTR( "%s\",\"switch\":\"%s\""), ps16dz_tx_buffer, rpower?"on":"off");
|
||||||
snprintf_P(log_data, sizeof(log_data), PSTR( "PSZ: Send serial command: %s"), ps16dz_tx_buffer );
|
snprintf_P(log_data, sizeof(log_data), PSTR( "PSZ: Send serial command: %s"), ps16dz_tx_buffer );
|
||||||
AddLog(LOG_LEVEL_DEBUG);
|
AddLog(LOG_LEVEL_DEBUG);
|
||||||
|
|
||||||
PS16DZSerial->print(ps16dz_tx_buffer);
|
PS16DZSerial->print(ps16dz_tx_buffer);
|
||||||
PS16DZSerial->write(0x1B);
|
PS16DZSerial->write(0x1B);
|
||||||
PS16DZSerial->flush();
|
PS16DZSerial->flush();
|
||||||
@ -82,7 +82,7 @@ void PS16DZSerialDuty(uint8_t duty)
|
|||||||
snprintf_P(ps16dz_tx_buffer, sizeof(ps16dz_tx_buffer), PSTR( "%s\",\"bright\":%d"), ps16dz_tx_buffer, round(duty * (100. / 255.)));
|
snprintf_P(ps16dz_tx_buffer, sizeof(ps16dz_tx_buffer), PSTR( "%s\",\"bright\":%d"), ps16dz_tx_buffer, round(duty * (100. / 255.)));
|
||||||
snprintf_P(log_data, sizeof(log_data), PSTR( "PSZ: Send serial command: %s"), ps16dz_tx_buffer );
|
snprintf_P(log_data, sizeof(log_data), PSTR( "PSZ: Send serial command: %s"), ps16dz_tx_buffer );
|
||||||
AddLog(LOG_LEVEL_DEBUG);
|
AddLog(LOG_LEVEL_DEBUG);
|
||||||
|
|
||||||
PS16DZSerial->print(ps16dz_tx_buffer);
|
PS16DZSerial->print(ps16dz_tx_buffer);
|
||||||
PS16DZSerial->write(0x1B);
|
PS16DZSerial->write(0x1B);
|
||||||
PS16DZSerial->flush();
|
PS16DZSerial->flush();
|
||||||
@ -117,9 +117,15 @@ boolean PS16DZModuleSelected(void)
|
|||||||
|
|
||||||
void PS16DZInit(void)
|
void PS16DZInit(void)
|
||||||
{
|
{
|
||||||
PS16DZSerial = new TasmotaSerial(pin[GPIO_RXD], pin[GPIO_TXD], 2);
|
ps16dz_tx_buffer = reinterpret_cast<char*>(malloc(PS16DZ_BUFFER_SIZE));
|
||||||
if (PS16DZSerial->begin(19200)) {
|
if (ps16dz_tx_buffer != NULL) {
|
||||||
if (PS16DZSerial->hardwareSerial()) { ClaimSerial(); }
|
ps16dz_rx_buffer = reinterpret_cast<char*>(malloc(PS16DZ_BUFFER_SIZE));
|
||||||
|
if (ps16dz_rx_buffer != NULL) {
|
||||||
|
PS16DZSerial = new TasmotaSerial(pin[GPIO_RXD], pin[GPIO_TXD], 2);
|
||||||
|
if (PS16DZSerial->begin(19200)) {
|
||||||
|
if (PS16DZSerial->hardwareSerial()) { ClaimSerial(); }
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -174,7 +180,7 @@ void PS16DZSerialInput(void)
|
|||||||
//ps16dz_seq = strtoull(token3+1, NULL, 10);
|
//ps16dz_seq = strtoull(token3+1, NULL, 10);
|
||||||
snprintf_P(log_data, sizeof(log_data), PSTR("PSZ: sequence received: %s"), token3);
|
snprintf_P(log_data, sizeof(log_data), PSTR("PSZ: sequence received: %s"), token3);
|
||||||
AddLog(LOG_LEVEL_DEBUG);
|
AddLog(LOG_LEVEL_DEBUG);
|
||||||
}
|
}
|
||||||
token = strtok_r(NULL, ",", &end_str);
|
token = strtok_r(NULL, ",", &end_str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user