![]() |
RumPi 1.0
A self-assembling C++ sensor & actuator library for the Raspberry Pi 5
|
PTQS1005 air-quality sensor read over serial, reporting PM2.5, TVOC, HCHO, CO2, internal temperature, and humidity, each with a rolling average. More...
#include <PTQS1005.h>
Public Member Functions | |
| PTQS1005 (const std::string &devicePath) | |
| Builds a PTQS1005 for the given serial device path, seeding its data map so each reading updates in place. More... | |
| virtual | ~PTQS1005 () |
| Destroys the sensor, turning it off first. More... | |
| virtual void | TurnOn () override |
| Opens the serial device at 9600 baud and marks the sensor running, reporting the result through the AlertManager. More... | |
| virtual void | TurnOff () override |
| Closes the serial device (if open) and marks the sensor stopped. More... | |
| virtual float | ReadRawValue () |
| Reads a single raw byte (as a float) from the serial device. More... | |
| virtual bool | IsDataValid (const float *dataToValidate, const size_t bufferSize) const |
| Validates a serial frame by summing all bytes except the trailing two and comparing against the big-endian checksum those two bytes carry. More... | |
| virtual void | ProcessRawValues () override |
| Sends the data-request command, reads and validates a serial frame (retrying up to RUMPI_MAX_READ_ATTEMPTS), decodes PM2.5/TVOC/HCHO/CO2/temperature/humidity from their byte pairs, and feeds each into its rolling average. More... | |
| virtual float | ConvertDivisionFactorToNumber (float divisionFactor) const |
| Maps the sensor's TVOC/HCHO division-factor code (0, 1, or 2) to its numeric divisor (10, 100, or 1000), defaulting to 100 with a warning for an unrecognized code. More... | |
| virtual std::string | ToString () const override |
| Serializes every current reading and rolling average (PM2.5, TVOC, HCHO, CO2, temperature, humidity) to a string. More... | |
| float | GetPmTwoPointFiveAtmospheric () const |
| Gets the current PM2.5 reading. More... | |
| float | GetPmTwoPointFiveAverageAtmospheric () const |
| Gets the rolling average of the PM2.5 reading. More... | |
| float | GetTVOC () const |
| Gets the current TVOC reading. More... | |
| float | GetTVOCAverage () const |
| Gets the rolling average of the TVOC reading. More... | |
| float | GetHCHO () const |
| Gets the current HCHO (formaldehyde) reading. More... | |
| float | GetHCHOAverage () const |
| Gets the rolling average of the HCHO (formaldehyde) reading. More... | |
| float | GetCO2 () const |
| Gets the current CO2 reading. More... | |
| float | GetCO2Average () const |
| Gets the rolling average of the CO2 reading. More... | |
| float | GetInternalTemperatureInC () const |
| Gets the sensor's current internal temperature. More... | |
| float | GetInternalTemperatureInCAverage () const |
| Gets the rolling average of the sensor's internal temperature. More... | |
| float | GetHumidity () const |
| Gets the current humidity reading. More... | |
| float | GetHumidityAverage () const |
| Gets the rolling average of the humidity reading. More... | |
Public Member Functions inherited from RumPi::BaseComponent | |
| BaseComponent () | |
| Builds a base component with an unknown type and an empty name. More... | |
| virtual | ~BaseComponent () |
| Virtual destructor so deleting a component through a BaseComponent* also cleans up the concrete subclass. More... | |
| virtual void | TurnOn ()=0 |
| Turns the component on (e.g. More... | |
| virtual void | TurnOff ()=0 |
| Turns the component off. More... | |
| virtual std::string | ToString () const =0 |
| Serializes the component's current readings to a string (usually JSON). More... | |
| virtual void | ProcessRawValues ()=0 |
| Reads and processes the component's latest raw values (called once per poll). More... | |
| virtual EComponentType | GetComponentType () const |
| Gets the component's type. More... | |
| const std::string & | GetName () const |
| Gets the component's unique per-instance name. More... | |
| void | SetName (const std::string &name) |
| Sets the component's unique per-instance name. More... | |
Protected Attributes | |
| bool | myIsRunning |
| True while the serial device is open and readable. More... | |
| int | mySerialDeviceFileDescriptor |
| The open serial device file descriptor. More... | |
| std::string | myDevicePath |
| The serial device path. More... | |
| float | myCalculatedTVOC |
| The most recent TVOC reading (raw / division factor). More... | |
| float | myCalculatedHCHO |
| The most recent HCHO reading (raw / division factor). More... | |
| float | myCalculatedInternalTemperatureInC |
| The most recent internal temperature, in Celsius. More... | |
| float | myCalculatedHumidity |
| The most recent humidity, as a percent. More... | |
| RollingAverage | myPMTwoPointFiveAverageAtmospheric |
| Rolling average of the PM2.5 reading. More... | |
| RollingAverage | myTVOCAverage |
| Rolling average of the TVOC reading. More... | |
| RollingAverage | myHCHOAverage |
| Rolling average of the HCHO reading. More... | |
| RollingAverage | myCO2Average |
| Rolling average of the CO2 reading. More... | |
| RollingAverage | myInternalTemperatureInCAverage |
| Rolling average of the internal temperature. More... | |
| RollingAverage | myHumidityAverage |
| Rolling average of the humidity. More... | |
| std::map< std::string, float > | myDustData |
| Most recent raw readings, keyed by measurement name. More... | |
Protected Attributes inherited from RumPi::BaseComponent | |
| EComponentType | myComponentType |
| The kind of component this is (set by each concrete subclass). More... | |
| std::string | myName |
| A unique per-instance name, assigned when the component is added to the manager. More... | |
Additional Inherited Members | |
Static Public Member Functions inherited from RumPi::BaseComponent | |
| static std::string | ComponentTypeToString (const EComponentType theComponentTypeToConvert) |
| Maps an EComponentType to its string name. More... | |
| static EComponentType | StringToComponentType (const std::string &theComponentTypeName) |
| Maps a type name back to its EComponentType (the inverse of ComponentTypeToString), so the client can turn the type carried on the wire back into a value it can look an icon up with. More... | |
PTQS1005 air-quality sensor read over serial, reporting PM2.5, TVOC, HCHO, CO2, internal temperature, and humidity, each with a rolling average.
References: https://airekart.com/images/catalogue/air-sensor/pm2-5-air-quality-sensor.pdf https://www.plantower.com/en/products_36/82.html
| RumPi::PTQS1005::PTQS1005 | ( | const std::string & | devicePath | ) |
Builds a PTQS1005 for the given serial device path, seeding its data map so each reading updates in place.
| [in] | devicePath | The serial device path the sensor is connected to. |
|
virtual |
|
virtual |
Maps the sensor's TVOC/HCHO division-factor code (0, 1, or 2) to its numeric divisor (10, 100, or 1000), defaulting to 100 with a warning for an unrecognized code.
Output: 100
| [in] | divisionFactor | The division-factor code from the sensor. |
| float RumPi::PTQS1005::GetCO2 | ( | ) | const |
Gets the current CO2 reading.
| float RumPi::PTQS1005::GetCO2Average | ( | ) | const |
Gets the rolling average of the CO2 reading.
| float RumPi::PTQS1005::GetHCHO | ( | ) | const |
Gets the current HCHO (formaldehyde) reading.
| float RumPi::PTQS1005::GetHCHOAverage | ( | ) | const |
Gets the rolling average of the HCHO (formaldehyde) reading.
| float RumPi::PTQS1005::GetHumidity | ( | ) | const |
Gets the current humidity reading.
| float RumPi::PTQS1005::GetHumidityAverage | ( | ) | const |
Gets the rolling average of the humidity reading.
| float RumPi::PTQS1005::GetInternalTemperatureInC | ( | ) | const |
Gets the sensor's current internal temperature.
| float RumPi::PTQS1005::GetInternalTemperatureInCAverage | ( | ) | const |
Gets the rolling average of the sensor's internal temperature.
| float RumPi::PTQS1005::GetPmTwoPointFiveAtmospheric | ( | ) | const |
Gets the current PM2.5 reading.
| float RumPi::PTQS1005::GetPmTwoPointFiveAverageAtmospheric | ( | ) | const |
Gets the rolling average of the PM2.5 reading.
| float RumPi::PTQS1005::GetTVOC | ( | ) | const |
Gets the current TVOC reading.
| float RumPi::PTQS1005::GetTVOCAverage | ( | ) | const |
Gets the rolling average of the TVOC reading.
|
virtual |
Validates a serial frame by summing all bytes except the trailing two and comparing against the big-endian checksum those two bytes carry.
| [in] | dataToValidate | The frame's bytes (as floats), including the trailing checksum. |
| [in] | bufferSize | The number of bytes in the frame. |
|
overridevirtual |
Sends the data-request command, reads and validates a serial frame (retrying up to RUMPI_MAX_READ_ATTEMPTS), decodes PM2.5/TVOC/HCHO/CO2/temperature/humidity from their byte pairs, and feeds each into its rolling average.
Implements RumPi::BaseComponent.
|
virtual |
Reads a single raw byte (as a float) from the serial device.
|
overridevirtual |
Serializes every current reading and rolling average (PM2.5, TVOC, HCHO, CO2, temperature, humidity) to a string.
Implements RumPi::BaseComponent.
|
overridevirtual |
Closes the serial device (if open) and marks the sensor stopped.
Implements RumPi::BaseComponent.
|
overridevirtual |
Opens the serial device at 9600 baud and marks the sensor running, reporting the result through the AlertManager.
Implements RumPi::BaseComponent.
|
protected |
The most recent HCHO reading (raw / division factor).
|
protected |
The most recent humidity, as a percent.
|
protected |
The most recent internal temperature, in Celsius.
|
protected |
The most recent TVOC reading (raw / division factor).
|
protected |
Rolling average of the CO2 reading.
|
protected |
The serial device path.
|
protected |
Most recent raw readings, keyed by measurement name.
|
protected |
Rolling average of the HCHO reading.
|
protected |
Rolling average of the humidity.
|
protected |
Rolling average of the internal temperature.
|
protected |
True while the serial device is open and readable.
|
protected |
Rolling average of the PM2.5 reading.
|
protected |
The open serial device file descriptor.
|
protected |
Rolling average of the TVOC reading.