upm  1.5.0
Sensor/Actuator repository for libmraa (v1.8.0)
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 }
Definition: curieimu.hpp:53
Definition: a110x.hpp:29
API for the Curie IMU via Firmata.
Definition: curieimu.hpp:76