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 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,6 +285,8 @@ 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;
} }
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); TuyaSerial = new TasmotaSerial(pin[GPIO_TUYA_RX], pin[GPIO_TUYA_TX], 2);
if (TuyaSerial->begin(9600)) { if (TuyaSerial->begin(9600)) {
if (TuyaSerial->hardwareSerial()) { ClaimSerial(); } if (TuyaSerial->hardwareSerial()) { ClaimSerial(); }
@ -294,6 +296,7 @@ void TuyaInit(void)
TuyaSendCmd(TUYA_CMD_MCU_CONF); TuyaSendCmd(TUYA_CMD_MCU_CONF);
} }
}
} }
void TuyaSerialInput(void) void TuyaSerialInput(void)

View File

@ -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;
/*********************************************************************************************\ /*********************************************************************************************\
@ -117,10 +117,16 @@ boolean PS16DZModuleSelected(void)
void PS16DZInit(void) void PS16DZInit(void)
{ {
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); PS16DZSerial = new TasmotaSerial(pin[GPIO_RXD], pin[GPIO_TXD], 2);
if (PS16DZSerial->begin(19200)) { if (PS16DZSerial->begin(19200)) {
if (PS16DZSerial->hardwareSerial()) { ClaimSerial(); } if (PS16DZSerial->hardwareSerial()) { ClaimSerial(); }
} }
}
}
} }
void PS16DZSerialInput(void) void PS16DZSerialInput(void)