robert@464: /* robert@464: * DboxSensors.cpp robert@464: * robert@464: * Created on: May 19, 2014 robert@464: * Author: Victor Zappi robert@464: */ robert@464: robert@464: robert@464: #include "DboxSensors.h" robert@464: #include "config.h" robert@464: robert@464: using namespace std; robert@464: robert@464: robert@464: robert@464: 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) robert@464: { robert@464: sensorType = sensorTypeToUse; robert@464: // init first touch key on i2c bus robert@464: if(tk0_address >= 0) { robert@464: if(TK0.initI2C_RW(tk0_bus, tk0_address, tk_file)>0) robert@464: return 1; robert@464: if(TK0.initTouchKey(sensorType)>0) robert@464: return 2; robert@464: } robert@464: robert@464: // init second touch key on i2c bus robert@464: if(tk1_address >= 0) { robert@464: if(TK1.initI2C_RW(tk1_bus, tk1_address, tk_file)>0) robert@464: return 1; robert@464: if(TK1.initTouchKey(sensorType)>0) robert@464: return 2; robert@464: } robert@464: robert@464: // init fsr on analog input pin robert@464: fsr_pinNum = fsr_pin; robert@464: fsr_max = fsrmax; robert@464: robert@464: if(FSR.initAnalogInputs()>0) robert@464: return 3; robert@464: robert@464: gpio[0] = gpio_0; robert@464: if(gpio[0]!=-1) robert@464: { robert@464: fdDi[0] = gpio_export(gpio[0]); robert@464: if(fdDi[0] == -1) robert@464: return 4; robert@464: } robert@464: digitalIn[0] = 1; robert@464: robert@464: return 0; robert@464: } robert@464: robert@464: robert@464: int DboxSensors::readSensors() robert@464: { robert@464: // write data into first touch key robert@464: if(TK0.ready()) { robert@464: if(TK0.readI2C()>0) robert@464: return 1; robert@464: robert@464: // retrieve data from first touch key robert@464: tk0_touchCnt = TK0.getTouchCount(); robert@464: } robert@464: else robert@464: tk0_touchCnt = 0; robert@464: robert@464: // write data into second touch key robert@464: if(TK1.ready()) { robert@464: if(TK1.readI2C()>0) robert@464: return 1; robert@464: // retrieve data from second touch key robert@464: tk1_touchCnt = TK1.getTouchCount(); robert@464: } robert@464: else robert@464: tk1_touchCnt = 0; robert@464: robert@464: robert@464: int max = 3; robert@464: if(sensorType != kSensorTypeTouchKey) robert@464: max = 5; robert@464: // if touches detected on main touch key robert@464: if(tk0_touchCnt == 0 && tk1_touchCnt == 0) robert@464: resetSensorsData(); robert@464: else robert@464: { robert@464: for(int i=0; i