Skip to content

Commit

Permalink
Add public const for INC/DEC/TOGGLE. (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
jdahlblom authored Apr 3, 2024
1 parent 4515e6c commit 1af04a6
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions src/DCS-BIOS/misc/DCSBIOSCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ public class DCSBIOSCommand
{
private readonly List<DCSBIOSInputType> _supportedInterfaces = new();
private readonly int _defaultVariableChangeValue = 0;

public const string DCSBIOS_INCREMENT = "INC\n";
public const string DCSBIOS_DECREMENT = "DEC\n";
public const string DCSBIOS_TOGGLE = "TOGGLE\n";
private readonly string _controlId;

public DCSBIOSCommand(DCSBIOSControl dcsbiosControl)
Expand All @@ -34,28 +36,38 @@ public DCSBIOSCommand(DCSBIOSControl dcsbiosControl)
}
}

public string ControlId
{
get => _controlId;
}

public string ControlIdWithSpace
{
get => _controlId + " ";
}

public string GetIncCommand()
{
if (_supportedInterfaces.Any(o => o == DCSBIOSInputType.FIXED_STEP) == false)
throw new ArgumentException($"DCSBIOSCommand: {_controlId} does not have {DCSBIOSInputType.FIXED_STEP}");

return $"{_controlId} INC\n";
return $"{_controlId} {DCSBIOS_INCREMENT}";
}

public string GetDecCommand()
{
if (_supportedInterfaces.Any(o => o == DCSBIOSInputType.FIXED_STEP) == false)
throw new ArgumentException($"DCSBIOSCommand: {_controlId} does not have {DCSBIOSInputType.FIXED_STEP}");

return $"{_controlId} DEC\n";
return $"{_controlId} {DCSBIOS_DECREMENT}";
}

public string GetActionCommand()
{
if (_supportedInterfaces.Any(o => o == DCSBIOSInputType.ACTION) == false)
throw new ArgumentException($"DCSBIOSCommand: {_controlId} does not have {DCSBIOSInputType.ACTION}");

return $"{_controlId} TOGGLE\n";
return $"{_controlId} {DCSBIOS_TOGGLE}";
}

public string GetSetStateCommand(uint value)
Expand All @@ -66,13 +78,20 @@ public string GetSetStateCommand(uint value)
return $"{_controlId} {value}\n";
}

public string GetSetStateCommand(bool increment)
{
if (_supportedInterfaces.Any(o => o == DCSBIOSInputType.SET_STATE) == false)
throw new ArgumentException($"DCSBIOSCommand: {_controlId} does not have {DCSBIOSInputType.SET_STATE}");

return $"{_controlId} {(increment ? DCSBIOS_INCREMENT : DCSBIOS_DECREMENT)}";
}

public string GetVariableCommand(int value)
{
if (_supportedInterfaces.Any(o => o == DCSBIOSInputType.VARIABLE_STEP) == false)
throw new ArgumentException($"DCSBIOSCommand: {_controlId} does not have {DCSBIOSInputType.VARIABLE_STEP}");

var s = value > 0 ? "+" + value : value.ToString();
return $"{_controlId} {s}\n";
return $"{_controlId} {(value > 0 ? "+" + value : value.ToString())}\n";
}

public string GetVariableCommand(int value, bool decrement)
Expand Down

0 comments on commit 1af04a6

Please sign in to comment.