diff --git a/lib/TasmotaSerial-2.3.2/src/TasmotaSerial.cpp b/lib/TasmotaSerial-2.3.2/src/TasmotaSerial.cpp index 3611a563c..a6b42bf03 100755 --- a/lib/TasmotaSerial-2.3.2/src/TasmotaSerial.cpp +++ b/lib/TasmotaSerial-2.3.2/src/TasmotaSerial.cpp @@ -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; @@ -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; @@ -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; } } @@ -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; } } @@ -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; @@ -297,7 +297,7 @@ if (!m_nwmode) { ss_byte|=(1<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; @@ -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; diff --git a/lib/TasmotaSerial-2.3.2/src/TasmotaSerial.h b/lib/TasmotaSerial-2.3.2/src/TasmotaSerial.h index 6e1d6469a..57adb9e26 100755 --- a/lib/TasmotaSerial-2.3.2/src/TasmotaSerial.h +++ b/lib/TasmotaSerial-2.3.2/src/TasmotaSerial.h @@ -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); @@ -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