Compare commits
4 Commits
5de7e3c0ce
...
67bb9c4f9a
Author | SHA1 | Date | |
---|---|---|---|
67bb9c4f9a | |||
2d47aa7492 | |||
d861c95ec3 | |||
cab3536412 |
4
CShocker.sln.DotSettings
Normal file
4
CShocker.sln.DotSettings
Normal file
@ -0,0 +1,4 @@
|
||||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Caixianlin/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Petrainer/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=rftransmit/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
|
@ -7,7 +7,7 @@
|
||||
<Authors>Glax</Authors>
|
||||
<RepositoryUrl>https://github.com/C9Glax/CShocker</RepositoryUrl>
|
||||
<RepositoryType>git</RepositoryType>
|
||||
<Version>1.3.1</Version>
|
||||
<Version>1.3.2</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
@ -7,6 +7,7 @@ namespace CShocker.Shockers.APIS;
|
||||
|
||||
public class OpenShockSerial : SerialShocker
|
||||
{
|
||||
// ReSharper disable once MemberCanBePrivate.Global external usage
|
||||
public readonly Dictionary<string, ShockerModel> Model;
|
||||
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)
|
||||
@ -23,7 +24,7 @@ public class OpenShockSerial : SerialShocker
|
||||
$"\"intensity\":{intensity}," +
|
||||
$"\"durationMs\":{duration}" +
|
||||
"}";
|
||||
serialPort.WriteLine(json);
|
||||
SerialPort.WriteLine(json);
|
||||
}
|
||||
|
||||
public Dictionary<string, ShockerModel> GetShockers()
|
||||
@ -31,8 +32,8 @@ public class OpenShockSerial : SerialShocker
|
||||
Dictionary<string, ShockerModel> ret = new();
|
||||
Regex shockerRex = new (@".*FetchDeviceInfo\(\): \[GatewayConnectionManager\] \[[a-z0-9\-]+\] rf=([0-9]{1,5}) model=([0,1])");
|
||||
this.Logger?.Log(LogLevel.Debug, "Restart");
|
||||
serialPort.WriteLine("restart");
|
||||
while (serialPort.ReadLine() is { } line && !line.Contains("Successfully verified auth token"))
|
||||
SerialPort.WriteLine("restart");
|
||||
while (SerialPort.ReadLine() is { } line && !line.Contains("Successfully verified auth token"))
|
||||
{
|
||||
this.Logger?.Log(LogLevel.Trace, line);
|
||||
Match match = shockerRex.Match(line);
|
||||
@ -50,7 +51,7 @@ public class OpenShockSerial : SerialShocker
|
||||
Petrainer = 1
|
||||
}
|
||||
|
||||
private string ControlActionToString(ControlAction action)
|
||||
private static string ControlActionToString(ControlAction action)
|
||||
{
|
||||
return action switch
|
||||
{
|
||||
|
@ -8,7 +8,9 @@ namespace CShocker.Shockers.APIS;
|
||||
|
||||
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)
|
||||
{
|
||||
this.Username = username;
|
||||
|
@ -23,7 +23,7 @@ public class PiShockSerial : SerialShocker
|
||||
$"\"id\": " +
|
||||
"}" +
|
||||
"}";
|
||||
serialPort.WriteLine(json);
|
||||
SerialPort.WriteLine(json);
|
||||
}
|
||||
|
||||
private static string ControlActionToOp(ControlAction action)
|
||||
|
@ -6,6 +6,7 @@ namespace CShocker.Shockers.Abstract;
|
||||
public abstract class HttpShocker : Shocker
|
||||
{
|
||||
protected readonly HttpClient HttpClient = new();
|
||||
// ReSharper disable twice MemberCanBeProtected.Global external usage
|
||||
public string Endpoint { get; init; }
|
||||
public string ApiKey { get; init; }
|
||||
|
||||
|
@ -10,13 +10,13 @@ namespace CShocker.Shockers.Abstract;
|
||||
public abstract class SerialShocker : Shocker
|
||||
{
|
||||
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)
|
||||
{
|
||||
this.SerialPortI = serialPortI;
|
||||
this.serialPort = new SerialPort(serialPortI.PortName, baudRate);
|
||||
this.serialPort.Open();
|
||||
this.SerialPort = new SerialPort(serialPortI.PortName, baudRate);
|
||||
this.SerialPort.Open();
|
||||
}
|
||||
|
||||
[SupportedOSPlatform("windows")]
|
||||
|
@ -6,6 +6,7 @@ namespace CShocker.Shockers.Abstract;
|
||||
|
||||
public abstract class Shocker
|
||||
{
|
||||
// ReSharper disable 4 times MemberCanBePrivate.Global external use
|
||||
public readonly List<string> ShockerIds;
|
||||
public readonly IntensityRange IntensityRange;
|
||||
public readonly DurationRange DurationRange;
|
||||
|
@ -29,6 +29,12 @@ public class ShockerJsonConverter : JsonConverter
|
||||
jo.SelectToken("Endpoint")!.Value<string>()!
|
||||
);
|
||||
case ShockerApi.OpenShockSerial:
|
||||
return new OpenShockSerial(
|
||||
jo.SelectToken("Model")!.ToObject<Dictionary<string, OpenShockSerial.ShockerModel>>()!,
|
||||
jo.SelectToken("IntensityRange")!.ToObject<IntensityRange>()!,
|
||||
jo.SelectToken("DurationRange")!.ToObject<DurationRange>()!,
|
||||
jo.SelectToken("SerialPortI")!.ToObject<SerialShocker.SerialPortInfo>()!
|
||||
);
|
||||
case ShockerApi.PiShockHttp:
|
||||
return new PiShockHttp(
|
||||
jo.SelectToken("ShockerIds")!.ToObject<List<string>>()!,
|
||||
|
@ -1,5 +1,7 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace TestApp;
|
||||
|
||||
public class Logger : ILogger
|
||||
{
|
||||
private LogLevel _enabledLoglevel;
|
||||
|
@ -2,6 +2,7 @@
|
||||
using CShocker.Shockers.Abstract;
|
||||
using CShocker.Shockers.APIS;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using TestApp;
|
||||
|
||||
Logger logger = new (LogLevel.Trace);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user