Starting library to get the SI1143 Gesture Sensor to work. Currently only works in forced conversion mode.
Dependents: Gesture_Sensor Gesture_Arm_Robot mbed_gesture Gesture_Sensor_Sample ... more
Revision 3:cb3e8160f18e, committed 2013-10-17
- Comitter:
- GAT27
- Date:
- Thu Oct 17 22:03:54 2013 +0000
- Parent:
- 2:21381f11a5af
- Child:
- 4:af8f820733e0
- Commit message:
- class definitions
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 Thu Oct 17 21:03:01 2013 +0000 +++ b/SI1143.cpp Thu Oct 17 22:03:54 2013 +0000 @@ -36,7 +36,7 @@ { wait_ms(30); i2c_ = new I2C(sda, scl); - //3.4MHz, as specified by the datasheet. (DO NOT USE) + //3.4MHz, as specified by the datasheet, but DO NOT USE. //i2c_->frequency(3400000); command(RESET); @@ -152,11 +152,11 @@ switch(point) { - case 1: return VIS; - case 2: return IR; - case 3: return PS1; - case 4: return PS2; - case 5: return PS3; + case 1: return PS1; + case 2: return PS2; + case 3: return PS3; + case 4: return VIS; + case 5: return IR; default: return 0; } //data[0] = VIS;
--- a/SI1143.h Thu Oct 17 21:03:01 2013 +0000 +++ b/SI1143.h Thu Oct 17 22:03:54 2013 +0000 @@ -33,8 +33,16 @@ #ifndef SI1143_h #define SI1143_h +/** + * Includes + */ + #include "mbed.h" +/** + * Defines + */ + #define IR_ADDRESS 0x5A #define HW_KEY_VAL0 0x17 //Value to write into the HW Key register @@ -146,6 +154,7 @@ #define ALS_IR_ADC_MISC 0x1F // Measurement Channel List + #define PS1_TASK 0x01 #define PS2_TASK 0x02 #define PS3_TASK 0x04 @@ -153,14 +162,37 @@ #define ALS_IR_TASK 0x20 #define AUX_TASK 0x40 +/** + * Parallax SI1143 Gesture Sensor. + */ class SI1143 { public: + /** + * Constructor. + * + * @param sda mbed pin to use for SDA line of I2C interface. + * @param scl mbed pin to use for SCL line of I2C interface. + */ SI1143(PinName sda, PinName scl); + /** + * Sample the device and return a result. + * + * @param A value of 1 will output led1 + * A value of 2 will output led2 + * A value of 3 will output led3 + * A value of 4 will output ambient light + * A value of 5 will output infrared light + * A value of anything else will output 0 + * @return In forced conversion output mode, will display the raw output minus any baseline + */ int sample(int point); + /** + * Creates a baseline for sampling measurements. + */ void bias(void); private: @@ -169,11 +201,20 @@ int bias1,bias2,bias3,PS1,PS2,PS3,VIS,IR; char LowB,HighB; + /** + * Wait for the device to respond, then send it a specific command. + */ void command(char cmd); - char read_reg(/*unsigned*/ char address, int num_data); // Read a Register + /** + * Read a register from the device. + */ + char read_reg(/*unsigned*/ char address, int num_data); - void write_reg(char address, char num_data);// Write a resigter + /** + * Write to a register on the device. + */ + void write_reg(char address, char num_data); };