Parallax Gesture Sensor

Committer:
frost1h
Date:
Fri Mar 13 20:53:11 2015 +0000
Revision:
0:817f868ca9c1
Gesture Sensor

Who changed what in which revision?

UserRevisionLine numberNew contents of line
frost1h 0:817f868ca9c1 1
frost1h 0:817f868ca9c1 2 #ifndef GestureSensor_h
frost1h 0:817f868ca9c1 3 #define GestureSensor_h
frost1h 0:817f868ca9c1 4
frost1h 0:817f868ca9c1 5 #include "mbed.h"
frost1h 0:817f868ca9c1 6
frost1h 0:817f868ca9c1 7 #define IR_ADDRESS 0x5A //Slave address of the Si1141/42/43
frost1h 0:817f868ca9c1 8 #define HW_KEY_VAL0 0x17 //Value to write into the HW Key register
frost1h 0:817f868ca9c1 9
frost1h 0:817f868ca9c1 10 //I2C Registers (Can be used with Write to Register Functions)
frost1h 0:817f868ca9c1 11
frost1h 0:817f868ca9c1 12 #define PART_ID 0x00
frost1h 0:817f868ca9c1 13 #define REV_ID 0x01
frost1h 0:817f868ca9c1 14 #define SEQ_ID 0x02
frost1h 0:817f868ca9c1 15 #define INT_CFG 0x03
frost1h 0:817f868ca9c1 16 #define IRQ_ENABLE 0x04
frost1h 0:817f868ca9c1 17 #define IRQ_MODE1 0x05
frost1h 0:817f868ca9c1 18 #define IRQ_MODE2 0x06
frost1h 0:817f868ca9c1 19 #define HW_KEY 0x07
frost1h 0:817f868ca9c1 20 #define MEAS_RATE 0x08
frost1h 0:817f868ca9c1 21 #define ALS_RATE 0x09
frost1h 0:817f868ca9c1 22 #define PS_RATE 0x0A
frost1h 0:817f868ca9c1 23 #define ALS_LOW_TH0 0x0B
frost1h 0:817f868ca9c1 24 #define ALS_LOW_TH1 0x0C
frost1h 0:817f868ca9c1 25 #define ALS_HI_TH0 0x0D
frost1h 0:817f868ca9c1 26 #define ALS_HI_TH1 0x0E
frost1h 0:817f868ca9c1 27 #define PS_LED21 0x0F
frost1h 0:817f868ca9c1 28 #define PS_LED3 0x10
frost1h 0:817f868ca9c1 29 #define PS1_TH0 0x11
frost1h 0:817f868ca9c1 30 #define PS1_TH1 0x12
frost1h 0:817f868ca9c1 31 #define PS2_TH0 0x13
frost1h 0:817f868ca9c1 32 #define PS2_TH1 0x14
frost1h 0:817f868ca9c1 33 #define PS3_TH0 0x15
frost1h 0:817f868ca9c1 34 #define PS3_TH1 0x16
frost1h 0:817f868ca9c1 35 #define PARAM_WR 0x17
frost1h 0:817f868ca9c1 36 #define COMMAND 0x18
frost1h 0:817f868ca9c1 37 #define RESPONSE 0x20
frost1h 0:817f868ca9c1 38 #define IRQ_STATUS 0x21
frost1h 0:817f868ca9c1 39 #define ALS_VIS_DATA0 0x22
frost1h 0:817f868ca9c1 40 #define ALS_VIS_DATA1 0x23
frost1h 0:817f868ca9c1 41 #define ALS_IR_DATA0 0x24
frost1h 0:817f868ca9c1 42 #define ALS_IR_DATA1 0x25
frost1h 0:817f868ca9c1 43 #define PS1_DATA0 0x26
frost1h 0:817f868ca9c1 44 #define PS1_DATA1 0x27
frost1h 0:817f868ca9c1 45 #define PS2_DATA0 0x28
frost1h 0:817f868ca9c1 46 #define PS2_DATA1 0x29
frost1h 0:817f868ca9c1 47 #define PS3_DATA0 0x2A
frost1h 0:817f868ca9c1 48 #define PS3_DATA1 0x2B
frost1h 0:817f868ca9c1 49 #define AUX_DATA0 0x2C
frost1h 0:817f868ca9c1 50 #define AUX_DATA1 0x2D
frost1h 0:817f868ca9c1 51 #define PARAM_RD 0x2E
frost1h 0:817f868ca9c1 52 #define CHIP_STAT 0x30
frost1h 0:817f868ca9c1 53 #define ANA_IN_KEY 0x3B
frost1h 0:817f868ca9c1 54
frost1h 0:817f868ca9c1 55 //Command Register Values
frost1h 0:817f868ca9c1 56
frost1h 0:817f868ca9c1 57 #define PARAM_QUERY 0x80 //Value is ORed with Parameter Offset
frost1h 0:817f868ca9c1 58 #define PARAM_SET 0xA0 //Value is ORed with Parameter Offset
frost1h 0:817f868ca9c1 59 #define PARAM_AND 0xC0 //Value is ORed with Parameter Offset
frost1h 0:817f868ca9c1 60 #define PARAM_OR 0xE0 //Value is ORed with Parameter Offset
frost1h 0:817f868ca9c1 61 #define NOP 0x00
frost1h 0:817f868ca9c1 62 #define RESET 0x01
frost1h 0:817f868ca9c1 63 #define BUSADDR 0x02
frost1h 0:817f868ca9c1 64 #define PS_FORCE 0x05
frost1h 0:817f868ca9c1 65 #define ALS_FORCE 0x06
frost1h 0:817f868ca9c1 66 #define PSALS_FORCE 0x07
frost1h 0:817f868ca9c1 67 #define PS_PAUSE 0x09
frost1h 0:817f868ca9c1 68 #define ALS_PAUSE 0x0A
frost1h 0:817f868ca9c1 69 #define PSALS_PAUSE 0x0B
frost1h 0:817f868ca9c1 70 #define PS_AUTO 0x0D
frost1h 0:817f868ca9c1 71 #define ALS_AUTO 0x0E
frost1h 0:817f868ca9c1 72 #define PSALS_AUTO 0x0F
frost1h 0:817f868ca9c1 73
frost1h 0:817f868ca9c1 74 //Parameter Offsets to use in the Command Register (Can be used with ParamSet function)
frost1h 0:817f868ca9c1 75
frost1h 0:817f868ca9c1 76 #define I2C_ADDR 0x00
frost1h 0:817f868ca9c1 77 #define CHLIST 0x01
frost1h 0:817f868ca9c1 78 #define PSLED12_SELECT 0x02
frost1h 0:817f868ca9c1 79 #define PSLED3_SELECT 0x03
frost1h 0:817f868ca9c1 80 #define FILTER_EN 0x04
frost1h 0:817f868ca9c1 81 #define PS_ENCODING 0x05
frost1h 0:817f868ca9c1 82 #define ALS_ENCODING 0x06
frost1h 0:817f868ca9c1 83 #define PS1_ADCMUX 0x07
frost1h 0:817f868ca9c1 84 #define PS2_ADCMUX 0x08
frost1h 0:817f868ca9c1 85 #define PS3_ADCMUX 0x09
frost1h 0:817f868ca9c1 86 #define PS_ADC_COUNTER 0x0A
frost1h 0:817f868ca9c1 87 #define PS_ADC_GAIN 0x0B
frost1h 0:817f868ca9c1 88 #define PS_ADC_MISC 0x0C
frost1h 0:817f868ca9c1 89 #define ALS1_ADCMUX 0x0D
frost1h 0:817f868ca9c1 90 #define ALS2_ADCMUX 0x0E
frost1h 0:817f868ca9c1 91 #define ALS3_ADCMUX 0x0F
frost1h 0:817f868ca9c1 92 #define ALS_VIS_ADC_COUNTER 0x10
frost1h 0:817f868ca9c1 93 #define ALS_VIS_ADC_GAIN 0x11
frost1h 0:817f868ca9c1 94 #define ALS_VIS_ADC_MISC 0x12
frost1h 0:817f868ca9c1 95 #define ALS_HYST 0x16
frost1h 0:817f868ca9c1 96 #define PS_HYST 0x17
frost1h 0:817f868ca9c1 97 #define PS_HISTORY 0x18
frost1h 0:817f868ca9c1 98 #define ALS_HISTORY 0x19
frost1h 0:817f868ca9c1 99 #define ADC_OFFSET 0x1A
frost1h 0:817f868ca9c1 100 #define SLEEP_CTRL 0x1B
frost1h 0:817f868ca9c1 101 #define LED_REC 0x1C
frost1h 0:817f868ca9c1 102 #define ALS_IR_ADC_COUNTER 0x1D
frost1h 0:817f868ca9c1 103 #define ALS_IR_ADC_GAIN 0x1E
frost1h 0:817f868ca9c1 104 #define ALS_IR_ADC_MISC 0x1F
frost1h 0:817f868ca9c1 105
frost1h 0:817f868ca9c1 106 //Measurement Channel List
frost1h 0:817f868ca9c1 107
frost1h 0:817f868ca9c1 108 #define PS1_TASK 0x01
frost1h 0:817f868ca9c1 109 #define PS2_TASK 0x02
frost1h 0:817f868ca9c1 110 #define PS3_TASK 0x04
frost1h 0:817f868ca9c1 111 #define ALS_VIS_TASK 0x10
frost1h 0:817f868ca9c1 112 #define ALS_IR_TASK 0x20
frost1h 0:817f868ca9c1 113 #define AUX_TASK 0x40
frost1h 0:817f868ca9c1 114
frost1h 0:817f868ca9c1 115 class GestureSensor
frost1h 0:817f868ca9c1 116 {
frost1h 0:817f868ca9c1 117 public:
frost1h 0:817f868ca9c1 118
frost1h 0:817f868ca9c1 119 //Initiate the Device
frost1h 0:817f868ca9c1 120 GestureSensor(PinName sda, PinName scl);
frost1h 0:817f868ca9c1 121
frost1h 0:817f868ca9c1 122 //Restarts the device.
frost1h 0:817f868ca9c1 123 void restart(void);
frost1h 0:817f868ca9c1 124
frost1h 0:817f868ca9c1 125 // Baseline for sampling
frost1h 0:817f868ca9c1 126 void baseline(int time, int num);
frost1h 0:817f868ca9c1 127
frost1h 0:817f868ca9c1 128 // Get samples from left sensor
frost1h 0:817f868ca9c1 129 int sample_left(int num);
frost1h 0:817f868ca9c1 130
frost1h 0:817f868ca9c1 131 // Get samples from top sensor
frost1h 0:817f868ca9c1 132 int sample_top(int num);
frost1h 0:817f868ca9c1 133
frost1h 0:817f868ca9c1 134 // Get samples from right sensor
frost1h 0:817f868ca9c1 135 int sample_right(int num);
frost1h 0:817f868ca9c1 136
frost1h 0:817f868ca9c1 137
frost1h 0:817f868ca9c1 138 private:
frost1h 0:817f868ca9c1 139
frost1h 0:817f868ca9c1 140 I2C* i2cp;
frost1h 0:817f868ca9c1 141 char firstHalf,secondHalf;
frost1h 0:817f868ca9c1 142 int sampleleft,sampletop,sampleright,left,top,right;
frost1h 0:817f868ca9c1 143
frost1h 0:817f868ca9c1 144 // write register
frost1h 0:817f868ca9c1 145 void wreg(char address, char data);
frost1h 0:817f868ca9c1 146
frost1h 0:817f868ca9c1 147 // read register
frost1h 0:817f868ca9c1 148 char rreg(char address, int data);
frost1h 0:817f868ca9c1 149
frost1h 0:817f868ca9c1 150 // Send command; On page 20 of the data sheet.
frost1h 0:817f868ca9c1 151 void command(char code);
frost1h 0:817f868ca9c1 152 };
frost1h 0:817f868ca9c1 153
frost1h 0:817f868ca9c1 154 #endif