dofile(LockOn_Options.script_path .. "command_defs.lua")
dofile(LockOn_Options.script_path .. "devices.lua")
dofile(LockOn_Options.script_path .. "config.lua")
dofile(LockOn_Options.script_path .. "sounds.lua")



local gettext = require("i_18n")
_ = gettext.translate



cursor_mode = {
    CUMODE_CLICKABLE = 0,
    CUMODE_CLICKABLE_AND_CAMERA = 1,
    CUMODE_CAMERA = 2,
};
clickable_mode_initial_status = cursor_mode.CUMODE_CLICKABLE
use_pointer_name = true
--show_element_boxes = true
--show_other_pointers = true



function default_button ( hint_, device_, command_, arg_, arg_val_, arg_lim_ )
    local arg_val_ = arg_val_ or 1
    local arg_lim_ = arg_lim_ or {0,1}

    return {
        class               = {class_type.BTN},
        hint                = hint_,
        device              = device_,
        action              = {command_},
        stop_action         = {command_},
        arg                 = {arg_},
        arg_value           = {arg_val_}, 
        arg_lim             = {arg_lim_},
        use_release_message = {true},
        sound               = {{SOUND_METALLIC_BUTTON_OFF, SOUND_METALLIC_BUTTON_ON}},
    }
end

function default_1_position_tumb ( hint_, device_, command_, arg_, arg_val_, arg_lim_ )
    local arg_val_ = arg_val_ or 1
    local arg_lim_ = arg_lim_ or {0, 1}
    return {
        class = {class_type.TUMB},
        hint = hint_,
        device = device_,
        action = {command_},
        arg = {arg_},
        arg_value = {arg_val_},
        arg_lim = {arg_lim_},
        updatable = true,
        use_OBB = true
    }
end

function default_2_position_tumb ( hint_, device_, command_, arg_ )
    return {
        class = {class_type.TUMB, class_type.TUMB},
        hint = hint_,
        device = device_,
        action = {command_, command_},
        arg = {arg_, arg_},
        arg_value = {1, -1},
        arg_lim = {{0, 1}, {0, 1}},
        updatable = true,
        use_OBB = true
    }
end

function default_3_position_tumb ( hint_, device_, command_, arg_, cycled_, inversed_ )
    local cycled = true
    local val = 1
    if inversed_ then
        val = -1
    end
    if cycled_ ~= nil then
        cycled = cycled_
    end

    return {
        class = {class_type.TUMB, class_type.TUMB},
        hint = hint_,
        device = device_,
        action = {command_, command_},
        arg = {arg_, arg_},
        arg_value = {-val, val},
        arg_lim = {{-1, 1}, {-1, 1}},
        updatable = true,
        use_OBB = true,
        cycle = cycled
    }
end

function default_axis ( hint_, device_, command_, arg_, default_, gain_, updatable_, relative_, cycle_ )
    local default = default_ or 1
    local gain = gain_ or 0.1
    local updatable = updatable_ or false
    local relative = relative_ or false
    local cycled = cycle_ or false

    return {
        class = {class_type.LEV},
        hint = hint_,
        device = device_,
        action = {command_},
        arg = {arg_},
        arg_value = {default},
        arg_lim = {{0, 1}},
        updatable = updatable,
        use_OBB = true,
        gain = {gain},
        relative = {relative},
        cycle = cycled,
    }
end

function default_movable_axis ( hint_, device_, command_, arg_, default_, gain_, updatable_, relative_ )
    local default = default_ or 1
    local gain = gain_ or 0.1
    local updatable = updatable_ or false
    local relative = relative_ or false

    return {
        class = {class_type.MOVABLE_LEV},
        hint = hint_,
        device = device_,
        action = {command_},
        arg = {arg_},
        arg_value = {default},
        arg_lim = {{0, 1}},
        updatable = updatable,
        use_OBB = true,
        gain = {gain},
        relative = {relative},
    }
end

function default_axis_limited ( hint_, device_, command_, arg_, default_, gain_, updatable_, relative_, arg_lim_ )
    local relative = false
    local default = default_ or 0
    local updatable = updatable_ or false
    if relative_ ~= nil then
        relative = relative_
    end
    local gain = gain_ or 0.1

    return {
        class = {class_type.LEV},
        hint = hint_,
        device = device_,
        action = {command_},
        arg = {arg_},
        arg_value = {default},
        arg_lim = {arg_lim_},
        updatable = updatable,
        use_OBB = false,
        gain = {gain},
        relative = {relative},
        cycle = false,
    }
end

function multiposition_switch ( hint_, device_, command_, arg_, count_, delta_, inversed_, min_ )
    local min_ = min_ or 0
    local delta_ = delta_ or 0.5
    local inversed = 1
    if inversed_ then
        inversed = -1
    end

    return {
        class = {class_type.TUMB, class_type.TUMB},
        hint = hint_,
        device = device_,
        action = {command_, command_},
        arg = {arg_, arg_},
        arg_value = {-delta_ * inversed, delta_ * inversed},
        arg_lim = {{min_, min_ + delta_ * (count_ - 1)}, {min_, min_ + delta_ * (count_ - 1)}},
        updatable = true,
        use_OBB = true
    }
end

function multiposition_switch_limited ( hint_, device_, command_, arg_, count_, delta_, inversed_, min_ )
    local min_ = min_ or 0
    local delta_ = delta_ or 0.5
    local inversed = 1
    if inversed_ then
        inversed = -1
    end

    return {
        class = {class_type.TUMB, class_type.TUMB},
        hint = hint_,
        device = device_,
        action = {command_ ,command_},
        arg = {arg_, arg_},
        arg_value = {-delta_ * inversed, delta_ * inversed}, 
        arg_lim = {{min_, min_ + delta_ * (count_ - 1)}, {min_, min_ + delta_ * (count_ - 1)}},
        updatable = true,
        use_OBB = true,
        cycle = false,
    }
end

function default_button_axis ( hint_, device_, command_1, command_2, arg_1, arg_2, limit_1, limit_2 )
    local limit_1_ = limit_1 or 1.0
    local limit_2_ = limit_2 or 1.0
    return {
        class = {class_type.BTN, class_type.LEV},
        hint = hint_,
        device = device_,
        action = {command_1, command_2},
        stop_action = {command_1, 0},
        arg = {arg_1, arg_2},
        arg_value = {1, 0.5},
        arg_lim = {{0, limit_1_}, {0, limit_2_}},
        animated = {false, true},
        animation_speed = {0, 0.4},
        gain = {0, 0.1},
        relative = {false, false},
        updatable = true,
        use_OBB = true,
        use_release_message = {true, false}
    }
end

function default_animated_lever ( hint_, device_, command_, arg_, animation_speed_, arg_lim_ )
    local arg_lim__ = arg_lim_ or {0.0, 1.0}

    return {
        class = {class_type.TUMB, class_type.TUMB},
        hint = hint_,
        device = device_,
        action = {command_, command_},
        arg = {arg_, arg_},
        arg_value = {1, 0},
        arg_lim = {arg_lim__, arg_lim__},
        updatable = true,
        gain = {0.1, 0.1},
        animated = {true, true},
        animation_speed = {animation_speed_, 0},
        cycle = true
    }
end

function pull_handle ( hint_, device_, command_, arg_, animation_speed_ )
    return {
        class = {class_type.BTN},
        hint = hint_, 
        device = device_,
        action = {command_},
        stop_action = {command_},
        arg = {arg_},
        arg_value = {1},
        arg_lim = {{0, 1}},
        updatable = true,
        gain = {0.1},
        animated = {true},
        animation_speed = {animation_speed_},
        use_release_message = {true},
        sound = {{SOUND_HANDLE_PULL, SOUND_HANDLE_RELEASE}, {SOUND_HANDLE_PULL, SOUND_HANDLE_RELEASE}},
    }
end

function default_button_tumb ( hint_, device_, command1_, command2_, arg_ )
    return {
        class = {class_type.BTN, class_type.TUMB},
        hint = hint_,
        device = device_,
        action = {command1_, command2_},
        stop_action = {command1_, 0},
        arg = {arg_, arg_},
        arg_value = {-1, 1},
        arg_lim = {{-1, 0}, {0, 1}},
        updatable = true,
        use_OBB = true,
        use_release_message = {true, false}
    }
end



-- ------------------------------------------------------------------------------------------------
-- Bf 109 K-4
-- ------------------------------------------------------------------------------------------------



elements = {}

-- FuseBox Controls - Electrical Switches
    -- RH Fuse Box Circuit Breakers
        -- Left Row
            -- A 100 - Generator Cut-Off Relay
            elements["A100"] = default_2_position_tumb(_("Generator On/Off"), devices.FUSEBOX, device_commands.Button_75, 114)
            elements["A100"].sound = {{SOUND_CB_RESET, SOUND_CB_ON}, {SOUND_CB_RESET, SOUND_CB_ON}}
            elements["A100_1"] = default_1_position_tumb(_("Generator On"), devices.FUSEBOX, device_commands.Button_77, 114, 1, {1, 1})
            elements["A100_1"].sound = {{SOUND_NOSOUND, SOUND_NOSOUND}}
            elements["A100_0"] = default_button(_("Generator Off"), devices.FUSEBOX, device_commands.Button_92, 151)
            elements["A100_0"].sound = {{SOUND_NOSOUND, SOUND_NOSOUND}}

            -- D 100 - Heating CB
            elements["D100"] = default_2_position_tumb(_("Pitot/Windscreen Heating On/Off"), devices.FUSEBOX, device_commands.Button_12, 115)
            elements["D100"].sound = {{SOUND_CB_RESET, SOUND_CB_ON}, {SOUND_CB_RESET, SOUND_CB_ON}}
            elements["D100_1"] = default_1_position_tumb(_("Pitot/Windscreen Heating On"), devices.FUSEBOX, device_commands.Button_14, 115, 1, {1, 1})
            elements["D100_1"].sound = {{SOUND_NOSOUND, SOUND_NOSOUND}}
            elements["D100_0"] = default_button(_("Pitot/Windscreen Heating Off"), devices.FUSEBOX, device_commands.Button_86, 152)
            elements["D100_0"].sound = {{SOUND_NOSOUND, SOUND_NOSOUND}}

            -- C 100 - Navigation Lights CB
            elements["C100"] = default_2_position_tumb(_("Nav. Lights On/Off"), devices.FUSEBOX, device_commands.Button_6, 116)
            elements["C100"].sound = {{SOUND_CB_RESET, SOUND_CB_ON}, {SOUND_CB_RESET, SOUND_CB_ON}}
            elements["C100_1"] = default_1_position_tumb(_("Nav. Lights On"), devices.FUSEBOX, device_commands.Button_8, 116, 1, {1, 1})
            elements["C100_1"].sound = {{SOUND_NOSOUND, SOUND_NOSOUND}}
            elements["C100_0"] = default_button(_("Nav. Lights Off"), devices.FUSEBOX, device_commands.Button_84, 153)
            elements["C100_0"].sound = {{SOUND_NOSOUND, SOUND_NOSOUND}}

            -- C 101 - Instrument Panel Illumination CB
            elements["C101"] = default_2_position_tumb(_("UV Lights On/Off"), devices.FUSEBOX, device_commands.Button_9, 117)
            elements["C101"].sound = {{SOUND_CB_RESET, SOUND_CB_ON}, {SOUND_CB_RESET, SOUND_CB_ON}}
            elements["C101_1"] = default_1_position_tumb(_("UV Lights On"), devices.FUSEBOX, device_commands.Button_11, 117, 1, {1, 1})
            elements["C101_1"].sound = {{SOUND_NOSOUND, SOUND_NOSOUND}}
            elements["C101_0"] = default_button(_("UV Lights Off"), devices.FUSEBOX, device_commands.Button_85, 154)
            elements["C101_0"].sound = {{SOUND_NOSOUND, SOUND_NOSOUND}}

            -- V 101 - Drop Ordnance & Optional Armament CB
            elements["V101"] = default_2_position_tumb(_("Wing / Drop Ordnance On/Off"), devices.FUSEBOX, device_commands.Button_24, 118)
            elements["V101"].sound = {{SOUND_CB_RESET, SOUND_CB_ON}, {SOUND_CB_RESET, SOUND_CB_ON}}
            elements["V101_1"] = default_1_position_tumb(_("Wing / Drop Ordnance On"), devices.FUSEBOX, device_commands.Button_26, 118, 1, {1, 1})
            elements["V101_1"].sound = {{SOUND_NOSOUND, SOUND_NOSOUND}}
            elements["V101_0"] = default_button(_("Wing / Drop Ordnance Off"), devices.FUSEBOX, device_commands.Button_90, 155)
            elements["V101_0"].sound = {{SOUND_NOSOUND, SOUND_NOSOUND}}

            -- V 100 - Systematic & Ignition CB
            elements["V100"] = default_2_position_tumb(_("Ignition On/Off"), devices.FUSEBOX, device_commands.Button_3, 119)
            elements["V100"].sound = {{SOUND_CB_RESET, SOUND_CB_ON}, {SOUND_CB_RESET, SOUND_CB_ON}}
            elements["V100_1"] = default_1_position_tumb(_("Ignition On"), devices.FUSEBOX, device_commands.Button_5, 119, 1, {1, 1})
            elements["V100_1"].sound = {{SOUND_NOSOUND, SOUND_NOSOUND}}
            elements["V100_0"] = default_button(_("Ignition Off"), devices.FUSEBOX, device_commands.Button_83, 156)
            elements["V100_0"].sound = {{SOUND_NOSOUND, SOUND_NOSOUND}}

            -- Spotlights CB - TODO implement when landing lights rustsatz is available
            --elements["ScheinwerferCB"] = default_2_position_tumb(_("Spotlights On/Off"), devices.FUSEBOX, device_commands.Button_27, 999999)
            --elements["ScheinwerferCB"].sound = {{SOUND_CB_RESET, SOUND_CB_ON}, {SOUND_CB_RESET, SOUND_CB_ON}}
            --elements["ScheinwerferCB_1"] = default_1_position_tumb(_("Spotlights On"), devices.FUSEBOX, device_commands.Button_29, 999999, 1, {0, 1})
            --elements["ScheinwerferCB_1"].sound = {{SOUND_NOSOUND, SOUND_NOSOUND}}
            --elements["ScheinwerferCB_0"] = default_button(_("Spotlights Off"), devices.FUSEBOX, device_commands.Button_91, 999999)
            --elements["ScheinwerferCB_0"].sound = {{SOUND_NOSOUND, SOUND_NOSOUND}}
        --

        -- Right Row
            -- A 101 - Battery Cut-Off Relay
            elements["A101"] = default_2_position_tumb(_("Battery On/Off"), devices.FUSEBOX, device_commands.Button_78, 120)
            elements["A101"].sound = {{SOUND_CB_RESET, SOUND_CB_ON}, {SOUND_CB_RESET, SOUND_CB_ON}}
            elements["A101_1"] = default_1_position_tumb(_("Battery On"), devices.FUSEBOX, device_commands.Button_80, 120, 1, {1, 1})
            elements["A101_1"].sound = {{SOUND_NOSOUND, SOUND_NOSOUND}}
            elements["A101_0"] = default_button(_("Battery Off"), devices.FUSEBOX, device_commands.Button_93, 157)
            elements["A101_0"].sound = {{SOUND_NOSOUND, SOUND_NOSOUND}}

            -- F 135 - Radio CB - Labelled "FuG 16"
            elements["F135"] = default_2_position_tumb(_("Radio On/Off"), devices.FUSEBOX, device_commands.Button_18, 121)
            elements["F135"].sound = {{SOUND_CB_RESET, SOUND_CB_ON}, {SOUND_CB_RESET, SOUND_CB_ON}}
            elements["F135_1"] = default_1_position_tumb(_("Radio On"), devices.FUSEBOX, device_commands.Button_20, 121, 1, {1, 1})
            elements["F135_1"].sound = {{SOUND_NOSOUND, SOUND_NOSOUND}}
            elements["F135_0"] = default_button(_("Radio Off"), devices.FUSEBOX, device_commands.Button_88, 158)
            elements["F135_0"].sound = {{SOUND_NOSOUND, SOUND_NOSOUND}}

            -- F 211 - IFF CB - Labelled "FuG 25a"
            elements["F211"] = default_2_position_tumb(_("IFF On/Off"), devices.FUSEBOX, device_commands.Button_21, 122)
            elements["F211"].sound = {{SOUND_CB_RESET, SOUND_CB_ON}, {SOUND_CB_RESET, SOUND_CB_ON}}
            elements["F211_1"] = default_1_position_tumb(_("IFF On"), devices.FUSEBOX, device_commands.Button_23, 122, 1, {1, 1})
            elements["F211_1"].sound = {{SOUND_NOSOUND, SOUND_NOSOUND}}
            elements["F211_0"] = default_button(_("IFF Off"), devices.FUSEBOX, device_commands.Button_89, 159)
            elements["F211_0"].sound = {{SOUND_NOSOUND, SOUND_NOSOUND}}

            -- E 101 - Fuel Pump CB - Labelled "Tankpumpe"
            elements["E101"] = default_2_position_tumb(_("Fuel Pump On/Off"), devices.FUSEBOX, device_commands.Button_15, 123)
            elements["E101"].sound = {{SOUND_CB_RESET, SOUND_CB_ON}, {SOUND_CB_RESET, SOUND_CB_ON}}
            elements["E101_1"] = default_1_position_tumb(_("Fuel Pump On"), devices.FUSEBOX, device_commands.Button_17, 123, 1, {1, 1})
            elements["E101_1"].sound = {{SOUND_NOSOUND, SOUND_NOSOUND}}
            elements["E101_0"] = default_button(_("Fuel Pump Off"), devices.FUSEBOX, device_commands.Button_87, 160)
            elements["E101_0"].sound = {{SOUND_NOSOUND, SOUND_NOSOUND}}
        --
    --

    -- Control Stick Triggers and Buttons
        -- Stick Safety / Trigger Lever
        elements["SAFETY"] = default_animated_lever(_("Weapon Safety"), devices.FUSEBOX, device_commands.Button_73, 107, 3.0)
        -- Button A - MG Trigger
        elements["BUTTON_A"] = default_button(_("Button A"), devices.FUSEBOX, device_commands.Button_51, 108)
        -- Button B1 - Cannon Trigger
        elements["BUTTON_B1"] = default_button(_("Button B1"), devices.FUSEBOX, device_commands.Button_52, 109)
        -- Button B2 - Secondary & Drop Ordnance Trigger
        elements["BUTTON_B2"] = default_button(_("Button B2"), devices.FUSEBOX, device_commands.Button_53, 110)
        -- Button D - MK 108 Charge Button
        elements["BUTTON_D"] = default_button(_("Button D"), devices.FUSEBOX, device_commands.Button_55, 111)
    --

    -- Ignition Controls and Starter and Motor-Related Switches
        -- Magneto Selector
        elements["B102"] = multiposition_switch_limited(_("Magnetos"), devices.FUSEBOX, device_commands.Button_66, 59, 4, 0.1, false)
        elements["B102"].sound = {{SOUND_CHOPPER_SWITCH, SOUND_CHOPPER_SWITCH}, {SOUND_CHOPPER_SWITCH, SOUND_CHOPPER_SWITCH}}
        elements["B102_0"] = default_1_position_tumb(_("Magnetos Off"), devices.FUSEBOX, device_commands.Button_68, 59, 0, {0.0, 0.0})
        elements["B102_M1"] = default_1_position_tumb(_("Magnetos M1"), devices.FUSEBOX, device_commands.Button_68, 59, 0, {0.1, 0.1})
        elements["B102_M2"] = default_1_position_tumb(_("Magnetos M2"), devices.FUSEBOX, device_commands.Button_68, 59, 0, {0.2, 0.2})
        elements["B102_M1M2"] = default_1_position_tumb(_("Magnetos M1+M2"), devices.FUSEBOX, device_commands.Button_68, 59, 0, {0.3, 0.3})

        -- Starter Handle Cover
        elements["STRTR_COVER"] = default_2_position_tumb(_("Starter Handle Cover"), devices.FUSEBOX, device_commands.Button_63, 51)
        elements["STRTR_COVER"].sound = {{SOUND_METALLIC_TAB, SOUND_METALLIC_TAB}, {SOUND_METALLIC_TAB, SOUND_METALLIC_TAB}}
        --TODO remove elements["STRTR_COVER_0"] = default_1_position_tumb(_("Starter Handle Cover Close"), devices.FUSEBOX, device_commands.Button_63, 51, 0, {0, 0})
        --TODO remove elements["STRTR_COVER_1"] = default_1_position_tumb(_("Starter Handle Cover Open"), devices.FUSEBOX, device_commands.Button_63, 51, 1, {1, 1})
        -- Starter Turn Handle
        elements["STRTR_HANDLE"] = default_button(_("Starter"), devices.FUSEBOX, device_commands.Button_65, 52)
        elements["STRTR_HANDLE"].sound = {{SOUND_CHOPPER_SWITCH, SOUND_CHOPPER_SWITCH}}

        -- WM-Kommandgerat Toggle
        elements["V114"] = default_2_position_tumb(_("Governor Automation"), devices.FUSEBOX, device_commands.Button_58, 62)
    --

    -- Dashboard and Secondary Switches
        -- A 104 - Kill Switch
        elements["A104"] = default_button(_("Kill Switch"), devices.FUSEBOX, device_commands.Button_1, 49)

        -- Button T - Gun Camera Trigger
        elements["BUTTON_T"] = default_button(_("Button T"), devices.FUSEBOX, device_commands.Button_54, 149)

        -- SZKK3 Weapons Control Master Switch
        elements["P102"] = default_2_position_tumb(_("Weapons Master"), devices.FUSEBOX, device_commands.Button_32, 37)
        -- LH SZ 500 Ammo Counter
        elements["SZKK3_LHP"] = default_axis(_("Ammo Counter Setter Pinion"), devices.WEAPONS_CONTROLS, device_commands.Button_1, 38, 0.0, 0.1, false, true, true)
        elements["SZKK3_LHP"].sound = {{SOUND_PINION, SOUND_PINION}}
        -- RH SZ 500 Ammo Counter
        elements["SZKK3_RHP"] = default_axis(_("Ammo Counter Setter Pinion"), devices.WEAPONS_CONTROLS, device_commands.Button_4, 39, 0.0, 0.1, false, true, true)
        elements["SZKK3_RHP"].sound = {{SOUND_PINION, SOUND_PINION}}

        -- MW50 Operational Toggle
        elements["T100"] = default_2_position_tumb(_("MW50 Boost"), devices.FUSEBOX, device_commands.Button_36, 60)
        -- Wing Cannons Toggle
        elements["P150"] = default_2_position_tumb(_("Wing Cannons"), devices.FUSEBOX, device_commands.Button_34, 61)
        -- MK 108 / Wing Guns Toggle
        elements["V114"] = default_2_position_tumb(_("MK 108 / R 21"), devices.FUSEBOX, device_commands.Button_81, 62)

        -- R 101 ZSK 244 A Bomb Panel Master Switch
        -- Operated internally via ZSK 244 A Mode Control
        -- R 101 ZSK 244 A Mode Selector
        elements["SZK"] = multiposition_switch_limited(_("Bomb Fusing Selector"), devices.WEAPONS_CONTROLS, device_commands.Button_13, 64, 5, 0.25)
        elements["SZK_DIVE"] = default_1_position_tumb(_("Bomb Fusing DIVE (INSTANT)"), devices.WEAPONS_CONTROLS, device_commands.Button_15, 64, 0, {0.0, 0.0})
        elements["SZK_DIVE_DLY"] = default_1_position_tumb(_("Bomb Fusing DIVE (DELAYED)"), devices.WEAPONS_CONTROLS, device_commands.Button_15, 64, 0, {0.25, 0.25})
        elements["SZK_OFF"] = default_1_position_tumb(_("Bomb Fusing OFF"), devices.WEAPONS_CONTROLS, device_commands.Button_15, 64, 0, {0.5, 0.5})
        elements["SZK_LEVL_DLY"] = default_1_position_tumb(_("Bomb Fusing LEVEL (DELAYED)"), devices.WEAPONS_CONTROLS, device_commands.Button_15, 64, 0, {0.75, 0.75})
        elements["SZK_LEVL"] = default_1_position_tumb(_("Bomb Fusing LEVEL (INSTANT)"), devices.WEAPONS_CONTROLS, device_commands.Button_15, 64, 0, {1.0, 1.0})

        -- Heated Gloves Socket
        -- TODO implement
    --

    -- Illumination Controls
        -- C 102 LH UV Lamp Rheostat
        elements["PITLITE_LH"] = default_axis(_("Left UV Lamp Brightness"), devices.FUSEBOX, device_commands.Button_38, 80, 0.5, 0.1, false, false)
        elements["PITLITE_LH"].sound = {{SOUND_PINION, SOUND_PINION}}

        -- C 103 RH UV Lamp Rheostat
        elements["PITLITE_RH"] = default_axis(_("Right UV Lamp Brightness"), devices.FUSEBOX, device_commands.Button_41, 82, 0.5, 0.1, false, false)
        elements["PITLITE_RH"].sound = {{SOUND_PINION, SOUND_PINION}}
    --
--

-- Oxygen Apparatus Controls
    -- Apparatus Connecting Valve
    elements["OXY_VALVE"] = default_animated_lever(_("Oxygen Operating Valve"), devices.OXYGEN, device_commands.Button_1, 127, 0.6)

    -- Regulator "Oxygen Shower" Blue Button
    elements["OXY_SHOWER"] = default_button(_("Oxygen Emergency By-Pass"), devices.OXYGEN, device_commands.Button_3, 126)
--

-- Main Panel Controls
    -- Undercarriage Controls
        -- U/C Plungers Cover
        elements["UC_COVER"] = default_2_position_tumb(_("Undercarriage Controls Cover"), devices.CONTROLS, device_commands.Button_39, 53)
        elements["UC_COVER"].sound = {{SOUND_METALLIC_TAB, SOUND_METALLIC_TAB}, {SOUND_METALLIC_TAB, SOUND_METALLIC_TAB}}
        -- U/C Raise Plunger
        elements["UC_UP"] = default_1_position_tumb(_("Undercarriage Raise"), devices.CONTROLS, device_commands.Button_1, 54, 1, {1.0, 1.0})
        -- U/C Extension Plunger
        elements["UC_DN"] = default_1_position_tumb(_("Undercarriage Lower"), devices.CONTROLS, device_commands.Button_2, 55, 1, {1.0, 1.0})
        -- U/C Locks Release Pull Handle
        elements["UC_EMER"] = pull_handle(_("Undercarriage Emergency Release"), devices.CONTROLS, device_commands.Button_4, 63, 5.0)
    --

    -- Fuel and MW50 Systems Controls
        -- Fuel Primer Hand Pump
        elements["FUEL_PUMPH"] = default_button(_("Fuel Priming Pump"), devices.CONTROLS, device_commands.Button_12, 140)
        elements["FUEL_PUMPH"].sound = {{SOUND_PUMP_DOWN, SOUND_PUMP_UP}}

        -- Schnellstop Lever
        elements["THTL_STOP"] = default_animated_lever(_("Engine Stop"), devices.ENGINE_CONTROLS, device_commands.Button_6, 88, 2.5)
        elements["THTL_STOP"].sound = {{SOUND_QUAD_LEVER_LEFT, SOUND_QUAD_LEVER_RIGHT}, {SOUND_QUAD_LEVER_LEFT, SOUND_QUAD_LEVER_RIGHT}}

        -- Booster Pumps Lever
        -- TODO make lever occupy a different argument and animate it smoothly separately from switch logic - Made Dragon
        elements["THTL_PUMPS"] = multiposition_switch_limited(_("Booster Pumps"), devices.CONTROLS, device_commands.Button_23, 87, 4, 0.1)
        elements["THTL_PUMPS"].sound = {{SOUND_QUAD_LEVER_LEFT, SOUND_QUAD_LEVER_RIGHT}, {SOUND_QUAD_LEVER_LEFT, SOUND_QUAD_LEVER_RIGHT}}
        elements["THTL_PUMPS_0"] = default_1_position_tumb(_("Booster Pumps Off"), devices.CONTROLS, device_commands.Button_25, 87, 0, {0.0, 0.0})
        elements["THTL_PUMPS_1"] = default_1_position_tumb(_("Booster Pumps P1"), devices.CONTROLS, device_commands.Button_25, 87, 0, {0.1, 0.1})
        elements["THTL_PUMPS_2"] = default_1_position_tumb(_("Booster Pumps P2"), devices.CONTROLS, device_commands.Button_25, 87, 0, {0.2, 0.2})
        elements["THTL_PUMPS_12"] = default_1_position_tumb(_("Booster Pumps P1+P2"), devices.CONTROLS, device_commands.Button_25, 87, 0, {0.3, 0.3})

        -- Stoff-Kraftstoff Ventilbatterie Lever
        elements["FUEL_MWVALVE"] = default_animated_lever(_("MW / Fuel"), devices.CONTROLS, device_commands.Button_27, 96, 5.0)
        elements["FUEL_MWVALVE"].sound = {{SOUND_QUAD_LEVER_LEFT, SOUND_QUAD_LEVER_LEFT}, {SOUND_QUAD_LEVER_LEFT, SOUND_QUAD_LEVER_LEFT}}

        -- Fuel Jettison Knob
        elements["FUEL_JETTISON"] = default_animated_lever(_("Fuel / MW Jettison"), devices.CONTROLS, device_commands.Button_41, 112, 7.5)
        elements["FUEL_JETTISON"].sound = {{SOUND_HANDLE_PULL, SOUND_HANDLE_RELEASE}, {SOUND_HANDLE_PULL, SOUND_HANDLE_RELEASE}}
    --

    -- Coolant System Controls
        -- Radiator Mode Lever
        elements["WRAD"] = multiposition_switch(_("Radiators Mode"), devices.CONTROLS, device_commands.Button_35, 113, 4, 0.1, false)
        elements["WRAD"].sound = {{SOUND_CHOPPER_SWITCH, SOUND_CHOPPER_SWITCH}, {SOUND_CHOPPER_SWITCH, SOUND_CHOPPER_SWITCH}}
        elements["WRAD_OFF"] = default_1_position_tumb(_("Radiators Drive Off"), devices.CONTROLS, device_commands.Button_37, 113, 0, {0.0, 0.0})
        elements["WRAD_OPEN"] = default_1_position_tumb(_("Radiators Close"), devices.CONTROLS, device_commands.Button_37, 113, 0, {0.1, 0.1})
        elements["WRAD_AUTO"] = default_1_position_tumb(_("Radiators Automatic"), devices.CONTROLS, device_commands.Button_37, 113, 0, {0.2, 0.2})
        elements["WRAD_CLOSE"] = default_1_position_tumb(_("Radiators Open"), devices.CONTROLS, device_commands.Button_37, 113, 0, {0.3, 0.3})

        -- LH Radiator Hose Cut-Off Pull Handle
        elements["WRAD_CUT_LH"] = default_animated_lever(_("LH Radiator Cut-Off"), devices.CONTROLS, device_commands.Button_43, 90, 5.0)
        elements["WRAD_CUT_LH"].sound = {{SOUND_HANDLE_PULL, SOUND_HANDLE_RELEASE}, {SOUND_HANDLE_PULL, SOUND_HANDLE_RELEASE}}
        -- RH Radiator Hose Cut-Off Pull Handle
        elements["WRAD_CUT_RH"] = default_animated_lever(_("RH Radiator Cut-Off"), devices.CONTROLS, device_commands.Button_45, 91, 5.0)
        elements["WRAD_CUT_RH"].sound = {{SOUND_HANDLE_PULL, SOUND_HANDLE_RELEASE}, {SOUND_HANDLE_PULL, SOUND_HANDLE_RELEASE}}
    --

    -- Rudder and Wheel Brakes
        -- Left Pedal
        elements["LH_WHEELBRAKE"] = default_movable_axis(_("Wheel Brake Left"), devices.CONTROLS, device_commands.Button_15, 103, 0.0, 0.1, true, false)
        -- Right Pedal
        elements["RH_WHEELBRAKE"] = default_movable_axis(_("Wheel Brake Right"), devices.CONTROLS, device_commands.Button_18, 104, 0.0, 0.1, true, false)
    --

    -- Navigation Instruments
        -- Altimeter
        elements["ALT_MBAR"] = default_axis(_("Altimeter Pressure Set"), devices.ALTIMETER, device_commands.Button_1, 11, 1.0, 0.4, false, true)

        -- Artificial Horizon
        elements["AH_LK"] = default_axis_limited(_("Horizon Cage"), devices.ARTIFICIAL_HORIZON, device_commands.Button_1, 7, 0.0, 0.04, false, false, {0.0, 0.511})

        -- Repeater Compass
        elements["RCS_RING"] = default_axis(_("Course Set"), devices.REMOTE_COMPASS, device_commands.Button_1, 12, 0.0, 0.05, false, true, true)
    --

    -- Instruments
        -- Clock Scale
        elements["CLK_SCALE"] = default_axis(_("Scale Set"), devices.CONTROLS, device_commands.Button_51, 21, 0.0, 0.01612434, false, true, true)
        -- Clock Setter Pinion
        elements["CLK_PINION"] = default_axis(_("Adjusting Knob"), devices.CONTROLS, device_commands.Button_54, 22, 0.0, 0.1, false, true, true)
        -- Clock Freeze Lever
        elements["CLK_SET"] = default_2_position_tumb(_("Time Setting Lever"), devices.CONTROLS, device_commands.Button_56, 23)
        -- Clock Stopwatch Button
        elements["CLK_SW"] = default_button(_("Start/Stop/Reset Chronometer"), devices.CONTROLS, device_commands.Button_58, 24)

        -- P 112 Gun Sight Brightness Rheostat
        elements["REVI_DIMMER"] = default_axis(_("Gun Sight Brightness"), devices.FUSEBOX, device_commands.Button_44, 48, 0.5, 0.1, true, false)
        -- P 9 / P 10 REVI Power Plug and Socket
        -- Operated internally via gun sight movement
        -- P 112 Gun Sight Folding Controls
        elements["REVI_MOUNT"] = default_2_position_tumb(_("Gunsight Fold"), devices.WEAPONS_CONTROLS, device_commands.Button_7, 139)
        elements["REVI_MOUNT"].sound = {{SOUND_REVI_UNFOLD, SOUND_REVI_FOLD}, {SOUND_REVI_UNFOLD, SOUND_REVI_FOLD}}
        -- P 112 Gun Sight Smoked Screen Controls
        elements["REVI_SCREEN"] = default_animated_lever(_("Gunsight Smoked Screen"), devices.WEAPONS_CONTROLS, device_commands.Button_10, 47, 3.0)
        elements["REVI_SCREEN"].sound = {{SOUND_REVI_SCREEN_DOWN, SOUND_REVI_SCREEN_UP}, {SOUND_REVI_SCREEN_DOWN, SOUND_REVI_SCREEN_UP}}
    --
	-- Radio Controls
		elements["FUG"]	=    multiposition_switch_limited(_("FuG16ZY Preset Selector"), devices.VHF_RADIO, device_commands.Button_1, 128, 4, 0.1)
        elements["FUG16_1"]		= default_1_position_tumb(_("FuG16ZY Preset 1"),  		devices.VHF_RADIO, device_commands.Button_2, 128, 0, {0.0, 0.0})
        elements["FUG16_2"]		= default_1_position_tumb(_("FuG16ZY Preset 2"),  		devices.VHF_RADIO, device_commands.Button_2, 128, 0, {0.1, 0.1})
        elements["FUG16_TR"]	= default_1_position_tumb(_("FuG16ZY Preset TR"), 		devices.VHF_RADIO, device_commands.Button_2, 128, 0, {0.2, 0.2})
        elements["FUG16_SQ"]	= default_1_position_tumb(_("FuG16ZY Preset SQ"), 		devices.VHF_RADIO, device_commands.Button_2, 128, 0, {0.3, 0.3})
		
		elements["FUG16_FINE"] 		= default_axis_limited(_("FuG16 ZY Fine Tune"), devices.VHF_RADIO, device_commands.Button_8, 129, 0.5, 0.05, false, true, false)
		elements["FUG16_VOLUME"] 	= default_axis(_("FuG16 ZY Volume"), devices.VHF_RADIO, device_commands.Button_3, 130, 0.0, 0.04, false,true)
		elements["FUG16_MIC"] 		= default_2_position_tumb(_("FT FT/Y ZF"),devices.VHF_RADIO, device_commands.Button_6, 131)
	
		--elements["FUG25"] 		= default_2_position_tumb(_("FuG25 Mode Selector"), devices.VHF_RADIO, device_commands.Button_6, 132)
		elements["FUG25_1"]		= default_1_position_tumb(_("FuG25 Mode 1"),  devices.VHF_RADIO, device_commands.Button_12, 132, 0, {0.0, 0.0})
		elements["FUG25_2"]		= default_1_position_tumb(_("FuG25 Mode 2"),  devices.VHF_RADIO, device_commands.Button_12, 132, 0, {1.0, 1.0})
		elements["FUG25_TEST"] 	= default_button(_("FuG25 Test"), devices.VHF_RADIO, device_commands.Button_14, 133)
	--
--

-- Left Wall Controls
    -- Tail Wheel Lock Handle
    elements["TAIL_LOCK"] = default_animated_lever(_("Tail Wheel Lock"), devices.CONTROLS, device_commands.Button_21, 97, 5.0)
    elements["TAIL_LOCK"].sound = {{SOUND_QUAD_LEVER_LEFT, SOUND_QUAD_LEVER_LEFT}, {SOUND_QUAD_LEVER_LEFT, SOUND_QUAD_LEVER_LEFT}}

    -- Cockpit Open/Close Control
    elements["HATCH"] = default_2_position_tumb(_("Canopy"), devices.CONTROLS, device_commands.Button_29, 136)
    elements["HATCH"].sound = {{SOUND_NOSOUND, SOUND_NOSOUND}, {SOUND_NOSOUND, SOUND_NOSOUND}}
    elements["HATCH_H"] = default_2_position_tumb(_("Canopy"), devices.CONTROLS, device_commands.Button_33, 137)
    elements["HATCH_H"].sound = {{SOUND_COCKPIT_HANDLE_SPECIAL, SOUND_COCKPIT_HANDLE_SPECIAL}, {SOUND_COCKPIT_HANDLE_SPECIAL, SOUND_COCKPIT_HANDLE_SPECIAL}}
    elements["HATCH_S"] = default_2_position_tumb(_("Canopy"), devices.CONTROLS, device_commands.Button_34, 138)
    elements["HATCH_S"].sound = {{SOUND_COCKPIT_CANOPY_CLOSE, SOUND_COCKPIT_CANOPY_OPEN}, {SOUND_COCKPIT_CANOPY_CLOSE, SOUND_COCKPIT_CANOPY_OPEN}}
    -- Cockpit Jettison Pull Handle
    elements["HATCH_JETTISON"] = pull_handle(_("Jettison Canopy"), devices.CONTROLS, device_commands.Button_32, 83, 5.0)

    -- Trim Wheel
    elements["TRIM_NU"] = default_button(_("Stabilizer Trim Nose Up"), devices.CONTROLS, device_commands.Button_8, 141)
    elements["TRIM_NU"].sound = {{SOUND_NOSOUND, SOUND_NOSOUND}}
    elements["TRIM_ND"] = default_button(_("Stabilizer Trim Nose Down"), devices.CONTROLS, device_commands.Button_9, 142)
    elements["TRIM_ND"].sound = {{SOUND_NOSOUND, SOUND_NOSOUND}}

    -- Flaps Wheel
    elements["FLAPS_EXT"] = default_button(_("Extend Flaps"), devices.CONTROLS, device_commands.Button_10, 143)
    elements["FLAPS_EXT"].sound = {{SOUND_NOSOUND, SOUND_NOSOUND}}
    elements["FLAPS_RET"] = default_button(_("Retract Flaps"), devices.CONTROLS, device_commands.Button_11, 144)
    elements["FLAPS_RET"].sound = {{SOUND_NOSOUND, SOUND_NOSOUND}}

    -- Notwurf / Ordinance Dump
    elements["NOTWURF"] = pull_handle(_("Ordinance Emergency Release"), devices.WEAPONS_CONTROLS, device_commands.Button_18, 92, 5.0)

    -- LH Cockpit Vent
    --elements["VENT_LH"] = default_animated_lever(_("Cockpit Vent"), devices.CONTROLS, device_commands.Button_60, 98, 4.0)
--

-- Right Wall Controls
    -- RH Cockpit Vent
    --elements["VENT_RH"] = default_animated_lever(_("Cockpit Vent"), devices.CONTROLS, device_commands.Button_62, 99, 4.0)
    -- Flare Gun Trigger
    elements["PSTL_FIRE"] = default_button(_("Fire Flare Gun"), devices.CONTROLS, device_commands.Button_95, 72)
    elements["PSTL_FIRE"].sound = {{SOUND_NOSOUND, SOUND_FLARE_GUN}}
--

-- Engine Controls & Quadrant
    -- Ground Crew Signal -- TODO remove
    --elements["SS_SS"] = default_button(_("Signal Starter Crew"), devices.ENGINE_CONTROLS, device_commands.Button_1, 145)

    -- Throttle Lever
    elements["THTL"] = default_movable_axis(_("Throttle"), devices.ENGINE_CONTROLS, device_commands.Button_3, 84, 0.0, 0.1, true, false)
    -- Propellor Control Rocker
    elements["PROP_MINUS"] = default_button(_("Decrease RPM"), devices.FUSEBOX, device_commands.Button_60, 85, -1)
    elements["PROP_MINUS"].sound = {{SOUND_METALLIC_BUTTON_OFF, SOUND_METALLIC_BUTTON_OFF}}
    elements["PROP_PLUS"] = default_button(_("Increase RPM"), devices.FUSEBOX, device_commands.Button_60, 85, 1)
    elements["PROP_PLUS"].sound = {{SOUND_METALLIC_BUTTON_OFF, SOUND_METALLIC_BUTTON_OFF}}
    -- Radio Transmit Button
    elements["FUG16_TX"] = default_button(_("Microphone On"), devices.FUSEBOX, device_commands.Button_56, 150)

    -- E 103 Propellor Automation Switch
    elements["E103"] = default_2_position_tumb(_("Governor Automation"), devices.FUSEBOX, device_commands.Button_58, 89)

    -- Cold Weather Start Valve Handle
    elements["THTL_CWVALVE"] = default_animated_lever(_("Cold Weather Start"), devices.ENGINE_CONTROLS, device_commands.Button_8, 86, 10.0)
    elements["THTL_CWVALVE"].sound = {{SOUND_HANDLE_PULL, SOUND_HANDLE_RELEASE}, {SOUND_HANDLE_PULL, SOUND_HANDLE_RELEASE}}
--

-- Linking elements
    local thtl = elements["THTL"]
    thtl.children = {"PROP_MINUS", "PROP_PLUS", "FUG16_TX"}
    elements["PROP_MINUS"].updatable = true
    elements["PROP_PLUS"].updatable = true
    elements["FUG16_TX"].updatable = true

    local revi = elements["REVI_MOUNT"]
    revi.children = {"REVI_DIMMER", "REVI_SCREEN"}
--



for i,o in pairs(elements) do
	if  o.class[1] == class_type.TUMB or 
	   (o.class[2]  and o.class[2] == class_type.TUMB) or
	   (o.class[3]  and o.class[3] == class_type.TUMB)  then
	   o.updatable = true
	   o.use_OBB   = true
	end
end


