Skip to content

Commit

Permalink
chore: add workflows and flake8
Browse files Browse the repository at this point in the history
  • Loading branch information
iomz committed Jun 7, 2023
1 parent beb5952 commit 6f06e7e
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 42 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Build
on:
release:
types: [published]
jobs:
build-wheel:
strategy:
fail-fast: false
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
os: [macOS-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Lint
run: |
pip install flake8
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics --exclude=examples,myo/handle.py
- name: Build
run: |
pip install hatch
python -m hatch build
- name: Upload wheel
uses: actions/upload-artifact@v3
with:
name: dist
path: dist
build-wheel-linux:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Build
run: |
pip install hatch
python -m hatch build
- name: Upload wheel
uses: actions/upload-artifact@v3
with:
name: dist
path: dist
37 changes: 16 additions & 21 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,28 @@
# documentation.

name: Upload Python Package

on:
release:
types: [published]

permissions:
contents: read

jobs:
deploy:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build
- name: Build package
run: python -m build
- name: Publish package
uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: "3.x"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build
- name: Build package
run: python -m build
- name: Publish package
uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
17 changes: 15 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
# dl-myo
# dl-myo (Dongle-less Myo)

A replacement middleware to MyoConnect for Myo Armband without an official Myo dongle.
[![PyPI Version](https://badge.fury.io/py/dl-myo.svg)](https://badge.fury.io/py/dl-myo)
[![Build Status](https://github.com/iomz/dl-myo/workflows/Build/badge.svg)](https://github.com/iomz/dl-myo/actions?query=workflow%3ABuild)

dl-myo is a replacement to MyoConnect for Myo Armband without an official Myo dongle.

If you are fed up with the dongle and still need to use Myo anyway this is the right stuff to grab.

This project is a reimplementation of [Dongleless-myo](https://github.com/iomz/Dongleless-myo) (originally created by [@mamo91] and enhanced by [@MyrikLD]) using [Bleak](https://github.com/hbldh/bleak) instead of [bluepy](https://github.com/IanHarvey/bluepy), and therefore supports asyncio on multiple platforms.

## Platform Support

| Linux | Raspberry Pi | macOS | Windows |
| :----------------: | :----------------: | :----------------: | :----------------: |
| :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |

## Install

Expand Down
4 changes: 3 additions & 1 deletion examples/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ async def main(args: argparse.Namespace):
await m.vibrate(client, VibrationType.MEDIUM)

# enable emg and imu
await m.set_mode(client, EMGMode.SEND_EMG, IMUMode.SEND_ALL, ClassifierMode.DISABLED)
await m.set_mode(
client, EMGMode.SEND_EMG, IMUMode.SEND_ALL, ClassifierMode.DISABLED
)

logging.info("sleep 1")
await asyncio.sleep(0.5)
Expand Down
20 changes: 15 additions & 5 deletions myo/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
# -*- coding: utf-8 -*-
"""
dl-myo: Dongleless Myo EMG/IMU with Bleak
Author: Iori Mizutani (@iomz)
Top-level package for dl-myo
~~~~~~~~~~~~~~~~~~~~
>>> import myo
"""
from .device import *

from __future__ import annotations

__author__ = """Iori Mizutani"""
__email__ = "[email protected]"

from pkgutil import extend_path

__path__ = extend_path(__path__, __name__)

from .commands import * # noqa: F401,F403
from .device import * # noqa: F401,F403
from .handle import * # noqa: F401,F403
from .types import * # noqa: F401,F403
10 changes: 8 additions & 2 deletions myo/commands.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
from .types import *
from .types import SleepMode, UnlockType, UserActionType


# myohw_command_t
Expand Down Expand Up @@ -86,7 +86,13 @@ def __init__(self, duration, strength):

@property
def payload(self) -> bytearray:
return bytearray((self.steps.duration >> 0xFF, self.steps.duration & 0xFF, self.steps.strength))
return bytearray(
(
self.steps.duration >> 0xFF,
self.steps.duration & 0xFF,
self.steps.strength,
)
)


# -> myohw_command_set_sleep_mode_t
Expand Down
20 changes: 10 additions & 10 deletions myo/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
from bleak.backends.device import BLEDevice
from bleak.backends.scanner import AdvertisementData

from .commands import *
from .handle import *
from .types import *
from .commands import Command, SetMode, Vibrate, DeepSleep, LED, Vibrate2, SetSleepMode, Unlock, UserAction
from .handle import Handle, UUID
from .types import FirmwareInfo, FirmwareVersion

# from .quaternion import Quaternion

Expand Down Expand Up @@ -46,8 +46,8 @@ def match_myo_mac(device: BLEDevice, _: AdvertisementData):
if self.device is None:
logger.error(f"could not find device with address {mac}")
return self
except:
logger.error("the mac address may be invalid")
except Exception as e:
logger.error("the mac address may be invalid", e)
return self

# get the device name
Expand Down Expand Up @@ -99,7 +99,7 @@ async def emg_service(self, client):
"""
await client.write_gatt_char(Handle.EMG_SERVICE.value, b"\x01\x00", True) # pyright: ignore

async def get_services(self, client: BleakClient, indent=2) -> str:
async def get_services(self, client: BleakClient, indent=2) -> str: # noqa: C901
"""fetch available services as dict"""
sd = {"services": {}}
for service in client.services: # BleakGATTServiceCollection
Expand Down Expand Up @@ -156,9 +156,9 @@ async def led(self, client: BleakClient, *args):
if not isinstance(args, tuple) or len(args) != 2:
raise Exception(f"Unknown payload for LEDs: {args}")

for l in args:
if any(not isinstance(v, int) for v in l):
raise Exception(f"Values must be int 0-255: {l}")
for lst in args:
if any(not isinstance(v, int) for v in lst):
raise Exception(f"Values must be int 0-255: {lst}")

await self.command(client, LED(args[0], args[1]))

Expand Down Expand Up @@ -197,4 +197,4 @@ async def vibrate2(self, client: BleakClient, duration, strength):
"""
Vibrate2 Command
"""
await self.command(client, Vibrate2(duration, strength))
await self.command(client, Vibrate2(duration, strength))
6 changes: 5 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@ version = "0.1.0"
authors = [
{ name="Iori Mizutani", email="[email protected]" },
]
Maintainers = [
maintainers = [
{ name="Iori Mizutani", email="[email protected]" },
]
description = "A replacement middleware to MyoConnect for Myo Armband"
readme = "README.md"
requires-python = ">=3.11"
dependencies = [
"aenum",
"bleak",
]
classifiers = [
"Framework :: AsyncIO",
"Intended Audience :: Education",
Expand Down

0 comments on commit 6f06e7e

Please sign in to comment.