50#include <sfTk/sfToolkit.h>
53#include <sfTk/sfTkII2C.h>
304 : _theBus{nullptr}, _breakTime{25}, _numEdges{1}, _readyPinMode{false}, _dividerEnabled{false},
305 _tempConvEnabled{true}, _indexMode{true}, _standbyState{false}, _startState{false},
308 _temperature{0.0f}, _outputConversionTime{0U}, _conversionA{0.0f}, _conversionB{0.0f}, _conversionC{0.0f}
316 bool begin(sfTkIBus *theBus =
nullptr);
619 sfTkError_t
getBreak(uint8_t &breakReg);
625 sfTkError_t
setBreak(
const uint8_t &breakReg);
631 sfTkError_t
getEdges(uint8_t &edgesReg);
637 sfTkError_t
setEdges(
const uint8_t &edgesReg);
661 float convertRawTempToTempC(
const uint16_t &inputVal);
668 float convertRawUVVal(
const uint16_t &rawVal,
const float &convFactor);
672 void calculateConversionFactors(
void);
675 void setDefaultSettings(
void);
683 bool _dividerEnabled;
684 bool _tempConvEnabled;
688 bool _powerDownEnableState;
702 uint32_t _outputConversionTime;
708 const float _fsrA = 348160.0;
709 const float _fsrB = 387072.0;
710 const float _fsrC = 169984.0;
Definition: sfDevAS7331.h:299
sfTkError_t setCReg1(const sfe_as7331_reg_cfg_creg1_t &creg1)
Sets the configuration register #1 when in configuration operation mode.
Definition: sfDevAS7331.cpp:902
sfTkError_t setCReg3(const sfe_as7331_reg_cfg_creg3_t &creg3)
Sets the configuration register #3 when in configuration operation mode.
Definition: sfDevAS7331.cpp:938
sfTkError_t setDigitalDividerEnabled(const bool &isEnabled)
Enables or disables the internal UV result divider.
Definition: sfDevAS7331.cpp:565
uint32_t getOutConv(void)
Returns the last valid output conversion.
Definition: sfDevAS7331.cpp:427
sfDevAS7331()
Definition: sfDevAS7331.h:303
sfTkError_t readAll(void)
Read the sensor's temperature, UV, and external time conversion clock counts, converts them,...
Definition: sfDevAS7331.cpp:337
sfTkError_t getBreak(uint8_t &breakReg)
Gets the break register when in configuration operation mode.
Definition: sfDevAS7331.cpp:947
sfTkError_t setOperationMode(const as7331_dev_op_state_t &opMode)
Set the sensor's operating mode.
Definition: sfDevAS7331.cpp:758
as7331_divider_val_t getDigitalDividerRange(void)
Getter for the currently configured divider range.
Definition: sfDevAS7331.cpp:592
sfTkError_t setMeasurementMode(const as7331_meas_mode_t &measMode)
Sets the sensor's measurement mode.
Definition: sfDevAS7331.cpp:784
sfTkError_t readUVB(void)
Reads the sensor's UVB register, converts it to a usable form, and saves it to the internal UVB varia...
Definition: sfDevAS7331.cpp:280
sfTkError_t readTemp(void)
Reads the sensor's temperature, converts it to a usable form, and saves it to the internal temperatur...
Definition: sfDevAS7331.cpp:255
float getUVB(void)
Returns the last valid UVB reading.
Definition: sfDevAS7331.cpp:412
bool begin(sfTkIBus *theBus=nullptr)
This method is called to initialize the AS7331 device through the specified bus.
Definition: sfDevAS7331.cpp:35
sfTkError_t getStatus(sfe_as7331_reg_meas_osr_status_t &statusReg)
Gets the sensor's status when in measurement operation mode.
Definition: sfDevAS7331.cpp:857
sfTkError_t getOSR(sfe_as7331_reg_cfg_osr_t &osrReg)
Gets the operational state register when in configuration operation mode.
Definition: sfDevAS7331.cpp:875
sfTkError_t getEdges(uint8_t &edgesReg)
Gets the edges register when in configuration operation mode.
Definition: sfDevAS7331.cpp:965
sfTkError_t getCReg3(sfe_as7331_reg_cfg_creg3_t &creg3)
Gets the configuration register #3 when in configuration operation mode.
Definition: sfDevAS7331.cpp:929
bool reset(void)
Performs a soft reset of the sensor.
Definition: sfDevAS7331.cpp:233
sfTkError_t readUVA(void)
Reads the sensor's UVA register, converts it to a usable form, and saves it to the internal UVA varia...
Definition: sfDevAS7331.cpp:275
sfTkError_t setReadyPinMode(const bool &pinMode)
Sets the ready pin type to push-pull or open-drain.
Definition: sfDevAS7331.cpp:539
float getUVC(void)
Returns the last valid UVC reading.
Definition: sfDevAS7331.cpp:417
uint16_t getConversionTimeMillis(void)
Getter for the currently configured conversion time.
Definition: sfDevAS7331.cpp:505
sfTkError_t getOptIndex(sfe_as7331_reg_cfg_optreg_t &optReg)
Gets the option register when in configuration operation mode.
Definition: sfDevAS7331.cpp:983
float getTemp(void)
Returns the last valid Temperature reading.
Definition: sfDevAS7331.cpp:422
as7331_conv_clk_freq_t getCClkRaw(void)
Getter for the currently configured conversion clock.
Definition: sfDevAS7331.cpp:466
as7331_dev_op_state_t getOperationMode(void)
Getter for the current operational state.
Definition: sfDevAS7331.cpp:753
sfTkError_t setNumEdges(const uint8_t &numEdges)
Set the minimum number of falling edges required at the SYN input until the conversion is terminated....
Definition: sfDevAS7331.cpp:706
sfTkError_t getCReg2(sfe_as7331_reg_cfg_creg2_t &creg2)
Gets the configuration register #2 when in configuration operation mode.
Definition: sfDevAS7331.cpp:911
float getUVA(void)
Returns the last valid UVA reading.
Definition: sfDevAS7331.cpp:407
as7331_gain_t getGainRaw(void)
Getter for the currently configured gain.
Definition: sfDevAS7331.cpp:432
sfTkError_t setGain(const as7331_gain_t &gain)
Sets the UV sensor's gain.
Definition: sfDevAS7331.cpp:442
uint8_t getBreakTime(void)
Getter for the currently configured minimum break time in CONT, CMD, SYNS modes.
Definition: sfDevAS7331.cpp:675
sfTkError_t setCReg2(const sfe_as7331_reg_cfg_creg2_t &creg2)
Sets the configuration register #2 when in configuration operation mode.
Definition: sfDevAS7331.cpp:920
sfTkError_t setStandbyState(const bool &standby)
Sets the sensor's standby mode.
Definition: sfDevAS7331.cpp:810
void setCommunicationBus(sfTkIBus *theBus)
Sets the communication bus to the specified bus.
Definition: sfDevAS7331.cpp:91
bool getReadyPinMode(void)
Getter for the currently configured pin mode.
Definition: sfDevAS7331.cpp:534
sfTkError_t readAllUV(void)
Read's all three UV registers, converts them to a usable form, then saves them to their respective in...
Definition: sfDevAS7331.cpp:290
bool getIndexMode(void)
Getter for the currently configured I2C compatibility mode.
Definition: sfDevAS7331.cpp:649
sfTkError_t setDigitalDividerRange(const as7331_divider_val_t ÷r, const bool &enableDiv=true)
Sets the value of the internal UV result divider.
Definition: sfDevAS7331.cpp:597
sfTkError_t setIndexMode(const bool &indexMode)
Set the index mode for compatibility with I2C controllers that don't support repeated start.
Definition: sfDevAS7331.cpp:654
bool getPowerDownState(void)
Getter for the current power state.
Definition: sfDevAS7331.cpp:727
sfTkError_t readUVC(void)
Reads the sensor's UVC register, converts it to a usable form, and saves it to the internal UVC varia...
Definition: sfDevAS7331.cpp:285
bool getDigitalDividerEnabled(void)
Getter for the currently configured divider status.
Definition: sfDevAS7331.cpp:560
sfTkError_t setBreak(const uint8_t &breakReg)
Sets the break register when in configuration operation mode.
Definition: sfDevAS7331.cpp:956
sfTkError_t getCReg1(sfe_as7331_reg_cfg_creg1_t &creg1)
Gets the configuration register #1 when in configuration operation mode.
Definition: sfDevAS7331.cpp:893
sfTkError_t setStartState(const bool &startState)
Sets the sensor's start state. This begins measurement.
Definition: sfDevAS7331.cpp:836
bool getStartState(void)
Getter for the current start state.
Definition: sfDevAS7331.cpp:831
sfTkError_t setOptIndex(const sfe_as7331_reg_cfg_optreg_t &optReg)
Sets the option register when in configuration operation mode.
Definition: sfDevAS7331.cpp:992
sfTkError_t setCClk(const as7331_conv_clk_freq_t &cclk)
Set the sensor's internal clock speed.
Definition: sfDevAS7331.cpp:476
uint16_t getGainValue(void)
Getter for the currently configured gain.
Definition: sfDevAS7331.cpp:437
as7331_conv_time_t getConversionTimeRaw(void)
Getter for the currently configured conversion time.
Definition: sfDevAS7331.cpp:500
sfTkError_t setEdges(const uint8_t &edgesReg)
Sets the edges register when in configuration operation mode.
Definition: sfDevAS7331.cpp:974
sfTkError_t setOSR(const sfe_as7331_reg_cfg_osr_t &osrReg)
Sets the operational state register when in configuration operation mode.
Definition: sfDevAS7331.cpp:884
sfTkError_t setBreakTime(const uint8_t &breakTime)
Set the minimum time between measurements in CONT, SYNS, SYND modes.
Definition: sfDevAS7331.cpp:680
uint8_t getNumEdges(void)
Getter for the currently configured minimum number of edges to end conversion when in SYND mode.
Definition: sfDevAS7331.cpp:701
sfTkError_t readOutConv(void)
Read the conversion clock counts register and saves it to the internal output conversion time variabl...
Definition: sfDevAS7331.cpp:385
sfTkError_t setSyndTempConversionEnabled(const bool &isEnabled)
Enables or disables temperature conversion when in SYND mode.
Definition: sfDevAS7331.cpp:628
sfTkError_t setPowerDownState(const bool &pd)
Sets the power state of the sensor.
Definition: sfDevAS7331.cpp:732
bool runDefaultSetup(const bool &runSoftReset=false)
Helper class that sets up the sensor and state in the POR configuration.
Definition: sfDevAS7331.cpp:96
bool getSyndTempConversionEnabled(void)
Getter for the SYND temperature conversion status.
Definition: sfDevAS7331.cpp:623
bool getStandbyState(void)
Getter for the current standby state.
Definition: sfDevAS7331.cpp:805
uint8_t getDeviceID(void)
Requests the device ID from the sensor.
Definition: sfDevAS7331.cpp:49
uint16_t getCClkKHz(void)
Getter for the currently configured conversion clock.
Definition: sfDevAS7331.cpp:471
as7331_meas_mode_t getMeasurementMode(void)
Getter for the current measurement state.
Definition: sfDevAS7331.cpp:779
bool prepareMeasurement(const as7331_meas_mode_t &measMode=MEAS_MODE_CONT, const bool &startMeasure=false)
Puts the sensor in the specified measurement mode.
Definition: sfDevAS7331.cpp:187
sfTkError_t setConversionTime(const as7331_conv_time_t &convTime)
Sets the conversion time that the sensor will run to.
Definition: sfDevAS7331.cpp:510
const uint8_t kDefaultAS7331DeviceID
Definition: sfDevAS7331.h:64
const uint8_t kSfeAS7331RegMeasTemp
Definition: sfDevAS7331.h:289
const uint8_t kSfeAS7331RegMeasOutConvL
Definition: sfDevAS7331.h:293
as7331_conv_clk_freq_t
Definition: sfDevAS7331.h:100
@ CCLK_4_096_MHZ
Definition: sfDevAS7331.h:103
@ CCLK_1_024_MHZ
Definition: sfDevAS7331.h:101
@ CCLK_8_192_MHZ
Definition: sfDevAS7331.h:104
@ CCLK_2_048_MHZ
Definition: sfDevAS7331.h:102
const uint8_t kSfeAS7331RegMeasMres3
Definition: sfDevAS7331.h:292
const uint8_t kSfeAS7331RegCfgEdges
Definition: sfDevAS7331.h:244
as7331_divider_val_t
Definition: sfDevAS7331.h:139
@ DIV_2
Definition: sfDevAS7331.h:140
@ DIV_64
Definition: sfDevAS7331.h:145
@ DIV_16
Definition: sfDevAS7331.h:143
@ DIV_8
Definition: sfDevAS7331.h:142
@ DIV_4
Definition: sfDevAS7331.h:141
@ DIV_256
Definition: sfDevAS7331.h:147
@ DIV_32
Definition: sfDevAS7331.h:144
@ DIV_128
Definition: sfDevAS7331.h:146
const uint8_t kSfeAS7331RegMeasOutConvH
Definition: sfDevAS7331.h:294
const uint8_t kSfeAS7331RegMeasMres2
Definition: sfDevAS7331.h:291
const uint8_t kSecondaryAS7331Addr
Definition: sfDevAS7331.h:60
const uint8_t kAS7331DeviceIDTopNibble
Definition: sfDevAS7331.h:65
const uint8_t kTertiaryAS7331Addr
Definition: sfDevAS7331.h:61
const uint8_t kSfeAS7331RegCfgAgen
Definition: sfDevAS7331.h:182
const uint8_t kSfeAS7331RegMeasOsrStatus
Definition: sfDevAS7331.h:268
as7331_uv_type
Definition: sfDevAS7331.h:152
@ AS7331_UVA
Definition: sfDevAS7331.h:153
@ AS7331_UVB
Definition: sfDevAS7331.h:154
@ AS7331_UVC
Definition: sfDevAS7331.h:155
as7331_dev_op_state_t
Definition: sfDevAS7331.h:73
@ DEVICE_MODE_CFG
Definition: sfDevAS7331.h:75
@ DEVICE_MODE_MEAS
Definition: sfDevAS7331.h:76
const uint8_t kSfeAS7331RegMeasMres1
Definition: sfDevAS7331.h:290
const uint8_t kSfeAS7331RegCfgOsr
Definition: sfDevAS7331.h:166
const uint8_t kSfeAS7331RegCfgBreak
Definition: sfDevAS7331.h:242
as7331_gain_t
Definition: sfDevAS7331.h:82
@ GAIN_16
Definition: sfDevAS7331.h:90
@ GAIN_512
Definition: sfDevAS7331.h:85
@ GAIN_1024
Definition: sfDevAS7331.h:84
@ GAIN_2
Definition: sfDevAS7331.h:93
@ GAIN_4
Definition: sfDevAS7331.h:92
@ GAIN_8
Definition: sfDevAS7331.h:91
@ GAIN_128
Definition: sfDevAS7331.h:87
@ GAIN_1
Definition: sfDevAS7331.h:94
@ GAIN_64
Definition: sfDevAS7331.h:88
@ GAIN_256
Definition: sfDevAS7331.h:86
@ GAIN_32
Definition: sfDevAS7331.h:89
@ GAIN_2048
Definition: sfDevAS7331.h:83
const uint8_t kDefaultAS7331Addr
Definition: sfDevAS7331.h:59
const uint8_t kSfeAS7331RegCfgCreg3
Definition: sfDevAS7331.h:225
as7331_meas_mode_t
Definition: sfDevAS7331.h:109
@ MEAS_MODE_CMD
Definition: sfDevAS7331.h:111
@ MEAS_MODE_SYND
Definition: sfDevAS7331.h:113
@ MEAS_MODE_CONT
Definition: sfDevAS7331.h:110
@ MEAS_MODE_SYNS
Definition: sfDevAS7331.h:112
const uint8_t kSfeAS7331RegCfgCreg2
Definition: sfDevAS7331.h:209
const uint8_t kSfeAS7331RegCfgOptReg
Definition: sfDevAS7331.h:246
const uint8_t kSfeAS7331RegCfgCreg1
Definition: sfDevAS7331.h:196
const uint8_t kQuaternaryAS7331Addr
Definition: sfDevAS7331.h:62
as7331_conv_time_t
Definition: sfDevAS7331.h:119
@ TIME_512MS
Definition: sfDevAS7331.h:129
@ TIME_16MS
Definition: sfDevAS7331.h:124
@ TIME_32MS
Definition: sfDevAS7331.h:125
@ TIME_4096MS
Definition: sfDevAS7331.h:132
@ TIME_2MS
Definition: sfDevAS7331.h:121
@ TIME_8192MS
Definition: sfDevAS7331.h:133
@ TIME_16384MS
Definition: sfDevAS7331.h:134
@ TIME_2048MS
Definition: sfDevAS7331.h:131
@ TIME_128MS
Definition: sfDevAS7331.h:127
@ TIME_1MS
Definition: sfDevAS7331.h:120
@ TIME_4MS
Definition: sfDevAS7331.h:122
@ TIME_1024MS
Definition: sfDevAS7331.h:130
@ TIME_8MS
Definition: sfDevAS7331.h:123
@ TIME_256MS
Definition: sfDevAS7331.h:128
@ TIME_64MS
Definition: sfDevAS7331.h:126
Definition: sfDevAS7331.h:186
uint8_t byte
Definition: sfDevAS7331.h:193
uint8_t mut
Definition: sfDevAS7331.h:189
uint8_t devid
Definition: sfDevAS7331.h:191
Definition: sfDevAS7331.h:200
uint8_t time
Definition: sfDevAS7331.h:203
uint8_t byte
Definition: sfDevAS7331.h:206
uint8_t gain
Definition: sfDevAS7331.h:204
Definition: sfDevAS7331.h:213
uint8_t byte
Definition: sfDevAS7331.h:222
uint8_t en_tm
Definition: sfDevAS7331.h:219
uint8_t reserved
Definition: sfDevAS7331.h:218
uint8_t reserved1
Definition: sfDevAS7331.h:220
uint8_t en_div
Definition: sfDevAS7331.h:217
uint8_t div
Definition: sfDevAS7331.h:216
Definition: sfDevAS7331.h:229
uint8_t sb
Definition: sfDevAS7331.h:235
uint8_t reserved1
Definition: sfDevAS7331.h:236
uint8_t byte
Definition: sfDevAS7331.h:239
uint8_t reserved
Definition: sfDevAS7331.h:233
uint8_t cclk
Definition: sfDevAS7331.h:232
uint8_t mmode
Definition: sfDevAS7331.h:237
uint8_t rdyod
Definition: sfDevAS7331.h:234
Definition: sfDevAS7331.h:250
uint8_t init_idx
Definition: sfDevAS7331.h:253
uint8_t byte
Definition: sfDevAS7331.h:256
uint8_t reserved
Definition: sfDevAS7331.h:254
Definition: sfDevAS7331.h:170
uint8_t pd
Definition: sfDevAS7331.h:176
uint8_t dos
Definition: sfDevAS7331.h:173
uint8_t ss
Definition: sfDevAS7331.h:177
uint8_t sw_res
Definition: sfDevAS7331.h:174
uint8_t reserved
Definition: sfDevAS7331.h:175
uint8_t byte
Definition: sfDevAS7331.h:179
Definition: sfDevAS7331.h:272
uint8_t adcof
Definition: sfDevAS7331.h:281
sfe_as7331_reg_cfg_osr_t osr
Definition: sfDevAS7331.h:275
uint8_t powerstate
Definition: sfDevAS7331.h:276
uint8_t notready
Definition: sfDevAS7331.h:278
uint8_t mresof
Definition: sfDevAS7331.h:282
uint8_t standbystate
Definition: sfDevAS7331.h:277
uint8_t ndata
Definition: sfDevAS7331.h:279
uint8_t ldata
Definition: sfDevAS7331.h:280
uint16_t word
Definition: sfDevAS7331.h:285
uint8_t outconvof
Definition: sfDevAS7331.h:283