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.

Hub.hpp 3.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 <vector>
  5. #include <myo/libmyo.h>
  6. namespace myo {
  7. class Myo;
  8. class DeviceListener;
  9. /// @brief A Hub provides access to one or more Myo instances.
  10. class Hub {
  11. public:
  12. /// Construct a hub.
  13. /// \a applicationIdentifier must follow a reverse domain name format (ex. com.domainname.appname). Application
  14. /// identifiers can be formed from the set of alphanumeric ASCII characters (a-z, A-Z, 0-9). The hyphen (-) and
  15. /// underscore (_) characters are permitted if they are not adjacent to a period (.) character (i.e. not at the
  16. /// start or end of each segment), but are not permitted in the top-level domain. Application identifiers must have
  17. /// three or more segments. For example, if a company's domain is example.com and the application is named
  18. /// hello-world, one could use "com.example.hello-world" as a valid application identifier. \a applicationIdentifier
  19. /// can be an empty string.
  20. /// Throws an exception of type std::invalid_argument if \a applicationIdentifier is not in the proper reverse
  21. /// domain name format or is longer than 255 characters.
  22. /// Throws an exception of type std::runtime_error if the hub initialization failed for some reason, typically
  23. /// because Myo Connect is not running and a connection can thus not be established.
  24. Hub(const std::string& applicationIdentifier = "");
  25. /// Deallocate any resources associated with a Hub.
  26. /// This will cause all Myo instances retrieved from this Hub to become invalid.
  27. ~Hub();
  28. /// Wait for a Myo to become paired, or time out after \a timeout_ms milliseconds if provided.
  29. /// If \a timeout_ms is zero, this function blocks until a Myo is found.
  30. /// This function must not be called concurrently with run() or runOnce().
  31. Myo* waitForMyo(unsigned int milliseconds = 0);
  32. /// Register a listener to be called when device events occur.
  33. void addListener(DeviceListener* listener);
  34. /// Remove a previously registered listener.
  35. void removeListener(DeviceListener* listener);
  36. /// Locking policies supported by Myo.
  37. enum LockingPolicy {
  38. lockingPolicyNone = libmyo_locking_policy_none,
  39. lockingPolicyStandard = libmyo_locking_policy_standard
  40. };
  41. /// Set the locking policy for Myos connected to the Hub.
  42. void setLockingPolicy(LockingPolicy lockingPolicy);
  43. /// Run the event loop for the specified duration (in milliseconds).
  44. void run(unsigned int duration_ms);
  45. /// Run the event loop until a single event occurs, or the specified duration (in milliseconds) has elapsed.
  46. void runOnce(unsigned int duration_ms);
  47. /// @cond MYO_INTERNALS
  48. /// Return the internal libmyo object corresponding to this hub.
  49. libmyo_hub_t libmyoObject();
  50. protected:
  51. void onDeviceEvent(libmyo_event_t event);
  52. Myo* lookupMyo(libmyo_myo_t opaqueMyo) const;
  53. Myo* addMyo(libmyo_myo_t opaqueMyo);
  54. libmyo_hub_t _hub;
  55. std::vector<Myo*> _myos;
  56. std::vector<DeviceListener*> _listeners;
  57. /// @endcond
  58. private:
  59. // Not implemented
  60. Hub(const Hub&);
  61. Hub& operator=(const Hub&);
  62. };
  63. /// @example hello-myo.cpp
  64. /// @example multiple-myos.cpp
  65. /// @example emg-data-sample.cpp
  66. } // namespace myo
  67. #include "impl/Hub_impl.hpp"