blip  0.1
SensorManager.hpp
Go to the documentation of this file.
1 #ifndef __blip_SensorManager_hpp
2 #define __blip_SensorManager_hpp
3 
4 #include <deque>
5 #include <vector>
6 
7 #include <blip/Blip.hpp>
8 #include <blip/Sensor.hpp>
9 
10 struct ALooper;
11 struct ASensorEvent;
12 struct ASensorEventQueue;
13 struct ASensorManager;
14 
15 namespace blip {
16 
17 class SensorEvent;
18 
24 {
25  friend class NativeActivity;
26 
27  public:
28 
31 
33  int getSensorCount() const;
34 
41  Sensor* getSensor(int index);
42 
50 
58  bool enableSensor(Sensor* sensor);
59 
67  bool disableSensor(Sensor* sensor);
68 
79  bool setSensorEventRate(Sensor* sensor, timespan_us_t rate);
80 
81  private: // Called by NativeActivity
82 
83  SensorManager(ALooper* looper, int id);
84 
85  bool hasEvents();
86  SensorEvent* nextEvent();
87  void finishEvent(SensorEvent* event);
88 
89  private:
90 
91  void loadSensors();
92  SensorEvent* buildEvent(ASensorEvent* event);
93 
94  static const int EVENT_BUF_SIZE;
95 
96  ASensorManager* _sensorMgr;
97  std::vector<Sensor*> _sensors;
98  ASensorEventQueue* _queue;
99  ASensorEvent* _eventBuf;
100  std::deque<SensorEvent*> _events;
101 
102  CCXX_COPY_DECLS(SensorManager);
103 };
104 
105 } // namespace blip
106 
107 #endif // __blip_SensorManager_hpp
Type
Sensor types.
Definition: Sensor.hpp:25
bool setSensorEventRate(Sensor *sensor, timespan_us_t rate)
Set the rate, in microseconds, at which the given sensor will send events to the application.
Definition: SensorManager.cpp:162
bool enableSensor(Sensor *sensor)
Enable the given sensor, so that the application may begin receiving events from it.
Definition: SensorManager.cpp:146
An abstract base class for sensor events.
Definition: SensorEvent.hpp:20
int getSensorCount() const
Get the number of sensors in the system.
Definition: SensorManager.cpp:56
WAV file format details at: https://ccrma.stanford.edu/courses/422/projects/WaveFormat/.
Definition: AccelerometerSensorEvent.cpp:3
~SensorManager()
Destructor.
Definition: SensorManager.cpp:47
An abstract base class for all "native" (C++) Android activities.
Definition: NativeActivity.hpp:71
A class representing a sensor.
Definition: Sensor.hpp:17
bool disableSensor(Sensor *sensor)
Disable the given sensor, so that the application will no longer receive events from it...
Definition: SensorManager.cpp:154
A class that provides access to the hardware sensors.
Definition: SensorManager.hpp:23
Sensor * getDefaultSensor(Sensor::Type type)
Get the default sensor for the given sensor type.
Definition: SensorManager.cpp:75
Sensor * getSensor(int index)
Get the sensor at the given index.
Definition: SensorManager.cpp:64
uint64_t timespan_us_t
A time interval, measured in microseconds.
Definition: Blip.hpp:30