Skip to content

Commit

Permalink
AH-64D: Add 2pos interface for power lever idle/off (#1003)
Browse files Browse the repository at this point in the history
Fixes #999

`defineLoSetCommand2Pos` is now available for all modules
  • Loading branch information
charliefoxtwo authored Sep 2, 2024
1 parent e6d81c9 commit 3ad6809
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 4 deletions.
26 changes: 26 additions & 0 deletions Scripts/DCS-BIOS/lib/modules/Module.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions Scripts/DCS-BIOS/lib/modules/aircraft_modules/AH-64D.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions Scripts/DCS-BIOS/test/ModuleTest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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")
64 changes: 64 additions & 0 deletions Scripts/DCS-BIOS/test/controls/LoSetCommand2PosTest.lua
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 3ad6809

Please sign in to comment.