13 Commits
3.0 ... 3.1

Author SHA1 Message Date
92cc79f707 Improved Setup
Update Dependency
2024-01-19 03:08:03 +01:00
6778375f43 Fix Dependency 2024-01-19 02:22:17 +01:00
0dcee037fc Update Readme 2024-01-19 02:22:12 +01:00
ee0ca69475 Fix wrong order of parameters 2024-01-19 02:13:25 +01:00
18d3b6bf66 Update Dependency Cshocker
Update Dependency CS2GSI
Update README
OpenShock now automatically gets shockerIds
2024-01-19 02:06:26 +01:00
d040995051 Dictionary 2024-01-19 01:55:21 +01:00
dbb0bcd89f ConfigurationValid() tobeimplemented 2024-01-19 01:55:15 +01:00
968c3a5c37 Add PiShockHttp 2024-01-19 01:43:04 +01:00
4039455bfd Update Dependecy CShocker 2024-01-19 01:42:47 +01:00
b196f62111 Update Readme... 2024-01-18 18:16:50 +01:00
b085de2b39 Update Readme 2024-01-18 18:16:10 +01:00
ba8b76bfba Update Readme 2024-01-18 18:15:11 +01:00
0f62e9e9c9 Fix setup 2024-01-18 00:21:51 +01:00
7 changed files with 105 additions and 36 deletions

View File

@ -6,5 +6,6 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=libraryfolders/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=NYAA/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=OpenCS2hock/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Sharecode/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=steamapps/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=steamid/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>

View File

@ -31,6 +31,8 @@ public struct Configuration
Setup.Run().SaveConfiguration();
Configuration c = JsonConvert.DeserializeObject<Configuration>(File.ReadAllText(settingsFilePath), new CShocker.Shockers.ShockerJsonConverter());
if (!c.ConfigurationValid())
throw new Exception("Configuration validation failed.");
foreach (Shocker cShocker in c.Shockers)
cShocker.SetLogger(logger);
return c;
@ -41,4 +43,9 @@ public struct Configuration
string settingsFilePath = path ?? "config.json";
File.WriteAllText(settingsFilePath, JsonConvert.SerializeObject(this, Formatting.Indented));
}
private bool ConfigurationValid()
{
return true; //TODO Check values
}
}

View File

@ -2,7 +2,7 @@
using CS2GSI;
using CShocker.Ranges;
using CShocker.Shockers.Abstract;
using CS2Event = CS2GSI.CS2GSI.CS2Event;
using CS2Event = CS2GSI.CS2Event;
namespace OpenCS2hock;

View File

@ -10,8 +10,8 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="CS2GSI" Version="1.0.6" />
<PackageReference Include="CShocker" Version="1.1.11" />
<PackageReference Include="CS2GSI" Version="1.0.7" />
<PackageReference Include="CShocker" Version="1.2.5" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>

View File

@ -4,7 +4,7 @@ using CShocker.Shockers;
using CShocker.Shockers.Abstract;
using CShocker.Shockers.APIS;
using Microsoft.Extensions.Logging;
using CS2Event = CS2GSI.CS2GSI.CS2Event;
using CS2Event = CS2GSI.CS2Event;
namespace OpenCS2hock;
@ -105,31 +105,43 @@ public static class Setup
{
Console.WriteLine("Select API:");
Console.WriteLine("1) OpenShock (HTTP)");
Console.WriteLine("2) OpenShock (Serial)");
Console.WriteLine("2) OpenShock (Serial) NotImplemented"); //TODO
Console.WriteLine("3) PiShock (HTTP)");
Console.WriteLine("4) PiShock (Serial)");
Console.WriteLine("4) PiShock (Serial) NotImplemented"); //TODO
string? selectedChar = Console.ReadLine();
int selected;
while (!int.TryParse(selectedChar, out selected) || selected < 1 || selected > 1)
while (!int.TryParse(selectedChar, out selected) || (selected != 1 && selected != 3))
selectedChar = Console.ReadLine();
string apiUri, apiKey;
Shocker newShocker;
DurationRange durationRange;
IntensityRange intensityRange;
List<string> shockerIds = new();
switch (selected)
{
case 1: //OpenShock (HTTP)
string apiUri = QueryString("OpenShock API-Endpoint (https://api.shocklink.net):",
"https://api.shocklink.net");
string apiKey = QueryString("OpenShock API-Key:","");
apiUri = QueryString("OpenShock API-Endpoint (https://api.shocklink.net):", "https://api.shocklink.net");
apiKey = QueryString("OpenShock API-Key:","");
intensityRange = GetIntensityRange();
durationRange = GetDurationRange();
newShocker = new OpenShockHttp(shockerIds, intensityRange, durationRange, apiKey, apiUri);
newShocker.ShockerIds.AddRange(((OpenShockHttp)newShocker).GetShockers());
break;
case 3: //PiShock (HTTP)
apiUri = QueryString("PiShock API-Endpoint (https://do.pishock.com/api/apioperate):", "https://do.pishock.com/api/apioperate");
apiKey = QueryString("PiShock API-Key:","");
string username = QueryString("Username:","");
string shareCode = QueryString("Sharecode:","");
Console.WriteLine("Shocker IDs associated with this API:");
List<string> shockerIds = GetShockerIds(c.Shockers);
IntensityRange intensityRange = GetIntensityRange();
DurationRange durationRange = GetDurationRange();
shockerIds = AddShockerIds();
intensityRange = GetIntensityRange();
durationRange = GetDurationRange();
newShocker = new OpenShockHttp(shockerIds, intensityRange, durationRange, apiUri, apiKey);
newShocker = new PiShockHttp(shockerIds, intensityRange, durationRange, apiKey, username, shareCode, apiUri);
break;
// ReSharper disable thrice RedundantCaseLabel
case 2: //OpenShock (Serial)
case 3: //PiShock (HTTP)
case 4: //PiShock (Serial)
default:
throw new NotImplementedException();
@ -186,25 +198,46 @@ public static class Setup
return new DurationRange(min, max);
}
private static List<string> GetShockerIds(List<Shocker> shockers)
private static List<string> AddShockerIds()
{
List<string> allShockerIds = new();
foreach(Shocker shocker in shockers)
allShockerIds.AddRange(shocker.ShockerIds);
List<string> ids = new();
bool addAnother = true;
while (ids.Count < 1 || addAnother)
{
string id = QueryString("Shocker ID:", "");
while (id.Length < 1)
id = QueryString("Shocker ID:", "");
for (int i = 0; i < allShockerIds.Count; i++)
Console.WriteLine($"{i}) {allShockerIds[i]}");
ids.Add(id);
Console.WriteLine("Add another ID? (Y/N):");
addAnother = Console.ReadKey().Key == ConsoleKey.Y;
}
return ids;
}
private static List<string> GetShockerIds(List<Shocker> shockers)
{
List<string> ids = new();
bool addAnother = true;
while (ids.Count < 1 || addAnother)
{
Console.WriteLine("Select Shocker API:");
for(int i = 0; i < shockers.Count; i++)
Console.WriteLine($"{i}) {shockers[i]}");
int selectedShocker;
while (!int.TryParse(Console.ReadLine(), out selectedShocker) || selectedShocker < 0 || selectedShocker >= shockers.Count)
Console.WriteLine("Select Shocker API:");
for (int i = 0; i < shockers[selectedShocker].ShockerIds.Count; i++)
Console.WriteLine($"{i}) {shockers[selectedShocker].ShockerIds[i]}");
int selectedIndex;
while (!int.TryParse(Console.ReadLine(), out selectedIndex) || selectedIndex < 0 || selectedIndex >= allShockerIds.Count)
while (!int.TryParse(Console.ReadLine(), out selectedIndex) || selectedIndex < 0 || selectedIndex >= shockers[selectedShocker].ShockerIds.Count)
Console.WriteLine("Select ID:");
ids.Add(allShockerIds[selectedIndex]);
ids.Add(shockers[selectedShocker].ShockerIds[selectedIndex]);
Console.WriteLine("Add another ID? (Y/N):");
addAnother = Console.ReadKey().Key == ConsoleKey.Y;

View File

@ -1,5 +1,5 @@
using CShocker.Shockers;
using CS2Event = CS2GSI.CS2GSI.CS2Event;
using CS2GSI;
using CShocker.Shockers;
namespace OpenCS2hock;

View File

@ -43,30 +43,58 @@ Example `config.json`. Place next to executable. Will also be generated on first
}
```
## LogLevel
[Levels](https://learn.microsoft.com/de-de/dotnet/api/microsoft.extensions.logging.loglevel?view=dotnet-plat-ext-8.0)
## Shockers
### ApiKey
For OpenShock get token [here](https://shocklink.net/#/dashboard/tokens)
- For OpenShock (HTTP) get token [here](https://shocklink.net/#/dashboard/tokens)
- For PiShock (HTTP) get information [here](https://apidocs.pishock.com/#header-authenticating)
### ApiType
CShocker [![Github](https://img.shields.io/badge/Github-8A2BE2)](https://github.com/C9Glax/cshocker) [here](https://github.com/C9Glax/CShocker/blob/master/CShocker/Shockers/Abstract/ShockerApi.cs)
### ShockerIds
List of Shocker-Ids, comma seperated. Get Id [here](https://shocklink.net/#/dashboard/shockers/own). Press the three dots -> Edit
List of Shocker-Ids, comma seperated.
Example `[ "ID-1", "ID-2" ]`
`[ "ID-1-asdasd", "ID-2-fghfgh" ]`
### Intensity Range
`0-100`%
in percent
`0-100`
### Duration Range
in ms
- `0-30000` OpenShock
- `0-15000` PiShock
### Values for `Actions`
- Beep
- Shock
- Vibrate
- Nothing
### Username (PiShockHttp only)
For PiShock (HTTP) get information [here](https://apidocs.pishock.com/#header-authenticating)
### Sharecode (PiShockHttp only)
For PiShock (HTTP) get information [here](https://apidocs.pishock.com/#header-authenticating)
## ShockerActions
### TriggerEvent IDs
From CS2GSI [![Github](https://img.shields.io/badge/Github-8A2BE2)](https://github.com/C9Glax/CS2GSI) [here](https://github.com/C9Glax/CS2GSI/blob/master/CS2GSI/CS2Event.cs)
### ShockerIds
List of Shocker-Ids, comma seperated. (Same as in configured Shocker)
`[ "ID-1", "ID-2" ]`
### Actions
From CShocker [![Github](https://img.shields.io/badge/Github-8A2BE2)](https://github.com/C9Glax/cshocker) [here](https://github.com/C9Glax/CShocker/blob/master/CShocker/Shockers/ControlAction.cs)
### ValueFromInput
Use CS2GSI EventArgs value to determine Intensity (within configured IntensityRange)
# Using
### CS2GSI
[![GitHub License](https://img.shields.io/github/license/c9glax/CS2GSI)](/LICENSE)
[![GitHub License](https://img.shields.io/github/license/c9glax/CS2GSI)](https://img.shields.io/github/license/c9glax/CS2GSI/LICENSE)
[![NuGet Version](https://img.shields.io/nuget/v/CS2GSI)](https://www.nuget.org/packages/CS2GSI/)
[![Github](https://img.shields.io/badge/Github-8A2BE2)](https://github.com/C9Glax/CS2GSI)
[![GitHub Release](https://img.shields.io/github/v/release/c9glax/CS2GSI)](https://github.com/C9Glax/CS2GSI/releases/latest)