Library for using SI1141 sensor
Fork of SI1143 by
Revision 9:31d4e955ee92, committed 2014-05-23
- Comitter:
- dmcohen24
- Date:
- Fri May 23 21:34:54 2014 +0000
- Parent:
- 8:70933bf445af
- Commit message:
- autonomous sensing
Changed in this revision
SI1143.cpp | Show annotated file Show diff for this revision Revisions of this file |
SI1143.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/SI1143.cpp Tue May 20 21:33:31 2014 +0000 +++ b/SI1143.cpp Fri May 23 21:34:54 2014 +0000 @@ -71,15 +71,18 @@ command(PARAM_SET + (PS_ADC_COUNTER & 0x1F)); //Turn up the juice on PS ACD GAIN! - write_reg(PARAM_WR, 0x04); + write_reg(PARAM_WR, 0x00); command(PARAM_SET + (PS_ADC_GAIN & 0x1F)); - write_reg(INT_CFG,0); - write_reg(IRQ_ENABLE,0); + write_reg(INT_CFG,0x01); // Configure Interrupts + write_reg(IRQ_ENABLE,0x04); // Enable PS1 write_reg(IRQ_MODE1,0); write_reg(IRQ_MODE2,0); + write_reg(MEAS_RATE,0x94); //0x84 - wakes up every 10 ms + write_reg(PS_RATE,0x08); //0x84 - wakes up every time measurement clock wakes up + //write_reg(PS_ADC_MISC,0x24); //write_reg(PS1_ADCMUX,0x03); } @@ -141,7 +144,7 @@ bias3 = get_ps3(repeat); } -int SI1143::get_ps1(int repeat) // Read the data for the first LED +int SI1143::get_ps1(int repeat) // Read the data for the first LED (Used in forced mode) { int stack = 0; @@ -163,6 +166,27 @@ return PS1; } +void SI1143::start_ps_auto() +{ + command(PS_AUTO); +} + +int SI1143::read_ps1() // Read the data for the first LED (Used in autonomous mode) +{ + + + LowB = read_reg(PS1_DATA0,1); + HighB = read_reg(PS1_DATA1,1); + PS1 = (HighB * 256) + LowB; + + if(PS1 > bias1) + PS1 = PS1 - bias1; + else + PS1 = 0; + + return PS1; +} + int SI1143::get_ps2(int repeat) // Read the data for the second LED { int stack = 0; @@ -240,3 +264,8 @@ return IR; } + +void SI1143::clear_int() // Clear Interrupt register when an interrupt occurs. +{ + write_reg(IRQ_STATUS, 0x3F); // Writes one to every interrupt status, thereby clearing them +} \ No newline at end of file
--- a/SI1143.h Tue May 20 21:33:31 2014 +0000 +++ b/SI1143.h Fri May 23 21:34:54 2014 +0000 @@ -197,6 +197,10 @@ */ int get_ps1(int repeat); + void start_ps_auto(); + + int read_ps1(); + /** * Takes a number of samples from the proximity of led2 and returns a raw output. * @@ -231,6 +235,8 @@ */ int get_ir(int repeat); + void clear_int(); + private: I2C* i2c_;