fix: O-1PS not recognized

This commit is contained in:
Phat Nguyen
2024-03-06 17:20:55 +07:00
parent 6cf5e31843
commit 469d07a2d6
7 changed files with 133 additions and 41 deletions

View File

@ -79,19 +79,21 @@ bool PMS5003T::begin(void) {
#if ARDUINO_USB_CDC_ON_BOOT // Serial used for USB CDC
if (this->_serial == &Serial0) {
AgLog("Init Serial0");
_serial->begin(9600, SERIAL_8N1);
#else
if (this->_serial == &Serial) {
#endif
AgLog("Init Serial");
this->_serial->begin(9600, SERIAL_8N1, bsp->Pms5003.uart_rx_pin,
bsp->Pms5003.uart_tx_pin);
#endif
} else {
/** Share with sensor air s8*/
if (bsp->SenseAirS8.supported == false) {
AgLog("Board [%d] PMS5003T_2 not supported", this->_boardDef);
return false;
}
/** Share with sensor air s8*/
AgLog("Init Serialx");
this->_serial->begin(9600, SERIAL_8N1, bsp->SenseAirS8.uart_rx_pin,
bsp->SenseAirS8.uart_tx_pin);

View File

@ -228,7 +228,7 @@ int16_t S8::getCo2(void) {
return -1;
}
int16_t co2 = 0;
int16_t co2 = -1;
// Ask CO2 value
sendCommand(MODBUS_FUNC_READ_INPUT_REGISTERS, MODBUS_IR4, 0x0001);
@ -649,11 +649,25 @@ bool S8::init(int txPin, int rxPin, uint32_t baud) {
uart->begin(baud);
this->_uartStream = uart;
#else
#if ARDUINO_USB_CDC_ON_BOOT
/** The 'Serial0' can ont configure tx, rx pin, only use as default */
if (_serial == &Serial0) {
AgLog("Init on 'Serial0'");
_serial->begin(baud, SERIAL_8N1);
} else {
AgLog("Init on 'Serialx'");
this->_serial->begin(baud, SERIAL_8N1, rxPin, txPin);
}
this->_uartStream = this->_serial;
#else
AgLog("Init on 'Serialx'");
this->_serial->begin(baud, SERIAL_8N1, rxPin, txPin);
this->_uartStream = this->_serial;
#endif
#endif
/** Check communication by get firmware version */
delay(100);
char fwVers[11];
this->_isBegin = true;
this->getFirmwareVersion(fwVers);
@ -712,7 +726,7 @@ uint8_t S8::uartReadBytes(uint8_t max_bytes, uint32_t timeout_ms) {
#if defined(ESP32)
// Relax 5ms to avoid watchdog reset
vTaskDelay(pdMS_TO_TICKS(5));
vTaskDelay(pdMS_TO_TICKS(1));
#endif
}
return nb;

View File

@ -91,7 +91,7 @@ void Sgp41::handle(void) {
if (getRawSignal(srawVoc, srawNox)) {
nox = noxAlgorithm()->process(srawNox);
tvoc = vocAlgorithm()->process(srawVoc);
AgLog("Polling SGP41 success: tvoc: %d, nox: %d", tvoc, nox);
// AgLog("Polling SGP41 success: tvoc: %d, nox: %d", tvoc, nox);
}
}
}
@ -124,7 +124,7 @@ void Sgp41::_handle(void) {
noxRaw = srawNox;
nox = noxAlgorithm()->process(srawNox);
tvoc = vocAlgorithm()->process(srawVoc);
AgLog("Polling SGP41 success: tvoc: %d, nox: %d", tvoc, nox);
// AgLog("Polling SGP41 success: tvoc: %d, nox: %d", tvoc, nox);
}
}
}