-
Notifications
You must be signed in to change notification settings - Fork 1
/
DeviceController.cs
28 lines (21 loc) · 973 Bytes
/
DeviceController.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
using System.Threading;
using System.Threading.Tasks;
using Buttplug.Client;
using Buttplug.Client.Connectors.WebsocketConnector;
namespace Terragasm;
public static class DeviceController
{
private static readonly ButtplugClient _client = new("Terragasm");
private static readonly ButtplugWebsocketConnector _connector = new(new("ws://localhost:12345"));
public static Task ConnectAsync(CancellationToken cancellationToken = default)
=> _client.ConnectAsync(_connector, cancellationToken);
public static Task DisconnectAsync()
=> _client.DisconnectAsync();
public static Task VibrateAsync(double speed, int delay)
=> Parallel.ForEachAsync(_client.Devices, async (device, token) =>
{
await device.VibrateAsync(speed).ConfigureAwait(false);
await Task.Delay(delay, token).ConfigureAwait(false);
await device.VibrateAsync(0).ConfigureAwait(false);
});
}