What am I missing from this script?

Help creating logic scripts for Air Manager Instruments

Moderators: russ, Ralph

Post Reply
Message
Author
cypherdious
Posts: 23
Joined: Tue Nov 23, 2021 10:52 am

What am I missing from this script?

#1 Post by cypherdious »

Need some help with this script controlling the AP CMD A button on the MCP.

I followed the video by Tony under Hardware but it doesn't seem to work as I think I am missing some script or logic statement.

Code: Select all

function apcmd_a_callback(state) 

print("autopilot cmd status: " .. state) apcmd_a = state 
end
xpl_dataref_subscribe("laminar/B738/autopilot/cmd_a_status", "FLOAT", apcmd_a_callback) 

function button_pressed() 

print("button pressed")
end
xpl_command("laminar/B738/autopilot/cmd_a_press")

hw_button_add("ARDUINO_MEGA2560_A_D4", button_pressed)
I can get hw_button to work printing "pressed" and "released" and also outputting the state of the XP button. When AP is on its 1.0 and when off its 0.

How do you get the hardware button to connect with the XP button. I thought the last statement would have done that. Thanks.

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

Re: What am I missing from this script?

#2 Post by Keith Baxter »

cypherdious wrote: Thu Dec 02, 2021 1:34 am Need some help with this script controlling the AP CMD A button on the MCP.

I followed the video by Tony under Hardware but it doesn't seem to work as I think I am missing some script or logic statement.

I can get hw_button to work printing "pressed" and "released" and also outputting the state of the XP button. When AP is on its 1.0 and when off its 0.

How do you get the hardware button to connect with the XP button. I thought the last statement would have done that. Thanks.
Hi,
Your <xpl_command("laminar/B738/autopilot/cmd_a_press")> needs to be within the <button_pressed> callback.

So..

Code: Select all

function button_pressed() 
xpl_command("laminar/B738/autopilot/cmd_a_press")
print("button pressed")
end

hw_button_add("ARDUINO_MEGA2560_A_D4", button_pressed)
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 

cypherdious
Posts: 23
Joined: Tue Nov 23, 2021 10:52 am

Re: What am I missing from this script?

#3 Post by cypherdious »

Hi Keith,

Much obliged. I m out at the moment. I will test this as soon as I am home. Will update.

Alex

cypherdious
Posts: 23
Joined: Tue Nov 23, 2021 10:52 am

Re: What am I missing from this script?

#4 Post by cypherdious »

Thanks Keith. Got it working. Slowly but surely understanding the scripting process.

Post Reply