mirror of
https://github.com/airgradienthq/arduino.git
synced 2025-07-28 07:57:18 +02:00
set active mode on init
This commit is contained in:
@ -4,7 +4,7 @@
|
|||||||
/**
|
/**
|
||||||
* @brief Initializes the sensor and attempts to read data.
|
* @brief Initializes the sensor and attempts to read data.
|
||||||
*
|
*
|
||||||
* @param stream UART stream
|
* @param HardwareSerial UART stream
|
||||||
* @return true Sucecss
|
* @return true Sucecss
|
||||||
* @return false Failure
|
* @return false Failure
|
||||||
*/
|
*/
|
||||||
@ -13,7 +13,19 @@ bool PMSBase::begin(HardwareSerial &serial) {
|
|||||||
_connected = false;
|
_connected = false;
|
||||||
|
|
||||||
// Run and check sensor data for 4sec
|
// Run and check sensor data for 4sec
|
||||||
|
int bytesCleared = serial.available();
|
||||||
serial.flush();
|
serial.flush();
|
||||||
|
if (bytesCleared) {
|
||||||
|
Serial.printf("cleared %d byte(s)\n", bytesCleared);
|
||||||
|
}
|
||||||
|
|
||||||
|
// explicitly put the sensor into active mode, this seems to be be needed for
|
||||||
|
// the Cubic PM2009X
|
||||||
|
Serial.printf("Setting active mode\n");
|
||||||
|
uint8_t activeModeCommand[] = {0x42, 0x4D, 0xE1, 0x00, 0x01, 0x01, 0x71};
|
||||||
|
size_t bytesWritten =
|
||||||
|
serial.write(activeModeCommand, sizeof(activeModeCommand));
|
||||||
|
Serial.printf("%d byte(s) written\n", bytesWritten);
|
||||||
|
|
||||||
unsigned long lastInit = millis();
|
unsigned long lastInit = millis();
|
||||||
while (true) {
|
while (true) {
|
||||||
@ -25,9 +37,15 @@ bool PMSBase::begin(HardwareSerial &serial) {
|
|||||||
delay(1);
|
delay(1);
|
||||||
unsigned long ms = (unsigned long)(millis() - lastInit);
|
unsigned long ms = (unsigned long)(millis() - lastInit);
|
||||||
if (ms >= 4000) {
|
if (ms >= 4000) {
|
||||||
|
Serial.println("Initialize PMS sensor: Timeout");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (_connected) {
|
||||||
|
Serial.println("Initialize PMS sensor");
|
||||||
|
}
|
||||||
|
|
||||||
return _connected;
|
return _connected;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user