![]() |
SparkFun Spectral UV Sensor - AS7331
v2.1.2-21-g3e22fb4
Library for the SparkFun Spectral UV Sensor - AS7331
|
#include <sfDevAS7331.h>
Public Member Functions | |
sfDevAS7331 () | |
bool | begin (sfTkIBus *theBus=nullptr) |
This method is called to initialize the AS7331 device through the specified bus. More... | |
uint8_t | getDeviceID (void) |
Requests the device ID from the sensor. More... | |
void | setCommunicationBus (sfTkIBus *theBus) |
Sets the communication bus to the specified bus. More... | |
bool | runDefaultSetup (const bool &runSoftReset=false) |
Helper class that sets up the sensor and state in the POR configuration. More... | |
bool | prepareMeasurement (const as7331_meas_mode_t &measMode=MEAS_MODE_CONT, const bool &startMeasure=false) |
Puts the sensor in the specified measurement mode. More... | |
bool | reset (void) |
Performs a soft reset of the sensor. More... | |
sfTkError_t | readTemp (void) |
Reads the sensor's temperature, converts it to a usable form, and saves it to the internal temperature variable. More... | |
sfTkError_t | readUVA (void) |
Reads the sensor's UVA register, converts it to a usable form, and saves it to the internal UVA variable. More... | |
sfTkError_t | readUVB (void) |
Reads the sensor's UVB register, converts it to a usable form, and saves it to the internal UVB variable. More... | |
sfTkError_t | readUVC (void) |
Reads the sensor's UVC register, converts it to a usable form, and saves it to the internal UVC variable. More... | |
sfTkError_t | readAllUV (void) |
Read's all three UV registers, converts them to a usable form, then saves them to their respective internal variable. More... | |
sfTkError_t | readAll (void) |
Read the sensor's temperature, UV, and external time conversion clock counts, converts them, and then saves them to their respective internal variable. More... | |
sfTkError_t | readOutConv (void) |
Read the conversion clock counts register and saves it to the internal output conversion time variable. More... | |
float | getUVA (void) |
Returns the last valid UVA reading. More... | |
float | getUVB (void) |
Returns the last valid UVB reading. More... | |
float | getUVC (void) |
Returns the last valid UVC reading. More... | |
float | getTemp (void) |
Returns the last valid Temperature reading. More... | |
uint32_t | getOutConv (void) |
Returns the last valid output conversion. More... | |
as7331_gain_t | getGainRaw (void) |
Getter for the currently configured gain. More... | |
uint16_t | getGainValue (void) |
Getter for the currently configured gain. More... | |
sfTkError_t | setGain (const as7331_gain_t &gain) |
Sets the UV sensor's gain. More... | |
as7331_conv_clk_freq_t | getCClkRaw (void) |
Getter for the currently configured conversion clock. More... | |
uint16_t | getCClkKHz (void) |
Getter for the currently configured conversion clock. More... | |
sfTkError_t | setCClk (const as7331_conv_clk_freq_t &cclk) |
Set the sensor's internal clock speed. More... | |
as7331_conv_time_t | getConversionTimeRaw (void) |
Getter for the currently configured conversion time. More... | |
uint16_t | getConversionTimeMillis (void) |
Getter for the currently configured conversion time. More... | |
sfTkError_t | setConversionTime (const as7331_conv_time_t &convTime) |
Sets the conversion time that the sensor will run to. More... | |
bool | getReadyPinMode (void) |
Getter for the currently configured pin mode. More... | |
sfTkError_t | setReadyPinMode (const bool &pinMode) |
Sets the ready pin type to push-pull or open-drain. More... | |
bool | getDigitalDividerEnabled (void) |
Getter for the currently configured divider status. More... | |
sfTkError_t | setDigitalDividerEnabled (const bool &isEnabled) |
Enables or disables the internal UV result divider. More... | |
as7331_divider_val_t | getDigitalDividerRange (void) |
Getter for the currently configured divider range. More... | |
sfTkError_t | setDigitalDividerRange (const as7331_divider_val_t ÷r, const bool &enableDiv=true) |
Sets the value of the internal UV result divider. More... | |
bool | getSyndTempConversionEnabled (void) |
Getter for the SYND temperature conversion status. More... | |
sfTkError_t | setSyndTempConversionEnabled (const bool &isEnabled) |
Enables or disables temperature conversion when in SYND mode. More... | |
bool | getIndexMode (void) |
Getter for the currently configured I2C compatibility mode. More... | |
sfTkError_t | setIndexMode (const bool &indexMode) |
Set the index mode for compatibility with I2C controllers that don't support repeated start. More... | |
uint8_t | getBreakTime (void) |
Getter for the currently configured minimum break time in CONT, CMD, SYNS modes. More... | |
sfTkError_t | setBreakTime (const uint8_t &breakTime) |
Set the minimum time between measurements in CONT, SYNS, SYND modes. More... | |
uint8_t | getNumEdges (void) |
Getter for the currently configured minimum number of edges to end conversion when in SYND mode. More... | |
sfTkError_t | setNumEdges (const uint8_t &numEdges) |
Set the minimum number of falling edges required at the SYN input until the conversion is terminated. Only operational in SYND mode. More... | |
bool | getPowerDownState (void) |
Getter for the current power state. More... | |
sfTkError_t | setPowerDownState (const bool &pd) |
Sets the power state of the sensor. More... | |
as7331_dev_op_state_t | getOperationMode (void) |
Getter for the current operational state. More... | |
sfTkError_t | setOperationMode (const as7331_dev_op_state_t &opMode) |
Set the sensor's operating mode. More... | |
as7331_meas_mode_t | getMeasurementMode (void) |
Getter for the current measurement state. More... | |
sfTkError_t | setMeasurementMode (const as7331_meas_mode_t &measMode) |
Sets the sensor's measurement mode. More... | |
bool | getStandbyState (void) |
Getter for the current standby state. More... | |
sfTkError_t | setStandbyState (const bool &standby) |
Sets the sensor's standby mode. More... | |
bool | getStartState (void) |
Getter for the current start state. More... | |
sfTkError_t | setStartState (const bool &startState) |
Sets the sensor's start state. This begins measurement. More... | |
sfTkError_t | getStatus (sfe_as7331_reg_meas_osr_status_t &statusReg) |
Gets the sensor's status when in measurement operation mode. More... | |
sfTkError_t | getOSR (sfe_as7331_reg_cfg_osr_t &osrReg) |
Gets the operational state register when in configuration operation mode. More... | |
sfTkError_t | setOSR (const sfe_as7331_reg_cfg_osr_t &osrReg) |
Sets the operational state register when in configuration operation mode. More... | |
sfTkError_t | getCReg1 (sfe_as7331_reg_cfg_creg1_t &creg1) |
Gets the configuration register #1 when in configuration operation mode. More... | |
sfTkError_t | setCReg1 (const sfe_as7331_reg_cfg_creg1_t &creg1) |
Sets the configuration register #1 when in configuration operation mode. More... | |
sfTkError_t | getCReg2 (sfe_as7331_reg_cfg_creg2_t &creg2) |
Gets the configuration register #2 when in configuration operation mode. More... | |
sfTkError_t | setCReg2 (const sfe_as7331_reg_cfg_creg2_t &creg2) |
Sets the configuration register #2 when in configuration operation mode. More... | |
sfTkError_t | getCReg3 (sfe_as7331_reg_cfg_creg3_t &creg3) |
Gets the configuration register #3 when in configuration operation mode. More... | |
sfTkError_t | setCReg3 (const sfe_as7331_reg_cfg_creg3_t &creg3) |
Sets the configuration register #3 when in configuration operation mode. More... | |
sfTkError_t | getBreak (uint8_t &breakReg) |
Gets the break register when in configuration operation mode. More... | |
sfTkError_t | setBreak (const uint8_t &breakReg) |
Sets the break register when in configuration operation mode. More... | |
sfTkError_t | getEdges (uint8_t &edgesReg) |
Gets the edges register when in configuration operation mode. More... | |
sfTkError_t | setEdges (const uint8_t &edgesReg) |
Sets the edges register when in configuration operation mode. More... | |
sfTkError_t | getOptIndex (sfe_as7331_reg_cfg_optreg_t &optReg) |
Gets the option register when in configuration operation mode. More... | |
sfTkError_t | setOptIndex (const sfe_as7331_reg_cfg_optreg_t &optReg) |
Sets the option register when in configuration operation mode. More... | |
|
inline |
bool sfDevAS7331::begin | ( | sfTkIBus * | theBus = nullptr | ) |
This method is called to initialize the AS7331 device through the specified bus.
theBus | Pointer to the bus object. |
sfTkError_t sfDevAS7331::getBreak | ( | uint8_t & | breakReg | ) |
Gets the break register when in configuration operation mode.
breakReg | Pointer to a register struct to store the sensor's current break register. |
uint8_t sfDevAS7331::getBreakTime | ( | void | ) |
Getter for the currently configured minimum break time in CONT, CMD, SYNS modes.
uint16_t sfDevAS7331::getCClkKHz | ( | void | ) |
Getter for the currently configured conversion clock.
as7331_conv_clk_freq_t sfDevAS7331::getCClkRaw | ( | void | ) |
Getter for the currently configured conversion clock.
uint16_t sfDevAS7331::getConversionTimeMillis | ( | void | ) |
Getter for the currently configured conversion time.
as7331_conv_time_t sfDevAS7331::getConversionTimeRaw | ( | void | ) |
Getter for the currently configured conversion time.
sfTkError_t sfDevAS7331::getCReg1 | ( | sfe_as7331_reg_cfg_creg1_t & | creg1 | ) |
Gets the configuration register #1 when in configuration operation mode.
creg1 | Pointer to a register struct to store the sensor's current creg1 register. |
sfTkError_t sfDevAS7331::getCReg2 | ( | sfe_as7331_reg_cfg_creg2_t & | creg2 | ) |
Gets the configuration register #2 when in configuration operation mode.
creg2 | Pointer to a register struct to store the sensor's current creg2 register. |
sfTkError_t sfDevAS7331::getCReg3 | ( | sfe_as7331_reg_cfg_creg3_t & | creg3 | ) |
Gets the configuration register #3 when in configuration operation mode.
creg3 | Pointer to a register struct to store the sensor's current creg3 register. |
uint8_t sfDevAS7331::getDeviceID | ( | void | ) |
Requests the device ID from the sensor.
bool sfDevAS7331::getDigitalDividerEnabled | ( | void | ) |
Getter for the currently configured divider status.
as7331_divider_val_t sfDevAS7331::getDigitalDividerRange | ( | void | ) |
Getter for the currently configured divider range.
sfTkError_t sfDevAS7331::getEdges | ( | uint8_t & | edgesReg | ) |
Gets the edges register when in configuration operation mode.
edgesReg | Pointer to a register struct to store the sensor's current edges register. |
as7331_gain_t sfDevAS7331::getGainRaw | ( | void | ) |
Getter for the currently configured gain.
uint16_t sfDevAS7331::getGainValue | ( | void | ) |
Getter for the currently configured gain.
bool sfDevAS7331::getIndexMode | ( | void | ) |
Getter for the currently configured I2C compatibility mode.
as7331_meas_mode_t sfDevAS7331::getMeasurementMode | ( | void | ) |
Getter for the current measurement state.
uint8_t sfDevAS7331::getNumEdges | ( | void | ) |
Getter for the currently configured minimum number of edges to end conversion when in SYND mode.
as7331_dev_op_state_t sfDevAS7331::getOperationMode | ( | void | ) |
Getter for the current operational state.
sfTkError_t sfDevAS7331::getOptIndex | ( | sfe_as7331_reg_cfg_optreg_t & | optReg | ) |
Gets the option register when in configuration operation mode.
optReg | Pointer to a register struct to store the sensor's current option register. |
sfTkError_t sfDevAS7331::getOSR | ( | sfe_as7331_reg_cfg_osr_t & | osrReg | ) |
Gets the operational state register when in configuration operation mode.
osrReg | Pointer to a register struct to store the sensor's current OSR register. |
uint32_t sfDevAS7331::getOutConv | ( | void | ) |
Returns the last valid output conversion.
bool sfDevAS7331::getPowerDownState | ( | void | ) |
Getter for the current power state.
bool sfDevAS7331::getReadyPinMode | ( | void | ) |
Getter for the currently configured pin mode.
bool sfDevAS7331::getStandbyState | ( | void | ) |
Getter for the current standby state.
bool sfDevAS7331::getStartState | ( | void | ) |
Getter for the current start state.
sfTkError_t sfDevAS7331::getStatus | ( | sfe_as7331_reg_meas_osr_status_t & | statusReg | ) |
Gets the sensor's status when in measurement operation mode.
statusReg | Pointer to a register struct to store the sensor's current status. |
bool sfDevAS7331::getSyndTempConversionEnabled | ( | void | ) |
Getter for the SYND temperature conversion status.
float sfDevAS7331::getTemp | ( | void | ) |
Returns the last valid Temperature reading.
float sfDevAS7331::getUVA | ( | void | ) |
Returns the last valid UVA reading.
float sfDevAS7331::getUVB | ( | void | ) |
Returns the last valid UVB reading.
float sfDevAS7331::getUVC | ( | void | ) |
Returns the last valid UVC reading.
bool sfDevAS7331::prepareMeasurement | ( | const as7331_meas_mode_t & | measMode = MEAS_MODE_CONT , |
const bool & | startMeasure = false |
||
) |
Puts the sensor in the specified measurement mode.
measMode | Measurement mode to enter. |
startMeasure | Flag to start measuring immediately if set. |
sfTkError_t sfDevAS7331::readAll | ( | void | ) |
Read the sensor's temperature, UV, and external time conversion clock counts, converts them, and then saves them to their respective internal variable.
sfTkError_t sfDevAS7331::readAllUV | ( | void | ) |
Read's all three UV registers, converts them to a usable form, then saves them to their respective internal variable.
sfTkError_t sfDevAS7331::readOutConv | ( | void | ) |
Read the conversion clock counts register and saves it to the internal output conversion time variable.
sfTkError_t sfDevAS7331::readTemp | ( | void | ) |
Reads the sensor's temperature, converts it to a usable form, and saves it to the internal temperature variable.
sfTkError_t sfDevAS7331::readUVA | ( | void | ) |
Reads the sensor's UVA register, converts it to a usable form, and saves it to the internal UVA variable.
sfTkError_t sfDevAS7331::readUVB | ( | void | ) |
Reads the sensor's UVB register, converts it to a usable form, and saves it to the internal UVB variable.
sfTkError_t sfDevAS7331::readUVC | ( | void | ) |
Reads the sensor's UVC register, converts it to a usable form, and saves it to the internal UVC variable.
bool sfDevAS7331::reset | ( | void | ) |
Performs a soft reset of the sensor.
bool sfDevAS7331::runDefaultSetup | ( | const bool & | runSoftReset = false | ) |
Helper class that sets up the sensor and state in the POR configuration.
runSoftReset | Flag that runs the soft reset function to reset the device. |
sfTkError_t sfDevAS7331::setBreak | ( | const uint8_t & | breakReg | ) |
Sets the break register when in configuration operation mode.
breakReg | Pointer to a register struct that has the new register configuration. |
sfTkError_t sfDevAS7331::setBreakTime | ( | const uint8_t & | breakTime | ) |
Set the minimum time between measurements in CONT, SYNS, SYND modes.
breakTime | Time between measurements, 8us step time, max 2048us. A 0 value is a minimum of 3 cclk cycles. |
sfTkError_t sfDevAS7331::setCClk | ( | const as7331_conv_clk_freq_t & | cclk | ) |
Set the sensor's internal clock speed.
cclk | Clock speed to set on the sensor. |
void sfDevAS7331::setCommunicationBus | ( | sfTkIBus * | theBus | ) |
Sets the communication bus to the specified bus.
theBus | Bus to set as the communication device. |
sfTkError_t sfDevAS7331::setConversionTime | ( | const as7331_conv_time_t & | convTime | ) |
Sets the conversion time that the sensor will run to.
convTime | Conversion time to set the sensor to. |
sfTkError_t sfDevAS7331::setCReg1 | ( | const sfe_as7331_reg_cfg_creg1_t & | creg1 | ) |
Sets the configuration register #1 when in configuration operation mode.
creg1 | Pointer to a register struct that has the new register configuration. |
sfTkError_t sfDevAS7331::setCReg2 | ( | const sfe_as7331_reg_cfg_creg2_t & | creg2 | ) |
Sets the configuration register #2 when in configuration operation mode.
creg2 | Pointer to a register struct that has the new register configuration. |
sfTkError_t sfDevAS7331::setCReg3 | ( | const sfe_as7331_reg_cfg_creg3_t & | creg3 | ) |
Sets the configuration register #3 when in configuration operation mode.
creg3 | Pointer to a register struct that has the new register configuration. |
sfTkError_t sfDevAS7331::setDigitalDividerEnabled | ( | const bool & | isEnabled | ) |
Enables or disables the internal UV result divider.
isEnabled | Enable or disable the divder. |
sfTkError_t sfDevAS7331::setDigitalDividerRange | ( | const as7331_divider_val_t & | divider, |
const bool & | enableDiv = true |
||
) |
Sets the value of the internal UV result divider.
divider | Divider value to set. |
setEnableDiv | Option to turn on the divider if desired. |
sfTkError_t sfDevAS7331::setEdges | ( | const uint8_t & | edgesReg | ) |
Sets the edges register when in configuration operation mode.
edgesReg | Pointer to a register struct that has the new register configuration. |
sfTkError_t sfDevAS7331::setGain | ( | const as7331_gain_t & | gain | ) |
Sets the UV sensor's gain.
gain | The gain to set the sensor to. |
sfTkError_t sfDevAS7331::setIndexMode | ( | const bool & | indexMode | ) |
Set the index mode for compatibility with I2C controllers that don't support repeated start.
indexMode | Simple or standard I2C addressing mode. |
sfTkError_t sfDevAS7331::setMeasurementMode | ( | const as7331_meas_mode_t & | measMode | ) |
Sets the sensor's measurement mode.
measMode | Measurement mode to set. |
sfTkError_t sfDevAS7331::setNumEdges | ( | const uint8_t & | numEdges | ) |
Set the minimum number of falling edges required at the SYN input until the conversion is terminated. Only operational in SYND mode.
numEdges | Number of edges prior to terminating conversion in SYND mode. 0 is not allowed, 1 is the minimum. |
sfTkError_t sfDevAS7331::setOperationMode | ( | const as7331_dev_op_state_t & | opMode | ) |
Set the sensor's operating mode.
opMode | Operating mode to set. |
sfTkError_t sfDevAS7331::setOptIndex | ( | const sfe_as7331_reg_cfg_optreg_t & | optReg | ) |
Sets the option register when in configuration operation mode.
optReg | Pointer to a register struct that has the new register configuration. |
sfTkError_t sfDevAS7331::setOSR | ( | const sfe_as7331_reg_cfg_osr_t & | osrReg | ) |
Sets the operational state register when in configuration operation mode.
osrReg | Pointer to a register struct that has the new register configuration. |
sfTkError_t sfDevAS7331::setPowerDownState | ( | const bool & | pd | ) |
Sets the power state of the sensor.
pd | Power state to set. |
sfTkError_t sfDevAS7331::setReadyPinMode | ( | const bool & | pinMode | ) |
Sets the ready pin type to push-pull or open-drain.
pinMode | Mode to set the ready pin to. |
sfTkError_t sfDevAS7331::setStandbyState | ( | const bool & | standby | ) |
Sets the sensor's standby mode.
standby | State to set. |
sfTkError_t sfDevAS7331::setStartState | ( | const bool & | startState | ) |
Sets the sensor's start state. This begins measurement.
startState | Start state to set. |
sfTkError_t sfDevAS7331::setSyndTempConversionEnabled | ( | const bool & | isEnabled | ) |
Enables or disables temperature conversion when in SYND mode.
isEnabled | Enable or disable the feature. |