Skip to content

Commit

Permalink
JSON data is now mostly correct but there's still something wrong wit…
Browse files Browse the repository at this point in the history
…h it
  • Loading branch information
cosmii02 committed Dec 7, 2024
1 parent 0cae7c1 commit a63000c
Show file tree
Hide file tree
Showing 9 changed files with 505 additions and 522 deletions.
6 changes: 3 additions & 3 deletions GameParsers/ForzaParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ public override ReportableInstruction GetPreRaceInstructions()
}


RightTrigger.parameters = new object[] { controllerIndex, Trigger.Right, TriggerMode.Normal, 0, 0 };
LeftTrigger.parameters = new object[] { controllerIndex, Trigger.Left, TriggerMode.Normal, 0, 0 };
RightTrigger.Parameters = new object[] { controllerIndex, Trigger.Right, TriggerMode.Normal, 0, 0 };
LeftTrigger.Parameters = new object[] { controllerIndex, Trigger.Left, TriggerMode.Normal, 0, 0 };

#region Light Bar color
int CPIcolorR = 255;
Expand Down Expand Up @@ -122,7 +122,7 @@ public override ReportableInstruction GetPreRaceInstructions()
CPIcolorB = ColorClassX[2];
}

LightBar.parameters = new object[] { controllerIndex, CPIcolorR, CPIcolorG, CPIcolorB };
LightBar.Parameters = new object[] { controllerIndex, CPIcolorR, CPIcolorG, CPIcolorB };
#endregion


Expand Down
24 changes: 12 additions & 12 deletions GameParsers/Parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ public virtual bool IsRaceOn()
public virtual ReportableInstruction GetPreRaceInstructions()
{
ReportableInstruction p = new ReportableInstruction();
RightTrigger.parameters = new object[] { controllerIndex, Trigger.Right, TriggerMode.Normal, 0, 0 };
LeftTrigger.parameters = new object[] { controllerIndex, Trigger.Left, TriggerMode.Normal, 0, 0 };
LightBar.parameters = new object[] { controllerIndex, 220, 120, 220};
RightTrigger.Parameters = new object[] { controllerIndex, Trigger.Right, TriggerMode.Normal, 0, 0 };
LeftTrigger.Parameters = new object[] { controllerIndex, Trigger.Left, TriggerMode.Normal, 0, 0 };
LightBar.Parameters = new object[] { controllerIndex, 220, 120, 220};
p.Instructions = new Instruction[] { LightBar, LeftTrigger, RightTrigger };

return p;
Expand Down Expand Up @@ -80,7 +80,7 @@ public virtual ReportableInstruction GetInRaceLightbarInstruction()
}

// Set LightBar instruction
LightBar.parameters = new object[] { controllerIndex, RedChannel, GreenChannel, BlueChannel, Brightness };
LightBar.Parameters = new object[] { controllerIndex, RedChannel, GreenChannel, BlueChannel, Brightness };

// Add report for verbose output
reportableInstruction.RacingDSXReportStructs.Add(new RacingDSXReportStruct(
Expand Down Expand Up @@ -110,7 +110,7 @@ public virtual ReportableInstruction GetInRaceLeftTriggerInstruction()

if (brakeSettings.TriggerMode == Config.TriggerMode.Off)
{
LeftTrigger.parameters = new object[] { controllerIndex, Trigger.Left, TriggerMode.Normal, 0, 0 };
LeftTrigger.Parameters = new object[] { controllerIndex, Trigger.Left, TriggerMode.Normal, 0, 0 };
}
// If losing grip, start to "vibrate"
else if (bLosingBrakeGrip && brakeSettings.TriggerMode == Config.TriggerMode.Vibration)
Expand All @@ -125,11 +125,11 @@ public virtual ReportableInstruction GetInRaceLeftTriggerInstruction()

if (filteredFreq <= brakeSettings.MinVibration)
{
LeftTrigger.parameters = new object[] { controllerIndex, Trigger.Left, TriggerMode.Resistance, 0, 0 };
LeftTrigger.Parameters = new object[] { controllerIndex, Trigger.Left, TriggerMode.Resistance, 0, 0 };
}
else
{
LeftTrigger.parameters = new object[] { controllerIndex, Trigger.Left, TriggerMode.CustomTriggerValue, CustomTriggerValueMode.VibrateResistance,
LeftTrigger.Parameters = new object[] { controllerIndex, Trigger.Left, TriggerMode.CustomTriggerValue, CustomTriggerValueMode.VibrateResistance,
filteredFreq *brakeSettings.EffectIntensity, filteredResistance * brakeSettings.EffectIntensity, brakeSettings.VibrationStart, 0, 0, 0, 0 };
}
//Set left trigger to the custom mode VibrateResitance with values of Frequency = freq, Stiffness = 104, startPostion = 76.
Expand All @@ -143,7 +143,7 @@ public virtual ReportableInstruction GetInRaceLeftTriggerInstruction()
filteredResistance = (int)EWMA(resistance, lastBrakeResistance, brakeSettings.ResistanceSmoothing);
lastBrakeResistance = filteredResistance;

LeftTrigger.parameters = new object[] { controllerIndex, Trigger.Left, TriggerMode.Resistance, 0, filteredResistance * brakeSettings.EffectIntensity };
LeftTrigger.Parameters = new object[] { controllerIndex, Trigger.Left, TriggerMode.Resistance, 0, filteredResistance * brakeSettings.EffectIntensity };

reportableInstruction.RacingDSXReportStructs.Add(new RacingDSXReportStruct(VerboseLevel.Limited, RacingDSXReportStruct.ReportType.RACING, RacingDSXReportStruct.RacingReportType.BRAKE_VIBRATION, ""));

Expand Down Expand Up @@ -177,7 +177,7 @@ public virtual ReportableInstruction GetInRaceRightTriggerInstruction()

if (throttleSettings.TriggerMode == Config.TriggerMode.Off)
{
RightTrigger.parameters = new object[] { controllerIndex, Trigger.Right, TriggerMode.Normal, 0, 0 };
RightTrigger.Parameters = new object[] { controllerIndex, Trigger.Right, TriggerMode.Normal, 0, 0 };
}
// If losing grip, start to "vibrate"
else if (bLosingAccelGrip && throttleSettings.TriggerMode == Config.TriggerMode.Vibration)
Expand All @@ -193,14 +193,14 @@ public virtual ReportableInstruction GetInRaceRightTriggerInstruction()
if (filteredFreq <= throttleSettings.MinVibration
|| data.Accelerator <= throttleSettings.VibrationModeStart)
{
RightTrigger.parameters = new object[] { controllerIndex, Trigger.Right, TriggerMode.Resistance, 0, filteredResistance * throttleSettings.EffectIntensity };
RightTrigger.Parameters = new object[] { controllerIndex, Trigger.Right, TriggerMode.Resistance, 0, filteredResistance * throttleSettings.EffectIntensity };

filteredFreq = 0;
filteredResistance = 0;
}
else
{
RightTrigger.parameters = new object[] {
RightTrigger.Parameters = new object[] {
controllerIndex, Trigger.Right, TriggerMode.CustomTriggerValue, CustomTriggerValueMode.VibrateResistance,
filteredFreq * throttleSettings.EffectIntensity, filteredResistance * throttleSettings.EffectIntensity,throttleSettings.VibrationModeStart, 0, 0, 0, 0 };
}
Expand All @@ -215,7 +215,7 @@ public virtual ReportableInstruction GetInRaceRightTriggerInstruction()
filteredResistance = (int)EWMA(resistance, lastThrottleResistance, throttleSettings.ResistanceSmoothing);

lastThrottleResistance = filteredResistance;
RightTrigger.parameters = new object[] { controllerIndex, Trigger.Right, TriggerMode.Resistance, 0, filteredResistance * throttleSettings.EffectIntensity };
RightTrigger.Parameters = new object[] { controllerIndex, Trigger.Right, TriggerMode.Resistance, 0, filteredResistance * throttleSettings.EffectIntensity };

reportableInstruction.RacingDSXReportStructs.Add(new RacingDSXReportStruct(VerboseLevel.Limited, RacingDSXReportStruct.ReportType.RACING, RacingDSXReportStruct.RacingReportType.THROTTLE_VIBRATION, ""));

Expand Down
47 changes: 40 additions & 7 deletions Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Net;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Windows.Forms;

namespace RacingDSX
Expand Down Expand Up @@ -39,17 +40,40 @@ public static class Triggers
{
public static IPAddress localhost = new IPAddress(new byte[] { 127, 0, 0, 1 });

private static readonly JsonSerializerOptions jsonOptions = new JsonSerializerOptions
{
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
WriteIndented = false,
Converters = { new JsonStringEnumConverter() }
};

public static string PacketToJson(Packet packet)
{
return JsonSerializer.Serialize(packet);
try
{
return JsonSerializer.Serialize(packet, jsonOptions);
}
catch (Exception ex)
{
throw new InvalidOperationException("Failed to serialize packet to JSON", ex);
}
}

public static Packet JsonToPacket(string json)
{
return JsonSerializer.Deserialize<Packet>(json);
try
{
return JsonSerializer.Deserialize<Packet>(json, jsonOptions)
?? throw new InvalidOperationException("Deserialized packet is null");
}
catch (Exception ex)
{
throw new InvalidOperationException("Failed to deserialize JSON to packet", ex);
}
}
}

[JsonConverter(typeof(JsonStringEnumConverter))]
public enum TriggerMode
{
Normal = 0,
Expand All @@ -73,6 +97,7 @@ public enum TriggerMode
Machine = 18
}

[JsonConverter(typeof(JsonStringEnumConverter))]
public enum CustomTriggerValueMode
{
OFF = 0,
Expand All @@ -94,13 +119,15 @@ public enum CustomTriggerValueMode
VibratePulseAB = 16
}

[JsonConverter(typeof(JsonStringEnumConverter))]
public enum Trigger
{
Invalid,
Left,
Right
}

[JsonConverter(typeof(JsonStringEnumConverter))]
public enum InstructionType
{
Invalid,
Expand All @@ -110,18 +137,24 @@ public enum InstructionType
TriggerThreshold
}

public struct Instruction
public class Instruction
{
[JsonConstructor]
public Instruction(InstructionType type)
{
this.type = type;
Type = type;
}
public InstructionType type;
public object[] parameters;

[JsonPropertyName("type")]
public InstructionType Type { get; set; }

[JsonPropertyName("parameters")]
public object[] Parameters { get; set; }
}

public class Packet
{
public Instruction[] instructions;
[JsonPropertyName("instructions")]
public Instruction[] Instructions { get; set; }
}
}
1 change: 1 addition & 0 deletions RacingDSX.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Ini" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="9.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>

<ItemGroup>
Expand Down
Loading

0 comments on commit a63000c

Please sign in to comment.