comparison projects/d-box/DboxSensors.cpp @ 15:901d205d1a3c

Updated to latest PRU library; external PRU file no longer needed. Also catch SIGTERM as well as SIGINT to clean up gracefully.
author andrewm
date Sat, 07 Feb 2015 16:41:56 +0000
parents 8a575ba3ab52
children
comparison
equal deleted inserted replaced
14:06f93bef7dd2 15:901d205d1a3c
11 11
12 using namespace std; 12 using namespace std;
13 13
14 14
15 15
16 int DboxSensors::initSensors(int tk0_bus, int tk0_address, int tk1_bus, int tk1_address, int tk_file, int fsr_pin, int fsrmax, bool useNewSensors, int gpio_0, int gpio_1) 16 int DboxSensors::initSensors(int tk0_bus, int tk0_address, int tk1_bus, int tk1_address, int tk_file, int fsr_pin, int fsrmax, int sensorTypeToUse, int gpio_0, int gpio_1)
17 { 17 {
18 newSensors = useNewSensors; 18 sensorType = sensorTypeToUse;
19 // init first touch key on i2c bus 19 // init first touch key on i2c bus
20 if(tk0_address >= 0) { 20 if(tk0_address >= 0) {
21 if(TK0.initI2C_RW(tk0_bus, tk0_address, tk_file)>0) 21 if(TK0.initI2C_RW(tk0_bus, tk0_address, tk_file)>0)
22 return 1; 22 return 1;
23 if(TK0.initTouchKey(newSensors)>0) 23 if(TK0.initTouchKey(sensorType)>0)
24 return 2; 24 return 2;
25 } 25 }
26 26
27 // init second touch key on i2c bus 27 // init second touch key on i2c bus
28 if(tk1_address >= 0) { 28 if(tk1_address >= 0) {
29 if(TK1.initI2C_RW(tk1_bus, tk1_address, tk_file)>0) 29 if(TK1.initI2C_RW(tk1_bus, tk1_address, tk_file)>0)
30 return 1; 30 return 1;
31 if(TK1.initTouchKey(newSensors)>0) 31 if(TK1.initTouchKey(sensorType)>0)
32 return 2; 32 return 2;
33 } 33 }
34 34
35 // init fsr on analog input pin 35 // init fsr on analog input pin
36 fsr_pinNum = fsr_pin; 36 fsr_pinNum = fsr_pin;
75 else 75 else
76 tk1_touchCnt = 0; 76 tk1_touchCnt = 0;
77 77
78 78
79 int max = 3; 79 int max = 3;
80 if(newSensors) 80 if(sensorType != kSensorTypeTouchKey)
81 max = 5; 81 max = 5;
82 // if touches detected on main touch key 82 // if touches detected on main touch key
83 if(tk0_touchCnt == 0 && tk1_touchCnt == 0) 83 if(tk0_touchCnt == 0 && tk1_touchCnt == 0)
84 resetSensorsData(); 84 resetSensorsData();
85 else 85 else
129 129
130 // idle values 130 // idle values
131 void DboxSensors::resetSensorsData() 131 void DboxSensors::resetSensorsData()
132 { 132 {
133 int max = 3; 133 int max = 3;
134 if(newSensors) 134 if(sensorType != kSensorTypeTouchKey)
135 max = 5; 135 max = 5;
136 136
137 for(int i=0; i<max; i++) 137 for(int i=0; i<max; i++)
138 { 138 {
139 tk0_touchPosX[i] = -1; 139 tk0_touchPosX[i] = -1;