Skip to content

Instantly share code, notes, and snippets.

@awebneck
Last active October 20, 2018 22:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save awebneck/d68dc5ad8a437b58950cae9d04e7c7cd to your computer and use it in GitHub Desktop.
Save awebneck/d68dc5ad8a437b58950cae9d04e7c7cd to your computer and use it in GitHub Desktop.
local small_throttle_axis_number = 27
local mixture_lever_axis_number = 29
local flap_up_switch_number = 181
local flap_mid_switch_number = 267
local flap_down_switch_number = 182
dataref("emergency_override_axis", "sim/joystick/joystick_axis_values", "readonly", small_throttle_axis_number)
dataref("throttle_notch_axis", "sim/joystick/joystick_axis_values", "readonly", mixture_lever_axis_number)
dataref("emerg_power", "tbm900/controls/engine/emerg_power", "writable")
dataref("flaps_pos", "sim/flightmodel/controls/flaprqst", "readonly")
local lastNotch = throttle_notch_axis
function handleThrottleNotches()
if (lastNotch < 0.25 and throttle_notch_axis >= 0.25) or
(lastNotch < 0.5 and throttle_notch_axis >= 0.5) or
(lastNotch < 0.75 and throttle_notch_axis >= 0.75) then
command_once("sim/engines/mixture_down")
elseif (lastNotch >= 0.25 and throttle_notch_axis < 0.25) or
(lastNotch >= 0.5 and throttle_notch_axis < 0.5) or
(lastNotch >= 0.75 and throttle_notch_axis < 0.75) then
command_once("sim/engines/mixture_up")
end
lastNotch = throttle_notch_axis
end
function setTbmFlapsUP()
posref = XPLMFindDataRef("sim/flightmodel/controls/flaprqst")
XPLMSetDataf(posref, 0.0)
end
function setTbmFlapsTO()
posref = XPLMFindDataRef("sim/flightmodel/controls/flaprqst")
XPLMSetDataf(posref, 0.5)
end
function setTbmFlapsLDG()
posref = XPLMFindDataRef("sim/flightmodel/controls/flaprqst")
XPLMSetDataf(posref, 1.0)
end
create_command("fwl/tbm900/controls/flaps_up", "Flaps UP", "", "", "setTbmFlapsUP()")
create_command("fwl/tbm900/controls/flaps_to", "Flaps TO", "", "", "setTbmFlapsTO()")
create_command("fwl/tbm900/controls/flaps_ldg", "Flaps LDG", "", "", "setTbmFlapsLDG()")
if PLANE_ICAO == "TBM9" then
set_button_assignment(flap_up_switch_number,"fwl/tbm900/controls/flaps_up")
set_button_assignment(flap_mid_switch_number,"fwl/tbm900/controls/flaps_to")
set_button_assignment(flap_down_switch_number,"fwl/tbm900/controls/flaps_ldg")
do_every_frame("emerg_power = 1 - emergency_override_axis")
do_every_frame("handleThrottleNotches()")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment