From 3ad6809863f2e8d04f685b41617950f722c38ead Mon Sep 17 00:00:00 2001 From: Charlie <30303272+charliefoxtwo@users.noreply.github.com> Date: Mon, 2 Sep 2024 09:00:20 -0700 Subject: [PATCH] AH-64D: Add 2pos interface for power lever idle/off (#1003) Fixes #999 `defineLoSetCommand2Pos` is now available for all modules --- Scripts/DCS-BIOS/lib/modules/Module.lua | 26 ++++++++ .../lib/modules/aircraft_modules/AH-64D.lua | 6 +- Scripts/DCS-BIOS/test/ModuleTest.lua | 1 + .../test/controls/LoSetCommand2PosTest.lua | 64 +++++++++++++++++++ 4 files changed, 93 insertions(+), 4 deletions(-) create mode 100644 Scripts/DCS-BIOS/test/controls/LoSetCommand2PosTest.lua diff --git a/Scripts/DCS-BIOS/lib/modules/Module.lua b/Scripts/DCS-BIOS/lib/modules/Module.lua index 638d55678..b13fe5fe3 100644 --- a/Scripts/DCS-BIOS/lib/modules/Module.lua +++ b/Scripts/DCS-BIOS/lib/modules/Module.lua @@ -443,6 +443,32 @@ function Module:defineLoSetCommand(identifier, iCommand, category, description) return control end +--- Adds an input-only control which performs a specific LoSetCommand with no arguments +--- @param identifier string the unique identifier for the control +--- @param iCommand_off ICommand the dcs icommand to move the switch down +--- @param iCommand_on ICommand the dcs icommand to move the switch up +--- @param category string the category in which the control should appear +--- @param description string additional information about the control +--- @return Control control the control which was added to the module +function Module:defineLoSetCommand2Pos(identifier, iCommand_off, iCommand_on, category, description) + local control = Control:new(category, ControlType.action, identifier, description, { + FixedStepInput:new("switch to previous or next state"), + SetStateInput:new(1, "set the switch position -- 0 = off, 1 = on"), + }, {}) + + self:addControl(control) + + self:addInputProcessor(identifier, function(action) + if action == "1" or action == "INC" then + LoSetCommand(iCommand_on) + elseif action == "0" or action == "DEC" then + LoSetCommand(iCommand_off) + end + end) + + return control +end + --- Adds a new rotary potentiometer with values between 0 and 65535 --- @param identifier string the unique identifier for the control --- @param device_id integer the dcs device id diff --git a/Scripts/DCS-BIOS/lib/modules/aircraft_modules/AH-64D.lua b/Scripts/DCS-BIOS/lib/modules/aircraft_modules/AH-64D.lua index 1d48e2042..4adc49862 100644 --- a/Scripts/DCS-BIOS/lib/modules/aircraft_modules/AH-64D.lua +++ b/Scripts/DCS-BIOS/lib/modules/aircraft_modules/AH-64D.lua @@ -1041,9 +1041,7 @@ AH_64D:definePushButton("CPG_CYCLIC_ATA_CAGE", devices.HOTAS_INPUT, 3023, 576, C -- additional throttle lever controls (these don't seem to work for the CP/G) AH_64D:defineInputOnlySetStatePushButton("PLT_ENG_L_PW_LVR_LIFT", devices.CONTROL_INTERFACE, 3011, "PLT Left Console", "Power Lever Finger Lift (Left)") AH_64D:defineInputOnlySetStatePushButton("PLT_ENG_R_PW_LVR_LIFT", devices.CONTROL_INTERFACE, 3012, "PLT Left Console", "Power Lever Finger Lift (Right)") -AH_64D:defineLoSetCommand("PLT_ENG_L_PW_LVR_IDLE", ICommand.left_engine_start, "PLT Left Console", "Power Lever Idle (Left)") -AH_64D:defineLoSetCommand("PLT_ENG_R_PW_LVR_IDLE", ICommand.right_engine_start, "PLT Left Console", "Power Lever Idle (Right)") -AH_64D:defineLoSetCommand("PLT_ENG_L_PW_LVR_OFF", ICommand.left_engine_stop, "PLT Left Console", "Power Lever Off (Left)") -AH_64D:defineLoSetCommand("PLT_ENG_R_PW_LVR_OFF", ICommand.right_engine_stop, "PLT Left Console", "Power Lever Off (Right)") +AH_64D:defineLoSetCommand2Pos("PLT_ENG_L_PW_LVR_IDLE", ICommand.left_engine_stop, ICommand.left_engine_start, "PLT Left Console", "Power Lever Idle/Off (Left)") +AH_64D:defineLoSetCommand2Pos("PLT_ENG_R_PW_LVR_IDLE", ICommand.right_engine_stop, ICommand.right_engine_start, "PLT Left Console", "Power Lever Idle/Off (Right)") return AH_64D diff --git a/Scripts/DCS-BIOS/test/ModuleTest.lua b/Scripts/DCS-BIOS/test/ModuleTest.lua index 6629e80e8..4789cdd30 100644 --- a/Scripts/DCS-BIOS/test/ModuleTest.lua +++ b/Scripts/DCS-BIOS/test/ModuleTest.lua @@ -62,3 +62,4 @@ require("Scripts.DCS-BIOS.test.controls.ReadWriteRadioTest") require("Scripts.DCS-BIOS.test.controls.InputOnlyPushButtonTest") require("Scripts.DCS-BIOS.test.controls.InputOnlySetStatePushButtonTest") require("Scripts.DCS-BIOS.test.controls.LoSetCommandTest") +require("Scripts.DCS-BIOS.test.controls.LoSetCommand2PosTest") diff --git a/Scripts/DCS-BIOS/test/controls/LoSetCommand2PosTest.lua b/Scripts/DCS-BIOS/test/controls/LoSetCommand2PosTest.lua new file mode 100644 index 000000000..e1f9eea04 --- /dev/null +++ b/Scripts/DCS-BIOS/test/controls/LoSetCommand2PosTest.lua @@ -0,0 +1,64 @@ +local ControlType = require("Scripts.DCS-BIOS.lib.modules.documentation.ControlType") +local ICommand = require("Scripts.DCS-BIOS.lib.modules.ICommand") +local InputType = require("Scripts.DCS-BIOS.lib.modules.documentation.InputType") +local MockDevice = require("Scripts.DCS-BIOS.test.controls.MockDevice") +local Module = require("Scripts.DCS-BIOS.lib.modules.Module") + +local lu = require("Scripts.DCS-BIOS.test.ext.luaunit") + +--- @class TestLoSetCommand2Pos +--- @field module Module +TestLoSetCommand2Pos = {} +local moduleName = "MyModule" +local moduleAddress = 0x4200 + +function TestLoSetCommand2Pos:setUp() + self.module = Module:new(moduleName, moduleAddress, {}) + Input_Processor_Device = MockDevice:new(0) +end + +local id = "MY_LO_SET_COMMAND_2_POS" +local iCommand_off = ICommand.left_engine_stop +local iCommand_on = ICommand.left_engine_start +local category = "LoSetCommands2Pos" +local description = "This is a LoSetCommand2Pos" + +function TestLoSetCommand2Pos:testAddLoSetCommand() + local control = self.module:defineLoSetCommand2Pos(id, iCommand_off, iCommand_on, category, description) + + lu.assertEquals(control, self.module.documentation[category][id]) + lu.assertEquals(control.control_type, ControlType.action) + lu.assertEquals(control.category, category) + lu.assertEquals(control.description, description) + lu.assertEquals(control.identifier, id) + lu.assertIsNil(control.api_variant) + + lu.assertEquals(#control.inputs, 2) + + local fixed_step_input = control.inputs[1] --[[@as FixedStepInput]] + lu.assertEquals(fixed_step_input.interface, InputType.fixed_step) + + local set_state_input = control.inputs[2] --[[@as SetStateInput]] + lu.assertEquals(set_state_input.interface, InputType.set_state) + lu.assertEquals(set_state_input.max_value, 1) + + lu.assertEquals(#control.outputs, 0) +end + +function LoSetCommand(iCommand) + lu.assertEquals(ICommand.left_engine_start, iCommand) +end + +function TestLoSetCommand2Pos:testLoSetCommand2PosInc() + self.module:defineLoSetCommand2Pos(id, iCommand_off, iCommand_on, category, description) + local input_processor = self.module.inputProcessors[id] + + input_processor("INC") +end + +function TestLoSetCommand2Pos:testLoSetCommand2PosSetState() + self.module:defineLoSetCommand2Pos(id, iCommand_off, iCommand_on, category, description) + local input_processor = self.module.inputProcessors[id] + + input_processor("1") +end