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