Myo Scol plugin
sMyo.h
1 /*
2 -----------------------------------------------------------------------------
3 This source file is part of OpenSpace3D
4 For the latest info, see http://www.openspace3d.com
5 
6 Copyright (c) 2012 I-maginer
7 
8 This program is free software; you can redistribute it and/or modify it under
9 the terms of the GNU Lesser General Public License as published by the Free Software
10 Foundation; either version 2 of the License, or (at your option) any later
11 version.
12 
13 This program is distributed in the hope that it will be useful, but WITHOUT
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
16 
17 You should have received a copy of the GNU Lesser General Public License along with
18 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
19 Place - Suite 330, Boston, MA 02111-1307, USA, or go to
20 http://www.gnu.org/copyleft/lesser.txt
21 
22 -----------------------------------------------------------------------------
23 */
24 
25 #ifndef S_LEAPMOTION_H
26 #define S_LEAPMOTION_H
27 
28 #include <scolPlugin.h>
29 #include <boost/thread/thread.hpp>
30 #include <boost/bind.hpp>
31 #include <set>
32 
33 #include <myo/myo.hpp>
34 
35 using namespace myo;
36 
40 class SCbData
41 {
42 public:
43  Vector3<float> svec;
44  Quaternion<float> quat;
45  Pose pose;
46 protected:
47 private:
48 
49 public:
50  SCbData()
51  {
52  pose = Pose(myo::Pose::unknown);
53  };
54 
55  ~SCbData() {};
56 protected:
57 private:
58 };
59 
63 class SMyo
64 {
65 public:
66 
67 protected:
68  bool mConnected;
69 
70 private:
71  bool mTerminate;
72  Myo* mMyoInstance;
73  Quaternion<float> mPrevQuat;
74  XDirection mDirection;
75 
76 public:
80  SMyo();
81 
85  ~SMyo();
86 
87  void Connect();
88  void Disconnect();
89 
90  myo::Myo* GetMyoInstance();
91  void SetMyoInstance(myo::Myo* myoInstance);
92  void SetDirection(XDirection direction);
93  XDirection GetDirection();
94  void Vibrate(myo::Myo::VibrationType type);
95  void SendPose(myo::Pose pose);
96  void SendOrientation(myo::Quaternion<float> quat);
97  void SendAccel(myo::Vector3<float> vec);
98 protected:
99 private:
100 };
101 
106 class SMyoManager : public DeviceListener
107 {
108  public:
109  typedef std::set<SMyo*> MyoList;
110  typedef std::set<myo::Myo*> MyoAvailables;
111  public:
112  protected:
113 
114  private:
115  static SMyoManager* _singleton;
116  myo::Hub* mMyoHub;
117  boost::thread mThread;
118  boost::shared_mutex mMutex;
119  bool mTerminate;
120  MyoList mMyoList;
121  MyoAvailables mMyoAvailable;
122 
123  public:
124  static SMyoManager* GetInstance();
125  static void Kill();
126 
127  SMyo* AddMyoInstance();
128  void RemoveMyoInstance(SMyo* myoInstance);
129  protected:
130  ~SMyoManager();
131 
132  virtual void onPair (Myo *myo, uint64_t timestamp, FirmwareVersion firmwareVersion);
133  virtual void onConnect (Myo *myo, uint64_t timestamp, FirmwareVersion firmwareVersion);
134  virtual void onDisconnect (Myo *myo, uint64_t timestamp);
135  virtual void onPose (Myo *myo, uint64_t timestamp, Pose pose);
136  virtual void onOrientationData (Myo *myo, uint64_t timestamp, const Quaternion<float> &rotation);
137  virtual void onAccelerometerData (Myo *myo, uint64_t timestamp, const Vector3<float> &accel);
138  virtual void onGyroscopeData (Myo *myo, uint64_t timestamp, const Vector3<float> &gyro);
139  virtual void onRssi (Myo *myo, uint64_t timestamp, int8_t rssi);
140  virtual void onArmSync(Myo* myo, uint64_t timestamp, Arm arm, XDirection xDirection);
141  virtual void onArmUnsync(Myo* myo, uint64_t timestamp);
142  virtual void onUnlock(Myo* myo, uint64_t timestamp);
143  virtual void onLock(Myo* myo, uint64_t timestamp);
144 
145  private:
146  SMyoManager();
147  void UpdateThread();
148 };
149 
150 
151 #endif
Definition: sMyo.h:63
Definition: sMyo.h:40