From cbbf9577548abaad4e46bc6fb69660d848434305 Mon Sep 17 00:00:00 2001 From: Jerker Dahlblom Date: Fri, 1 Mar 2024 18:44:03 +0200 Subject: [PATCH] Add Arduino macros to DCSBIOSOutput (#493) - these are used when creating APIs for the controls - made auto properties in DCSBIOSOutput --- src/DCS-BIOS/Json/DCSBIOSControl.cs | 15 +-- src/DCS-BIOS/Json/DCSBIOSControlOutput.cs | 9 ++ src/DCS-BIOS/Serialized/DCSBIOSOutput.cs | 109 +++++++----------- .../misc/DCSBIOSArduinoInformation.cs | 16 ++- 4 files changed, 63 insertions(+), 86 deletions(-) diff --git a/src/DCS-BIOS/Json/DCSBIOSControl.cs b/src/DCS-BIOS/Json/DCSBIOSControl.cs index 783a79f43..0f22757ad 100644 --- a/src/DCS-BIOS/Json/DCSBIOSControl.cs +++ b/src/DCS-BIOS/Json/DCSBIOSControl.cs @@ -26,20 +26,11 @@ public class DCSBIOSControl [JsonProperty("inputs", Required = Required.Default)] public List Inputs { get; set; } - /* - [Obsolete] - [JsonIgnore] - [JsonProperty("momentary_positions", Required = Required.Default)] - public string MomentaryPositions { get; set; } - */ + [JsonProperty("outputs", Required = Required.Default)] public List Outputs { get; set; } - /* - [Obsolete] - [JsonIgnore] - [JsonProperty("physical_variant", Required = Required.Default)] - public string PhysicalVariant { get; set; } - */ + + public bool HasOutput() { return Outputs.Count > 0; diff --git a/src/DCS-BIOS/Json/DCSBIOSControlOutput.cs b/src/DCS-BIOS/Json/DCSBIOSControlOutput.cs index 56b4affc7..b6b337dba 100644 --- a/src/DCS-BIOS/Json/DCSBIOSControlOutput.cs +++ b/src/DCS-BIOS/Json/DCSBIOSControlOutput.cs @@ -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 diff --git a/src/DCS-BIOS/Serialized/DCSBIOSOutput.cs b/src/DCS-BIOS/Serialized/DCSBIOSOutput.cs index ac5859feb..9af35c018 100644 --- a/src/DCS-BIOS/Serialized/DCSBIOSOutput.cs +++ b/src/DCS-BIOS/Serialized/DCSBIOSOutput.cs @@ -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(); @@ -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, @@ -98,12 +87,15 @@ 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; @@ -111,13 +103,13 @@ public void Copy(DCSBIOSOutput dcsbiosOutput) } 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; } @@ -125,12 +117,16 @@ public void Consume(DCSBIOSControl dcsbiosControl, DCSBiosOutputType dcsBiosOutp { 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) { @@ -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}"); } } @@ -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) @@ -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 @@ -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 @@ -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] @@ -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.") diff --git a/src/DCS-BIOS/misc/DCSBIOSArduinoInformation.cs b/src/DCS-BIOS/misc/DCSBIOSArduinoInformation.cs index ca900f1d6..bdb4de5e7 100644 --- a/src/DCS-BIOS/misc/DCSBIOSArduinoInformation.cs +++ b/src/DCS-BIOS/misc/DCSBIOSArduinoInformation.cs @@ -136,7 +136,7 @@ public static List 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; @@ -298,7 +298,8 @@ private static string IntegerOutput(DCSBIOSControl dcsbiosControl, DCSBIOSContro str += $"\t\t/* your code here */\n}}\n"; //code.append($("").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; } @@ -308,7 +309,8 @@ private static string LEDOutput(DCSBIOSControl dcsbiosControl, DCSBIOSControlOut var str = ""; if (addBanner) str += CommonOutputData(dcsbiosControl, output); //code.append($("").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; } @@ -323,7 +325,8 @@ private static string StringOutput(DCSBIOSControl dcsbiosControl, DCSBIOSControl str += $"\t\t/* your code here */\n}}\n"; //code.append($("").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; } @@ -332,7 +335,7 @@ private static string ServoOutput(DCSBIOSControl dcsbiosControl, DCSBIOSControlO var functionName = MakeCamelCase(dcsbiosControl.Identifier); var str = CommonOutputData(dcsbiosControl, output); //code.append($("").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; } @@ -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($("").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; }