upm
1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
|
API for the SI1145 UV Light Sensor. More...
This module was tested with the Adafruit* UV Light Sensor
This device is capable of measuring IR and visible ambient light as well. It also supports the ability to use externally attached LEDs to perform proximity detection on 3 separate channels.
Currently, this class only supports the retrieving of the calculated UV index measured by the device, but enough infrastructure is provided to make it easy to enhance this driver in the future to support additional capabilities, including interrupt support.
Public Types | |
enum | SI114X_REG_T { REG_PART_ID = 0x00, REG_REV_ID = 0x01, REG_SEQ_ID = 0x02, REG_INT_CFG = 0x03, REG_IRQ_ENABLE = 0x04, REG_IRQ_MODE1 = 0x05, REG_IRQ_MODE2 = 0x06, REG_HW_KEY = 0x07, REG_MEAS_RATE0 = 0x08, REG_MEAS_RATE1 = 0x09, REG_PS_LED21 = 0x0f, REG_PS_LED3 = 0x10, REG_UCOEF0 = 0x13, REG_UCOEF1 = 0x14, REG_UCOEF2 = 0x15, REG_UCOEF3 = 0x16, REG_PARAM_WR = 0x17, REG_COMMAND = 0x18, REG_RESPONSE = 0x20, REG_IRQ_STATUS = 0x21, REG_ALS_VIS_DATA0 = 0x22, REG_ALS_VIS_DATA1 = 0x23, REG_ALS_IR_DATA0 = 0x24, REG_ALS_IR_DATA1 = 0x25, REG_PS1_DATA0 = 0x26, REG_PS1_DATA1 = 0x27, REG_PS2_DATA0 = 0x28, REG_PS2_DATA1 = 0x29, REG_PS3_DATA0 = 0x2a, REG_PS3_DATA1 = 0x2b, REG_AUX_UVINDEX0 = 0x2c, REG_AUX_UVINDEX1 = 0x2d, REG_PARAM_READ = 0x2e, REG_CHIP_STAT = 0x30, REG_ANA_IN_KEY0 = 0x3b, REG_ANA_IN_KEY1 = 0x3c, REG_ANA_IN_KEY2 = 0x3d, REG_ANA_IN_KEY3 = 0x3e } |
enum | SI114X_PARAM_T { PARAM_I2C_ADDDR = 0x00, PARAM_CHLIST = 0x01, PARAM_PSLED12_SEL = 0x02, PARAM_PSLED3_SEL = 0x03, PARAM_PS_ENCODING = 0x05, PARAM_ALS_ENCODING = 0x06, PARAM_PS1_ADCMUX = 0x07, PARAM_PS2_ADCMUX = 0x08, PARAM_PS3_ADCMUX = 0x09, PARAM_PS_ADC_COUNT = 0x0a, PARAM_PS_ADC_GAIN = 0x0b, PARAM_PS_ADC_MISC = 0x0c, PARAM_ALS_IR_ADCMUX = 0x0e, PARAM_AUX_ADCMUX = 0x0f, PARAM_ALS_VIS_ADC_COUNT = 0x10, PARAM_ALS_VIS_ADC_GAIN = 0x11, PARAM_ALS_VIS_ADC_MISC = 0x12, PARAM_LED_REC = 0x1c, PARAM_ALS_IR_ADC_COUNT = 0x1d, PARAM_ALS_IR_ADX_GAIN = 0x1e, PARAM_ALS_IR_ADC_MISC = 0x1f } |
enum | SI114X_CMD_T { CMD_NOOP = 0x00, CMD_RESET = 0x01, CMD_BUSADDR = 0x02, CMD_PS_FORCE = 0x05, CMD_GET_CAL = 0x12, CMD_ALS_FORCE = 0x06, CMD_PSALS_FORCE = 0x07, CMD_PS_PAUSE = 0x09, CMD_ALS_PAUSE = 0x0a, CMD_PSALS_PAUSE = 0x0b, CMD_PS_AUTO = 0x0d, CMD_ALS_AUTO = 0x0e, CMD_PSALS_AUTO = 0x0f, CMD_PARAM_QUERY = 0x80, CMD_PARAM_SET = 0xa0 } |
enum | SI114X_CHLIST_BITS_T { CHLIST_EN_PS1 = 0x01, CHLIST_EN_PS2 = 0x02, CHLIST_EN_PS3 = 0x04, CHLIST_EN_ALS_VIS = 0x10, CHLIST_EN_ALS_IR = 0x20, CHLIST_EN_AUX = 0x40, CHLIST_EN_UV = 0x80 } |
enum | SI114X_ERR_T { ERR_NONE = 0x00, ERR_INVALID_SET = 0x80, ERR_PS1_ADC_OVER = 0x88, ERR_PS2_ADC_OVER = 0x89, ERR_PS3_ADC_OVER = 0x8a, ERR_ALS_VIS_ADC_OVER = 0x8c, ERR_ALS_IR_ADC_OVER = 0x8d, ERR_AUX_ADC_OVER = 0x8e } |
enum | SI114X_IRQEN_BITS_T { IRQEN_ALS_IE = 0x01, IRQEN_PS1_IE = 0x04, IRQEN_PS2_IE = 0x08, IRQEN_PS3_IE = 0x10 } |
Public Member Functions | |
SI114X (int bus, uint8_t address=SI114X_DEFAULT_I2C_ADDR) | |
~SI114X () | |
bool | writeByte (uint8_t reg, uint8_t byte) |
uint8_t | readByte (uint8_t reg) |
uint16_t | readWord (uint8_t reg) |
void | reset () |
void | setUVCalibration (uint8_t uvcoeff0, uint8_t uvcoeff1, uint8_t uvcoeff2, uint8_t uvcoeff3) |
void | writeParam (SI114X_PARAM_T param, uint8_t value) |
uint8_t | readParam (SI114X_PARAM_T param) |
void | initialize () |
void | update () |
float | getUVIndex () |
enum SI114X_REG_T |
SI114X registers
enum SI114X_PARAM_T |
Parameter memory (PARAM)
enum SI114X_CMD_T |
Commands (written to the REG_COMMAND register)
enum SI114X_CHLIST_BITS_T |
Channel list enable bits
enum SI114X_ERR_T |
Error codes from the RESPONSE register
enum SI114X_IRQEN_BITS_T |
Interrupt enable bits
SI114X | ( | int | bus, |
uint8_t | address = SI114X_DEFAULT_I2C_ADDR |
||
) |
SI114X constructor
bus | I2C bus to use |
address | Address for this device |
bool writeByte | ( | uint8_t | reg, |
uint8_t | byte | ||
) |
Writes a byte value into a register
reg | Register location to write into |
byte | Byte to write |
uint8_t readByte | ( | uint8_t | reg | ) |
Reads a byte value from a register
reg | Register location to read from |
uint16_t readWord | ( | uint8_t | reg | ) |
Reads a word value from a register
reg | Register location to read from |
void reset | ( | ) |
Disables interrupts and auto-measuring, issues a device reset, and then sets the hardware key.
void setUVCalibration | ( | uint8_t | uvcoeff0, |
uint8_t | uvcoeff1, | ||
uint8_t | uvcoeff2, | ||
uint8_t | uvcoeff3 | ||
) |
Sets UV calibration values. The constructor sets default values for you, so you only need this function if you need different values for your device and situation. If you set new values here, be sure to do so before calling initialize().
uvcoeff0 | Coefficient for REG_UCOEF0 |
uvcoeff1 | Coefficient for REG_UCOEF1 |
uvcoeff2 | Coefficient for REG_UCOEF2 |
uvcoeff3 | Coefficient for REG_UCOEF3 |
void writeParam | ( | SI114X_PARAM_T | param, |
uint8_t | value | ||
) |
Writes a value to the parameter memory.
param | SI114X_PARAM_T register to write |
value | Value to write |
uint8_t readParam | ( | SI114X_PARAM_T | param | ) |
Reads a value from the parameter memory
param | SI114X_PARAM_T register to read |
void initialize | ( | ) |
Resets and initializes the device and starts auto-sampling
void update | ( | void | ) |
Updates stored values. You should call this before calling getUVIndex()
|
inline |
Reads the currently measured UV index value