HiSimPassion wrote: ↑Sun Nov 20, 2022 10:38 pm Amazing sample, my LUA embedded intellisense got crazy while trying to check syntax ...
Yes I thought you would smile.
Keith
HiSimPassion wrote: ↑Sun Nov 20, 2022 10:38 pm Amazing sample, my LUA embedded intellisense got crazy while trying to check syntax ...
Also edited the last post and added a precision ...Keith Baxter wrote: ↑Sun Nov 20, 2022 10:44 pmHiSimPassion wrote: ↑Sun Nov 20, 2022 10:38 pm Amazing sample, my LUA embedded intellisense got crazy while trying to check syntax ...
Yes I thought you would smile.
Keith
Code: Select all
---- Boeing 737-800X Transponder for xplane ZIBO---
-- Add ONE characters display
atc_display_chr = hw_chr_display_add("ATC frequency", "MAX7219", 1)
--add the led indicators
hw_led_atc_fail = hw_led_add("ATC Fail", 0)
hw_led_atc_1 = hw_led_add("ATC 1 indicator", 0)
hw_led_atc_2 = hw_led_add("ATC 2 indicator", 0)
hw_led_atc_R = hw_led_add("ATC R indicator", 0)
--Subscribe to the datarefs to set the indicators
xpl_dataref_subscribe("laminar/B738/transponder/indicators/xpond_fail","FLOAT",
"laminar/B738/switch/xpndr_atc_pos","FLOAT",
"sim/cockpit/radios/transponder_light","INT",
"laminar/B738/knob/transponder_pos","FLOAT",
"sim/cockpit2/radios/actuators/transponder_code","INT",
"laminar/B738/electric/panel_brightness","FLOAT[4]",
"laminar/B738/comm/rtp_D/off_status","FLOAT",function(fail,atc,light,knob,code,bright,status)
if tonumber(status) == 0 then
hw_chr_display_set_brightness(atc_display_chr,0,tonumber(bright[4]))
atc_value = string.format("%04.0f",(code))
hw_led_set(hw_led_atc_fail,tonumber(fail))
if tonumber(atc) == 0 then
hw_led_set(hw_led_atc_1,tonumber(bright[4]))
hw_led_set(hw_led_atc_2,0)
else
hw_led_set(hw_led_atc_1,0)
hw_led_set(hw_led_atc_2,tonumber(bright[4]))
end
if tonumber(knob) > 1 and tonumber(light) == 1 then
hw_led_set(hw_led_atc_R,tonumber(bright[4]))
else
hw_led_set(hw_led_atc_R,0)
end
if tonumber(fail)~= 0 then
hw_led_set(hw_led_atc_fail,tonumber(fail))
hw_led_set(hw_led_atc_1,tonumber(fail))
hw_led_set(hw_led_atc_2,tonumber(fail))
hw_led_set(hw_led_atc_R,tonumber(fail))
atc_value = "8888"
hw_chr_display_set_brightness(atc_display_chr,0,tonumber(fail))
end
if tonumber(knob)== 0 then
hw_led_set(hw_led_atc_fail,0)
hw_led_set(hw_led_atc_1,0)
hw_led_set(hw_led_atc_2,0)
hw_led_set(hw_led_atc_R,0)
atc_value = " "
hw_chr_display_set_brightness(atc_display_chr,0,0)
end
hw_chr_display_set_text(atc_display_chr, 0, 0,atc_value)
else
hw_led_set(hw_led_atc_fail,0)
hw_led_set(hw_led_atc_1,0)
hw_led_set(hw_led_atc_2,0)
hw_led_set(hw_led_atc_R,0)
atc_value = " "
hw_chr_display_set_text(atc_display_chr, 0, 0,atc_value)
hw_chr_display_set_brightness(atc_display_chr,0,0)
end
end)
--Add the ATC Ident button
hw_button_add("ATC Ident",function()
xpl_command("laminar/B738/push_button/transponder_ident_dn")
end)
--Add the ATC 1/2 switch
atc_val = 0
hw_switch_add("ATC 1/2 switch",1,function(pos)
xpl_dataref_subscribe("laminar/B738/switch/xpndr_atc_pos","FLOAT",function(val)
atc_val = val
end)
if pos ~= atc_val then
xpl_command("laminar/B738/toggle_switch/xpndr_atc")
end
end)
--Add the ALT 1/2 switch
alt_val = 0
hw_switch_add("ALT 1/2 switch",1,function(pos)
xpl_dataref_subscribe("laminar/B738/switch/xpndr_alt_pos","FLOAT",function(val)
alt_val = val
end)
if pos ~= val then
xpl_command("laminar/B738/toggle_switch/xpndr_alt")
end
end)
--Add the mode switch
mode_pos = 0
hw_switch_add("Mode switch",6,function(pos)
mode_pos = pos
xpl_dataref_subscribe("laminar/B738/knob/transponder_pos","FLOAT",function(val)
if mode_pos ~= 0 and val > mode_pos then
xpl_command("laminar/B738/knob/transponder_mode_dn")
elseif mode_pos ~= 0 and val < mode_pos then
xpl_command("laminar/B738/knob/transponder_mode_up")
end
if mode_pos ==0 then
xpl_command("laminar/B738/knob/transponder_mode_dn","BEGIN")
elseif mode_pos ~= 0 then
xpl_command("laminar/B738/knob/transponder_mode_dn","END")
end
end)
end)
--Add the Dials
ones_val=0
tens_val=0
huns_val=7
thous_val=4
hw_dial_add("Transponder ones",function(dir)
ones_val = var_cap(ones_val+dir,0,7)
xpl_dataref_write("sim/cockpit/radios/transponder_code","INT", tonumber(thous_val..huns_val..tens_val..ones_val))
end)
hw_dial_add("Transponder tens",function(dir)
tens_val = var_cap(tens_val+dir,0,7)
xpl_dataref_write("sim/cockpit/radios/transponder_code","INT", tonumber(thous_val..huns_val..tens_val..ones_val))
end)
hw_dial_add("Transponder hundreds",function(dir)
huns_val = var_cap(huns_val+dir,0,7)
xpl_dataref_write("sim/cockpit/radios/transponder_code","INT", tonumber(thous_val..huns_val..tens_val..ones_val))
end)
hw_dial_add("Transponder thousands",function(dir)
thous_val = var_cap(thous_val+dir,0,7)
xpl_dataref_write("sim/cockpit/radios/transponder_code","INT", tonumber(thous_val..huns_val..tens_val..ones_val))
end)
Code: Select all
--Add the ATC 1/2 switch
atc_val = 0
hw_switch_add("ATC 1/2 switch",1,function(pos)
xpl_dataref_subscribe("laminar/B738/switch/xpndr_atc_pos","FLOAT",function(val)
atc_val = val
end)
if pos ~= atc_val then
xpl_command("laminar/B738/toggle_switch/xpndr_atc")
end
end)
Gilles,SimPassion wrote: ↑Sun Nov 20, 2022 11:19 pm I don't put into question the inline function, it's often a useful way to write the LUA code, though in the specific case of "speedbrake" or "flaps" sample, I don't see how it could work for a hw_adc_input_add using the "Named" choice, again in this specific case, I would rather use the "Hardware Id" one, otherwise we will not be able to bind an input properly ? What do you think Keith ?
Code: Select all
-- Bind to the first pin of hardware port A
hw_adc_input_add("HW_PORT_A1", function (value)
print("new value= " .. tostring(value) )
end)
Code: Select all
-- Bind to your choice pin of hardware port A
hw_adc_input_add("Volume", function (value)
print("new value= " .. tostring(value) )
end)
Code: Select all
local brake_var = 0
local sb_settings = { {0.171, 0},
{0.167, 0.2},
{0.37, 0.8},
{0.458, 1}}
-- Create a ADC input
hw_adc_input_add("speedbrake", function(value)
-- hw_adc_input_add("ARDUINO_NANO_I_A0", function(value)
print (value)
brake_var = interpolate_linear(sb_settings,value)
xpl_dataref_write("laminar/B738/flt_ctrls/speedbrake_lever","FLOAT", brake_var)
end)
Does this works when you switch several time from ATC 1 to ATC 2, then back to ATC 1 ?Keith Baxter wrote: ↑Sun Nov 20, 2022 11:09 pm
EDIT: And there you have a hardware ZIBO transponder instrument which is still in BETA my side....
It I important to note that one can subscribe within callbacks as I do here....
Code: Select all
--Add the ATC 1/2 switch atc_val = 0 hw_switch_add("ATC 1/2 switch",1,function(pos) xpl_dataref_subscribe("laminar/B738/switch/xpndr_atc_pos","FLOAT",function(val) atc_val = val end) if pos ~= atc_val then xpl_command("laminar/B738/toggle_switch/xpndr_atc") end end)