Skip to content

Commit

Permalink
fixed some clang issues and removed warnning with ms init
Browse files Browse the repository at this point in the history
  • Loading branch information
hpsaturn committed Sep 20, 2024
1 parent fe317d2 commit 0b216f3
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 66 deletions.
2 changes: 1 addition & 1 deletion src/Sensors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1387,7 +1387,7 @@ bool Sensors::PM1006Init() {
return pm1006Read();
}

bool Sensors::PM5003TInit(){
bool Sensors::PM5003TInit() {
pm5003t = new PMS5003T(*_serial);
if (!pm5003t->begin()) return false;
sensorRegister(SENSORS::P5003T);
Expand Down
2 changes: 1 addition & 1 deletion src/Sensors.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
#include <SensirionI2CSgp41.h>
#include <SparkFun_Particle_Sensor_SN-GCJA5_Arduino_Library.h>
#include <cm1106_uart.h>
#include <drivers/PMS5003T.h>
#include <drivers/geiger.h>
#include <drivers/pm1006.h>
#include <drivers/PMS5003T.h>
#include <s8_uart.h>
#include <sps30.h>

Expand Down
98 changes: 49 additions & 49 deletions src/drivers/PMS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/**
* @brief Init and check that sensor has connected
*
*
* @param stream UART stream
* @return true Sucecss
* @return false Failure
Expand All @@ -11,7 +11,7 @@ bool PMSBase::begin(Stream *stream) {
this->stream = stream;

failed = true;
lastRead = 0; // To read buffer on handle without wait after 1.5sec
lastRead = 0; // To read buffer on handle without wait after 1.5sec

this->stream->flush();

Expand All @@ -36,7 +36,7 @@ bool PMSBase::begin(Stream *stream) {
* Check result from method @isFailed before get value
*/
void PMSBase::handle() {
uint32_t ms;
uint32_t ms = 0;
if (lastRead == 0) {
lastRead = millis();
if (lastRead == 0) {
Expand Down Expand Up @@ -64,58 +64,58 @@ void PMSBase::handle() {
while (stream->available()) {
char value = stream->read();
switch (step) {
case 0: {
if (value == 0x42) {
step = 1;
bufIndex = 0;
buf[bufIndex++] = value;
}
break;
}
case 1: {
if (value == 0x4d) {
step = 2;
buf[bufIndex++] = value;
// Serial.println("Got 0x4d");
} else {
step = 0;
case 0: {
if (value == 0x42) {
step = 1;
bufIndex = 0;
buf[bufIndex++] = value;
}
break;
}
break;
}
case 2: {
buf[bufIndex++] = value;
if (bufIndex >= 4) {
len = toValue(&buf[2]);
if (len != 28) {
// Serial.printf("Got good bad len %d\r\n", len);
len += 4;
step = 3;
case 1: {
if (value == 0x4d) {
step = 2;
buf[bufIndex++] = value;
// Serial.println("Got 0x4d");
} else {
// Serial.println("Got good len");
step = 4;
step = 0;
}
break;
}
break;
}
case 3: {
bufIndex++;
if (bufIndex >= len) {
step = 0;
// Serial.println("Bad lengh read all buffer");
case 2: {
buf[bufIndex++] = value;
if (bufIndex >= 4) {
len = toValue(&buf[2]);
if (len != 28) {
// Serial.printf("Got good bad len %d\r\n", len);
len += 4;
step = 3;
} else {
// Serial.println("Got good len");
step = 4;
}
}
break;
}
break;
}
case 4: {
buf[bufIndex++] = value;
if (bufIndex >= 32) {
result |= validate(buf);
step = 0;
// Serial.println("Got data");
case 3: {
bufIndex++;
if (bufIndex >= len) {
step = 0;
// Serial.println("Bad lengh read all buffer");
}
break;
}
break;
}
default:
break;
case 4: {
buf[bufIndex++] = value;
if (bufIndex >= 32) {
result |= validate(buf);
step = 0;
// Serial.println("Got data");
}
break;
}
default:
break;
}

// Reduce core panic: delay 1 ms each 32bytes data
Expand Down
4 changes: 2 additions & 2 deletions src/drivers/PMS.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <Arduino.h>

class PMSBase {
public:
public:
bool begin(Stream *stream);
void handle();
bool isFailed(void);
Expand All @@ -29,7 +29,7 @@ class PMSBase {

int pm25ToAQI(int pm02);

private:
private:
Stream *stream;
char package[32];
int packageIndex;
Expand Down
13 changes: 4 additions & 9 deletions src/drivers/PMS5003T.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ bool PMS5003T::begin(void) {
}

if (pms.begin(this->_serial) == false) {
#if defined(ESP32)
#if defined(ESP32)
log_e("PMS failed");
#endif
#endif
return false;
}

Expand Down Expand Up @@ -70,18 +70,14 @@ int PMS5003T::convertPm25ToUsAqi(int pm25) { return pms.pm25ToAQI(pm25); }
*
* @return float Degree Celcius
*/
float PMS5003T::getTemperature(void) {
return pms.getTemp()/10.0f;
}
float PMS5003T::getTemperature(void) { return pms.getTemp() / 10.0f; }

/**
* @brief Get humidity, Must call this method after @ref readData() success
*
* @return float Percent (%)
*/
float PMS5003T::getRelativeHumidity(void) {
return pms.getHum()/10.0f;
}
float PMS5003T::getRelativeHumidity(void) { return pms.getHum() / 10.0f; }

/**
* @brief Check device initialized or not
Expand Down Expand Up @@ -123,4 +119,3 @@ void PMS5003T::handle(void) { pms.handle(); }
* @return false Communication timeout or sensor has removed
*/
bool PMS5003T::isFailed(void) { return pms.isFailed(); }

9 changes: 5 additions & 4 deletions src/drivers/PMS5003T.h
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
#ifndef _PMS5003T_H_
#define _PMS5003T_H_

#include <HardwareSerial.h>

#include "PMS.h"
#include "PMS5003TBase.h"
#include "Stream.h"
#include <HardwareSerial.h>

/**
* @brief The class define how to handle PMS5003T sensor bas on @ref PMS class
*/
class PMS5003T: public PMS5003TBase {
public:
class PMS5003T : public PMS5003TBase {
public:
explicit PMS5003T(Stream &serial);
bool begin(void);
void end(void);
Expand All @@ -24,7 +25,7 @@ class PMS5003T: public PMS5003TBase {
float getTemperature(void);
float getRelativeHumidity(void);

private:
private:
bool _isBegin = false;
bool _isSleep = false;
Stream *_serial;
Expand Down

0 comments on commit 0b216f3

Please sign in to comment.