upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.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 <pthread.h>
30 #include <queue>
31 
32 #define FIRMATA_START_SYSEX 0xF0
33 #define FIRMATA_END_SYSEX 0xF7
34 #define FIRMATA_CURIE_IMU 0x11
35 #define FIRMATA_CURIE_IMU_READ_ACCEL 0x00
36 #define FIRMATA_CURIE_IMU_READ_GYRO 0x01
37 #define FIRMATA_CURIE_IMU_READ_TEMP 0x02
38 #define FIRMATA_CURIE_IMU_SHOCK_DETECT 0x03
39 #define FIRMATA_CURIE_IMU_STEP_COUNTER 0x04
40 #define FIRMATA_CURIE_IMU_TAP_DETECT 0x05
41 #define FIRMATA_CURIE_IMU_READ_MOTION 0x06
42 
43 #define X 0
44 #define Y 1
45 #define Z 2
46 
47 namespace upm {
54 struct IMUDataItem {
55  int axis;
56  int direction;
57 };
58 
77 class CurieImu {
78  public:
79 
85  CurieImu (int subplatform_offset=512);
86 
90  ~CurieImu();
91 
95  void updateAccel();
96 
100  void updateGyro();
101 
106  void updateMotion();
107 
113  int16_t* getAccel();
114 
120  int16_t getAccelX();
121 
127  int16_t getAccelY();
128 
134  int16_t getAccelZ();
135 
141  int16_t* getGyro();
142 
148  int16_t getGyroX();
149 
155  int16_t getGyroY();
156 
162  int16_t getGyroZ();
163 
169  int16_t getTemperature();
170 
178  int16_t* getMotion();
179 
185  int16_t getAxis();
186 
192  int16_t getDirection();
193 
199  void enableShockDetection(bool enable);
200 
206  bool isShockDetected();
207 
212  void getNextShock();
213 
219  void enableStepCounter(bool enable);
220 
226  bool isStepDetected();
227 
233  int16_t getStepCount();
234 
240  void enableTapDetection(bool enable);
241 
247  bool isTapDetected();
248 
253  void getNextTap();
254 
258  void lock();
259 
263  void unlock();
264 
268  void waitForResponse();
269 
274  void proceed();
275 
282  void setResults(uint8_t* buf, int length);
283 
287  void processResponse();
288 
289  private:
290  mraa_firmata_context m_firmata;
291  pthread_mutex_t m_responseLock;
292  pthread_cond_t m_responseCond;
293  char* m_results;
294 
295  std::queue<IMUDataItem*> m_shockData;
296  std::queue<int> m_stepData;
297  std::queue<IMUDataItem*> m_tapData;
298 
299  int16_t m_accel[3];
300  int16_t m_gyro[3];
301  int16_t m_motion[6];
302 
303  int16_t m_axis;
304  int16_t m_direction;
305 };
306 
307 }
Definition: curieimu.hpp:54
C++ API wrapper for the bh1749 driver.
Definition: a110x.hpp:29
API for the Curie IMU via Firmata.
Definition: curieimu.hpp:77