Skip to content

Instantly share code, notes, and snippets.

@tyrelsouza
Last active September 30, 2019 18:05
Show Gist options
  • Save tyrelsouza/b67fa2e793519e19ad292e4889bfd770 to your computer and use it in GitHub Desktop.
Save tyrelsouza/b67fa2e793519e19ad292e4889bfd770 to your computer and use it in GitHub Desktop.
-- assign logical name to macro keyboard
lmc_assign_keyboard('MACROS');
local function has_value (tab, val)
for index, value in ipairs(tab) do
if value == val then
return true
end
end
return false
end
COM = "g430n1" -- com identifier
TANK = "lft" -- left tank
tank_other = "rgt"
HOLD_BUTTONS = {118, 67}
-- Keys with both keyup and keydown, put in constants so they will always match.
STARTER_KEY = 55
function_for = {}
function_for[192] = function () -- [1, 1] `
lmc_xpl_command("sim/flight_controls/flaps_up")
end
function_for[49] = function () -- [1, 2] 1
lmc_xpl_command("sim/fuel/fuel_pumps_tog")
end
function_for[50] = function () -- [1, 3] 2
lmc_xpl_command("sim/lights/landing_lights_toggle")
end
function_for[51] = function () -- [1, 4] 3
lmc_xpl_command("sim/lights/strobe_lights_toggle")
end
function_for[52] = function () -- [1, 5] 4
lmc_xpl_command("sim/lights/nav_lights_toggle")
end
-- function_for[53] = function () -- [1, 6] 5
-- end
-- function_for[54] = function () -- [1, 7] 6
-- end
function_for[STARTER_KEY] = function () -- [1, 8] 7
lmc_xpl_command_end('sim/engines/engage_starters')
end
function_for[56] = function () -- [2, 1] 8
lmc_xpl_command("sim/flight_controls/flaps_down")
end
function_for[57] = function () -- [2, 2] 9
TANK, tank_other = tank_other, TANK -- Toggle TANK
lmc_xpl_command("sim/fuel/fuel_selector_" .. TANK)
lmc_xpl_text("Switched to " .. TANK .. " Tank.")
end
-- function_for[48] = function () -- [2, 3] 0
-- end
-- function_for[189] = function () -- [2, 4] -
-- end
-- function_for[187] = function () -- [2, 5] =
-- end
-- function_for[81] = function () -- [2, 6] q
-- end
-- function_for[87] = function () -- [2, 7] w
-- end
-- function_for[69] = function () -- [2, 8] e
-- end
-- function_for[82] = function () -- [3, 1] r
-- end
-- function_for[84] = function () -- [3, 2] t
-- end
-- function_for[89] = function () -- [3, 3] y
-- end
-- function_for[85] = function () -- [3, 4] u
-- end
-- function_for[73] = function () -- [3, 5] i
-- end
-- function_for[79] = function () -- [3, 6] o
-- end
-- function_for[80] = function () -- [3, 7] p
-- end
-- function_for[219] = function () -- [3, 8] [
-- end
function_for[221] = function () -- [4, 1] ]
xpl_gps("nav_com_tog")
end
-- function_for[220] = function () -- [4, 2] \
-- end
-- function_for[65] = function () -- [4, 3] a
-- end
function_for[83] = function () -- [4, 4] s
xpl_gps("cursor")
end
function_for[68] = function () -- [4, 5] d
xpl_gps("menu")
end
function_for[70] = function () -- [4, 6] f
xpl_gps("clr")
end
-- function_for[71] = function () -- [4, 7] g
-- end
-- function_for[72] = function () -- [4, 8] h
-- end
function_for[74] = function () -- [5, 1] j
xpl_gps("com_ff")
end
function_for[75] = function () -- [5, 2] k
xpl_gps("fine_up") -- VHF
end
function_for[76] = function () -- [5, 3] l
xpl_gps("coarse_up") -- VHF
end
function_for[186] = function () -- [5, 4] ;
xpl_gps("page_up")
end
function_for[90] = function () -- [5, 5] z
xpl_gps("chapter_up")
end
function_for[88] = function () -- [5, 6] x
xpl_gps("direct")
end
function_for[67] = function () -- [5, 7] c
lmc_xpl_command("sim/radios/obs1_up")
end
-- function_for[86] = function () -- [5, 8] v
-- end
function_for[112] = function () -- [6, 1] F1
xpl_gps("nav_ff")
end
function_for[113] = function () -- [6, 2] F2
xpl_gps("fine_down") -- VHF
end
function_for[114] = function () -- [6, 3] F3
xpl_gps("coarse_down") -- VHF
end
function_for[115] = function () -- [6, 4] F4
xpl_gps("page_dn")
end
function_for[116] = function () -- [6, 5] F5
xpl_gps("chapter_dn")
end
function_for[117] = function () -- [6, 6] F6
xpl_gps("ent")
end
function_for[118] = function () -- [6, 7] F7
lmc_xpl_command("sim/radios/obs1_down")
end
-- function_for[119] = function () -- [6, 8] F8
-- end
function xpl_gps(command)
lmc_xpl_command("sim/GPS/".. COM .. "_" .. command)
end
function on_key_down(button)
-- starter begin
if button == STARTER_KEY then
lmc_xpl_command_begin('sim/engines/engage_starters')
return true
end
if has_value(HOLD_BUTTONS, button) then
function_for[button]()
end
return false
end
function on_key_up(button, holding)
-- call Button's function
function_for[button]()
end
-- define callback for whole device
lmc_set_handler('MACROS', function(button, direction)
holding = false
if direction == 1 then
holding = on_key_down(button)
end
if direction == 0 then
on_key_up(button, holding)
end
end)
-- 'sim/transponder/transponder_ident'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment