From c41b0ba140abcf72209ff34da999649a7495bde5 Mon Sep 17 00:00:00 2001 From: Charlie <30303272+charliefoxtwo@users.noreply.github.com> Date: Sun, 8 Oct 2023 00:45:44 -0700 Subject: [PATCH] #366 Fix Viggen missile select not working (#367) --- Scripts/DCS-BIOS/doc/Addresses.h | 2 - Scripts/DCS-BIOS/doc/json/AJS37.json | 52 ++----------------- Scripts/DCS-BIOS/doc/json/AJS37.jsonp | 52 ++----------------- .../lib/modules/aircraft_modules/AJS37.lua | 49 ++++++++++++++++- 4 files changed, 57 insertions(+), 98 deletions(-) diff --git a/Scripts/DCS-BIOS/doc/Addresses.h b/Scripts/DCS-BIOS/doc/Addresses.h index 46b467bf2..5c8d9284b 100644 --- a/Scripts/DCS-BIOS/doc/Addresses.h +++ b/Scripts/DCS-BIOS/doc/Addresses.h @@ -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 diff --git a/Scripts/DCS-BIOS/doc/json/AJS37.json b/Scripts/DCS-BIOS/doc/json/AJS37.json index 08f41f0b0..8a41221bb 100644 --- a/Scripts/DCS-BIOS/doc/json/AJS37.json +++ b/Scripts/DCS-BIOS/doc/json/AJS37.json @@ -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, @@ -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", diff --git a/Scripts/DCS-BIOS/doc/json/AJS37.jsonp b/Scripts/DCS-BIOS/doc/json/AJS37.jsonp index 0a6081f25..c5b0f08b2 100644 --- a/Scripts/DCS-BIOS/doc/json/AJS37.jsonp +++ b/Scripts/DCS-BIOS/doc/json/AJS37.jsonp @@ -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, @@ -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", diff --git a/Scripts/DCS-BIOS/lib/modules/aircraft_modules/AJS37.lua b/Scripts/DCS-BIOS/lib/modules/aircraft_modules/AJS37.lua index df8b4b5c4..275e127b5 100644 --- a/Scripts/DCS-BIOS/lib/modules/aircraft_modules/AJS37.lua +++ b/Scripts/DCS-BIOS/lib/modules/aircraft_modules/AJS37.lua @@ -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") @@ -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") @@ -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") @@ -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 = {}