upm  1.2.0
Sensor/Actuator repository for libmraa (v1.6.1)
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
curieimu.hpp
1 /*
2  * Author: Brendan Le Foll <brendan.le.foll@intel.com>
3  * Author: Ron Evans (@deadprogram)
4  * Author: Justin Zemlyansky (@JustInDevelopment)
5  * Copyright (c) 2016 Intel Corporation.
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining
8  * a copy of this software and associated documentation files (the
9  * "Software"), to deal in the Software without restriction, including
10  * without limitation the rights to use, copy, modify, merge, publish,
11  * distribute, sublicense, and/or sell copies of the Software, and to
12  * permit persons to whom the Software is furnished to do so, subject to
13  * the following conditions:
14  *
15  * The above copyright notice and this permission notice shall be
16  * included in all copies or substantial portions of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25  */
26 #pragma once
27 
28 #include <mraa/firmata.h>
29 #include <queue>
30 
31 #define FIRMATA_START_SYSEX 0xF0
32 #define FIRMATA_END_SYSEX 0xF7
33 #define FIRMATA_CURIE_IMU 0x11
34 #define FIRMATA_CURIE_IMU_READ_ACCEL 0x00
35 #define FIRMATA_CURIE_IMU_READ_GYRO 0x01
36 #define FIRMATA_CURIE_IMU_READ_TEMP 0x02
37 #define FIRMATA_CURIE_IMU_SHOCK_DETECT 0x03
38 #define FIRMATA_CURIE_IMU_STEP_COUNTER 0x04
39 #define FIRMATA_CURIE_IMU_TAP_DETECT 0x05
40 #define FIRMATA_CURIE_IMU_READ_MOTION 0x06
41 
42 #define X 0
43 #define Y 1
44 #define Z 2
45 
46 namespace upm {
53 struct IMUDataItem {
54  int axis;
55  int direction;
56 };
57 
76 class CurieImu {
77  public:
78 
84  CurieImu (int subplatform_offset=512);
85 
89  ~CurieImu();
90 
94  void updateAccel();
95 
99  void updateGyro();
100 
105  void updateMotion();
106 
112  int16_t* getAccel();
113 
119  int16_t getAccelX();
120 
126  int16_t getAccelY();
127 
133  int16_t getAccelZ();
134 
140  int16_t* getGyro();
141 
147  int16_t getGyroX();
148 
154  int16_t getGyroY();
155 
161  int16_t getGyroZ();
162 
168  int16_t getTemperature();
169 
177  int16_t* getMotion();
178 
184  int16_t getAxis();
185 
191  int16_t getDirection();
192 
198  void enableShockDetection(bool enable);
199 
205  bool isShockDetected();
206 
211  void getNextShock();
212 
218  void enableStepCounter(bool enable);
219 
225  bool isStepDetected();
226 
232  int16_t getStepCount();
233 
239  void enableTapDetection(bool enable);
240 
246  bool isTapDetected();
247 
252  void getNextTap();
253 
257  void lock();
258 
262  void unlock();
263 
267  void waitForResponse();
268 
273  void proceed();
274 
281  void setResults(uint8_t* buf, int length);
282 
286  void processResponse();
287 
288  private:
289  mraa_firmata_context m_firmata;
290  pthread_mutex_t m_responseLock;
291  pthread_cond_t m_responseCond;
292  char* m_results;
293 
294  std::queue<IMUDataItem*> m_shockData;
295  std::queue<int> m_stepData;
296  std::queue<IMUDataItem*> m_tapData;
297 
298  int16_t m_accel[3];
299  int16_t m_gyro[3];
300  int16_t m_motion[6];
301 
302  int16_t m_axis;
303  int16_t m_direction;
304 };
305 
306 }
int16_t * getGyro()
Definition: curieimu.cpp:183
void lock()
Definition: curieimu.cpp:70
void setResults(uint8_t *buf, int length)
Definition: curieimu.cpp:95
void updateMotion()
Definition: curieimu.cpp:267
void processResponse()
Definition: curieimu.cpp:128
bool isStepDetected()
Definition: curieimu.cpp:404
int16_t getStepCount()
Definition: curieimu.cpp:410
void proceed()
Definition: curieimu.cpp:89
bool isTapDetected()
Definition: curieimu.cpp:443
bool isShockDetected()
Definition: curieimu.cpp:364
void enableStepCounter(bool enable)
Definition: curieimu.cpp:382
int16_t getAccelY()
Definition: curieimu.cpp:171
int16_t getAccelX()
Definition: curieimu.cpp:165
void enableShockDetection(bool enable)
Definition: curieimu.cpp:342
CurieImu(int subplatform_offset=512)
Definition: curieimu.cpp:41
int16_t getTemperature()
Definition: curieimu.cpp:303
void waitForResponse()
Definition: curieimu.cpp:82
Definition: curieimu.hpp:53
void unlock()
Definition: curieimu.cpp:76
int16_t * getAccel()
Definition: curieimu.cpp:159
void updateAccel()
Definition: curieimu.cpp:213
~CurieImu()
Definition: curieimu.cpp:63
void updateGyro()
Definition: curieimu.cpp:240
void getNextTap()
Definition: curieimu.cpp:449
int16_t getDirection()
Definition: curieimu.cpp:336
int16_t getAxis()
Definition: curieimu.cpp:330
void enableTapDetection(bool enable)
Definition: curieimu.cpp:421
int16_t getGyroY()
Definition: curieimu.cpp:195
API for the Curie IMU via Firmata.
Definition: curieimu.hpp:76
int16_t getGyroX()
Definition: curieimu.cpp:189
void getNextShock()
Definition: curieimu.cpp:370
int16_t getGyroZ()
Definition: curieimu.cpp:201
int16_t * getMotion()
Definition: curieimu.cpp:207
int16_t getAccelZ()
Definition: curieimu.cpp:177