andrewm@0: /*
andrewm@0:  * I2c.h
andrewm@0:  *
andrewm@0:  *  Created on: Oct 14, 2013
andrewm@0:  *      Author: Victor Zappi
andrewm@0:  */
andrewm@0: 
andrewm@0: #ifndef I2CTK_H_
andrewm@0: #define I2CTK_H_
andrewm@0: 
andrewm@68: #include <I2c.h>
andrewm@0: 
andrewm@15: // #define NUM_BYTES_OLD 9
andrewm@15: // #define NUM_BYTES_NEW 13
andrewm@15: 
andrewm@15: #define MAX_SENSOR_BYTES 20
andrewm@15: 
andrewm@15: enum {
andrewm@15: 	kSensorTypeTouchKey = 0,
andrewm@15: 	kSensorTypeDBox1 = 1,
andrewm@15: 	kSensorTypeDBox2 = 2
andrewm@15: };
andrewm@15: 
andrewm@15: static const int kSensorBytes[3] = {9, 13, 20};
andrewm@0: 
andrewm@0: class I2c_TouchKey : public I2c
andrewm@0: {
andrewm@0: private:
andrewm@0: 	bool isReady;
andrewm@15: 	int sensorType;
andrewm@0: 	int numBytesToRead;
andrewm@0: 
andrewm@0: 	// read NUM_BYTES bytes, which have to be properly parsed
andrewm@15: 	char dataBuffer[MAX_SENSOR_BYTES];
andrewm@0: 	int bytesRead;
andrewm@0: 
andrewm@0: 	int rawSliderPosition[5];
andrewm@0: 	int rawSliderPositionH;
andrewm@0: 
andrewm@0: 	int touchCount;
andrewm@0: 	float sliderSize[5];
andrewm@0: 	float sliderPosition[5];
andrewm@0: 	float sliderPositionH;
andrewm@0: 
andrewm@0: 
andrewm@0: public:
andrewm@15: 	int initTouchKey(int sensorTypeToUse = kSensorTypeTouchKey);
andrewm@0: 	int readI2C();
andrewm@0: 	int getTouchCount();
andrewm@0: 	float * getSlidersize();
andrewm@0: 	float * getSliderPosition();
andrewm@0: 	float getSliderPositionH();
andrewm@0: 
andrewm@0: 	bool ready() { return isReady; }
andrewm@0: 
andrewm@0: 	I2c_TouchKey();
andrewm@0: 	~I2c_TouchKey();
andrewm@0: 
andrewm@0: };
andrewm@0: 
andrewm@0: inline int I2c_TouchKey::getTouchCount()
andrewm@0: {
andrewm@0: 	return touchCount;
andrewm@0: }
andrewm@0: 
andrewm@0: inline float * I2c_TouchKey::getSlidersize()
andrewm@0: {
andrewm@0: 	return sliderSize;
andrewm@0: }
andrewm@0: 
andrewm@0: inline float * I2c_TouchKey::getSliderPosition()
andrewm@0: {
andrewm@0: 	return sliderPosition;
andrewm@0: }
andrewm@0: 
andrewm@0: inline float I2c_TouchKey::getSliderPositionH()
andrewm@0: {
andrewm@0: 	return sliderPositionH;
andrewm@0: }
andrewm@0: 
andrewm@0: 
andrewm@0: 
andrewm@0: 
andrewm@0: 
andrewm@0: #endif /* I2CTK_H_ */