CShock/CShocker/Shockers/APIS/PiShockSerial.cs

39 lines
1.3 KiB
C#
Raw Normal View History

2024-01-17 17:59:10 +01:00
using CShocker.Ranges;
using CShocker.Shockers.Abstract;
2024-01-17 04:11:30 +01:00
using Microsoft.Extensions.Logging;
2024-01-17 22:16:40 +01:00
namespace CShocker.Shockers.APIS;
2024-01-17 04:11:30 +01:00
2024-01-17 04:36:38 +01:00
public class PiShockSerial : SerialShocker
2024-01-17 04:11:30 +01:00
{
2024-01-20 20:02:12 +01:00
private const int BaudRate = 115200;
public PiShockSerial(List<string> shockerIds, IntensityRange intensityRange, DurationRange durationRange, SerialPortInfo serialPortI, ILogger? logger = null) : base(shockerIds, intensityRange, durationRange, serialPortI, BaudRate, ShockerApi.PiShockSerial, logger)
2024-01-17 04:11:30 +01:00
{
throw new NotImplementedException();
}
protected override void ControlInternal(ControlAction action, string shockerId, int intensity, int duration)
{
2024-01-20 20:02:12 +01:00
string json = "{" +
"\"cmd\": \"operate\"," +
"\"value\":{" +
$"\"op\": \"{ControlActionToOp(action)}\"," +
$"\"duration\": {duration}," +
$"\"intensity\": {intensity}," +
$"\"id\": " +
"}" +
"}";
2024-01-20 20:25:31 +01:00
SerialPort.WriteLine(json);
2024-01-20 20:02:12 +01:00
}
private static string ControlActionToOp(ControlAction action)
{
return action switch
{
ControlAction.Beep => "",
ControlAction.Vibrate => "vibrate",
ControlAction.Shock => "",
_ => ""
};
2024-01-17 04:11:30 +01:00
}
}