Sensor Scol plugin
Multi platform sensors for handled devices
SSensor.h
1#ifndef _SENSOR_H_
2#define _SENSOR_H_
3
4#include <scolPlugin.h>
5#include <boost/thread/thread.hpp>
6#include <boost/bind/bind.hpp>
7
8#include <set>
9#include "tools/Quaternion.h"
10#include "orientationTracker.h"
11
12//Tickcount function
13#ifndef _WIN32
14#include <time.h>
15
16int64_t GetTickCountNano();
17#else
18#include "Windows.h"
19int64_t GetTickCountNano();
20#endif
21
22
23typedef struct
24{
25 Vector3d vec3;
26 float fval;
27 double delta;
29
30enum SSensorType{
31 SSENSOR_TYPE_UNKNOWN,
32 SSENSOR_TYPE_ACCELEROMETER,
33 SSENSOR_TYPE_MAGNETIC_FIELD,
34 SSENSOR_TYPE_GYROSCOPE,
35 SSENSOR_TYPE_LIGHT,
36 SSENSOR_TYPE_PROXIMITY,
37 SSENSOR_TYPE_ORIENTATION
38};
39
40//Update global mutex
41static boost::shared_mutex mGlobalMutex;
42
44{
45public:
46protected:
47 SSensorType mType;
48private:
49public:
50 SSensorCb(SSensorType type);
51 ~SSensorCb();
52 SSensorType GetType();
53};
54
55/* CLASS NAME: Sensor
56 * \brief Represents a sensor.
57
58 * Used to store sensor datas received by events. The purpose if to get datas synchronously (by a simple 'get' method)
59 */
61{
62 /* * * * * * * * * * * * * FRIENDS * * * * * * * * * * * * */
63
64 /* * * * * * * * * * * * * ATTRIBUTES * * * * * * * * * * * * */
65 public:
66 protected:
67 SSensorType mType;
68 bool mEnabled;
69 bool mPaused;
70 int64_t mLastTimeStamp;
71 std::list<SSensorCb*> mAxisCallbacks;
72 private:
73
74 /* * * * * * * * * * * * * CONSTRUCTORS * * * * * * * * * * * * */
75 public:
76 SSensor();
77 SSensor(SSensorType type);
78 ~SSensor();
79 protected:
80 private:
81
82 /* * * * * * * * * * * * * METHODS * * * * * * * * * * * * */
83 public:
84 SSensorType GetType();
85 bool IsEnabled();
86 void SetEnabled(bool enabled);
87 bool IsPaused();
88 void SetPaused(bool paused);
89 SSensorCb* AddCallBack();
90 void RemoveCallBack(SSensorCb* sensorCb);
91 void CallSensorCb(SSensorData data);
92 double GetElapsedTime(int64_t timeStamp);
93
94 virtual SSensorData GetData() = 0;
95 protected:
96 private:
97};
98
99/* CLASS NAME: SensorManager
100 * \brief Manager sensors.
101
102 * Used to list sensor objects. It is possible to manage them through this class (enable/disable, ...).
103 */
105{
106 /* * * * * * * * * * * * * FRIENDS * * * * * * * * * * * * */
107
108 /* * * * * * * * * * * * * ATTRIBUTES * * * * * * * * * * * * */
109 public:
110 protected:
111 std::set<SSensor*> mSensorList;
112 OrientationTracker* mOrientationTracker;
113 static SSensorManager* mSingletonInstance;
114 private:
115
116 /* * * * * * * * * * * * * CONSTRUCTORS * * * * * * * * * * * * */
117 public:
119 virtual ~SSensorManager();
120 protected:
121 private:
122
123 /* * * * * * * * * * * * * METHODS * * * * * * * * * * * * */
124 public:
125 static SSensorManager* GetInstance();
126 static void Kill();
127
128 SSensor* GetSensorByType(SSensorType sensorType);
129 std::set<SSensor*> GetSensorList();
130
131 bool IsAvailable(SSensorType sensorType);
132 bool IsEnabled(SSensorType sensorType);
133
134 SSensorCb* AddSensorCallBack(SSensorType sensorType);
135 void RemoveSensorCallBack(SSensorCb* sensorCb);
136
137 virtual int SetSensorEnable(SSensorType sensorType, bool state) = 0;
138 virtual void Vibrate(long millis) = 0;
139 virtual void StartVibration() = 0;
140 virtual void StopVibration() = 0;
141 virtual void VibratePattern(std::vector<int> pattern, bool loop) = 0;
142
143 virtual void StartLocationService() = 0;
144 virtual void StopLocationService() = 0;
145 virtual bool GetLocation(float &longitude, float &latitude, float &altitude) = 0;
146
147 void PauseSensorManager();
148 void ResumeSensorManager();
149
150 OrientationTracker* GetOrientationTracker();
151 Quaternion GetDeviceOrientation(double timeOffsetInSeconds);
152
153 protected:
154 private:
155};
156
157#endif