MyoLinux
|
Class for communication with the Myo device. More...
#include <myoclient.h>
Public Member Functions | |
Client (const Serial &) | |
Creates an object for communication with a Myo device from a serial socket. More... | |
Client (const gatt::Client &) | |
Creates an object for communication with a Myo device from a gatt::Client instance. More... | |
void | discover (std::function< bool(std::int8_t, Address, Buffer)>) |
Discovers the nearby Myo devices. More... | |
void | connect (const Address &) |
Connect to the device with the specified address. More... | |
void | connect (const std::string &) |
Connect to the device with the specified address in string form. More... | |
void | connect () |
Auto-connect the client to the first device. More... | |
bool | connected () |
Checks whether the client is connected. More... | |
Address | address () |
Returns the address of the connected device. More... | |
void | disconnect () |
Disconnect the client. More... | |
FwInfo | info () |
Get the device info. More... | |
FwVersion | firmwareVersion () |
Get the firmware version. More... | |
void | vibrate (const Vibration) |
Vibrate. More... | |
void | setMode (const EmgMode, const ImuMode, const ClassifierMode) |
Set the EMG and IMU modes. More... | |
void | setSleepMode (const SleepMode) |
Set the sleep mode. More... | |
std::string | deviceName () |
Read the device name. More... | |
void | onEmg (const std::function< void(EmgSample)> &) |
Set the callback for the EMG value event. More... | |
void | onImu (const std::function< void(OrientationSample, AccelerometerSample, GyroscopeSample)> &) |
Set the callback for the IMU value event. More... | |
void | listen () |
Wait for the value event and call the appropriate callback. More... | |
Class for communication with the Myo device.
This class depends on a gatt::Client instance for issuing GAP/GATT commands to the device.
Creates an object for communication with a Myo device from a serial socket.
This constructor creates the entire client stack internally. This is the prefered constructor for general use.
socket | the serial socket for communication |
Client | ( | const gatt::Client & | client | ) |
Creates an object for communication with a Myo device from a gatt::Client instance.
For debugging purposes the gatt::Client instance that has been passed to this constructor may still be used for issuing raw GATT commands, if the client has been connected beforehand. This limitation exists because a copy of the instance is stored and the call to the gatt::Client::connect alters the state of the object.
client | the gatt::Client instance |
Address address | ( | ) |
Returns the address of the connected device.
If the client is not connected an exception is thrown.
void connect | ( | const Address & | address | ) |
Connect to the device with the specified address.
Reviving the connection is only possible if no data has been sent i.e. setMode has not yet been called, otherwise the device will disconnect automatically when the program exits. There will be a short window before the disconnect in which the connection cannot be establised. To avoid this always call the disconnect method before exiting the program or add sleep(1) before the connect call.
address | address of the device |
void connect | ( | const std::string & | str | ) |
Connect to the device with the specified address in string form.
The address is represented as six hexadecimal digis separated with colons. This is also the format used by the bluetoothctl tool.
Example: 01:23:E2:D4:4D:66
str | string form of the address |
void connect | ( | ) |
Auto-connect the client to the first device.
The client scans for devices and connects to the first one it finds. The address of the device that the client connected to can then be found using the Client::address method.
bool connected | ( | ) |
Checks whether the client is connected.
std::string deviceName | ( | ) |
Read the device name.
void disconnect | ( | ) |
Disconnect the client.
Discovers the nearby Myo devices.
The functionality is the same as in gatt::Client::discover, except that the non-Myo devices are filtered out.
callback |
FwVersion firmwareVersion | ( | ) |
Get the firmware version.
FwInfo info | ( | ) |
Get the device info.
void listen | ( | ) |
Wait for the value event and call the appropriate callback.
myo::DisconnectedException |
void onEmg | ( | const std::function< void(EmgSample)> & | callback | ) |
Set the callback for the EMG value event.
The events are sent at 200 Hz.
callback |
void onImu | ( | const std::function< void(OrientationSample, AccelerometerSample, GyroscopeSample)> & | callback | ) |
Set the callback for the IMU value event.
The events are sent at 50 Hz. The values are provided as received from the device. To obtain the actual values they must be scaled by the appropriate scaling factor, see OrientationSample, AccelerometerSample, GyroscopeSample.
callback |
void setMode | ( | const EmgMode | emg_mode, |
const ImuMode | imu_mode, | ||
const ClassifierMode | classifier_mode | ||
) |
Set the EMG and IMU modes.
emg_mode | EMG mode |
imu_mode | IMU mode |
classifier_mode | classifier mode |
void setSleepMode | ( | const SleepMode | sleep_mode | ) |
void vibrate | ( | const Vibration | vibration_type | ) |
Vibrate.
vibration_type | vibration type |