#include <pas-co2-serial.hpp>
Public Member Functions | |
PASCO2Serial (pasco2::SBus *const sbus, pasco2::Timer *const timer=nullptr, pasco2::GPIO *const interrupt=nullptr, pasco2::GPIO *const protoSelect=nullptr, pasco2::GPIO *const power3V3=nullptr, pasco2::GPIO *const power12V=nullptr) | |
PAS CO2 Serial Constructor. More... | |
virtual | ~PASCO2Serial () |
PAS CO2 Serial Destructor. More... | |
Error_t | enable () |
Enables the sensor. More... | |
Error_t | disable () |
Disables the sensor. More... | |
Error_t | startMeasure (int16_t periodInSec=0, int16_t alarmTh=0, void(*cback)(void *)=nullptr) |
Triggers the internal measuring of the sensor. More... | |
Error_t | stopMeasure () |
Stops the internal measuring of the sensor. More... | |
Error_t | getCO2 (int16_t &CO2PPM) |
Gets the CO2 concentration measured. More... | |
Error_t | getDiagnosis (Diag_t &diagnosis) |
Gets diagnosis information. More... | |
Error_t | calibrate (ABOC_t aboc, int16_t abocRef, uint16_t pressRef) |
Calibrates the sensor. More... | |
Error_t | reset () |
Resets the sensor. More... | |
Error_t | getDeviceID (uint8_t &prodID, uint8_t &revID) |
Gets device product identifier. More... | |
PASCO2Serial::PASCO2Serial | ( | pasco2::SBus *const | sbus, |
pasco2::Timer *const | timer = nullptr , |
||
pasco2::GPIO *const | interrupt = nullptr , |
||
pasco2::GPIO *const | protoSelect = nullptr , |
||
pasco2::GPIO *const | power3V3 = nullptr , |
||
pasco2::GPIO *const | power12V = nullptr |
||
) |
PAS CO2 Serial Constructor.
Mandatory arguments:
Optional arguments:
Most of the GPIO will be fixed by hardware. In particular those enabling the sensor main power and the emitter power. They are part of the sensor library to provide potential absolute control by software. The hardware interface and its features, are also provided in the library. But it can be as well handled externally
[in] | *sbus | Serial bus instance |
[in] | *timer | Timer instance |
[in] | *interrupt | Interrupt GPIO instance. Default is nullptr |
[in] | *protoSelect | Protocol select GPIO instance. Default is nullptr |
[in] | *power3V3 | Power 3V3 control GPIO instance. Default is nullptr |
[in] | *power12V | Power 12V control GPIO instance. Default is nullptr |
|
virtual |
PAS CO2 Serial Destructor.
Error_t PASCO2Serial::enable | ( | ) |
Enables the sensor.
Initializes the controller peripheral interfaces and enable VDD and IR emitter power of the sensor.
OK | if success |
INTF_ERROR | if interface error |
IC_POWERON_ERROR | if power-on error |
Error_t PASCO2Serial::disable | ( | ) |
Disables the sensor.
Initializes the controller peripheral interfaces and enable VDD and IR emitter power of the sensor
OK | if success |
INTF_ERROR | if interface error |
Error_t PASCO2Serial::startMeasure | ( | int16_t | periodInSec = 0 , |
int16_t | alarmTh = 0 , |
||
void(*)(void *) | cback = nullptr |
||
) |
Triggers the internal measuring of the sensor.
The function start the measurement controlling the different sensor modes and features depending on the configured arguments.
If the function is called with no arguments, the sensor will be trigger to perform a single shot measurement. The users needs to poll with getCO2() until the CO2 value is available and has been readed from the sensor. The CO2 concentration value read will be zero as long as no value is avaiable, of -1 if any error occurred in the readout attempt. Polling example:
Periodic measurements (periodInSec) will configure the sensor to perform a measurements every desired period. Between 5 and 4095 seconds. Without further arguments, the user has to poll with getCO2() until the value is available. Any super loop or thread routine, can just consist on reading the CO2 (getCO2()). For example, measure every 5 minutes:
In order not to saturate the sensor with constant serial requests, especially in periodic mode, it is recommended to synch the readout with a timer. Or even better using the hardware GPIO hardware interrupt. If the interrupt GPIO interface has been provided, passing a callback function will enable the interrupt mode. The type of interrupt is decided depending on the value of the rest of the arguments and operations modes. Some example:
If the alarm threshold argument is non-zero, the alarm mode is activated, and an the sensor internal flag will be eanbled if the concentration of CO2 goes above the specified value. This option is better combined with the interupt mode. Thus, if the interrupt mode is available and a callback function is passed, the interrupt will occurr only when the co2 concentration goes above the threshold. This makes mostly sense for periodic measurement configuration. But it can be used as well for a single shot configuration
[in] | periodInSec | Enables periodic measurement with the specified period. The default, value is 0, meaning single shot operation. The valid period range goes between 5 and 4095 seconds |
[in] | alarmTh | Enables upper alarm threshold mode for the specified value. The default value is 0, meaning no alarm mode. For any non-zero value, the sensor will internally set the alarm flag. If an interrupt callback function is provided, then the interrupt will occurr only when the defined threshold has been tresspassed |
[in] | *cback | Pointer to the callback function to be called upon interrupt |
OK | if success |
INTF_ERROR | if interface error |
CONFIG_ERROR | if invalid configuration parameter |
Error_t PASCO2Serial::stopMeasure | ( | ) |
Stops the internal measuring of the sensor.
Sets operation mode to idle
OK | if success |
INTF_ERROR | if interface error |
Error_t PASCO2Serial::getCO2 | ( | int16_t & | co2ppm | ) |
Gets the CO2 concentration measured.
The value read is zero when no measurement is yet available. In case of error, the read value is set to -1. Before reading the co2 value, the measurement status register is read to know if a new measurement data is available.
[out] | co2ppm | CO2 concentration read (in ppm) |
OK | if success |
INTF_ERROR | if interface error |
Gets diagnosis information.
The sensor status registers includes the following flags:
[out] | diagnosis | Struct to store the diagnosis flags values |
OK | if success |
INTF_ERROR | if interface error |
Calibrates the sensor.
Configures the automatic baseline and the reference pressure compensation
[in] | aboc | Automatic baseline compenstation mode |
[in] | abocRef | Automatic baseline compensation reference |
[in] | pressRef | Pressure reference value. Min value is 600, and max 1600. |
OK | if success |
INTF_ERROR | if interface error |
CONFIG_ERROR | if pressure reference value is invalid |
Error_t PASCO2Serial::reset | ( | ) |
Resets the sensor.
The software reset performs the following operations:
OK | if success |
INTF_ERROR | if interface error |
RESET_ERROR | if the device reset error |
Error_t PASCO2Serial::getDeviceID | ( | uint8_t & | prodID, |
uint8_t & | revID | ||
) |
Gets device product identifier.
[out] | prodID | Product identifier |
[out] | revID | Version identifier |
OK | if success |
INTF_ERROR | if interface error |