Control MIDI in Ableton Live with a MYO armband
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

DeviceListener.hpp 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. // Copyright (C) 2013-2014 Thalmic Labs Inc.
  2. // Distributed under the Myo SDK license agreement. See LICENSE.txt for details.
  3. #pragma once
  4. #include <stdint.h>
  5. #include "Pose.hpp"
  6. namespace myo {
  7. class Myo;
  8. template<typename T>
  9. class Quaternion;
  10. template<typename T>
  11. class Vector3;
  12. /// Enumeration identifying a right arm or left arm.
  13. enum Arm {
  14. armLeft = libmyo_arm_left,
  15. armRight = libmyo_arm_right,
  16. armUnknown = libmyo_arm_unknown
  17. };
  18. /// Possible directions for Myo's +x axis relative to a user's arm.
  19. enum XDirection {
  20. xDirectionTowardWrist = libmyo_x_direction_toward_wrist,
  21. xDirectionTowardElbow = libmyo_x_direction_toward_elbow,
  22. xDirectionUnknown = libmyo_x_direction_unknown
  23. };
  24. /// Possible warmup states for a Myo.
  25. enum WarmupState {
  26. warmupStateUnknown = libmyo_warmup_state_unknown,
  27. warmupStateCold = libmyo_warmup_state_cold,
  28. warmupStateWarm = libmyo_warmup_state_warm,
  29. };
  30. /// Possible warmup results for a Myo.
  31. enum WarmupResult {
  32. warmupResultUnknown = libmyo_warmup_result_unknown,
  33. warmupResultSuccess = libmyo_warmup_result_success,
  34. warmupResultFailedTimeout = libmyo_warmup_result_failed_timeout,
  35. };
  36. /// Firmware version of Myo.
  37. struct FirmwareVersion {
  38. unsigned int firmwareVersionMajor; ///< Myo's major version must match the required major version.
  39. unsigned int firmwareVersionMinor; ///< Myo's minor version must match the required minor version.
  40. unsigned int firmwareVersionPatch; ///< Myo's patch version must greater or equal to the required patch version.
  41. unsigned int firmwareVersionHardwareRev; ///< Myo's hardware revision; not used to detect firmware version mismatch.
  42. };
  43. /// A DeviceListener receives events about a Myo.
  44. /// @see Hub::addListener()
  45. class DeviceListener {
  46. public:
  47. virtual ~DeviceListener() {}
  48. /// Called when a Myo has been paired.
  49. /// @param myo The Myo for this event.
  50. /// @param timestamp The timestamp of when the event is received by the SDK. Timestamps are 64 bit unsigned
  51. /// integers that correspond to a number of microseconds since some (unspecified) period in time. Timestamps
  52. /// are monotonically non-decreasing.
  53. /// @param firmwareVersion The firmware version of \a myo.
  54. virtual void onPair(Myo* myo, uint64_t timestamp, FirmwareVersion firmwareVersion) {}
  55. /// Called when a Myo has been unpaired.
  56. /// @param myo The Myo for this event.
  57. /// @param timestamp The timestamp of when the event is received by the SDK. Timestamps are 64 bit unsigned
  58. /// integers that correspond to a number of microseconds since some (unspecified) period in time. Timestamps
  59. /// are monotonically non-decreasing.
  60. virtual void onUnpair(Myo* myo, uint64_t timestamp) {}
  61. /// Called when a paired Myo has been connected.
  62. /// @param myo The Myo for this event.
  63. /// @param timestamp The timestamp of when the event is received by the SDK. Timestamps are 64 bit unsigned
  64. /// integers that correspond to a number of microseconds since some (unspecified) period in time. Timestamps
  65. /// are monotonically non-decreasing.
  66. /// @param firmwareVersion The firmware version of \a myo.
  67. virtual void onConnect(Myo* myo, uint64_t timestamp, FirmwareVersion firmwareVersion) {}
  68. /// Called when a paired Myo has been disconnected.
  69. /// @param myo The Myo for this event.
  70. /// @param timestamp The timestamp of when the event is received by the SDK. Timestamps are 64 bit unsigned
  71. /// integers that correspond to a number of microseconds since some (unspecified) period in time. Timestamps
  72. /// are monotonically non-decreasing.
  73. virtual void onDisconnect(Myo* myo, uint64_t timestamp) {}
  74. /// Called when a paired Myo recognizes that it is on an arm.
  75. /// @param myo The Myo for this event.
  76. /// @param timestamp The timestamp of when the event is received by the SDK. Timestamps are 64 bit unsigned
  77. /// integers that correspond to a number of microseconds since some (unspecified) period in time. Timestamps
  78. /// are monotonically non-decreasing.
  79. /// @param arm The identified Arm of \a myo.
  80. /// @param xDirection The identified XDirection of \a myo.
  81. /// @param rotation The estimated rotation of Myo on the user's arm after a sync.
  82. /// @param warmupState The warmup state of \a myo. If \a warmupState is equal to WarmupState::warmupStateCold,
  83. /// onWarmupCompleted() will be called when the warmup period has completed.
  84. virtual void onArmSync(Myo* myo, uint64_t timestamp, Arm arm, XDirection xDirection, float rotation,
  85. WarmupState warmupState) {}
  86. /// Called when a paired Myo is moved or removed from the arm.
  87. /// @param myo The Myo for this event.
  88. /// @param timestamp The timestamp of when the event is received by the SDK. Timestamps are 64 bit unsigned
  89. /// integers that correspond to a number of microseconds since some (unspecified) period in time. Timestamps
  90. /// are monotonically non-decreasing.
  91. virtual void onArmUnsync(Myo* myo, uint64_t timestamp) {}
  92. /// Called when a paired Myo becomes unlocked.
  93. /// @param myo The Myo for this event.
  94. /// @param timestamp The timestamp of when the event is received by the SDK. Timestamps are 64 bit unsigned
  95. /// integers that correspond to a number of microseconds since some (unspecified) period in time. Timestamps
  96. /// are monotonically non-decreasing.
  97. virtual void onUnlock(Myo* myo, uint64_t timestamp) {}
  98. /// Called when a paired Myo becomes locked.
  99. /// @param myo The Myo for this event.
  100. /// @param timestamp The timestamp of when the event is received by the SDK. Timestamps are 64 bit unsigned
  101. /// integers that correspond to a number of microseconds since some (unspecified) period in time. Timestamps
  102. /// are monotonically non-decreasing.
  103. virtual void onLock(Myo* myo, uint64_t timestamp) {}
  104. /// Called when a paired Myo has provided a new pose.
  105. /// @param myo The Myo for this event.
  106. /// @param timestamp The timestamp of when the event is received by the SDK. Timestamps are 64 bit unsigned
  107. /// integers that correspond to a number of microseconds since some (unspecified) period in time. Timestamps
  108. /// are monotonically non-decreasing.
  109. /// @param pose The identified Pose of \a myo.
  110. virtual void onPose(Myo* myo, uint64_t timestamp, Pose pose) {}
  111. /// Called when a paired Myo has provided new orientation data.
  112. /// @param myo The Myo for this event.
  113. /// @param timestamp The timestamp of when the event is received by the SDK. Timestamps are 64 bit unsigned
  114. /// integers that correspond to a number of microseconds since some (unspecified) period in time. Timestamps
  115. /// are monotonically non-decreasing.
  116. /// @param rotation The orientation data of \a myo, as a Quaternion.
  117. virtual void onOrientationData(Myo* myo, uint64_t timestamp, const Quaternion<float>& rotation) {}
  118. /// Called when a paired Myo has provided new accelerometer data in units of g.
  119. /// @param myo The Myo for this event.
  120. /// @param timestamp The timestamp of when the event is received by the SDK. Timestamps are 64 bit unsigned
  121. /// integers that correspond to a number of microseconds since some (unspecified) period in time. Timestamps
  122. /// are monotonically non-decreasing.
  123. /// @param accel The accelerometer data of \a myo, in units of g.
  124. virtual void onAccelerometerData(Myo* myo, uint64_t timestamp, const Vector3<float>& accel) {}
  125. /// Called when a paired Myo has provided new gyroscope data in units of deg/s.
  126. /// @param myo The Myo for this event.
  127. /// @param timestamp The timestamp of when the event is received by the SDK. Timestamps are 64 bit unsigned
  128. /// integers that correspond to a number of microseconds since some (unspecified) period in time. Timestamps
  129. /// are monotonically non-decreasing.
  130. /// @param gyro The gyroscope data of \a myo, in units of deg/s.
  131. virtual void onGyroscopeData(Myo* myo, uint64_t timestamp, const Vector3<float>& gyro) {}
  132. /// Called when a paired Myo has provided a new RSSI value.
  133. /// @param myo The Myo for this event.
  134. /// @param timestamp The timestamp of when the event is received by the SDK. Timestamps are 64 bit unsigned
  135. /// integers that correspond to a number of microseconds since some (unspecified) period in time. Timestamps
  136. /// are monotonically non-decreasing.
  137. /// @param rssi The RSSI (received signal strength indication) of \a myo.
  138. /// @see Myo::requestRssi() to request an RSSI value from the Myo.
  139. virtual void onRssi(Myo* myo, uint64_t timestamp, int8_t rssi) {}
  140. /// Called when a paired Myo receives an battery level update.
  141. /// Updates occur when the battery level changes and when the battery level is explicitly requested.
  142. /// @param myo The Myo for this event.
  143. /// @param timestamp The timestamp of when the event is received by the SDK. Timestamps are 64 bit unsigned
  144. /// integers that correspond to a number of microseconds since some (unspecified) period in time. Timestamps
  145. /// are monotonically non-decreasing.
  146. /// @param level battery level reported by the myo the value is a number from 0 to 100 representing the percentage
  147. /// of battery life remaining.
  148. virtual void onBatteryLevelReceived(myo::Myo* myo, uint64_t timestamp, uint8_t level) {}
  149. /// Called when a paired Myo has provided new EMG data.
  150. /// @param myo The Myo for this event.
  151. /// @param timestamp The timestamp of when the event is received by the SDK. Timestamps are 64 bit unsigned
  152. /// integers that correspond to a number of microseconds since some (unspecified) period in time. Timestamps
  153. /// are monotonically non-decreasing.
  154. /// @param emg An array of 8 elements, each corresponding to one sensor.
  155. virtual void onEmgData(myo::Myo* myo, uint64_t timestamp, const int8_t* emg) {}
  156. /// Called when the warmup period for a Myo has completed.
  157. /// @param myo The Myo for this event.
  158. /// @param timestamp The timestamp of when the event is received by the SDK. Timestamps are 64 bit unsigned
  159. /// integers that correspond to a number of microseconds since some (unspecified) period in time. Timestamps
  160. /// are monotonically non-decreasing.
  161. /// @param warmupResult The warmup result of \a myo.
  162. virtual void onWarmupCompleted(myo::Myo* myo, uint64_t timestamp, WarmupResult warmupResult) {}
  163. /// @cond LIBMYO_INTERNALS
  164. virtual void onOpaqueEvent(libmyo_event_t event) {}
  165. /// @endcond
  166. };
  167. } // namespace myo