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\": " +
|
|
|
|
|
"}" +
|
|
|
|
|
"}";
|
|
|
|
|
serialPort.WriteLine(json);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static string ControlActionToOp(ControlAction action)
|
|
|
|
|
{
|
|
|
|
|
return action switch
|
|
|
|
|
{
|
|
|
|
|
ControlAction.Beep => "",
|
|
|
|
|
ControlAction.Vibrate => "vibrate",
|
|
|
|
|
ControlAction.Shock => "",
|
|
|
|
|
_ => ""
|
|
|
|
|
};
|
2024-01-17 04:11:30 +01:00
|
|
|
|
}
|
|
|
|
|
}
|