Git Product home page Git Product logo

myolinux's Introduction

MyoLinux

License: MPL 2.0

C++ library for interfacing with the Myo armband on Linux.

Features

  • Full BLED112 protocol implementation (based on jrowberg/bglib)
  • GAP/GATT wrapper
    • discovering devices
    • discovering characteristics
    • reading/writing attributes
    • listening to notifications
  • myohw protocol (based on thalmiclabs/myo-bluetooth)
    • reading info
    • issuing commands (partial)
    • listening to IMU and EMG events

Documentation

The documentation can be accessed online here (clear the browser cache if it doesn't match the source) or generated using Doxygen by running:

doxygen

Installation

The binary form of the library can be downloaded here. It is available in deb, rpm and tarball formats for the x86-64 arhitecture. The library can also be installed the old fashioned way by compiling it from source. I will cover two installation methods and provide a minimal example to get you started.

Compiling from source

First thing you will need is the source code, you can download it by clicking here or by cloning the repository:

git clone https://github.com/brokenpylons/MyoLinux.git

The only nonstandard dependency of this project is CMake 2.8 (at least) which may already be installed by your distribution, if not install it. If you plan to modify the library you might also need Python 3.6 for auto-generating the BLED112 protocol implementation, however this step is otherwise not needed as the generated code is already included in the repository.

For an out-of-source build first create a directory inside the project source tree and swich to it:

mkdir build
cd build

Call CMake to generate the makefile and call Make to build the library. Finally install the library to the system (this will probably require the root permissions):

cmake ..
make
make install

CMake external project

Include this into your CMakeLists.txt and add the imported target as a dependency.

include(ExternalProject)

ExternalProject_Add(MyoLinux
    GIT_REPOSITORY    https://github.com/brokenpylons/MyoLinux.git
    CMAKE_ARGS        -DCMAKE_INSTALL_PREFIX=${CMAKE_CURRENT_BINARY_DIR}/myolinux)

set(myolinux_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/myolinux/include)
set(myolinux_LIB_DIR ${CMAKE_CURRENT_BINARY_DIR}/myolinux/lib)

add_library(myolinux SHARED IMPORTED)
set_target_properties(myolinux PROPERTIES IMPORTED_LOCATION ${myolinux_LIB_DIR}/libmyolinux.so)

Example

#include "myolinux/myoclient.h"
#include "myolinux/serial.h"

#include <cinttypes>

using namespace myolinux;

int main()
{
    myo::Client client(Serial{"/dev/ttyACM0", 115200});

    // Autoconnect to the first Myo device
    client.connect();
    if (!client.connected()) {
        return 1;
    }

    // Print device address
    print_address(client.address());

    // Read firmware version
    auto version = client.firmwareVersion();
    std::cout << version.major << "."
        << version.minor << "."
        << version.patch << "."
        << version.hardware_rev << std::endl;

    // Vibrate
    client.vibrate(myo::Vibration::Medium);

    // Read name
    auto name = client.deviceName();
    std::cout << name << std::endl;

    // Set sleep mode (otherwise the device auto disconnects after a while)
    client.setSleepMode(myo::SleepMode::NeverSleep);

    // Read EMG and IMU
    client.setMode(myo::EmgMode::SendEmg, myo::ImuMode::SendData, myo::ClassifierMode::Disabled);

    client.onEmg([](myo::EmgSample sample)
    {
        for (std::size_t i = 0; i < 8; i++) {
            std::cout << static_cast<int>(sample[i]);
            if (i != 7) {
                std::cout << ", ";
            }
        }
        std::cout << std::endl;
    });

    client.onImu([](myo::OrientationSample ori, myo::AccelerometerSample acc, myo::GyroscopeSample gyr)
    {
        std::cout << ori[0] << ", " << ori[1] << ", " << ori[2] << ", " <<  ori[3] << std::endl;
        std::cout << acc[0] << ", " << acc[1] << ", " << acc[2] << std::endl;
        std::cout << gyr[0] << ", " << gyr[1] << ", " << gyr[2] << std::endl;
    });

    for (int i = 0; i < 100; i++) {
        client.listen();
    }

    client.disconnect();
}

Contributing

Please open an issue if you find bugs or any other defficiencies. Pull requests are also wellcome. Note that by contributing to this repository you irrevocably license your work under the MPL 2.0.

Porting

Despite the name, the library might actually also work on Mac and Windows (using Cygwin) without or with minor modifications. If anyone is interested in testing the library on other platforms please open an issue and report your findings.

License

This repository is placed under the MPL 2.0. See LICENSE for more details.

myolinux's People

Contributors

brokenpylons avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

myolinux's Issues

Porting to Windows

Hi,

has someone succesfully ported the library to windows?
I had to switch from linux to windows so i tried to use the binary form from the myolinux_1.1.0_x86_64.tar file.

I downloaded and extracted into my project folder, renamed the folder to "myolinux" and included it into my project with cmake as follows:

target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/myolinux/include)
target_link_libraries(${PROJECT_NAME} ${CMAKE_SOURCE_DIR}/myolinux/lib/libmyolinux.so)

without cmake throwing errors, so I can do:

#include "myolinux/myoclient.h"
#include "myolinux/serial.h"

and the compiler finds the files but then i get houndreds of errors from "bleapi.h" as:

\myolinux\bleapi.h(20): error C2079: '__packed__' uses undefined struct 'myolinux::bled112::__attribute__'
\myolinux\bleapi.h(20): error C2146: syntax error: missing ';' before identifier 'Header'
\myolinux\bleapi.h(20): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
\myolinux\bleapi.h(21): error C2275: 'uint8_t': illegal use of this type as an expression
de\myolinux\bleapi.h(21): note: see declaration of 'uint8_t'
\myolinux\bleapi.h(21): error C2146: syntax error: missing ')' before identifier 'length1'
\myolinux\bleapi.h(21): error C2059: syntax error: 'constant'
\myolinux\bleapi.h(22): error C2143: syntax error: missing ';' before ':'
\myolinux\bleapi.h(22): error C2059: syntax error: ':'
\myolinux\bleapi.h(22): error C2059: syntax error: 'constant'
\myolinux\bleapi.h(23): error C2143: syntax error: missing ';' before ':'
\myolinux\bleapi.h(23): error C2059: syntax error: ':'
\myolinux\bleapi.h(23): error C2059: syntax error: 'constant'
\myolinux\bleapi.h(29): error C2270: 'length': modifiers not allowed on nonmember functions
\myolinux\bleapi.h(30): error C2065: 'length1': undeclared identifier
\myolinux\bleapi.h(35): error C2061: syntax error: identifier 'getHeader'
\myolinux\bleapi.h(36): error C2143: syntax error: missing ';' before '{'
\myolinux\bleapi.h(36): error C2447: '{': missing function header (old-style formal list?)
\myolinux\bleapi.h(57): error C2146: syntax error: missing ';' before identifier 'SystemReset'
\myolinux\bleapi.h(57): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
\myolinux\bleapi.h(58): error C2065: 'cls': undeclared identifier
\myolinux\bleapi.h(58): error C2065: 'cmd': undeclared identifier
\myolinux\bleapi.h(58): error C2059: syntax error: ';'
\myolinux\bleapi.h(62): error C2146: syntax error: missing ';' before identifier 'SystemResetResponse'
\myolinux\bleapi.h(62): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
\myolinux\bleapi.h(63): error C2065: 'cls': undeclared identifier
\myolinux\bleapi.h(63): error C2065: 'cmd': undeclared identifier
\myolinux\bleapi.h(63): error C2059: syntax error: ';'
\myolinux\bleapi.h(64): error C2059: syntax error: '}'
\myolinux\bleapi.h(64): error C2143: syntax error: missing ';' before '}'
\myolinux\bleapi.h(66): error C2146: syntax error: missing ';' before identifier 'SystemHello'
\myolinux\bleapi.h(66): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
\myolinux\bleapi.h(67): error C2065: 'cls': undeclared identifier
\myolinux\bleapi.h(67): error C2065: 'cmd': undeclared identifier
\myolinux\bleapi.h(67): error C2059: syntax error: ';'
\myolinux\bleapi.h(68): error C2059: syntax error: '}'
\myolinux\bleapi.h(68): error C2143: syntax error: missing ';' before '}'
\myolinux\bleapi.h(70): error C2146: syntax error: missing ';' before identifier 'SystemHelloResponse'
\myolinux\bleapi.h(70): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
\myolinux\bleapi.h(71): error C2065: 'cls': undeclared identifier
\myolinux\bleapi.h(71): error C2065: 'cmd': undeclared identifier
\myolinux\bleapi.h(71): error C2059: syntax error: ';'
\myolinux\bleapi.h(72): error C2059: syntax error: '}'
\myolinux\bleapi.h(72): error C2143: syntax error: missing ';' before '}'
\myolinux\bleapi.h(74): error C2146: syntax error: missing ';' before identifier 'SystemAddressGet'
\myolinux\bleapi.h(74): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
\myolinux\bleapi.h(75): error C2065: 'cls': undeclared identifier
\myolinux\bleapi.h(75): error C2065: 'cmd': undeclared identifier
\myolinux\bleapi.h(75): error C2059: syntax error: ';'
\myolinux\bleapi.h(76): error C2059: syntax error: '}'
\myolinux\bleapi.h(76): error C2143: syntax error: missing ';' before '}'
\myolinux\bleapi.h(78): error C2146: syntax error: missing ';' before identifier 'SystemAddressGetResponse'
\myolinux\bleapi.h(78): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
\myolinux\bleapi.h(79): error C2065: 'cls': undeclared identifier
\myolinux\bleapi.h(79): error C2065: 'cmd': undeclared identifier
\myolinux\bleapi.h(79): error C2059: syntax error: ';'
\myolinux\bleapi.h(81): error C2059: syntax error: '}'
\myolinux\bleapi.h(81): error C2143: syntax error: missing ';' before '}'
\myolinux\bleapi.h(83): error C2146: syntax error: missing ';' before identifier 'SystemRegWrite'
\myolinux\bleapi.h(83): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
\myolinux\bleapi.h(84): error C2065: 'cls': undeclared identifier
\myolinux\bleapi.h(84): error C2065: 'cmd': undeclared identifier
\myolinux\bleapi.h(84): error C2059: syntax error: ';'
\myolinux\bleapi.h(87): error C2059: syntax error: '}'
\myolinux\bleapi.h(87): error C2143: syntax error: missing ';' before '}'
\myolinux\bleapi.h(89): error C2146: syntax error: missing ';' before identifier 'SystemRegWriteResponse'
\myolinux\bleapi.h(89): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
\myolinux\bleapi.h(90): error C2065: 'cls': undeclared identifier
\myolinux\bleapi.h(90): error C2065: 'cmd': undeclared identifier
\myolinux\bleapi.h(90): error C2059: syntax error: ';'
\myolinux\bleapi.h(92): error C2059: syntax error: '}'
\myolinux\bleapi.h(92): error C2143: syntax error: missing ';' before '}'
\myolinux\bleapi.h(94): error C2146: syntax error: missing ';' before identifier 'SystemRegRead'
\myolinux\bleapi.h(94): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
\myolinux\bleapi.h(95): error C2065: 'cls': undeclared identifier
\myolinux\bleapi.h(95): error C2065: 'cmd': undeclared identifier
\myolinux\bleapi.h(95): error C2059: syntax error: ';'
\myolinux\bleapi.h(97): error C2059: syntax error: '}'
\myolinux\bleapi.h(97): error C2143: syntax error: missing ';' before '}'
\myolinux\bleapi.h(99): error C2146: syntax error: missing ';' before identifier 'SystemRegReadResponse'
\myolinux\bleapi.h(99): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
\myolinux\bleapi.h(100): error C2065: 'cls': undeclared identifier
\myolinux\bleapi.h(100): error C2065: 'cmd': undeclared identifier
\myolinux\bleapi.h(100): error C2059: syntax error: ';'
\myolinux\bleapi.h(103): error C2059: syntax error: '}'
\myolinux\bleapi.h(103): error C2143: syntax error: missing ';' before '}'
\myolinux\bleapi.h(105): error C2146: syntax error: missing ';' before identifier 'SystemGetCounters'
\myolinux\bleapi.h(105): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
\myolinux\bleapi.h(106): error C2065: 'cls': undeclared identifier
\myolinux\bleapi.h(106): error C2065: 'cmd': undeclared identifier
\myolinux\bleapi.h(106): error C2059: syntax error: ';'
\myolinux\bleapi.h(107): error C2059: syntax error: '}'
\myolinux\bleapi.h(107): error C2143: syntax error: missing ';' before '}'

and many more...

I don't know if it's not possible to import the binary form as i did or if i need to build from source on windows or what the problem is exactly - so any help is highly appreciated.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.