andrewm@0: /*
andrewm@0:  * DboxSensors.h
andrewm@0:  *
andrewm@0:  *  Created on: May 19, 2014
andrewm@0:  *      Author: Victor Zappi
andrewm@0:  */
andrewm@0: 
andrewm@0: #ifndef DBOXSENSORS_H_
andrewm@0: #define DBOXSENSORS_H_
andrewm@0: 
andrewm@0: #include <stdio.h>
andrewm@0: #include <sys/mount.h>	// mount()
andrewm@0: #include <string.h> 	// strerror()
andrewm@0: #include <fstream> 		// fstream
andrewm@0: #include <iostream>
andrewm@0: #include <unistd.h> 	// usleep()
andrewm@0: #include <glob.h>		// glob()
andrewm@0: #include <sys/time.h>	// elapsed time
andrewm@0: #include <sys/stat.h>	// mkdir()
andrewm@0: #include <algorithm>	// reverse() [string...]
andrewm@0: 
andrewm@0: #include "I2c_TouchKey.h"
andrewm@0: #include "AnalogInput.h"
andrewm@68: #include <GPIOcontrol.h>	// TODO wrap this into a class
andrewm@0: 
andrewm@0: /*---------------------------------------------------------------------------------------------------------------------------------------------------
andrewm@0:  * This class retrieves data from all the connected sensors,
andrewm@0:  * logs them
andrewm@0:  * and exposes to the main only the values needed to synthesize sound
andrewm@0:  *
andrewm@0:  * The simple instrument has:
andrewm@0:  *
andrewm@0:  *
andrewm@0:  *
andrewm@0:  *---------------------------------------------------------------------------------------------------------------------------------------------------
andrewm@0:  */
andrewm@0: class DboxSensors
andrewm@0: {
andrewm@0: public:
andrewm@15: 	int initSensors(int tk0_bus, int tk0_address, int tk1_bus, int tk1_address, int tk_file, int fsr_pin, int fsrmax, int sensorTypeToUse, int gpio0=-1, int gpio1=-1);
andrewm@0: 	int readSensors();
andrewm@0: 	int getTKTouchCount(int index);
andrewm@0: 	float *getTKXPositions(int index);
andrewm@0: 	float getTKYPosition(int index);
andrewm@0: 	float *getTKTouchSize(int index);
andrewm@0: 	double getFSRVAlue();
andrewm@0: 	int getDigitalIn(int index);
andrewm@0: 
andrewm@0: 	DboxSensors();
andrewm@0: 	~DboxSensors();
andrewm@0: 
andrewm@0: private:
andrewm@15: 	int sensorType;
andrewm@0: 
andrewm@0: 	I2c_TouchKey TK0;
andrewm@0: 	int tk0_touchCnt;
andrewm@0: 	float tk0_touchPosX[5];
andrewm@0: 	float tk0_touchPosY;
andrewm@0: 	float tk0_touchSize[5];
andrewm@0: 
andrewm@0: 	I2c_TouchKey TK1;
andrewm@0: 	int tk1_touchCnt;
andrewm@0: 	float tk1_touchPosX[5];
andrewm@0: 	float tk1_touchPosY;
andrewm@0: 	float tk1_touchSize[5];
andrewm@0: 
andrewm@0: 	AnalogInput FSR;
andrewm@0: 	int fsr_pinNum;
andrewm@0: 	double fsr_read;
andrewm@0: 	int fsr_max;
andrewm@0: 
andrewm@0: 	unsigned int digitalIn[2];
andrewm@0: 	int fdDi[2];
andrewm@0: 	int gpio[2];
andrewm@0: 
andrewm@0: 	void resetSensorsData();
andrewm@0: 
andrewm@0: };
andrewm@0: 
andrewm@0: 
andrewm@0: 
andrewm@0: //--------------------------------------------------------------------------------
andrewm@0: // read interface
andrewm@0: inline int DboxSensors::getTKTouchCount(int index)
andrewm@0: {
andrewm@0: 	if(index==0)
andrewm@0: 		return tk0_touchCnt;
andrewm@0: 	else
andrewm@0: 		return tk1_touchCnt;
andrewm@0: }
andrewm@0: 
andrewm@0: inline float *DboxSensors::getTKXPositions(int index)
andrewm@0: {
andrewm@0: 	if(index==0)
andrewm@0: 		return tk0_touchPosX;
andrewm@0: 	else
andrewm@0: 		return tk1_touchPosX;
andrewm@0: }
andrewm@0: 
andrewm@0: inline float DboxSensors::getTKYPosition(int index)
andrewm@0: {
andrewm@0: 	if(index==0)
andrewm@0: 		return tk0_touchPosY;
andrewm@0: 	else
andrewm@0: 		return tk1_touchPosY;
andrewm@0: }
andrewm@0: 
andrewm@0: inline float *DboxSensors::getTKTouchSize(int index)
andrewm@0: {
andrewm@0: 	if(index==0)
andrewm@0: 		return tk0_touchSize;
andrewm@0: 	else
andrewm@0: 		return tk1_touchSize;
andrewm@0: }
andrewm@0: 
andrewm@0: inline double DboxSensors::getFSRVAlue()
andrewm@0: {
andrewm@0: 	return fsr_read;
andrewm@0: }
andrewm@0: 
andrewm@0: inline int DboxSensors::getDigitalIn(int index)
andrewm@0: {
andrewm@0: 	return digitalIn[index];
andrewm@0: }
andrewm@0: //--------------------------------------------------------------------------------
andrewm@0: 
andrewm@0: 
andrewm@0: #endif /* DBOXSENSORS_H_ */