-
Notifications
You must be signed in to change notification settings - Fork 0
/
VibrationController.cs
32 lines (23 loc) · 1.04 KB
/
VibrationController.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
29
30
31
32
using System.Threading;
using System.Threading.Tasks;
using Buttplug.Client;
using Buttplug.Client.Connectors.WebsocketConnector;
namespace Terraplug
{
public static class VibrationController
{
private static readonly ButtplugWebsocketConnector _connector = new(new("ws://localhost:12345"));
private static readonly ButtplugClient _client = new("Terraplug! >_<");
public static Task ConnectAsync(CancellationToken cancellationToken = default)
=> _client.ConnectAsync(_connector, cancellationToken);
public static Task DisconnectAsync()
=> _client.DisconnectAsync();
public static Task Vibrate(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);
});
}
}