Formatting
This commit is contained in:
parent
d861c95ec3
commit
2d47aa7492
@ -7,6 +7,7 @@ namespace CShocker.Shockers.APIS;
|
|||||||
|
|
||||||
public class OpenShockSerial : SerialShocker
|
public class OpenShockSerial : SerialShocker
|
||||||
{
|
{
|
||||||
|
// ReSharper disable once MemberCanBePrivate.Global external usage
|
||||||
public readonly Dictionary<string, ShockerModel> Model;
|
public readonly Dictionary<string, ShockerModel> Model;
|
||||||
private const int BaudRate = 115200;
|
private const int BaudRate = 115200;
|
||||||
public OpenShockSerial(Dictionary<string, ShockerModel> shockerIds, IntensityRange intensityRange, DurationRange durationRange, SerialPortInfo serialPortI, ILogger? logger = null) : base(shockerIds.Keys.ToList(), intensityRange, durationRange, serialPortI, BaudRate, ShockerApi.OpenShockSerial, logger)
|
public OpenShockSerial(Dictionary<string, ShockerModel> shockerIds, IntensityRange intensityRange, DurationRange durationRange, SerialPortInfo serialPortI, ILogger? logger = null) : base(shockerIds.Keys.ToList(), intensityRange, durationRange, serialPortI, BaudRate, ShockerApi.OpenShockSerial, logger)
|
||||||
@ -23,7 +24,7 @@ public class OpenShockSerial : SerialShocker
|
|||||||
$"\"intensity\":{intensity}," +
|
$"\"intensity\":{intensity}," +
|
||||||
$"\"durationMs\":{duration}" +
|
$"\"durationMs\":{duration}" +
|
||||||
"}";
|
"}";
|
||||||
serialPort.WriteLine(json);
|
SerialPort.WriteLine(json);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Dictionary<string, ShockerModel> GetShockers()
|
public Dictionary<string, ShockerModel> GetShockers()
|
||||||
@ -31,8 +32,8 @@ public class OpenShockSerial : SerialShocker
|
|||||||
Dictionary<string, ShockerModel> ret = new();
|
Dictionary<string, ShockerModel> ret = new();
|
||||||
Regex shockerRex = new (@".*FetchDeviceInfo\(\): \[GatewayConnectionManager\] \[[a-z0-9\-]+\] rf=([0-9]{1,5}) model=([0,1])");
|
Regex shockerRex = new (@".*FetchDeviceInfo\(\): \[GatewayConnectionManager\] \[[a-z0-9\-]+\] rf=([0-9]{1,5}) model=([0,1])");
|
||||||
this.Logger?.Log(LogLevel.Debug, "Restart");
|
this.Logger?.Log(LogLevel.Debug, "Restart");
|
||||||
serialPort.WriteLine("restart");
|
SerialPort.WriteLine("restart");
|
||||||
while (serialPort.ReadLine() is { } line && !line.Contains("Successfully verified auth token"))
|
while (SerialPort.ReadLine() is { } line && !line.Contains("Successfully verified auth token"))
|
||||||
{
|
{
|
||||||
this.Logger?.Log(LogLevel.Trace, line);
|
this.Logger?.Log(LogLevel.Trace, line);
|
||||||
Match match = shockerRex.Match(line);
|
Match match = shockerRex.Match(line);
|
||||||
@ -50,7 +51,7 @@ public class OpenShockSerial : SerialShocker
|
|||||||
Petrainer = 1
|
Petrainer = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
private string ControlActionToString(ControlAction action)
|
private static string ControlActionToString(ControlAction action)
|
||||||
{
|
{
|
||||||
return action switch
|
return action switch
|
||||||
{
|
{
|
||||||
|
@ -8,7 +8,9 @@ namespace CShocker.Shockers.APIS;
|
|||||||
|
|
||||||
public class PiShockHttp : HttpShocker
|
public class PiShockHttp : HttpShocker
|
||||||
{
|
{
|
||||||
public String Username, ShareCode;
|
// ReSharper disable twice MemberCanBePrivate.Global external usage
|
||||||
|
public readonly string Username, ShareCode;
|
||||||
|
|
||||||
public PiShockHttp(List<string> shockerIds, IntensityRange intensityRange, DurationRange durationRange, string apiKey, string username, string shareCode, string endpoint = "https://do.pishock.com/api/apioperate", ILogger? logger = null) : base(shockerIds, intensityRange, durationRange, apiKey, endpoint, ShockerApi.PiShockHttp, logger)
|
public PiShockHttp(List<string> shockerIds, IntensityRange intensityRange, DurationRange durationRange, string apiKey, string username, string shareCode, string endpoint = "https://do.pishock.com/api/apioperate", ILogger? logger = null) : base(shockerIds, intensityRange, durationRange, apiKey, endpoint, ShockerApi.PiShockHttp, logger)
|
||||||
{
|
{
|
||||||
this.Username = username;
|
this.Username = username;
|
||||||
|
@ -23,7 +23,7 @@ public class PiShockSerial : SerialShocker
|
|||||||
$"\"id\": " +
|
$"\"id\": " +
|
||||||
"}" +
|
"}" +
|
||||||
"}";
|
"}";
|
||||||
serialPort.WriteLine(json);
|
SerialPort.WriteLine(json);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string ControlActionToOp(ControlAction action)
|
private static string ControlActionToOp(ControlAction action)
|
||||||
|
@ -6,6 +6,7 @@ namespace CShocker.Shockers.Abstract;
|
|||||||
public abstract class HttpShocker : Shocker
|
public abstract class HttpShocker : Shocker
|
||||||
{
|
{
|
||||||
protected readonly HttpClient HttpClient = new();
|
protected readonly HttpClient HttpClient = new();
|
||||||
|
// ReSharper disable twice MemberCanBeProtected.Global external usage
|
||||||
public string Endpoint { get; init; }
|
public string Endpoint { get; init; }
|
||||||
public string ApiKey { get; init; }
|
public string ApiKey { get; init; }
|
||||||
|
|
||||||
|
@ -10,13 +10,13 @@ namespace CShocker.Shockers.Abstract;
|
|||||||
public abstract class SerialShocker : Shocker
|
public abstract class SerialShocker : Shocker
|
||||||
{
|
{
|
||||||
public SerialPortInfo SerialPortI;
|
public SerialPortInfo SerialPortI;
|
||||||
protected SerialPort serialPort;
|
protected readonly SerialPort SerialPort;
|
||||||
|
|
||||||
protected SerialShocker(List<string> shockerIds, IntensityRange intensityRange, DurationRange durationRange, SerialPortInfo serialPortI, int baudRate, ShockerApi apiType, ILogger? logger = null) : base(shockerIds, intensityRange, durationRange, apiType, logger)
|
protected SerialShocker(List<string> shockerIds, IntensityRange intensityRange, DurationRange durationRange, SerialPortInfo serialPortI, int baudRate, ShockerApi apiType, ILogger? logger = null) : base(shockerIds, intensityRange, durationRange, apiType, logger)
|
||||||
{
|
{
|
||||||
this.SerialPortI = serialPortI;
|
this.SerialPortI = serialPortI;
|
||||||
this.serialPort = new SerialPort(serialPortI.PortName, baudRate);
|
this.SerialPort = new SerialPort(serialPortI.PortName, baudRate);
|
||||||
this.serialPort.Open();
|
this.SerialPort.Open();
|
||||||
}
|
}
|
||||||
|
|
||||||
[SupportedOSPlatform("windows")]
|
[SupportedOSPlatform("windows")]
|
||||||
|
@ -6,6 +6,7 @@ namespace CShocker.Shockers.Abstract;
|
|||||||
|
|
||||||
public abstract class Shocker
|
public abstract class Shocker
|
||||||
{
|
{
|
||||||
|
// ReSharper disable 4 times MemberCanBePrivate.Global external use
|
||||||
public readonly List<string> ShockerIds;
|
public readonly List<string> ShockerIds;
|
||||||
public readonly IntensityRange IntensityRange;
|
public readonly IntensityRange IntensityRange;
|
||||||
public readonly DurationRange DurationRange;
|
public readonly DurationRange DurationRange;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user