Add dynamic buffer space

Make serial buffer space reservation dynamic
This commit is contained in:
Theo Arends 2018-11-27 11:55:54 +01:00
parent 33a158fb0c
commit a360ac4ef6
2 changed files with 25 additions and 16 deletions

View File

@ -53,7 +53,7 @@ uint8_t tuya_cmd_checksum = 0; // Checksum of tuya 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()
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
/*********************************************************************************************\
@ -285,14 +285,17 @@ void TuyaInit(void)
if (!Settings.param[P_TUYA_DIMMER_ID]) {
Settings.param[P_TUYA_DIMMER_ID] = TUYA_DIMMER_ID;
}
TuyaSerial = new TasmotaSerial(pin[GPIO_TUYA_RX], pin[GPIO_TUYA_TX], 2);
if (TuyaSerial->begin(9600)) {
if (TuyaSerial->hardwareSerial()) { ClaimSerial(); }
// Get MCU Configuration
snprintf_P(log_data, sizeof(log_data), "TYA: Request MCU configuration");
AddLog(LOG_LEVEL_DEBUG);
tuya_buffer = reinterpret_cast<char*>(malloc(TUYA_BUFFER_SIZE));
if (tuya_buffer != NULL) {
TuyaSerial = new TasmotaSerial(pin[GPIO_TUYA_RX], pin[GPIO_TUYA_TX], 2);
if (TuyaSerial->begin(9600)) {
if (TuyaSerial->hardwareSerial()) { ClaimSerial(); }
// 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);
}
}
}

View File

@ -33,8 +33,8 @@ boolean ps16dz_power = false;
uint8_t ps16dz_bright = 0;
//uint64_t ps16dz_seq = 0;
char ps16dz_tx_buffer[PS16DZ_BUFFER_SIZE]; // Serial transmit buffer
char ps16dz_rx_buffer[PS16DZ_BUFFER_SIZE]; // Serial receive buffer
char *ps16dz_tx_buffer = NULL; // Serial transmit buffer
char *ps16dz_rx_buffer = NULL; // Serial receive buffer
int ps16dz_byte_counter = 0;
/*********************************************************************************************\
@ -117,9 +117,15 @@ boolean PS16DZModuleSelected(void)
void PS16DZInit(void)
{
PS16DZSerial = new TasmotaSerial(pin[GPIO_RXD], pin[GPIO_TXD], 2);
if (PS16DZSerial->begin(19200)) {
if (PS16DZSerial->hardwareSerial()) { ClaimSerial(); }
ps16dz_tx_buffer = reinterpret_cast<char*>(malloc(PS16DZ_BUFFER_SIZE));
if (ps16dz_tx_buffer != NULL) {
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(); }
}
}
}
}