Skip to content

Commit

Permalink
#366 Fix Viggen missile select not working (#367)
Browse files Browse the repository at this point in the history
  • Loading branch information
charliefoxtwo authored Oct 8, 2023
1 parent 0bb072c commit c41b0ba
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 98 deletions.
2 changes: 0 additions & 2 deletions Scripts/DCS-BIOS/doc/Addresses.h
Original file line number Diff line number Diff line change
Expand Up @@ -1632,8 +1632,6 @@
#define AJS37_MASTER_VOL_A 0x469E
#define AJS37_MAX_G_RESET 0x4670, 0x1000, 12
#define AJS37_MAX_G_RESET_AM 0x4670, 0x1000
#define AJS37_MISL_SEL_BTN 0x4696, 0x0080, 7
#define AJS37_MISL_SEL_BTN_AM 0x4696, 0x0080
#define AJS37_MISSILE_SELECT_BUTTON 0x460E, 0x2000, 13
#define AJS37_MISSILE_SELECT_BUTTON_AM 0x460E, 0x2000
#define AJS37_MOTVERK 0x4670, 0x0004, 2
Expand Down
52 changes: 5 additions & 47 deletions Scripts/DCS-BIOS/doc/json/AJS37.json
Original file line number Diff line number Diff line change
Expand Up @@ -1055,28 +1055,21 @@
"MISSILE_SELECT_BUTTON": {
"api_variant": "momentary_last_position",
"category": "Engine Panel",
"control_type": "selector",
"description": "Missile Select Button",
"control_type": "action",
"description": "Missile Select Button (IR-RB FRAMSTEGN)",
"identifier": "MISSILE_SELECT_BUTTON",
"inputs": [ {
"description": "switch to previous or next state",
"interface": "fixed_step"
}, {
"description": "set position",
"interface": "set_state",
"max_value": 1
}, {
"argument": "TOGGLE",
"description": "Toggle switch state",
"description": "Presses the button",
"interface": "action"
} ],
"momentary_positions": "none",
"momentary_positions": "last",
"outputs": [ {
"address": 17934,
"address_identifier": "AJS37_MISSILE_SELECT_BUTTON_A",
"address_mask_identifier": "AJS37_MISSILE_SELECT_BUTTON_AM",
"address_mask_shift_identifier": "AJS37_MISSILE_SELECT_BUTTON",
"description": "selector position",
"description": "The position of the button",
"mask": 8192,
"max_value": 1,
"shift_by": 13,
Expand Down Expand Up @@ -7841,41 +7834,6 @@
} ]
}
},
"Test": {
"MISL_SEL_BTN": {
"api_variant": "momentary_last_position",
"category": "Test",
"control_type": "selector",
"description": "Missile Select Button (IR-RB FRAMSTEGN)",
"identifier": "MISL_SEL_BTN",
"inputs": [ {
"description": "switch to previous or next state",
"interface": "fixed_step"
}, {
"description": "set position",
"interface": "set_state",
"max_value": 1
}, {
"argument": "TOGGLE",
"description": "Toggle switch state",
"interface": "action"
} ],
"momentary_positions": "none",
"outputs": [ {
"address": 18070,
"address_identifier": "AJS37_MISL_SEL_BTN_A",
"address_mask_identifier": "AJS37_MISL_SEL_BTN_AM",
"address_mask_shift_identifier": "AJS37_MISL_SEL_BTN",
"description": "selector position",
"mask": 128,
"max_value": 1,
"shift_by": 7,
"suffix": "",
"type": "integer"
} ],
"physical_variant": "push_button"
}
},
"Thrust Reverser": {
"REVERSAL": {
"category": "Thrust Reverser",
Expand Down
52 changes: 5 additions & 47 deletions Scripts/DCS-BIOS/doc/json/AJS37.jsonp
Original file line number Diff line number Diff line change
Expand Up @@ -1056,28 +1056,21 @@ docdata["AJS37"] =
"MISSILE_SELECT_BUTTON": {
"api_variant": "momentary_last_position",
"category": "Engine Panel",
"control_type": "selector",
"description": "Missile Select Button",
"control_type": "action",
"description": "Missile Select Button (IR-RB FRAMSTEGN)",
"identifier": "MISSILE_SELECT_BUTTON",
"inputs": [ {
"description": "switch to previous or next state",
"interface": "fixed_step"
}, {
"description": "set position",
"interface": "set_state",
"max_value": 1
}, {
"argument": "TOGGLE",
"description": "Toggle switch state",
"description": "Presses the button",
"interface": "action"
} ],
"momentary_positions": "none",
"momentary_positions": "last",
"outputs": [ {
"address": 17934,
"address_identifier": "AJS37_MISSILE_SELECT_BUTTON_A",
"address_mask_identifier": "AJS37_MISSILE_SELECT_BUTTON_AM",
"address_mask_shift_identifier": "AJS37_MISSILE_SELECT_BUTTON",
"description": "selector position",
"description": "The position of the button",
"mask": 8192,
"max_value": 1,
"shift_by": 13,
Expand Down Expand Up @@ -7842,41 +7835,6 @@ docdata["AJS37"] =
} ]
}
},
"Test": {
"MISL_SEL_BTN": {
"api_variant": "momentary_last_position",
"category": "Test",
"control_type": "selector",
"description": "Missile Select Button (IR-RB FRAMSTEGN)",
"identifier": "MISL_SEL_BTN",
"inputs": [ {
"description": "switch to previous or next state",
"interface": "fixed_step"
}, {
"description": "set position",
"interface": "set_state",
"max_value": 1
}, {
"argument": "TOGGLE",
"description": "Toggle switch state",
"interface": "action"
} ],
"momentary_positions": "none",
"outputs": [ {
"address": 18070,
"address_identifier": "AJS37_MISL_SEL_BTN_A",
"address_mask_identifier": "AJS37_MISL_SEL_BTN_AM",
"address_mask_shift_identifier": "AJS37_MISL_SEL_BTN",
"description": "selector position",
"mask": 128,
"max_value": 1,
"shift_by": 7,
"suffix": "",
"type": "integer"
} ],
"physical_variant": "push_button"
}
},
"Thrust Reverser": {
"REVERSAL": {
"category": "Thrust Reverser",
Expand Down
49 changes: 47 additions & 2 deletions Scripts/DCS-BIOS/lib/modules/aircraft_modules/AJS37.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
module("AJS37", package.seeall)

local ActionArgument = require("ActionArgument")
local ActionInput = require("ActionInput")
local ApiVariant = require("ApiVariant")
local Control = require("Control")
local ControlType = require("ControlType")
local Functions = require("Functions")
local IntegerOutput = require("IntegerOutput")
local MomentaryPositions = require("MomentaryPositions")
local PhysicalVariant = require("PhysicalVariant")
local Suffix = require("Suffix")

local Module = require("Module")

Expand All @@ -10,6 +19,40 @@ local AJS37 = Module:new("AJS37", 0x4600, { "AJS37" })
--overhaul by WarLord v1.0a
--remove Arg# Pilot 3333

--- Adds a new push button control with only a toggle input to push the button
--- @param identifier string the unique identifier for the control
--- @param device_id integer the dcs device id
--- @param command integer the dcs command
--- @param arg_number integer the dcs argument number
--- @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 AJS37:defineMissileSelectPushButton(identifier, device_id, command, arg_number, category, description)
local alloc = self:allocateInt(1)

local control = Control:new(category, ControlType.action, identifier, description, {
ActionInput:new(ActionArgument.toggle, "Presses the button"),
}, {
IntegerOutput:new(alloc, Suffix.none, "The position of the button"),
}, MomentaryPositions.last, PhysicalVariant.push_button, ApiVariant.momentary_last_position)

self:addInputProcessor(identifier, function(value)
if value == "TOGGLE" then
GetDevice(device_id):performClickableAction(command, 1)
end
end)

self:addExportHook(function(dev0)
local value = dev0:get_argument_value(arg_number)
-- the value of this button is a float between 0 and 1 depending on the position of the button
alloc:setValue(Module.round(Module.valueConvert(value, { -1, 1 }, { 0, 1 })))
end)

self:addControl(control)

return control
end

--Weapon System
AJS37:defineToggleSwitch("TRIGGER_SAFETY_BRACKET", 2, 3300, 8, "Weapon System", "Trigger Safety Bracket")
AJS37:defineToggleSwitch("WEAPON_RELEASE_COVER", 2, 3302, 260, "Weapon System", "Weapon Emergency Release Cover")
Expand Down Expand Up @@ -90,7 +133,8 @@ AJS37:defineTumb("FLIGHT_RECORDER", 18, 3924, 384, 0.5, { 0, 1 }, nil, false, "E
AJS37:definePushButton("RESTART", 18, 3401, 208, "Engine Panel", "Restart")
AJS37:defineTumb("AFK_LEVER", 18, 3304, 13, 1.138, { 0, 1.138 }, nil, false, "Engine Panel", "AFK Lever")
AJS37:defineToggleSwitch("DATA_CARTRIDGE", 18, 3925, 4200, "Engine Panel", "Insert/Remove Data Cartridge")
AJS37:definePushButton("MISSILE_SELECT_BUTTON", 18, 3000, 400, "Engine Panel", "Missile Select Button")
-- AJS37:definePushButton("MISSILE_SELECT_BUTTON", 18, 3000, 400, "Engine Panel", "Missile Select Button") -- this appears correct in the luas
AJS37:defineMissileSelectPushButton("MISSILE_SELECT_BUTTON", 2, 3800, 400, "Engine Panel", "Missile Select Button (IR-RB FRAMSTEGN)") -- but this is the one that actually accepts input

--Electric System
AJS37:defineToggleSwitch("GENERATOR", 19, 3002, 207, "Electric System", "Generator")
Expand Down Expand Up @@ -341,7 +385,8 @@ AJS37:definePotentiometer("EP13_CONTR", 2, 3319, 6902, { 0, 1 }, "Weapon System"
AJS37:definePotentiometer("CI_FILTER", 5, 3801, 6905, { 0, 1 }, "Radar", "CI filter")

--found no argument
AJS37:definePushButton("MISL_SEL_BTN", 2, 3800, 400, "Test", "Missile Select Button (IR-RB FRAMSTEGN)")
-- AJS37:definePushButton("MISL_SEL_BTN", 2, 3800, 400, "Test", "Missile Select Button (IR-RB FRAMSTEGN)")
AJS37:reserveIntValue(1) -- above control duplicated by "MISSILE_SELECT_BUTTON"

-- parse nav indicator
local nav_data = {}
Expand Down

0 comments on commit c41b0ba

Please sign in to comment.