2024-02-01 23:03:28 +01:00
|
|
|
|
using CShocker.Devices.Abstract;
|
2024-01-29 15:37:19 +01:00
|
|
|
|
using CShocker.Devices.Additional;
|
2024-02-01 23:03:28 +01:00
|
|
|
|
using CShocker.Devices.APIs;
|
2024-01-29 15:37:19 +01:00
|
|
|
|
using CShocker.Ranges;
|
|
|
|
|
using CShocker.Shockers;
|
2024-02-01 23:03:28 +01:00
|
|
|
|
using GlaxLogger;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
2024-01-29 15:37:19 +01:00
|
|
|
|
using Newtonsoft.Json;
|
2024-01-20 20:02:12 +01:00
|
|
|
|
|
2024-02-01 23:03:28 +01:00
|
|
|
|
Logger logger = new (LogLevel.Trace);
|
2024-01-20 20:02:12 +01:00
|
|
|
|
|
2024-01-29 15:37:19 +01:00
|
|
|
|
Console.WriteLine("OpenShock API Key:");
|
|
|
|
|
string? apiKey = Console.ReadLine();
|
|
|
|
|
while(apiKey is null || apiKey.Length < 1)
|
|
|
|
|
apiKey = Console.ReadLine();
|
|
|
|
|
|
2024-02-01 23:03:28 +01:00
|
|
|
|
/*
|
2024-01-29 15:37:19 +01:00
|
|
|
|
OpenShockHttp openShockHttp = new (new IntensityRange(30, 50), new DurationRange(1000, 1000), apiKey, logger: logger);
|
2024-02-01 23:03:28 +01:00
|
|
|
|
OpenShockShocker shocker = openShockHttp.GetShockers(apiKey).First();
|
|
|
|
|
shocker.Control(ControlAction.Vibrate, 20, 1000);
|
2024-01-29 15:37:19 +01:00
|
|
|
|
|
2024-02-01 23:03:28 +01:00
|
|
|
|
File.WriteAllText("shockers.json", JsonConvert.SerializeObject(shocker));
|
|
|
|
|
OpenShockShocker deserialized = JsonConvert.DeserializeObject<OpenShockShocker>(File.ReadAllText("shockers.json"), new ApiJsonConverter())!;
|
2024-01-29 15:37:19 +01:00
|
|
|
|
Thread.Sleep(1100); //Wait for previous to end
|
2024-02-01 23:03:28 +01:00
|
|
|
|
deserialized.Control(ControlAction.Vibrate, 20, 1000);
|
|
|
|
|
shocker.Dispose();
|
2024-01-29 15:37:19 +01:00
|
|
|
|
deserialized.Dispose();
|
2024-02-01 23:03:28 +01:00
|
|
|
|
*/
|
2024-01-29 15:37:19 +01:00
|
|
|
|
|
|
|
|
|
|
2024-01-20 20:02:12 +01:00
|
|
|
|
#pragma warning disable CA1416
|
2024-01-29 15:37:19 +01:00
|
|
|
|
List<SerialPortInfo> serialPorts = SerialHelper.GetSerialPorts();
|
2024-01-20 20:02:12 +01:00
|
|
|
|
|
|
|
|
|
if (serialPorts.Count < 1)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
for(int i = 0; i < serialPorts.Count; i++)
|
|
|
|
|
Console.WriteLine($"{i}) {serialPorts[i]}");
|
|
|
|
|
|
|
|
|
|
Console.WriteLine($"Select Serial Port [0-{serialPorts.Count-1}]:");
|
|
|
|
|
string? selectedPortStr = Console.ReadLine();
|
2024-01-29 15:37:19 +01:00
|
|
|
|
int selectedPort;
|
2024-01-20 20:02:12 +01:00
|
|
|
|
while (!int.TryParse(selectedPortStr, out selectedPort) || selectedPort < 0 || selectedPort > serialPorts.Count - 1)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine($"Select Serial Port [0-{serialPorts.Count-1}]:");
|
|
|
|
|
selectedPortStr = Console.ReadLine();
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-29 15:37:19 +01:00
|
|
|
|
OpenShockSerial openShockSerial = new(new IntensityRange(30, 50), new DurationRange(1000, 1000),serialPorts[selectedPort], apiKey, logger: logger);
|
2024-02-04 16:25:15 +01:00
|
|
|
|
OpenShockShocker shocker = openShockSerial.GetShockers().First();
|
2024-02-01 23:03:28 +01:00
|
|
|
|
shocker.Control(ControlAction.Vibrate, 20, 1000);
|
|
|
|
|
File.WriteAllText("shockers.json", JsonConvert.SerializeObject(shocker));
|
|
|
|
|
OpenShockShocker deserialized = JsonConvert.DeserializeObject<OpenShockShocker>(File.ReadAllText("shockers.json"), new ApiJsonConverter())!;
|
|
|
|
|
shocker.Dispose();
|
2024-01-29 15:37:19 +01:00
|
|
|
|
deserialized.Dispose();
|
|
|
|
|
|
2024-02-01 23:03:28 +01:00
|
|
|
|
logger.Dispose();
|