#include <pas-co2.hpp>
Public Member Functions | |
PASCO2 (pasco2::SBus *const sbus, pasco2::PWM *const pwm, 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, pasco2::GPIO *const pwmSelect=nullptr) | |
PAS CO2 Constructor. More... | |
virtual | ~PASCO2 () |
PAS CO2 Destructor. More... | |
Error_t | init () |
Initializes the sensor hardware interfaces. More... | |
Error_t | deinit () |
Deinitializes the sensor hardware interfaces. More... | |
Error_t | enableLogic () |
Enables the sensor logic. More... | |
Error_t | disableLogic () |
Disables the sensor logic. More... | |
Error_t | enableIREmitter () |
Enables the IR emitter. More... | |
Error_t | disableIREmitter () |
Disables the IR emitter. More... | |
Error_t | softReset () |
Resets the sensor via the serial interface. More... | |
Error_t | hardReset () |
Resets the sensor via the logic 3V3 power GPIO interface. More... | |
Error_t | setOperationMode (OpMode_t mode) |
Sets the sensor operation mode. More... | |
Error_t | enablePWM () |
Enables the PWM output. More... | |
Error_t | disablePWM () |
Disables the PWM output. More... | |
Error_t | setPWMMode (PWMMode_t mode) |
Sets the PWM pulse mode. More... | |
Error_t | setMeasPeriod (int16_t periodInSec) |
Sets the measurement period. More... | |
Error_t | getCO2 (int16_t &CO2PMM) |
Gets the CO2 concentration readout value from the sensor. More... | |
Error_t | getDiagnosis (Diag_t &diagnosis) |
Gets diagnosis information. More... | |
Error_t | getMeasStatus (MeasStatus_t &measSt) |
Gets measurement status information. More... | |
Error_t | enableInterrupt (void(*cback)(void *), Int_t intType, IntIOConf_t ioConf) |
Enables the hardware interrupt. More... | |
Error_t | disableInterrupt () |
Disables the hardware interrupt. More... | |
Error_t | enableABOCompensation (ABOC_t aboc, int16_t abocRef) |
Enables the automatic baseline compensation. More... | |
Error_t | disableABOCompensation () |
Disables the automatic baseline compensation. More... | |
Error_t | setPressureCompensation (uint16_t pressRef) |
Sets the pressure compensation reference. More... | |
Error_t | enableAlarm (int16_t thres, Alarm_t alarmType) |
Enables alarm mode. More... | |
Error_t | disableAlarm () |
Disables alarm mode. More... | |
Error_t | getDeviceID (uint8_t &prodID, uint8_t &revID) |
Gets device product identifier. More... | |
Status_t | getStatus () |
Protected Member Functions | |
virtual Error_t | setStatus (const Status_t newStatus, bool enoughIfImplicit=false) |
Sets the device status. More... | |
virtual Error_t | preResetSaveConfig (void) |
Saves the sensor register configuration and prepare the device for reset. More... | |
virtual Error_t | postResetRestoreConfig (void) |
Restores the device register configuration after reset. More... | |
Protected Attributes | |
pasco2::SBus *const | sbus |
pasco2::PWM *const | pwm |
pasco2::Timer *const | timer |
pasco2::GPIO *const | interrupt |
pasco2::GPIO *const | protoSelect |
pasco2::GPIO *const | power3V3 |
pasco2::GPIO *const | power12V |
pasco2::GPIO *const | pwmSelect |
pasco2::Reg | reg |
Status_t | status |
Static Protected Attributes | |
static const int16_t | periodMeasMin = 0x0005 |
static const int16_t | periodMeasMax = 0x0FFF |
static const uint16_t | pressRefMin = 0x258 |
static const uint16_t | pressRefMax = 0x640 |
PASCO2::PASCO2 | ( | pasco2::SBus *const | sbus, |
pasco2::PWM *const | pwm, | ||
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 , |
||
pasco2::GPIO *const | pwmSelect = nullptr |
||
) |
PAS CO2 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] | *pwm | Pwm 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 |
[in] | *pwmSelect | Pwm selection GPIO instalce. Default is nullptr |
|
virtual |
Error_t PASCO2::init | ( | void | ) |
Initializes the sensor hardware interfaces.
OK | if success |
INTF_ERROR | if interface error |
Error_t PASCO2::deinit | ( | void | ) |
Deinitializes the sensor hardware interfaces.
OK | if success |
INTF_ERROR | if interface error |
Error_t PASCO2::enableLogic | ( | ) |
Enables the sensor logic.
This function performs the following operations:
OK | if success |
INTF_ERROR | if interface error |
IC_POWERON_ERROR | if power-on error |
Error_t PASCO2::disableLogic | ( | ) |
Disables the sensor logic.
Disables the sensor 3V3 power if the instance has been provided for software power enablement. Otherwise, just updates the sensor status disabling POWER3V3 flag.
OK | if success |
INTF_ERROR | if interface error |
Error_t PASCO2::enableIREmitter | ( | ) |
Enables the IR emitter.
This function performs the following operations:
The sensor status is updated (xored) with the IR_ONLY_ON mask.
OK | if success |
INTF_ERROR | if interface error |
Error_t PASCO2::disableIREmitter | ( | ) |
Disables the IR emitter.
Disables the sensor 12V power if the instance has been provided for software IR emitter power enablement. Otherwise, just updates the sensor status disabling POWER12V flag.
OK | if success |
INTF_ERROR | if interface error |
Error_t PASCO2::softReset | ( | ) |
Resets the sensor via the serial interface.
The software reset performs the following operations:
OK | if success |
INTF_ERROR | if interface error |
RESET_ERROR | if the device reset error |
Error_t PASCO2::hardReset | ( | ) |
Resets the sensor via the logic 3V3 power GPIO interface.
The software reset performs the following operations:
OK | if success |
INTF_ERROR | if interface error |
RESET_ERROR | if the device reset error |
Sets the sensor operation mode.
The sensor supports 3 operating modes:
[in] | mode | Operation mode |
OK | if success |
INTF_ERROR | if interface error |
Error_t PASCO2::enablePWM | ( | ) |
Enables the PWM output.
PWM is enabled by default via the pwmSelect GPIO instance if provided. Otherwise, the serial interface is used.
OK | if success |
INTF_ERROR | if interface error |
Error_t PASCO2::disablePWM | ( | ) |
Disables the PWM output.
PWM is disabled by default via the pwmSelect GPIO instance if provided. Otherwise, the serial interface is used.
OK | if success |
INTF_ERROR | if interface error |
Sets the PWM pulse mode.
The sensor supports 2 PWM pulse modes:
By default, pulse train mode is enabled.
[in] | mode | PWM pulse mode |
OK | if success |
INTF_ERROR | if interface error |
Error_t PASCO2::setMeasPeriod | ( | int16_t | periodInSec | ) |
Sets the measurement period.
In continuous mode, the sensor will perform measurement with this period.
[in] | periodInSec | Measurement period in seconds. Min period is 5 second, and max 4095 seconds. |
OK | if success |
INTF_ERROR | if interface error |
CONFIG_ERROR | if period value is invalid |
Error_t PASCO2::getCO2 | ( | int16_t & | co2ppm | ) |
Gets the CO2 concentration readout value from the sensor.
If both the serial and the pwm interfaces are provided, the serial interface will be used.
[out] | co2ppm | Variable to store the read co2 concentration value (in ppm) |
OK | if success |
INTF_ERROR | if interface error |
10000/100
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 |
Error_t PASCO2::getMeasStatus | ( | MeasStatus_t & | measSt | ) |
Gets measurement status information.
The measurement status register provides the following information:
[out] | measSt | Struct to store the measurement status flags values |
OK | if success |
INTF_ERROR | if interface error |
Error_t PASCO2::enableInterrupt | ( | void(*)(void *) | cback, |
Int_t | intType, | ||
IntIOConf_t | ioConf | ||
) |
Enables the hardware interrupt.
[in] | *cback | Pointer to the interrupt callback function |
[in] | intType | Interrupt event |
[in] | ioConf | Interrupt output voltage logic configuration |
OK | if success |
INTF_ERROR | if interface error |
Error_t PASCO2::disableInterrupt | ( | ) |
Disables the hardware interrupt.
If the serial interface is available the interupt output will be as well disabled on the sensor. Otherwise, just the controller hardware GPIO interrupt is disabled.
OK | if success |
INTF_ERROR | if interface error |
Enables the automatic baseline compensation.
[in] | aboc | Automatic baseline compenstation mode |
[in] | abocRef | Automatic baseline compensation reference |
OK | if success |
INTF_ERROR | if interface error |
Error_t PASCO2::disableABOCompensation | ( | ) |
Disables the automatic baseline compensation.
OK | if success |
INTF_ERROR | if interface error |
Error_t PASCO2::setPressureCompensation | ( | uint16_t | pressRef | ) |
Sets the pressure 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 |
Enables alarm mode.
[in] | thres | Alarm CO2 concentration threshold (in ppm) |
[in] | alarmType | Upper or lower threshold configuration |
OK | if success |
INTF_ERROR | if interface error |
Error_t PASCO2::disableAlarm | ( | ) |
Disables alarm mode.
OK | if success |
INTF_ERROR | if interface error |
Error_t PASCO2::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 |
|
inline |
|
protectedvirtual |
Sets the device status.
From the host controller point of view, the device can be in the following statuses:
The device configuration can be only performed if at least LOGIC_ONLY_ON is fulfilled. For CO2 measurements, the IR emitter power has to be enabled. Thus, getCO2() is only available if the sensor is ON.
Some statuses ential that the sensor has been previously in a certain status. This is what implicit status means. For example, LOGIC_ONLY_ON means as well that the device is INITED.
This functions takes care of the state machine transition between the statuses.
[in] | newStatus | Desired new status to be set |
[in] | enoughIfImplicit | Flag indicating if the the exact status is required, or just implicitly. |
OK | if success |
INTF_ERROR | if interface error |
|
protectedvirtual |
Saves the sensor register configuration and prepare the device for reset.
The scratch pad register is used for later if the reser was properly performed. This register must be 0x00 after reset. Serial interface required, but not verified as it is a private function.
OK | if success |
INTF_ERROR | if interface error |
|
protectedvirtual |
Restores the device register configuration after reset.
Once the sensor is ready. The scratch pad register has to be 0x00.s Serial interface required, but not verified as it is a private function.
OK | if success |
IC_POWERON_ERROR | if device power on reset error |
INTF_ERROR | if interface error |
|
protected |
SBus interface
|
protected |
PWM interface
|
protected |
Timer
|
protected |
Interrupt
|
protected |
Serial protocol select
|
protected |
3V3 power
|
protected |
12V power
|
protected |
PWM select
|
protected |
Register map
|
protected |
Sensor host mcu state machine status
|
staticprotected |
Minimum measurement period in Seconds
|
staticprotected |
Maximum measurement period in Seconds
|
staticprotected |
Minimum pressure reference value
|
staticprotected |
Maximum pressure reference value