MyoLinux
myoclient.h
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2  * License, v. 2.0. If a copy of the MPL was not distributed with this
3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4 
5 #pragma once
6 #ifndef MYOLINUX_MYOCLIENT_H
7 #define MYOLINUX_MYOCLIENT_H
8 
9 #include "myolinux.h"
10 #include "gattclient.h"
11 #include "serial.h"
12 #include "myoapi.h"
13 
14 #include <cinttypes>
15 #include <map>
16 #include <memory>
17 
18 namespace MYOLINUX_NAMESPACE {
19 
22 namespace myo {
23 
26 
33 
36 class Client {
37 public:
38  Client(const Serial &);
39  Client(const gatt::Client &);
40 
41  void discover(std::function<bool(std::int8_t, Address, Buffer)>);
42  void connect(const Address &);
43  void connect(const std::string &);
44  void connect();
45  bool connected();
46  Address address();
47  void disconnect();
48 
49  FwInfo info();
50  FwVersion firmwareVersion();
51 
52  void vibrate(const Vibration);
53  void setMode(const EmgMode, const ImuMode, const ClassifierMode);
54  void setSleepMode(const SleepMode);
55 
56  std::string deviceName();
57 
58  void onEmg(const std::function<void(EmgSample)> &);
59  void onImu(const std::function<void(OrientationSample, AccelerometerSample, GyroscopeSample)> &);
60  void listen();
61 
62 private:
63  void enable_notifications();
64 
65  gatt::Client client;
66  std::function<void(EmgSample)> emg_callback;
67  std::function<void(OrientationSample, AccelerometerSample, GyroscopeSample)> imu_callback;
68 };
69 
70 }
71 }
72 
73 #undef PACKED
74 #endif // MYOLINUX_Client_H
std::array< std::int16_t, 3 > GyroscopeSample
GyroscopeSample Gyroscope data.
Definition: myoapi.h:133
std::array< std::int16_t, 3 > AccelerometerSample
AccelerometerSample Accelerometer data.
Definition: myoapi.h:128
gatt::Address Address
Address of the device.
Definition: myoclient.h:25
Class for communication using the GATT protocol.
Definition: gattclient.h:42
std::array< std::int16_t, 4 > OrientationSample
OrientationSample Orientation data, represented as a unit quaternion.
Definition: myoapi.h:123
std::vector< unsigned char > Buffer
Buffer used for packing and unpacking packets.
Definition: buffer.h:16
Version information for the Myo firmware.
Definition: myoapi.h:111
Class for communication with the Myo device.
Definition: myoclient.h:36
ImuMode
IMU modes.
Definition: myoapi.h:66
Vibration
Kinds of vibrations.
Definition: myoapi.h:87
std::array< std::uint8_t, 6 > Address
Address of the device.
Definition: gattclient.h:32
Various parameters that may affect the behaviour of this Myo armband.
Definition: myoapi.h:96
Class for communication over the serial port.
Definition: serial.h:19
SleepMode
Sleep modes.
Definition: myoapi.h:81
EmgMode
EMG modes.
Definition: myoapi.h:59
Exception thrown when the device disconnects.
Definition: gattclient.h:38
std::array< std::int8_t, 8 > EmgSample
EmgSample.
Definition: myoapi.h:119
ClassifierMode
Classifier modes.
Definition: myoapi.h:75