ZIBO speed breaks

Support for Arduino in combination with Air Manager and Air Player

Moderators: russ, Ralph

Message
Author
User avatar
Keith Baxter
Posts: 4674
Joined: Wed Dec 20, 2017 11:00 am
Location: Botswana

Re: ZIBO speed breaks

#31 Post by Keith Baxter »

SimPassion wrote: Sun Nov 20, 2022 10:38 pm Amazing sample, my LUA embedded intellisense got crazy while trying to check syntax ... :lol:
Hi
Yes I thought you would smile. :)

Keith
AMD RYZEN 9 5950X CPU, Corsair H80I cooler, ASUS TUF GAMING B550-PLUS AMD Ryzen Mother Board,  32Gb ram Corsair Vengeance 3000Mh, MSI GTX960 4G graphics card 

SimPassion
Posts: 5336
Joined: Thu Jul 27, 2017 12:22 am

Re: ZIBO speed breaks

#32 Post by SimPassion »

Keith Baxter wrote: Sun Nov 20, 2022 10:44 pm
SimPassion wrote: Sun Nov 20, 2022 10:38 pm Amazing sample, my LUA embedded intellisense got crazy while trying to check syntax ... :lol:
Hi
Yes I thought you would smile. :)

Keith
Also edited the last post and added a precision ... ;)

User avatar
Keith Baxter
Posts: 4674
Joined: Wed Dec 20, 2017 11:00 am
Location: Botswana

Re: ZIBO speed breaks

#33 Post by Keith Baxter »

Gilles,

This is a discussion that has different views. Sometimes you require a function to end before the next relating function is called. Sometime not.

I use this inline dataref subscribe and hardware adds for the Zibo transponder.
I think when you read the code it is much cleaner and understandable.
Might be just my preference.

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)
Keith

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)
Last edited by Keith Baxter on Sun Nov 20, 2022 11:23 pm, edited 1 time in total.
AMD RYZEN 9 5950X CPU, Corsair H80I cooler, ASUS TUF GAMING B550-PLUS AMD Ryzen Mother Board,  32Gb ram Corsair Vengeance 3000Mh, MSI GTX960 4G graphics card 

SimPassion
Posts: 5336
Joined: Thu Jul 27, 2017 12:22 am

Re: ZIBO speed breaks

#34 Post by SimPassion »

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 ?

User avatar
Keith Baxter
Posts: 4674
Joined: Wed Dec 20, 2017 11:00 am
Location: Botswana

Re: ZIBO speed breaks

#35 Post by Keith Baxter »

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 ?
Gilles,

Named or HW Id is irrelevant.

This works

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)
and this also works

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)
Keith
AMD RYZEN 9 5950X CPU, Corsair H80I cooler, ASUS TUF GAMING B550-PLUS AMD Ryzen Mother Board,  32Gb ram Corsair Vengeance 3000Mh, MSI GTX960 4G graphics card 

SimPassion
Posts: 5336
Joined: Thu Jul 27, 2017 12:22 am

Re: ZIBO speed breaks

#36 Post by SimPassion »

Sorry, I talked for nothing, I don't know why, however AM at first testing, don't bring me the ability to bind the input and I made false conclusion and wrong assumption

I was only getting this :

image.png
image.png (1.5 KiB) Viewed 663 times

So after new testing with both Named and Hardware Id way, all is working properly

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)
Last edited by SimPassion on Sun Nov 20, 2022 11:53 pm, edited 1 time in total.

User avatar
Keith Baxter
Posts: 4674
Joined: Wed Dec 20, 2017 11:00 am
Location: Botswana

Re: ZIBO speed breaks

#37 Post by Keith Baxter »

@SimPassion Gilles,

I am sure you will review the transponder instrument i posted and look forward to your comments for my learning.
My vision is to use a .json that can be loaded with parameters for pin connections.
As you are aware, Zibo has many instruments and not all arduino configurations are the same.

That is another discussion.

Keith
AMD RYZEN 9 5950X CPU, Corsair H80I cooler, ASUS TUF GAMING B550-PLUS AMD Ryzen Mother Board,  32Gb ram Corsair Vengeance 3000Mh, MSI GTX960 4G graphics card 

SimPassion
Posts: 5336
Joined: Thu Jul 27, 2017 12:22 am

Re: ZIBO speed breaks

#38 Post by SimPassion »

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)
Does this works when you switch several time from ATC 1 to ATC 2, then back to ATC 1 ?
In my case I found the real time switching between one side or the other for instrument duplicated on CAPT and FO side gave some unpredictable result, so I had to subscribe to both sides at the same time and just ignore dataref events which don't come from the current running side

All your other points are interesting solution though, nice work Keith

User avatar
Keith Baxter
Posts: 4674
Joined: Wed Dec 20, 2017 11:00 am
Location: Botswana

Re: ZIBO speed breaks

#39 Post by Keith Baxter »

Gilles,

Thank you. I have not done intensive testing. Just dev work on the hardware. Thank you for the pointer. I will check it out and address.
If you can recall, sometimes graphics "JUMP" or "STUTTER".
This is because some wait for other processes to end before starting.
For smother transition of loading .img and canvas() use inline functions. Also large databases.
But as I said sometimes inline functions are not the best choice as other functions might need to rely on the result.

Just some thoughts.

Nice simming. Enjoy

Keith
AMD RYZEN 9 5950X CPU, Corsair H80I cooler, ASUS TUF GAMING B550-PLUS AMD Ryzen Mother Board,  32Gb ram Corsair Vengeance 3000Mh, MSI GTX960 4G graphics card 

SimPassion
Posts: 5336
Joined: Thu Jul 27, 2017 12:22 am

Re: ZIBO speed breaks

#40 Post by SimPassion »

Thanks Keith for your advice, very valuable !
Just a small point to remember, all flight simulators are very restrictive on the variables subscribe and mostly don't like if we subscribe several times to the same values in the same run, this is why I chosen to subscribe to both sides at once and only one time on instrument start, in order to avoid counter-side effect

Have good flights :-)
Gilles

Post Reply