Skip to content

Commit

Permalink
implement openshock interface through sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
krogenth committed Aug 24, 2024
1 parent 939939a commit d1a8b20
Show file tree
Hide file tree
Showing 28 changed files with 589 additions and 229 deletions.
7 changes: 7 additions & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@
<PackageVersion Include="BuildSoft.OscCore" Version="1.2.1.1" />
<!-- OpenShock API -->
<PackageVersion Include="OpenShock.SDK.CSharp" Version="0.0.25" />
<PackageVersion Include="OpenShock.SDK.CSharp.Live" Version="0.0.25" />
<PackageVersion Include="OpenShock.SDK.CSharp.Hub" Version="0.0.24" />
<PackageVersion Include="Serilog" Version="4.0.1" />
<PackageVersion Include="Serilog.Extensions.Hosting" Version="8.0.0" />
<PackageVersion Include="Serilog.Sinks.Console" Version="6.0.0" />
<PackageVersion Include="Serilog.Sinks.File" Version="6.0.0" />
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Logging" Version="8.0.0" />
</ItemGroup>
</Project>
20 changes: 6 additions & 14 deletions OpenShock.VoiceRecognizer.Configuration/ConfigurationFileFormat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,9 @@ public class ConfigurationFileFormat
public int OscListenPort { get; set; } = 0;
public ShockCollarType CollarType { get; set; } = ShockCollarType.OpenShock;
public ObservableCollection<WordRecognition> Words { get; set; } = [];
/*public string OpenShockAPIKey { get; set; } = string.Empty;
public string OpenShockGroupName { get; set; } = string.Empty;*/
public string OpenShockSendHost { get; set; } = string.Empty;
public int OpenShockSendPort { get; set; } = 0;
public string OpenShockOscListenIntensityEndpoint { get; set; } = string.Empty;
public string OpenShockOscSendShockEndpoint { get; set; } = string.Empty;
public string OpenShockOscSendVibrateEndpoint { get; set; } = string.Empty;
public string OpenShockAPIKey { get; set; } = string.Empty;
public Guid OpenShockDeviceID { get; set;} = Guid.Empty;
public Guid OpenShockShockerID { get; set; } = Guid.Empty;
public BrowserProxyType BrowserProxyType { get; set; } = BrowserProxyType.Chrome;
public int BrowserProxyPort { get; set; } = 0;

Expand All @@ -30,13 +26,9 @@ public ConfigurationFileFormat(ConfigurationState state)
OscListenPort = state.OSC.ListenPort.Value;
CollarType = state.Shock.CollarType.Value;
Words = state.Shock.Words.Value;
/*OpenShockAPIKey = state.OpenShock.APIKey.Value;
OpenShockGroupName = state.OpenShock.GroupName.Value;*/
OpenShockSendHost = state.OpenShock.SendHost.Value;
OpenShockSendPort = state.OpenShock.SendPort.Value;
OpenShockOscListenIntensityEndpoint = state.OpenShock.ExternalListenSetIntensityEndpoint;
OpenShockOscSendShockEndpoint = state.OpenShock.ExternalSendStartShockEndpoint;
OpenShockOscSendVibrateEndpoint = state.OpenShock.ExternalSendStartShockEndpoint;
OpenShockAPIKey = state.OpenShock.APIKey.Value;
OpenShockDeviceID = state.OpenShock.DeviceID.Value;
OpenShockShockerID = state.OpenShock.ShockerID.Value;
BrowserProxyType = state.BrowserProxy.Proxy.Value;
BrowserProxyPort = state.BrowserProxy.ProxyPort.Value;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,48 +1,32 @@
using OpenShock.VoiceRecognizer.Common;
using System.Net.Sockets;
using OpenShock.VoiceRecognizer.Common;

namespace OpenShock.VoiceRecognizer.Configuration;

public class OpenShockConfigurationState
{
/*public ReactiveObject<string> APIKey { get; private set; }
public ReactiveObject<string> GroupName { get; private set; }*/
public ReactiveObject<string> SendHost { get; private set; }
public ReactiveObject<int> SendPort { get; private set; }

public ReactiveObject<string> ExternalListenSetIntensityEndpoint { get; set; }
public ReactiveObject<string> ExternalSendStartShockEndpoint { get; set; }
public ReactiveObject<string> ExternalSendStartVibrationEndpoint { get; set; }
public ReactiveObject<string> APIKey { get; private set; }
public ReactiveObject<Guid> DeviceID { get; private set; }
public ReactiveObject<Guid> ShockerID { get; private set; }

public OpenShockConfigurationState()
{
/*APIKey = new(string.Empty);
GroupName = new(string.Empty);*/
SendHost = new(string.Empty);
SendPort = new(9006);
ExternalListenSetIntensityEndpoint = new(string.Empty);
ExternalSendStartShockEndpoint = new(string.Empty);
ExternalSendStartVibrationEndpoint = new(string.Empty);
APIKey = new(string.Empty);
DeviceID = new(Guid.Empty);
ShockerID = new(Guid.Empty);
}

public void LoadFileConfiguration(ConfigurationFileFormat configurationFileFormat)
{
/*APIKey.Value = configurationFileFormat.OpenShockAPIKey;
GroupName.Value = configurationFileFormat.OpenShockGroupName;*/
SendHost.Value = configurationFileFormat.OpenShockSendHost;
SendPort.Value = configurationFileFormat.OpenShockSendPort;
ExternalListenSetIntensityEndpoint.Value = configurationFileFormat.OpenShockOscListenIntensityEndpoint;
ExternalSendStartShockEndpoint.Value = configurationFileFormat.OpenShockOscSendShockEndpoint;
ExternalSendStartVibrationEndpoint.Value = configurationFileFormat.OpenShockOscSendVibrateEndpoint;
APIKey.Value = configurationFileFormat.OpenShockAPIKey;
DeviceID.Value = configurationFileFormat.OpenShockDeviceID;
ShockerID.Value = configurationFileFormat.OpenShockShockerID;
}

public void LoadDefaultConfiguration()
{
/*APIKey.Value = string.Empty;
GroupName.Value = string.Empty;*/
SendHost.Value = "127.0.0.1";
SendPort.Value = 0;
ExternalListenSetIntensityEndpoint.Value = string.Empty;
ExternalSendStartShockEndpoint.Value = string.Empty;
ExternalSendStartVibrationEndpoint.Value = string.Empty;
APIKey.Value = string.Empty;
DeviceID.Value = Guid.Empty;
ShockerID.Value = Guid.Empty;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ public class WordRecognition
{
public string Word { get; set; } = string.Empty;
public ShockType Type { get; set; }
public float MinInitialDelay { get; set; }
public float MaxInitialDelay { get; set; }
public float MinDelay { get; set; }
public float MaxDelay { get; set; }
public byte Intensity { get; set; }
public ushort MinDuration { get; set; }
public ushort MaxDuration { get; set; }
}
34 changes: 34 additions & 0 deletions OpenShock.VoiceRecognizer.IO/Logger/Logger.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using Microsoft.Extensions.Logging;
using Serilog;
using Serilog.Extensions.Logging;

namespace OpenShock.VoiceRecognizer.IO.Logger;

public static class Logger
{
private static ILoggerFactory? _logFactory;

public static ILogger<T>? GetLogger<T>() =>
_logFactory?.CreateLogger<T>();

public static void Initialize()
{
if (_logFactory is not null)
{
throw new InvalidOperationException("Log factory already initialize");
}

var logConfig = new LoggerConfiguration()
.MinimumLevel.Debug()
.MinimumLevel.Override("Microsoft", Serilog.Events.LogEventLevel.Information)
.Enrich.FromLogContext()
.WriteTo.Console()
.WriteTo.File("log.txt");

Log.Logger = logConfig.CreateLogger();

_logFactory = new SerilogLoggerFactory(
Log.Logger
);
}
}
14 changes: 14 additions & 0 deletions OpenShock.VoiceRecognizer.IO/OpenShock.VoiceRecognizer.IO.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,18 @@
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Serilog" />
<PackageReference Include="Serilog.Sinks.Console" />
<PackageReference Include="Serilog.Sinks.File" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Serilog" />
<PackageReference Include="Serilog.Extensions.Hosting" />
<PackageReference Include="Serilog.Sinks.Console" />
<PackageReference Include="Serilog.Sinks.File" />
<PackageReference Include="Microsoft.Extensions.Logging" />
</ItemGroup>

</Project>
34 changes: 0 additions & 34 deletions OpenShock.VoiceRecognizer.Integrations/OSC/OSCClient.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,17 @@
<ItemGroup>
<PackageReference Include="BuildSoft.OscCore" />
<PackageReference Include="OpenShock.SDK.CSharp" />
<PackageReference Include="OpenShock.SDK.CSharp.Hub" />
<PackageReference Include="OpenShock.SDK.CSharp.Hub" />
<PackageReference Include="OpenShock.SDK.CSharp.Live" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Serilog" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\OpenShock.VoiceRecognizer.Configuration\OpenShock.VoiceRecognizer.Configuration.csproj" />
<ProjectReference Include="..\OpenShock.VoiceRecognizer.IO\OpenShock.VoiceRecognizer.IO.csproj" />
</ItemGroup>

</Project>
Loading

0 comments on commit d1a8b20

Please sign in to comment.