MyoLinux
Public Member Functions | List of all members
Client Class Reference

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...
 

Detailed Description

Class for communication with the Myo device.

This class depends on a gatt::Client instance for issuing GAP/GATT commands to the device.

Constructor & Destructor Documentation

§ Client() [1/2]

Client ( const Serial socket)

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.

Parameters
socketthe serial socket for communication

§ Client() [2/2]

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.

Parameters
clientthe gatt::Client instance

Member Function Documentation

§ address()

Address address ( )

Returns the address of the connected device.

If the client is not connected an exception is thrown.

Returns
the address of the device

§ connect() [1/3]

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.

Parameters
addressaddress of the device

§ connect() [2/3]

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

Parameters
strstring form of the address

§ connect() [3/3]

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.

§ connected()

bool connected ( )

Checks whether the client is connected.

Returns
is the client connected

§ deviceName()

std::string deviceName ( )

Read the device name.

Returns
device name

§ disconnect()

void disconnect ( )

Disconnect the client.

§ discover()

void discover ( std::function< bool(std::int8_t, Address, Buffer)>  callback)

Discovers the nearby Myo devices.

The functionality is the same as in gatt::Client::discover, except that the non-Myo devices are filtered out.

Parameters
callback

§ firmwareVersion()

FwVersion firmwareVersion ( )

Get the firmware version.

Returns
firmware version

§ info()

FwInfo info ( )

Get the device info.

Returns
device info

§ listen()

void listen ( )

Wait for the value event and call the appropriate callback.

Exceptions
myo::DisconnectedException

§ onEmg()

void onEmg ( const std::function< void(EmgSample)> &  callback)

Set the callback for the EMG value event.

The events are sent at 200 Hz.

Parameters
callback

§ onImu()

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.

Parameters
callback

§ setMode()

void setMode ( const EmgMode  emg_mode,
const ImuMode  imu_mode,
const ClassifierMode  classifier_mode 
)

Set the EMG and IMU modes.

Parameters
emg_modeEMG mode
imu_modeIMU mode
classifier_modeclassifier mode

§ setSleepMode()

void setSleepMode ( const SleepMode  sleep_mode)

Set the sleep mode.

Parameters
sleep_modesleep mode
See also
DisconnectedException

§ vibrate()

void vibrate ( const Vibration  vibration_type)

Vibrate.

Parameters
vibration_typevibration type

The documentation for this class was generated from the following files: