RumPi 1.0
A self-assembling C++ sensor & actuator library for the Raspberry Pi 5
RumPi::PTQS1005 Class Reference

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>

Inheritance diagram for RumPi::PTQS1005:
[legend]
Collaboration diagram for RumPi::PTQS1005:
[legend]

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...
 

Detailed Description

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

Author
Eddie O'Hagan
Date
8/13/2026

Constructor & Destructor Documentation

◆ PTQS1005()

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.

Author
Eddie O'Hagan
Date
8/13/2026
PTQS1005 airSensor("/dev/serial0");
PTQS1005(const std::string &devicePath)
Builds a PTQS1005 for the given serial device path, seeding its data map so each reading updates in p...
Definition: PTQS1005.cpp:19
Parameters
[in]devicePathThe serial device path the sensor is connected to.

◆ ~PTQS1005()

RumPi::PTQS1005::~PTQS1005 ( )
virtual

Destroys the sensor, turning it off first.

Author
Eddie O'Hagan
Date
8/13/2026
PTQS1005* airSensor = new PTQS1005("/dev/serial0");
delete airSensor;

Member Function Documentation

◆ ConvertDivisionFactorToNumber()

float RumPi::PTQS1005::ConvertDivisionFactorToNumber ( float  divisionFactor) const
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.

Author
Eddie O'Hagan
Date
8/13/2026
float divisor = airSensor.ConvertDivisionFactorToNumber(1.0f);

Output: 100

Parameters
[in]divisionFactorThe division-factor code from the sensor.
Returns
The numeric divisor (10, 100, or 1000).

◆ GetCO2()

float RumPi::PTQS1005::GetCO2 ( ) const

Gets the current CO2 reading.

Author
Eddie O'Hagan
Date
8/13/2026
float value = airSensor.GetCO2();
Returns
The CO2 reading, in ppm.

◆ GetCO2Average()

float RumPi::PTQS1005::GetCO2Average ( ) const

Gets the rolling average of the CO2 reading.

Author
Eddie O'Hagan
Date
8/13/2026
float value = airSensor.GetCO2Average();
Returns
The rolling average CO2 reading, in ppm, or NaN if no reading has been taken yet.
Author
Eddie O'Hagan
Date
8/13/2026
float value = airSensor.GetCO2Average();
Returns
The rolling average CO2 reading in ppm, or NaN if no reading has been taken yet.

◆ GetHCHO()

float RumPi::PTQS1005::GetHCHO ( ) const

Gets the current HCHO (formaldehyde) reading.

Author
Eddie O'Hagan
Date
8/13/2026
float value = airSensor.GetHCHO();
Returns
The HCHO reading, in ppm.

◆ GetHCHOAverage()

float RumPi::PTQS1005::GetHCHOAverage ( ) const

Gets the rolling average of the HCHO (formaldehyde) reading.

Author
Eddie O'Hagan
Date
8/13/2026
float value = airSensor.GetHCHOAverage();
Returns
The rolling average HCHO reading, in ppm, or NaN if no reading has been taken yet.
Author
Eddie O'Hagan
Date
8/13/2026
float value = airSensor.GetHCHOAverage();
Returns
The rolling average HCHO reading in ppm, or NaN if no reading has been taken yet.

◆ GetHumidity()

float RumPi::PTQS1005::GetHumidity ( ) const

Gets the current humidity reading.

Author
Eddie O'Hagan
Date
8/13/2026
float value = airSensor.GetHumidity();
Returns
The humidity, as a percent.

◆ GetHumidityAverage()

float RumPi::PTQS1005::GetHumidityAverage ( ) const

Gets the rolling average of the humidity reading.

Author
Eddie O'Hagan
Date
8/13/2026
float value = airSensor.GetHumidityAverage();
Returns
The rolling average humidity, as a percent, or NaN if no reading has been taken yet.
Author
Eddie O'Hagan
Date
8/13/2026
float value = airSensor.GetHumidityAverage();
Returns
The rolling average humidity as a percent, or NaN if no reading has been taken yet.

◆ GetInternalTemperatureInC()

float RumPi::PTQS1005::GetInternalTemperatureInC ( ) const

Gets the sensor's current internal temperature.

Author
Eddie O'Hagan
Date
8/13/2026
float value = airSensor.GetInternalTemperatureInC();
Returns
The internal temperature, in Celsius.

◆ GetInternalTemperatureInCAverage()

float RumPi::PTQS1005::GetInternalTemperatureInCAverage ( ) const

Gets the rolling average of the sensor's internal temperature.

Author
Eddie O'Hagan
Date
8/13/2026
float value = airSensor.GetInternalTemperatureInCAverage();
Returns
The rolling average internal temperature, in Celsius, or NaN if no reading has been taken yet.

◆ GetPmTwoPointFiveAtmospheric()

float RumPi::PTQS1005::GetPmTwoPointFiveAtmospheric ( ) const

Gets the current PM2.5 reading.

Author
Eddie O'Hagan
Date
8/13/2026
float value = airSensor.GetPmTwoPointFiveAtmospheric();
Returns
The PM2.5 reading, in ug/m3.

◆ GetPmTwoPointFiveAverageAtmospheric()

float RumPi::PTQS1005::GetPmTwoPointFiveAverageAtmospheric ( ) const

Gets the rolling average of the PM2.5 reading.

Author
Eddie O'Hagan
Date
8/13/2026
float value = airSensor.GetPmTwoPointFiveAverageAtmospheric();
Returns
The rolling average PM2.5 reading, in ug/m3, or NaN if no reading has been taken yet.

◆ GetTVOC()

float RumPi::PTQS1005::GetTVOC ( ) const

Gets the current TVOC reading.

Author
Eddie O'Hagan
Date
8/13/2026
float value = airSensor.GetTVOC();
Returns
The TVOC reading, in ppm.

◆ GetTVOCAverage()

float RumPi::PTQS1005::GetTVOCAverage ( ) const

Gets the rolling average of the TVOC reading.

Author
Eddie O'Hagan
Date
8/13/2026
float value = airSensor.GetTVOCAverage();
Returns
The rolling average TVOC reading, in ppm, or NaN if no reading has been taken yet.
Author
Eddie O'Hagan
Date
8/13/2026
float value = airSensor.GetTVOCAverage();
Returns
The rolling average TVOC reading in ppm, or NaN if no reading has been taken yet.

◆ IsDataValid()

bool RumPi::PTQS1005::IsDataValid ( const float *  dataToValidate,
const size_t  bufferSize 
) const
virtual

Validates a serial frame by summing all bytes except the trailing two and comparing against the big-endian checksum those two bytes carry.

Author
Eddie O'Hagan
Date
8/13/2026
bool valid = airSensor.IsDataValid(readData, bufferSize);
Parameters
[in]dataToValidateThe frame's bytes (as floats), including the trailing checksum.
[in]bufferSizeThe number of bytes in the frame.
Returns
True if the computed checksum matches the received checksum.

◆ ProcessRawValues()

void RumPi::PTQS1005::ProcessRawValues ( )
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.

Author
Eddie O'Hagan
Date
8/13/2026
airSensor.ProcessRawValues();

Implements RumPi::BaseComponent.

◆ ReadRawValue()

float RumPi::PTQS1005::ReadRawValue ( )
virtual

Reads a single raw byte (as a float) from the serial device.

Author
Eddie O'Hagan
Date
8/13/2026
float value = airSensor.ReadRawValue();
Returns
The next byte from the serial device, as a float (-1 on read error).

◆ ToString()

std::string RumPi::PTQS1005::ToString ( ) const
overridevirtual

Serializes every current reading and rolling average (PM2.5, TVOC, HCHO, CO2, temperature, humidity) to a string.

Author
Eddie O'Hagan
Date
8/13/2026
std::string data = airSensor.ToString();
Returns
A multi-line string describing the sensor's readings.

Implements RumPi::BaseComponent.

◆ TurnOff()

void RumPi::PTQS1005::TurnOff ( )
overridevirtual

Closes the serial device (if open) and marks the sensor stopped.

Author
Eddie O'Hagan
Date
8/13/2026
airSensor.TurnOff();

Implements RumPi::BaseComponent.

◆ TurnOn()

void RumPi::PTQS1005::TurnOn ( )
overridevirtual

Opens the serial device at 9600 baud and marks the sensor running, reporting the result through the AlertManager.

Author
Eddie O'Hagan
Date
8/13/2026
airSensor.TurnOn();

Implements RumPi::BaseComponent.

Member Data Documentation

◆ myCalculatedHCHO

float RumPi::PTQS1005::myCalculatedHCHO
protected

The most recent HCHO reading (raw / division factor).

◆ myCalculatedHumidity

float RumPi::PTQS1005::myCalculatedHumidity
protected

The most recent humidity, as a percent.

◆ myCalculatedInternalTemperatureInC

float RumPi::PTQS1005::myCalculatedInternalTemperatureInC
protected

The most recent internal temperature, in Celsius.

◆ myCalculatedTVOC

float RumPi::PTQS1005::myCalculatedTVOC
protected

The most recent TVOC reading (raw / division factor).

◆ myCO2Average

RollingAverage RumPi::PTQS1005::myCO2Average
protected

Rolling average of the CO2 reading.

◆ myDevicePath

std::string RumPi::PTQS1005::myDevicePath
protected

The serial device path.

◆ myDustData

std::map<std::string, float> RumPi::PTQS1005::myDustData
protected

Most recent raw readings, keyed by measurement name.

◆ myHCHOAverage

RollingAverage RumPi::PTQS1005::myHCHOAverage
protected

Rolling average of the HCHO reading.

◆ myHumidityAverage

RollingAverage RumPi::PTQS1005::myHumidityAverage
protected

Rolling average of the humidity.

◆ myInternalTemperatureInCAverage

RollingAverage RumPi::PTQS1005::myInternalTemperatureInCAverage
protected

Rolling average of the internal temperature.

◆ myIsRunning

bool RumPi::PTQS1005::myIsRunning
protected

True while the serial device is open and readable.

◆ myPMTwoPointFiveAverageAtmospheric

RollingAverage RumPi::PTQS1005::myPMTwoPointFiveAverageAtmospheric
protected

Rolling average of the PM2.5 reading.

◆ mySerialDeviceFileDescriptor

int RumPi::PTQS1005::mySerialDeviceFileDescriptor
protected

The open serial device file descriptor.

◆ myTVOCAverage

RollingAverage RumPi::PTQS1005::myTVOCAverage
protected

Rolling average of the TVOC reading.


The documentation for this class was generated from the following files: