<s> import logging <EOL> import time <EOL> import I2C <EOL> SI1145_PARAM_QUERY = <NUM_LIT> <EOL> SI1145_PARAM_SET = <NUM_LIT> <EOL> SI1145_NOP = <NUM_LIT> <EOL> SI1145_RESET = <NUM_LIT> <EOL> SI1145_BUSADDR = <NUM_LIT> <EOL> SI1145_PS_FORCE = <NUM_LIT> <EOL> SI1145_ALS_FORCE = <NUM_LIT> <EOL> SI1145_PSALS_FORCE = <NUM_LIT> <EOL> SI1145_PS_PAUSE = <NUM_LIT> <EOL> SI1145_ALS_PAUSE = <NUM_LIT> <EOL> SI1145_PSALS_PAUSE = <NUM_LIT> <EOL> SI1145_PS_AUTO = <NUM_LIT> <EOL> SI1145_ALS_AUTO = <NUM_LIT> <EOL> SI1145_PSALS_AUTO = <NUM_LIT> <EOL> SI1145_GET_CAL = <NUM_LIT> <EOL> SI1145_PARAM_I2CADDR = <NUM_LIT> <EOL> SI1145_PARAM_CHLIST = <NUM_LIT> <EOL> SI1145_PARAM_CHLIST_ENUV = <NUM_LIT> <EOL> SI1145_PARAM_CHLIST_ENAUX = <NUM_LIT> <EOL> SI1145_PARAM_CHLIST_ENALSIR = <NUM_LIT> <EOL> SI1145_PARAM_CHLIST_ENALSVIS = <NUM_LIT> <EOL> SI1145_PARAM_CHLIST_ENPS1 = <NUM_LIT> <EOL> SI1145_PARAM_CHLIST_ENPS2 = <NUM_LIT> <EOL> SI1145_PARAM_CHLIST_ENPS3 = <NUM_LIT> <EOL> SI1145_PARAM_PSLED12SEL = <NUM_LIT> <EOL> SI1145_PARAM_PSLED12SEL_PS2NONE = <NUM_LIT> <EOL> SI1145_PARAM_PSLED12SEL_PS2LED1 = <NUM_LIT> <EOL> SI1145_PARAM_PSLED12SEL_PS2LED2 = <NUM_LIT> <EOL> SI1145_PARAM_PSLED12SEL_PS2LED3 = <NUM_LIT> <EOL> SI1145_PARAM_PSLED12SEL_PS1NONE = <NUM_LIT> <EOL> SI1145_PARAM_PSLED12SEL_PS1LED1 = <NUM_LIT> <EOL> SI1145_PARAM_PSLED12SEL_PS1LED2 = <NUM_LIT> <EOL> SI1145_PARAM_PSLED12SEL_PS1LED3 = <NUM_LIT> <EOL> SI1145_PARAM_PSLED3SEL = <NUM_LIT> <EOL> SI1145_PARAM_PSENCODE = <NUM_LIT> <EOL> SI1145_PARAM_ALSENCODE = <NUM_LIT> <EOL> SI1145_PARAM_PS1ADCMUX = <NUM_LIT> <EOL> SI1145_PARAM_PS2ADCMUX = <NUM_LIT> <EOL> SI1145_PARAM_PS3ADCMUX = <NUM_LIT> <EOL> SI1145_PARAM_PSADCOUNTER = <NUM_LIT> <EOL> SI1145_PARAM_PSADCGAIN = <NUM_LIT> <EOL> SI1145_PARAM_PSADCMISC = <NUM_LIT> <EOL> SI1145_PARAM_PSADCMISC_RANGE = <NUM_LIT> <EOL> SI1145_PARAM_PSADCMISC_PSMODE = <NUM_LIT> <EOL> SI1145_PARAM_ALSIRADCMUX = <NUM_LIT> <EOL> SI1145_PARAM_AUXADCMUX = <NUM_LIT> <EOL> SI1145_PARAM_ALSVISADCOUNTER = <NUM_LIT> <EOL> SI1145_PARAM_ALSVISADCGAIN = <NUM_LIT> <EOL> SI1145_PARAM_ALSVISADCMISC = <NUM_LIT> <EOL> SI1145_PARAM_ALSVISADCMISC_VISRANGE = <NUM_LIT> <EOL> SI1145_PARAM_ALSIRADCOUNTER = <NUM_LIT> <EOL> SI1145_PARAM_ALSIRADCGAIN = <NUM_LIT> <EOL> SI1145_PARAM_ALSIRADCMISC = <NUM_LIT> <EOL> SI1145_PARAM_ALSIRADCMISC_RANGE = <NUM_LIT> <EOL> SI1145_PARAM_ADCCOUNTER_511CLK = <NUM_LIT> <EOL> SI1145_PARAM_ADCMUX_SMALLIR = <NUM_LIT> <EOL> SI1145_PARAM_ADCMUX_LARGEIR = <NUM_LIT> <EOL> SI1145_REG_PARTID = <NUM_LIT> <EOL> SI1145_REG_REVID = <NUM_LIT> <EOL> SI1145_REG_SEQID = <NUM_LIT> <EOL> SI1145_REG_INTCFG = <NUM_LIT> <EOL> SI1145_REG_INTCFG_INTOE = <NUM_LIT> <EOL> SI1145_REG_INTCFG_INTMODE = <NUM_LIT> <EOL> SI1145_REG_IRQEN = <NUM_LIT> <EOL> SI1145_REG_IRQEN_ALSEVERYSAMPLE = <NUM_LIT> <EOL> SI1145_REG_IRQEN_PS1EVERYSAMPLE = <NUM_LIT> <EOL> SI1145_REG_IRQEN_PS2EVERYSAMPLE = <NUM_LIT> <EOL> SI1145_REG_IRQEN_PS3EVERYSAMPLE = <NUM_LIT> <EOL> SI1145_REG_IRQMODE1 = <NUM_LIT> <EOL> SI1145_REG_IRQMODE2 = <NUM_LIT> <EOL> SI1145_REG_HWKEY = <NUM_LIT> <EOL> SI1145_REG_MEASRATE0 = <NUM_LIT> <EOL> SI1145_REG_MEASRATE1 = <NUM_LIT> <EOL> SI1145_REG_PSRATE = <NUM_LIT> <EOL> SI1145_REG_PSLED21 = <NUM_LIT> <EOL> SI1145_REG_PSLED3 = <NUM_LIT> <EOL> SI1145_REG_UCOEFF0 = <NUM_LIT> <EOL> SI1145_REG_UCOEFF1 = <NUM_LIT> <EOL> SI1145_REG_UCOEFF2 = <NUM_LIT> <EOL> SI1145_REG_UCOEFF3 = <NUM_LIT> <EOL> SI1145_REG_PARAMWR = <NUM_LIT> <EOL> SI1145_REG_COMMAND = <NUM_LIT> <EOL> SI1145_REG_RESPONSE = <NUM_LIT> <EOL> SI1145_REG_IRQSTAT = <NUM_LIT> <EOL> SI1145_REG_IRQSTAT_ALS = <NUM_LIT> <EOL> SI1145_REG_ALSVISDATA0 = <NUM_LIT> <EOL> SI1145_REG_ALSVISDATA1 = <NUM_LIT> <EOL> SI1145_REG_ALSIRDATA0 = <NUM_LIT> <EOL> SI1145_REG_ALSIRDATA1 = <NUM_LIT> <EOL> SI1145_REG_PS1DATA0 = <NUM_LIT> <EOL> SI1145_REG_PS1DATA1 = <NUM_LIT> <EOL> SI1145_REG_PS2DATA0 = <NUM_LIT> <EOL> SI1145_REG_PS2DATA1 = <NUM_LIT> <EOL> SI1145_REG_PS3DATA0 = <NUM_LIT> <EOL> SI1145_REG_PS3DATA1 = <NUM_LIT> <EOL> SI1145_REG_UVINDEX0 = <NUM_LIT> <EOL> SI1145_REG_UVINDEX1 = <NUM_LIT> <EOL> SI1145_REG_PARAMRD = <NUM_LIT> <EOL> SI1145_REG_CHIPSTAT = <NUM_LIT> <EOL> SI1145_ADDR = <NUM_LIT> <EOL> class SI1145 ( object ) : <EOL> def __init__ ( self , address = SI1145_ADDR , busnum = I2C . get_default_bus ( ) ) : <EOL> self . _logger = logging . getLogger ( '<STR_LIT>' ) <EOL> self . _device = I2C . Device ( address , busnum ) <EOL> self . _reset ( ) <EOL> self . _load_calibration ( ) <EOL> def _reset ( self ) : <EOL> self . _device . write8 ( SI1145_REG_MEASRATE0 , <NUM_LIT:0> ) <EOL> self . _device . write8 ( SI1145_REG_MEASRATE1 , <NUM_LIT:0> ) <EOL> self . _device . write8 ( SI1145_REG_IRQEN , <NUM_LIT:0> ) <EOL> self . _device . write8 ( SI1145_REG_IRQMODE1 , <NUM_LIT:0> ) <EOL> self . _device . write8 ( SI1145_REG_IRQMODE2 , <NUM_LIT:0> ) <EOL> self . _device . write8 ( SI1145_REG_INTCFG , <NUM_LIT:0> ) <EOL> self . _device . write8 ( SI1145_REG_IRQSTAT , <NUM_LIT> ) <EOL> self . _device . write8 ( SI1145_REG_COMMAND , SI1145_RESET ) <EOL> time . sleep ( <NUM_LIT> ) <EOL> self . _device . write8 ( SI1145_REG_HWKEY , <NUM_LIT> ) <EOL> time . sleep ( <NUM_LIT> ) <EOL> def writeParam ( self , p , v ) : <EOL> self . _device . write8 ( SI1145_REG_PARAMWR , v ) <EOL> self . _device . write8 ( SI1145_REG_COMMAND , p | SI1145_PARAM_SET ) <EOL> paramVal = self . _device . readU8 ( SI1145_REG_PARAMRD ) <EOL> return paramVal <EOL> def _load_calibration ( self ) : <EOL> self . _device . write8 ( SI1145_REG_UCOEFF0 , <NUM_LIT> ) <EOL> self . _device . write8 ( SI1145_REG_UCOEFF1 , <NUM_LIT> ) <EOL> self . _device . write8 ( SI1145_REG_UCOEFF2 , <NUM_LIT> ) <EOL> self . _device . write8 ( SI1145_REG_UCOEFF3 , <NUM_LIT> ) <EOL> self . writeParam ( SI1145_PARAM_CHLIST , SI1145_PARAM_CHLIST_ENUV | SI1145_PARAM_CHLIST_ENALSIR | SI1145_PARAM_CHLIST_ENALSVIS | SI1145_PARAM_CHLIST_ENPS1 ) <EOL> self . _device . write8 ( SI1145_REG_INTCFG , SI1145_REG_INTCFG_INTOE ) <EOL> self . _device . write8 ( SI1145_REG_IRQEN , SI1145_REG_IRQEN_ALSEVERYSAMPLE ) <EOL> self . _device . write8 ( SI1145_REG_PSLED21 , <NUM_LIT> ) <EOL> self . writeParam ( SI1145_PARAM_PS1ADCMUX , SI1145_PARAM_ADCMUX_LARGEIR ) <EOL> self . writeParam ( SI1145_PARAM_PSLED12SEL , SI1145_PARAM_PSLED12SEL_PS1LED1 ) <EOL> self . writeParam ( SI1145_PARAM_PSADCGAIN , <NUM_LIT:0> ) <EOL> self . writeParam ( SI1145_PARAM_PSADCOUNTER , SI1145_PARAM_ADCCOUNTER_511CLK ) <EOL> self . writeParam ( SI1145_PARAM_PSADCMISC , SI1145_PARAM_PSADCMISC_RANGE | SI1145_PARAM_PSADCMISC_PSMODE ) <EOL> self . writeParam ( SI1145_PARAM_ALSIRADCMUX , SI1145_PARAM_ADCMUX_SMALLIR ) <EOL> self . writeParam ( SI1145_PARAM_ALSIRADCGAIN , <NUM_LIT:0> ) <EOL> self . writeParam ( SI1145_PARAM_ALSIRADCOUNTER , SI1145_PARAM_ADCCOUNTER_511CLK ) <EOL> self . writeParam ( SI1145_PARAM_ALSIRADCMISC , SI1145_PARAM_ALSIRADCMISC_RANGE ) <EOL> self . writeParam ( SI1145_PARAM_ALSVISADCGAIN , <NUM_LIT:0> ) <EOL> self . writeParam ( SI1145_PARAM_ALSVISADCOUNTER , SI1145_PARAM_ADCCOUNTER_511CLK ) <EOL> self . writeParam ( SI1145_PARAM_ALSVISADCMISC , SI1145_PARAM_ALSVISADCMISC_VISRANGE ) <EOL> self . _device . write8 ( SI1145_REG_MEASRATE0 , <NUM_LIT> ) <EOL> self . _device . write8 ( SI1145_REG_COMMAND , SI1145_PSALS_AUTO ) <EOL> def readUV ( self ) : <EOL> return self . _device . readU16LE ( <NUM_LIT> ) <EOL> def readVisible ( self ) : <EOL> return self . _device . readU16LE ( <NUM_LIT> ) <EOL> def readIR ( self ) : <EOL> return self . _device . readU16LE ( <NUM_LIT> ) <EOL> def readProx ( self ) : <EOL> return self . _device . readU16LE ( <NUM_LIT> ) </s>
