Skip to main content

Description

This is a cross-platform Python library for the USB Griffin PowerMate (don't think it will work with the Bluetooth version). It is tested to work on both Windows and Linux. While it is two completely separate implementations, they have the same interface. Both rely on asyncio.

Picking a Device

Multiple PowerMates can be used at once. The PowerMate class constructor requires a path to the device. On Linux this will be something like /dev/input/event15. On Windows it will be something horrible like \\?\hid#vid_077d&pid_0410#6&1c38037f&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}. Rather that type the path directly, you can use PowerMate.enumerate() which returns a list of PowerMate device paths.

Callbacks

This library works on a callback system. The PowerMate constructor takes callback functions for when the knob is turned and when the button is pressed (or released). These callback will be called on an asyncio event loop. The turn_callback should take a single parameter that will be an integer number of ticks the knob has turned. Postive means clockwise and negative means counter-clockwise. The button_callback takes a boolean that is True when the button is pressed and False when it is released.

Example

from powermate import PowerMate

def on_turn(amount):
  print(f'Turned: {amount}')

def on_button(pressed):
  if pressed:
    print('Button pressed')
  else:
    print('Button released')

paths = PowerMate.enumerate()
if not paths:
  print('No PowerMates detected')
else:
  powermate = PowerMate(
      paths[0],
      turn_callback=on_turn,
      button_callback=on_button)

LED Control

The PowerMate has a somewhat controllable blue LED in it. It can either be solid on or pulsing. When it is solid, you can adjust the brightness. When it is pulsing, you can adjust the speed.

To turn it solid on, call powermate.set_led_solid(brightness) where the brightness is 0-255 (default: 128).

To cause it to pulse, call powermate.set_led_pulse(speed, table, when_sleeping). Speed is from -255 to 255. 0 is its default speed (also 1 and -1). Positive numbers multiply its default speed (2 is twice as fast, 3 is three times as fast, etc), and negative numbers divide its default speed (-2 is half as fast, -3 is a third as fast, etc). The table is 0-2, but I haven't noticed any difference. when_sleeping is a boolean that controls if it should continue to pulse when the device is suppose to be asleep (violating the USB power management standards) or whether to go into low-power mode.

asyncio Event Loop

The PowerMate class requires an asyncio event loop to function. In the Linux version, the events are polled on this event loop. In Windows the events are polled on a thread, however in both versions the callbacks are called on the event loop. By default PowerMate will use the current event loop when its constructor is called. However, if you wish to specify another event loop (perhaps one that is created but not started when PowerMate is constructed that will be run on a separate thread), you can pass it to the loop parameter to the contructor.

Shutting Down

Calling powermate.close() will disconnect from the device and prevent further event callbacks from being called.

Metadata

Release files for powermateusb 0.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for powermateusb 0.0.4
File Size Uploaded Provenance
powermateusb-0.0.4.tar.gz 6.2 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for powermateusb 0.0.4
File Interpreter ABI Platform
powermateusb-0.0.4-py3-none-any.whl Python 3 none any Details

Total release size: 13.5 kB

Release files / powermateusb-0.0.4.tar.gz

Download URL powermateusb-0.0.4.tar.gz
Size 6.2 kB
Tags Source
SHA-256 checksum
How to use checksums
350313cca6102b678abbc8c8caee148a98680bdb3ee8b8780c3ff4040755c35f
BLAKE2b-256 checksum
How to use checksums
f863d5cdd78ee04f4bcaf9f70ab670ef4bda4742113328be8d5fd04131518255
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.8.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.8

Release files / powermateusb-0.0.4-py3-none-any.whl

Download URL powermateusb-0.0.4-py3-none-any.whl
Size 7.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7e5d8e420291dc0108bc7b182c61b1574fc384878a64369cd12c46736f687a15
BLAKE2b-256 checksum
How to use checksums
e28746b718978e1ba6897d2efe0590467a3e0c722cfee7a46e5b723772191073
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.8.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.8

Security for powermateusb 0.0.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.0.4 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page