PowerMate 0.0.1-SNAPSHOT2
See the version list below for details.
dotnet add package PowerMate --version 0.0.1-SNAPSHOT2
NuGet\Install-Package PowerMate -Version 0.0.1-SNAPSHOT2
<PackageReference Include="PowerMate" Version="0.0.1-SNAPSHOT2" />
paket add PowerMate --version 0.0.1-SNAPSHOT2
#r "nuget: PowerMate, 0.0.1-SNAPSHOT2"
// Install PowerMate as a Cake Addin #addin nuget:?package=PowerMate&version=0.0.1-SNAPSHOT2&prerelease // Install PowerMate as a Cake Tool #tool nuget:?package=PowerMate&version=0.0.1-SNAPSHOT2&prerelease
Receive events from a Griffin PowerMate device over USB
Quick Start
dotnet install PowerMate
using PowerMate;
using IPowerMateClient powerMate = new PowerMateClient();
powerMate.InputReceived += (sender, input) => {
switch (input) {
case { IsPressed: true, IsRotationClockwise: null }:
Console.WriteLine("PowerMate was pressed");
break;
case { IsPressed: false, IsRotationClockwise: true }:
Console.WriteLine("PowerMate was rotated clockwise");
break;
case { IsPressed: false, IsRotationClockwise: false }:
Console.WriteLine("PowerMate was rotated counterclockwise");
break;
default:
break;
}
};
Prerequisites
- A Griffin PowerMate
- ✅ The USB version is supported
- ❌ The Bluetooth version is not supported
- Any Microsoft .NET runtime that supports .NET Standard 2.0 or later
- A supported operating system
- ✅ Windows (verified on 10 22H2 and 11 22H2)
- ✅ MacOS (verified on 12.6)
- ❓ Linux is currently unverified
Installation
You can install this library into your project from NuGet Gallery:
dotnet add package PowerMate
Install-Package PowerMate
- Go to Project › Manage NuGet Packages in Visual Studio and search for
PowerMate
Usage
Construct a new instance of the
PowerMateClient
class.using IPowerMateClient powerMate = new PowerMateClient();
You should dispose of instances when you're done with them by calling
Dispose()
, or with ausing
statement or declaration.Now you can listen for
InputReceived
events from the client.powerMate.InputReceived += (sender, input) => Console.WriteLine($"Received PowerMate event: {input}");
Connections
This library will automatically try to connect to one of the PowerMate devices that are plugged into your computer. If no device is connected, it will automatically wait until one appears and then connect to it. If a device disconnects, this library will reconnect automatically when one reappears.
If multiple PowerMate devices are present simultaneously, this library will pick one of them arbitrarily and use it until it disconnects.
The connection state is exposed by the bool IsConnected
property, and changes to this state are emitted by the IsConnectedChanged
event.
Console.WriteLine(powerMate.IsConnected
? "Listening for movements from PowerMate."
: "Waiting for a PowerMate to be connected.");
powerMate.IsConnectedChanged += (_, isConnected) => Console.WriteLine(isConnected
? "Reconnected to a PowerMate."
: "Disconnected from the PowerMate, attempting reconnection...");
Events
InputReceived
Fired whenever the PowerMate knob is rotated, pressed, or released.
The event argument is a PowerMateInput
struct with the following fields.
Field name | Type | Example values | Description |
---|---|---|---|
IsPressed |
bool |
true false |
true if the knob is being held down, or false if it is up. Pressing and releasing the knob will generate two events, with true and false in order. Will also be true when the knob is rotated while being held down. |
IsRotationClockwise |
bool? |
true false null |
true if the knob is being rotated clockwise when viewed from above, false if it is being rotated counterclockwise, or null if it is not being rotated. |
RotationDistance |
uint |
0 1 2 |
How far, in arbitrary angular units, the knob was rotated since the last update. When you rotate the knob slowly, you will receive multiple events, each with this set to 1 . As you rotate it faster, updates are batched and this number increases to 2 or more. The highest value I have seen is 8 . This is always non-negative, regardless of the rotation direction; use IsRotationClockwise to determine the direction. If the knob is pressed without being rotated, this is 0 . |
IsConnectedChanged
Fired whenever the connection state of the PowerMate changes. Not fired when constructing or disposing the PowerMateClient
instance.
The event argument is a bool
which is true
when a PowerMate has reconnected, or false
when it has disconnected.
To get the value of this state at any time, read the IsConnected
property on the IPowerMateClient
instance.
Limitations
- This library currently does not allow you to change the LED brightness.
- This library does not connect to Bluetooth PowerMates.
Acknowledgements
- Luke Ma for giving me a PowerMate as a Christmas gift in 2013
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- HidSharp (>= 2.1.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.1.0 | 254 | 8/1/2023 |
1.0.0 | 249 | 2/25/2023 |
0.0.1-SNAPSHOT2 | 141 | 2/18/2023 |
0.0.1-SNAPSHOT1 | 150 | 2/16/2023 |