Skip to content

Commit

Permalink
Add Arduino macros to DCSBIOSOutput (#493)
Browse files Browse the repository at this point in the history
- these are used when creating APIs for the controls
- made auto properties in DCSBIOSOutput
  • Loading branch information
jdahlblom authored Mar 1, 2024
1 parent 3a2dc25 commit cbbf957
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 86 deletions.
15 changes: 3 additions & 12 deletions src/DCS-BIOS/Json/DCSBIOSControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,11 @@ public class DCSBIOSControl

[JsonProperty("inputs", Required = Required.Default)]
public List<DCSBIOSControlInput> Inputs { get; set; }
/*
[Obsolete]
[JsonIgnore]
[JsonProperty("momentary_positions", Required = Required.Default)]
public string MomentaryPositions { get; set; }
*/

[JsonProperty("outputs", Required = Required.Default)]
public List<DCSBIOSControlOutput> Outputs { get; set; }
/*
[Obsolete]
[JsonIgnore]
[JsonProperty("physical_variant", Required = Required.Default)]
public string PhysicalVariant { get; set; }
*/


public bool HasOutput()
{
return Outputs.Count > 0;
Expand Down
9 changes: 9 additions & 0 deletions src/DCS-BIOS/Json/DCSBIOSControlOutput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ public class DCSBIOSControlOutput

[JsonProperty("max_length", Required = Required.Default)]
public int MaxLength { get; set; }

[JsonProperty("address_identifier", Required = Required.Default)]
public string AddressIdentifier { get; set; }

[JsonProperty("address_mask_identifier", Required = Required.Default)]
public string AddressMaskIdentifier { get; set; }

[JsonProperty("address_mask_shift_identifier", Required = Required.Default)]
public string AddressMaskShiftIdentifier { get; set; }

[JsonProperty("type", Required = Required.Default)]
public string Type
Expand Down
109 changes: 41 additions & 68 deletions src/DCS-BIOS/Serialized/DCSBIOSOutput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,23 +46,13 @@ public enum DCSBiosOutputComparison
[SerializeCritical]
public class DCSBIOSOutput
{
// These are loaded and saved, all the rest are fetched from DCS-BIOS
private string _controlId;

// The target value used for comparison as chosen by the user
private uint _specifiedValueUInt;

private string _controlDescription;
private int _maxValue;
private uint _address;
private uint _mask;
private int _shiftValue;
private int _maxLength;
private volatile uint _lastUIntValue = uint.MaxValue;
private volatile string _lastStringValue = "";
private DCSBiosOutputType _dcsBiosOutputType = DCSBiosOutputType.None;
private DCSBiosOutputComparison _dcsBiosOutputComparison = DCSBiosOutputComparison.Equals;
private bool _uintValueHasChanged = false;
private bool _uintValueHasChanged;

[NonSerialized] private object _lockObject = new();

Expand All @@ -74,7 +64,6 @@ public static DCSBIOSOutput CreateCopy(DCSBIOSOutput dcsbiosOutput)
ControlId = dcsbiosOutput.ControlId,
Address = dcsbiosOutput.Address,
ControlDescription = dcsbiosOutput.ControlDescription,
//ControlType = dcsbiosOutput.ControlType,
DCSBiosOutputComparison = dcsbiosOutput.DCSBiosOutputComparison,
Mask = dcsbiosOutput.Mask,
MaxLength = dcsbiosOutput.MaxLength,
Expand All @@ -98,39 +87,46 @@ public void Copy(DCSBIOSOutput dcsbiosOutput)
ControlId = dcsbiosOutput.ControlId;
Address = dcsbiosOutput.Address;
ControlDescription = dcsbiosOutput.ControlDescription;
//ControlType = dcsbiosOutput.ControlType;
DCSBiosOutputComparison = dcsbiosOutput.DCSBiosOutputComparison;
Mask = dcsbiosOutput.Mask;
MaxLength = dcsbiosOutput.MaxLength;
MaxValue = dcsbiosOutput.MaxValue;
ShiftValue = dcsbiosOutput.ShiftValue;
AddressIdentifier = dcsbiosOutput.AddressIdentifier;
AddressMaskIdentifier = dcsbiosOutput.AddressMaskIdentifier;
AddressMaskShiftIdentifier = dcsbiosOutput.AddressMaskShiftIdentifier;

if (DCSBiosOutputType == DCSBiosOutputType.IntegerType)
{
SpecifiedValueUInt = dcsbiosOutput.SpecifiedValueUInt;
}
}
public void Consume(DCSBIOSControl dcsbiosControl, DCSBiosOutputType dcsBiosOutputType)
{
_controlId = dcsbiosControl.Identifier;
_controlDescription = dcsbiosControl.Description;
ControlId = dcsbiosControl.Identifier;
ControlDescription = dcsbiosControl.Description;
try
{
if (!dcsbiosControl.HasOutput())
{
_dcsBiosOutputType = DCSBiosOutputType.None;
DCSBiosOutputType = DCSBiosOutputType.None;
return;
}

foreach (var dcsbiosControlOutput in dcsbiosControl.Outputs)
{
if (dcsbiosControlOutput.OutputDataType == dcsBiosOutputType)
{
_dcsBiosOutputType = dcsbiosControlOutput.OutputDataType;
DCSBiosOutputType = dcsbiosControlOutput.OutputDataType;
_address = dcsbiosControlOutput.Address;
_mask = dcsbiosControlOutput.Mask;
_maxValue = dcsbiosControlOutput.MaxValue;
_maxLength = dcsbiosControlOutput.MaxLength;
_shiftValue = dcsbiosControlOutput.ShiftBy;
Mask = dcsbiosControlOutput.Mask;
MaxValue = dcsbiosControlOutput.MaxValue;
MaxLength = dcsbiosControlOutput.MaxLength;
ShiftValue = dcsbiosControlOutput.ShiftBy;

AddressIdentifier = dcsbiosControlOutput.AddressIdentifier;
AddressMaskIdentifier = dcsbiosControlOutput.AddressMaskIdentifier;
AddressMaskShiftIdentifier = dcsbiosControlOutput.AddressMaskShiftIdentifier;

if (dcsBiosOutputType == DCSBiosOutputType.StringType)
{
Expand All @@ -143,7 +139,7 @@ public void Consume(DCSBIOSControl dcsbiosControl, DCSBiosOutputType dcsBiosOutp
}
catch (Exception)
{
throw new Exception($"Failed to copy control {_controlId}. Control output is missing.{Environment.NewLine}");
throw new Exception($"Failed to copy control {ControlId}. Control output is missing.{Environment.NewLine}");
}
}

Expand Down Expand Up @@ -270,12 +266,12 @@ public uint GetUIntValue(uint data)

public override string ToString()
{
if (_dcsBiosOutputType == DCSBiosOutputType.StringType)
if (DCSBiosOutputType == DCSBiosOutputType.StringType)
{
return "";
}

return "DCSBiosOutput{" + _controlId + "|" + _dcsBiosOutputComparison + "|" + _specifiedValueUInt + "}";
return "DCSBiosOutput{" + ControlId + "|" + DCSBiosOutputComparison + "|" + _specifiedValueUInt + "}";
}

public void ImportString(string str)
Expand All @@ -296,19 +292,15 @@ public void ImportString(string str)

// AAP_EGIPWR|Equals|0
var entries = value.Split(new[] { "|" }, StringSplitOptions.RemoveEmptyEntries);
_controlId = entries[0];
var dcsBIOSControl = DCSBIOSControlLocator.GetControl(_controlId);
ControlId = entries[0];
var dcsBIOSControl = DCSBIOSControlLocator.GetControl(ControlId);
Consume(dcsBIOSControl, DCSBiosOutputType.IntegerType);
_dcsBiosOutputComparison = (DCSBiosOutputComparison)Enum.Parse(typeof(DCSBiosOutputComparison), entries[1]);
DCSBiosOutputComparison = (DCSBiosOutputComparison)Enum.Parse(typeof(DCSBiosOutputComparison), entries[1]);
_specifiedValueUInt = (uint)int.Parse(entries[2]);
}

[JsonProperty("ControlId", Required = Required.Default)]
public string ControlId
{
get => _controlId;
set => _controlId = value;
}
public string ControlId { get; set; }

[JsonProperty("Address", Required = Required.Default)]
public uint Address
Expand All @@ -322,32 +314,16 @@ public uint Address
}

[JsonProperty("Mask", Required = Required.Default)]
public uint Mask
{
get => _mask;
set => _mask = value;
}
public uint Mask { get; set; }

[JsonProperty("Shiftvalue", Required = Required.Default)]
public int ShiftValue
{
get => _shiftValue;
set => _shiftValue = value;
}
public int ShiftValue { get; set; }

[JsonProperty("DCSBiosOutputType", Required = Required.Default)]
public DCSBiosOutputType DCSBiosOutputType
{
get => _dcsBiosOutputType;
set => _dcsBiosOutputType = value;
}
public DCSBiosOutputType DCSBiosOutputType { get; set; } = DCSBiosOutputType.None;

[JsonProperty("DCSBiosOutputComparison", Required = Required.Default)]
public DCSBiosOutputComparison DCSBiosOutputComparison
{
get => _dcsBiosOutputComparison;
set => _dcsBiosOutputComparison = value;
}
public DCSBiosOutputComparison DCSBiosOutputComparison { get; set; } = DCSBiosOutputComparison.Equals;

[JsonIgnore]
public uint SpecifiedValueUInt
Expand All @@ -365,25 +341,22 @@ public uint SpecifiedValueUInt
}

[JsonProperty("ControlDescription", Required = Required.Default)]
public string ControlDescription
{
get => _controlDescription;
set => _controlDescription = value;
}
public string ControlDescription { get; set; }

[JsonProperty("MaxValue", Required = Required.Default)]
public int MaxValue
{
get => _maxValue;
set => _maxValue = value;
}
public int MaxValue { get; set; }

[JsonIgnore]
public string AddressIdentifier { get; set; }

[JsonIgnore]
public string AddressMaskIdentifier { get; set; }

[JsonIgnore]
public string AddressMaskShiftIdentifier { get; set; }

[JsonProperty("MaxLength", Required = Required.Default)]
public int MaxLength
{
get => _maxLength;
set => _maxLength = value;
}
public int MaxLength { get; set; }

[Obsolete]
[JsonIgnore]
Expand Down Expand Up @@ -423,7 +396,7 @@ public string GetOutputType()
DCSBiosOutputType.IntegerType => "integer",
DCSBiosOutputType.StringType => "string",
DCSBiosOutputType.None => "none",
DCSBiosOutputType.FloatBuffer => "float buffer",
DCSBiosOutputType.FloatBuffer => "float",
DCSBiosOutputType.LED => "led",
DCSBiosOutputType.ServoOutput => "servo output",
_ => throw new Exception($"GetOutputType() : Failed to identify {DCSBiosOutputType} output type.")
Expand Down
16 changes: 10 additions & 6 deletions src/DCS-BIOS/misc/DCSBIOSArduinoInformation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public static List<string> GetInformation(DCSBIOSControl dcsbiosControl)
result.Add(LEDOutput(dcsbiosControl, output, true));
break;
}
case DCSBiosOutputType.FloatBuffer:
case DCSBiosOutputType.FloatBuffer: // does this still exist?
{
result.Add(FloatOutput(dcsbiosControl, output));
break;
Expand Down Expand Up @@ -298,7 +298,8 @@ private static string IntegerOutput(DCSBIOSControl dcsbiosControl, DCSBIOSContro
str += $"\t\t/* your code here */\n}}\n";

//code.append($("<span>").text("DcsBios::IntegerBuffer "+idCamelCase(cid+"_BUFFER")+'('+io.address_identifier+', '+idCamelCase("ON_"+cid+"_CHANGE")+');'));
str += $"DcsBios::IntegerBuffer {MakeCamelCase(dcsbiosControl.Identifier + "_BUFFER")}({Common.GetHex(output.Address)}, {Common.GetHex(output.Mask)}, {output.ShiftBy}, {functionName});";
//str += $"DcsBios::IntegerBuffer {MakeCamelCase(dcsbiosControl.Identifier + "_BUFFER")}({Common.GetHex(output.Address)}, {Common.GetHex(output.Mask)}, {output.ShiftBy}, {functionName});";
str += $"DcsBios::IntegerBuffer {MakeCamelCase(dcsbiosControl.Identifier + "_BUFFER")}({output.AddressMaskShiftIdentifier}, {functionName});";
return str;
}

Expand All @@ -308,7 +309,8 @@ private static string LEDOutput(DCSBIOSControl dcsbiosControl, DCSBIOSControlOut
var str = "";
if (addBanner) str += CommonOutputData(dcsbiosControl, output);
//code.append($("<span>").text('DcsBios::LED '+idCamelCase(cid)+'('+io.address_identifier+', '));
str += $"DcsBios::LED {functionName}({Common.GetHex(output.Address)}, PIN);";
//str += $"DcsBios::LED {functionName}({Common.GetHex(output.Address)}, PIN);";
str += $"DcsBios::LED {functionName}({output.AddressMaskIdentifier}, PIN);";

return str;
}
Expand All @@ -323,7 +325,8 @@ private static string StringOutput(DCSBIOSControl dcsbiosControl, DCSBIOSControl
str += $"\t\t/* your code here */\n}}\n";

//code.append($("<span>").text("DcsBios::StringBuffer<" + io.max_length.toString() + "> " + idCamelCase(cid + io.suffix + "_BUFFER") + '(' + io.address_identifier + ', ' + idCamelCase("ON_" + cid + "_CHANGE") + ');'));
str += $"DcsBios::StringBuffer<{output.MaxLength}> {MakeCamelCase(dcsbiosControl.Identifier + output.Suffix + "_BUFFER")}(\"{Common.GetHex(output.Address)}\", {functionName});";
//str += $"DcsBios::StringBuffer<{output.MaxLength}> {MakeCamelCase(dcsbiosControl.Identifier + output.Suffix + "_BUFFER")}(\"{Common.GetHex(output.Address)}\", {functionName});";
str += $"DcsBios::StringBuffer<{output.MaxLength}> {MakeCamelCase(dcsbiosControl.Identifier + output.Suffix + "_BUFFER")}({output.AddressIdentifier}, {functionName});";
return str;
}

Expand All @@ -332,7 +335,7 @@ private static string ServoOutput(DCSBIOSControl dcsbiosControl, DCSBIOSControlO
var functionName = MakeCamelCase(dcsbiosControl.Identifier);
var str = CommonOutputData(dcsbiosControl, output);
//code.append($("<span>").text('DcsBios::ServoOutput ' + idCamelCase(cid) + '(' + io.address_only_identifier + ', '));
str += $"DcsBios::ServoOutput {functionName}({Common.GetHex(output.Address)}, PIN, 544, 2400);";
str += $"DcsBios::ServoOutput {functionName}({output.AddressIdentifier}, PIN, 544, 2400);";

return str;
}
Expand All @@ -341,7 +344,8 @@ private static string FloatOutput(DCSBIOSControl dcsbiosControl, DCSBIOSControlO
var functionName = MakeCamelCase(dcsbiosControl.Identifier + output.Suffix + "_BUFFER");
var str = CommonOutputData(dcsbiosControl, output);
//code.append($("<span>").text("DcsBios::FloatBuffer "+idCamelCase(cid+io.suffix+"_BUFFER")+'('+io.address_identifier+', '+io.value_range[0].toFixed()+', '+io.value_range[1]+ending+');'));
str += $"DcsBios::FloatBuffer {functionName}({Common.GetHex(output.Address)}, 0, {output.MaxLength});";
//str += $"DcsBios::FloatBuffer {functionName}({Common.GetHex(output.Address)}, 0, {output.MaxLength});";
str += $"DcsBios::FloatBuffer {functionName}({output.AddressMaskShiftIdentifier}, 0, {output.MaxLength});";

return str;
}
Expand Down

0 comments on commit cbbf957

Please sign in to comment.