upm  0.8.0
Sensor/Actuator repository for libmraa (v1.1.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 namespace upm {
32 
57 #define FIRMATA_START_SYSEX 0xF0
58 #define FIRMATA_END_SYSEX 0xF7
59 #define FIRMATA_CURIE_IMU 0x11
60 #define FIRMATA_CURIE_IMU_READ_ACCEL 0x00
61 #define FIRMATA_CURIE_IMU_READ_GYRO 0x01
62 #define FIRMATA_CURIE_IMU_READ_TEMP 0x02
63 #define FIRMATA_CURIE_IMU_SHOCK_DETECT 0x03
64 #define FIRMATA_CURIE_IMU_STEP_COUNTER 0x04
65 #define FIRMATA_CURIE_IMU_TAP_DETECT 0x05
66 #define FIRMATA_CURIE_IMU_READ_MOTION 0x06
67 
68 #define X 0
69 #define Y 1
70 #define Z 2
71 
72 struct IMUDataItem {
73  int axis;
74  int direction;
75 };
76 
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 }
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:72
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
Definition: curieimu.hpp:77
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