From 5a39e3948f745d0d0bd80653a211ca9f113f1b02 Mon Sep 17 00:00:00 2001 From: Charlie <30303272+charliefoxtwo@users.noreply.github.com> Date: Wed, 11 Oct 2023 18:07:27 -0700 Subject: [PATCH] Update bios communicator library to support string inputs --- Configuration/Configuration.csproj | 4 +- TouchDcsConsole/TouchDcsConsole.csproj | 2 +- .../BiosConfigurations/ButtonTests.json | 21 +++- TouchDcsTest/TouchDcsTest.csproj | 6 +- TouchDcsTest/TranslatorTests/FromOscTests.cs | 115 ++++++++++-------- .../Keys/ButtonTranslatorKeys.cs | 20 +-- TouchDcsWorker/BiosOscTranslator.cs | 10 +- TouchDcsWorker/TouchDcsWorker.csproj | 2 +- 8 files changed, 109 insertions(+), 71 deletions(-) diff --git a/Configuration/Configuration.csproj b/Configuration/Configuration.csproj index df0144f..85b9a4e 100644 --- a/Configuration/Configuration.csproj +++ b/Configuration/Configuration.csproj @@ -12,8 +12,8 @@ - - + + diff --git a/TouchDcsConsole/TouchDcsConsole.csproj b/TouchDcsConsole/TouchDcsConsole.csproj index fa28a50..a8adf79 100644 --- a/TouchDcsConsole/TouchDcsConsole.csproj +++ b/TouchDcsConsole/TouchDcsConsole.csproj @@ -12,7 +12,7 @@ - + diff --git a/TouchDcsTest/Resources/BiosConfigurations/ButtonTests.json b/TouchDcsTest/Resources/BiosConfigurations/ButtonTests.json index 84f86a0..d370601 100644 --- a/TouchDcsTest/Resources/BiosConfigurations/ButtonTests.json +++ b/TouchDcsTest/Resources/BiosConfigurations/ButtonTests.json @@ -124,6 +124,25 @@ "type":"integer" } ] + }, + "SetStringInput":{ + "category":"Button", + "control_type":"radio", + "description":"UHF Radio Frequency", + "identifier":"SetStringInput", + "inputs":[ + { + "description":"Set the frequency of the radio", + "interface":"set_string" + } + ], + "outputs":[ + { + "description":"Get the frequency of the radio", + "max_length":7, + "type":"string" + } + ] } } -} \ No newline at end of file +} diff --git a/TouchDcsTest/TouchDcsTest.csproj b/TouchDcsTest/TouchDcsTest.csproj index 42a7b6b..0d3ca34 100644 --- a/TouchDcsTest/TouchDcsTest.csproj +++ b/TouchDcsTest/TouchDcsTest.csproj @@ -9,10 +9,10 @@ - + - - + + diff --git a/TouchDcsTest/TranslatorTests/FromOscTests.cs b/TouchDcsTest/TranslatorTests/FromOscTests.cs index 6629e21..886570e 100644 --- a/TouchDcsTest/TranslatorTests/FromOscTests.cs +++ b/TouchDcsTest/TranslatorTests/FromOscTests.cs @@ -2,55 +2,68 @@ using NUnit.Framework; using TouchDcsTest.TranslatorTests.Keys; -namespace TouchDcsTest.TranslatorTests +namespace TouchDcsTest.TranslatorTests; + +public class FromOscTests : TranslatorTestBase { - public class FromOscTests : TranslatorTestBase - { - public FromOscTests() : base("ButtonTests") { } - - [Theory] - [TestCase(0)] - [TestCase(1)] - [TestCase(65535)] - [TestCase(-1)] - public void Button_FromOsc(int value) - { - BiosVerifier.Exactly(ButtonTranslatorKeys.SetStateButton, value); - } - - [TestCase(InputFixedStep.Increment, 1)] - [TestCase(InputFixedStep.Decrement, -1)] - public void Button_FromOsc_FixedStepRotary_IntIn(string expected, int valueIn) - { - BiosVerifier.Exactly(ButtonTranslatorKeys.FixedStepRotary, expected, valueIn); - } - - [TestCase(0)] - [TestCase(2)] - public void Button_FromOsc_SetStateRotary(int value) - { - BiosVerifier.Exactly(ButtonTranslatorKeys.SetStateRotary, value); - } - - [TestCase(InputFixedStep.Increment)] - [TestCase(InputFixedStep.Decrement)] - public void Button_FromOsc_FixedStepSetStateRotary_StringIn(string value) - { - BiosVerifier.Exactly(ButtonTranslatorKeys.FixedStepSetStateRotary, value); - } - - [TestCase(1)] - [TestCase(-1)] - public void Button_FromOsc_FixedStepSetStateRotary_IntIn(int value) - { - BiosVerifier.Exactly(ButtonTranslatorKeys.FixedStepSetStateRotary, value); - } - - [TestCase("+3200", InputFixedStep.Increment)] - [TestCase("-3200", InputFixedStep.Decrement)] - public void Button_FromOsc_VariableStepRotary(string expected, string valueIn) - { - BiosVerifier.Exactly(ButtonTranslatorKeys.VariableStepRotary, expected, valueIn); - } - } -} \ No newline at end of file + public FromOscTests() : base("ButtonTests") { } + + [Theory] + [TestCase(0)] + [TestCase(1)] + [TestCase(65535)] + [TestCase(-1)] + public void Button_FromOsc(int value) + { + BiosVerifier.Exactly(ButtonTranslatorKeys.SetStateButton, value); + } + + [TestCase(InputFixedStep.Increment, 1)] + [TestCase(InputFixedStep.Decrement, -1)] + public void Button_FromOsc_FixedStepRotary_IntIn(string expected, int valueIn) + { + BiosVerifier.Exactly(ButtonTranslatorKeys.FixedStepRotary, expected, valueIn); + } + + [TestCase(0)] + [TestCase(2)] + public void Button_FromOsc_SetStateRotary(int value) + { + BiosVerifier.Exactly(ButtonTranslatorKeys.SetStateRotary, value); + } + + [TestCase(InputFixedStep.Increment)] + [TestCase(InputFixedStep.Decrement)] + public void Button_FromOsc_FixedStepSetStateRotary_StringIn(string value) + { + BiosVerifier.Exactly(ButtonTranslatorKeys.FixedStepSetStateRotary, value); + } + + [TestCase(1)] + [TestCase(-1)] + public void Button_FromOsc_FixedStepSetStateRotary_IntIn(int value) + { + BiosVerifier.Exactly(ButtonTranslatorKeys.FixedStepSetStateRotary, value); + } + + [TestCase("+3200", InputFixedStep.Increment)] + [TestCase("-3200", InputFixedStep.Decrement)] + public void Button_FromOsc_VariableStepRotary(string expected, string valueIn) + { + BiosVerifier.Exactly(ButtonTranslatorKeys.VariableStepRotary, expected, valueIn); + } + + [TestCase("TOGGLE")] + public void String_FromOsc_ToggleAction(string expected) + { + // set state button has a toggle input + BiosVerifier.Exactly(ButtonTranslatorKeys.SetStateButton, expected, expected); + } + + [TestCase("123.450")] + [TestCase("foo bar")] + public void String_FromOsc_SetString(string expected) + { + BiosVerifier.Exactly(ButtonTranslatorKeys.SetStringInput, expected, expected); + } +} diff --git a/TouchDcsTest/TranslatorTests/Keys/ButtonTranslatorKeys.cs b/TouchDcsTest/TranslatorTests/Keys/ButtonTranslatorKeys.cs index 6654f98..6f01a0c 100644 --- a/TouchDcsTest/TranslatorTests/Keys/ButtonTranslatorKeys.cs +++ b/TouchDcsTest/TranslatorTests/Keys/ButtonTranslatorKeys.cs @@ -1,11 +1,11 @@ -namespace TouchDcsTest.TranslatorTests.Keys +namespace TouchDcsTest.TranslatorTests.Keys; + +public static class ButtonTranslatorKeys { - public static class ButtonTranslatorKeys - { - public const string SetStateButton = "SetStateButton"; - public const string FixedStepRotary = "FixedStepRotary"; - public const string SetStateRotary = "SetStateRotary"; - public const string FixedStepSetStateRotary = "FixedStepSetStateRotary"; - public const string VariableStepRotary = "VariableStepRotary"; - } -} \ No newline at end of file + public const string SetStateButton = "SetStateButton"; + public const string FixedStepRotary = "FixedStepRotary"; + public const string SetStateRotary = "SetStateRotary"; + public const string FixedStepSetStateRotary = "FixedStepSetStateRotary"; + public const string VariableStepRotary = "VariableStepRotary"; + public const string SetStringInput = "SetStringInput"; +} diff --git a/TouchDcsWorker/BiosOscTranslator.cs b/TouchDcsWorker/BiosOscTranslator.cs index cbd119b..cb3cb94 100644 --- a/TouchDcsWorker/BiosOscTranslator.cs +++ b/TouchDcsWorker/BiosOscTranslator.cs @@ -144,6 +144,8 @@ public void FromOsc(string ipAddress, string address, T data) var setStateInput = inputs.OfType().FirstOrDefault(); var fixedStepInput = inputs.OfType().FirstOrDefault(); var variableStepInput = inputs.OfType().FirstOrDefault(); + var actionInput = inputs.OfType().FirstOrDefault(); + var setStringInput = inputs.OfType().FirstOrDefault(); if (setStateInput != null && floatData.HasValue) { _biosSender.Send(address, floatData.Value.ToString()); @@ -171,9 +173,13 @@ public void FromOsc(string ipAddress, string address, T data) var stringifiedAmount = $"{(amount < 0 ? string.Empty : "+")}{amount}"; _biosSender.Send(address, stringifiedAmount); } + else if ((actionInput is not null || setStringInput is not null) && stringData is not null) + { + _biosSender.Send(address, stringData); + } else { - _log.LogError("input type {{set_state}} not found for control {Address}", address); + _log.LogError("no supported input found for control {Address}", address); } } @@ -230,4 +236,4 @@ public record BiosInfo(List BiosData); public class BiosCodeInfo : Dictionary> { } public sealed record OscMessage(string Address, object Data); -} \ No newline at end of file +} diff --git a/TouchDcsWorker/TouchDcsWorker.csproj b/TouchDcsWorker/TouchDcsWorker.csproj index bf70bfd..080245c 100644 --- a/TouchDcsWorker/TouchDcsWorker.csproj +++ b/TouchDcsWorker/TouchDcsWorker.csproj @@ -9,7 +9,7 @@ - +