robert@464
|
1 /*
|
robert@464
|
2 * DboxSensors.h
|
robert@464
|
3 *
|
robert@464
|
4 * Created on: May 19, 2014
|
robert@464
|
5 * Author: Victor Zappi
|
robert@464
|
6 */
|
robert@464
|
7
|
robert@464
|
8 #ifndef DBOXSENSORS_H_
|
robert@464
|
9 #define DBOXSENSORS_H_
|
robert@464
|
10
|
robert@464
|
11 #include <stdio.h>
|
robert@464
|
12 #include <sys/mount.h> // mount()
|
robert@464
|
13 #include <string.h> // strerror()
|
robert@464
|
14 #include <fstream> // fstream
|
robert@464
|
15 #include <iostream>
|
robert@464
|
16 #include <unistd.h> // usleep()
|
robert@464
|
17 #include <glob.h> // glob()
|
robert@464
|
18 #include <sys/time.h> // elapsed time
|
robert@464
|
19 #include <sys/stat.h> // mkdir()
|
robert@464
|
20 #include <algorithm> // reverse() [string...]
|
robert@464
|
21
|
robert@464
|
22 #include "I2c_TouchKey.h"
|
robert@464
|
23 #include "AnalogInput.h"
|
robert@464
|
24 #include <GPIOcontrol.h> // TODO wrap this into a class
|
robert@464
|
25
|
robert@464
|
26 /*---------------------------------------------------------------------------------------------------------------------------------------------------
|
robert@464
|
27 * This class retrieves data from all the connected sensors,
|
robert@464
|
28 * logs them
|
robert@464
|
29 * and exposes to the main only the values needed to synthesize sound
|
robert@464
|
30 *
|
robert@464
|
31 * The simple instrument has:
|
robert@464
|
32 *
|
robert@464
|
33 *
|
robert@464
|
34 *
|
robert@464
|
35 *---------------------------------------------------------------------------------------------------------------------------------------------------
|
robert@464
|
36 */
|
robert@464
|
37 class DboxSensors
|
robert@464
|
38 {
|
robert@464
|
39 public:
|
robert@464
|
40 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);
|
robert@464
|
41 int readSensors();
|
robert@464
|
42 int getTKTouchCount(int index);
|
robert@464
|
43 float *getTKXPositions(int index);
|
robert@464
|
44 float getTKYPosition(int index);
|
robert@464
|
45 float *getTKTouchSize(int index);
|
robert@464
|
46 double getFSRVAlue();
|
robert@464
|
47 int getDigitalIn(int index);
|
robert@464
|
48
|
robert@464
|
49 DboxSensors();
|
robert@464
|
50 ~DboxSensors();
|
robert@464
|
51
|
robert@464
|
52 private:
|
robert@464
|
53 int sensorType;
|
robert@464
|
54
|
robert@464
|
55 I2c_TouchKey TK0;
|
robert@464
|
56 int tk0_touchCnt;
|
robert@464
|
57 float tk0_touchPosX[5];
|
robert@464
|
58 float tk0_touchPosY;
|
robert@464
|
59 float tk0_touchSize[5];
|
robert@464
|
60
|
robert@464
|
61 I2c_TouchKey TK1;
|
robert@464
|
62 int tk1_touchCnt;
|
robert@464
|
63 float tk1_touchPosX[5];
|
robert@464
|
64 float tk1_touchPosY;
|
robert@464
|
65 float tk1_touchSize[5];
|
robert@464
|
66
|
robert@464
|
67 AnalogInput FSR;
|
robert@464
|
68 int fsr_pinNum;
|
robert@464
|
69 double fsr_read;
|
robert@464
|
70 int fsr_max;
|
robert@464
|
71
|
robert@464
|
72 unsigned int digitalIn[2];
|
robert@464
|
73 int fdDi[2];
|
robert@464
|
74 int gpio[2];
|
robert@464
|
75
|
robert@464
|
76 void resetSensorsData();
|
robert@464
|
77
|
robert@464
|
78 };
|
robert@464
|
79
|
robert@464
|
80
|
robert@464
|
81
|
robert@464
|
82 //--------------------------------------------------------------------------------
|
robert@464
|
83 // read interface
|
robert@464
|
84 inline int DboxSensors::getTKTouchCount(int index)
|
robert@464
|
85 {
|
robert@464
|
86 if(index==0)
|
robert@464
|
87 return tk0_touchCnt;
|
robert@464
|
88 else
|
robert@464
|
89 return tk1_touchCnt;
|
robert@464
|
90 }
|
robert@464
|
91
|
robert@464
|
92 inline float *DboxSensors::getTKXPositions(int index)
|
robert@464
|
93 {
|
robert@464
|
94 if(index==0)
|
robert@464
|
95 return tk0_touchPosX;
|
robert@464
|
96 else
|
robert@464
|
97 return tk1_touchPosX;
|
robert@464
|
98 }
|
robert@464
|
99
|
robert@464
|
100 inline float DboxSensors::getTKYPosition(int index)
|
robert@464
|
101 {
|
robert@464
|
102 if(index==0)
|
robert@464
|
103 return tk0_touchPosY;
|
robert@464
|
104 else
|
robert@464
|
105 return tk1_touchPosY;
|
robert@464
|
106 }
|
robert@464
|
107
|
robert@464
|
108 inline float *DboxSensors::getTKTouchSize(int index)
|
robert@464
|
109 {
|
robert@464
|
110 if(index==0)
|
robert@464
|
111 return tk0_touchSize;
|
robert@464
|
112 else
|
robert@464
|
113 return tk1_touchSize;
|
robert@464
|
114 }
|
robert@464
|
115
|
robert@464
|
116 inline double DboxSensors::getFSRVAlue()
|
robert@464
|
117 {
|
robert@464
|
118 return fsr_read;
|
robert@464
|
119 }
|
robert@464
|
120
|
robert@464
|
121 inline int DboxSensors::getDigitalIn(int index)
|
robert@464
|
122 {
|
robert@464
|
123 return digitalIn[index];
|
robert@464
|
124 }
|
robert@464
|
125 //--------------------------------------------------------------------------------
|
robert@464
|
126
|
robert@464
|
127
|
robert@464
|
128 #endif /* DBOXSENSORS_H_ */
|