'Left and Right brake axis via lua code' problem

Help creating logic scripts for Air Manager Instruments

Moderators: Ralph, russ

Post Reply
Message
Author
artako
Posts: 2
Joined: Fri Jul 15, 2022 5:54 pm

'Left and Right brake axis via lua code' problem

#1 Post by artako »

In Air Manager i like to add a left (and right) brake axis for a cessna 172.
I started by cloning the generic throttle hardware by SimInnovations. In x-plane (version 11.00) i looked up what dataref is used by the program -> sim/cockpit2/controls/left_brake_ratio. In the 'create/modify tab' in Air Manager i modified the lua code, see below. But it does not work. Did i do something wrong? Any suggestions what this might be? (The brakes do not need to differentiate between engine numbers..)

adc_min_user_prop = user_prop_add_real("Lower value", 0.0, 1.0, 0.0, "Lower value of the ADC input, default is 0.")
adc_max_user_prop = user_prop_add_real("Upper value", 0.0, 1.0, 1.0, "Upper value of the ADC input, default is 1.")
eng_user_prop = user_prop_add_integer("Engine", 1, 8, 1, "Choose the engine number.")
local settings = nil
if user_prop_get(adc_max_user_prop) > user_prop_get(adc_min_user_prop) then
settings = { { 0 , 0 },
{ user_prop_get(adc_min_user_prop), 0 },
{ user_prop_get(adc_max_user_prop), 1 },
{ 1, 1 } }
else
settings = { { 0 , 1 },
{ user_prop_get(adc_max_user_prop), 1 },
{ user_prop_get(adc_min_user_prop), 0 },
{ 1, 0 } }
end

function left_brake_adc_callback(value)
local left_brake_pos = var_cap(interpolate_linear(settings, value), 0, 1)
xpl_dataref_write("sim/cockpit2/controls/left_brake_ratio", "FLOAT[8]", {left_brake_pos}, user_prop_get(eng_user_prop) - 1)
fs2020_variable_write("GENERAL LEFT BRAKE POSITION:" .. user_prop_get(eng_user_prop), "Percent", left_brake_pos * 100)
end

hw_adc_input_add("Brake left", left_brake_adc_callback)

User avatar
jph
Posts: 2099
Joined: Fri Apr 10, 2020 12:50 pm
Location: Somewhere over the rainbow..

Re: 'Left and Right brake axis via lua code' problem

#2 Post by jph »

Something like - but my Lua is crap and I can't test it :lol: one of the wise men will correct it.

Code: Select all

function left_brake_adc_callback(value)
local left_brake_pos = var_cap( value,0,1))
xpl_dataref_write("sim/cockpit2/controls/left_brake_ratio", "FLOAT", left_brake_pos)
end

hw_adc_input_add("Brake_left", left_brake_adc_callback)
“Everything in moderation, including moderation.”
“Experience is merely the name men gave to their mistakes.”
Joe (CISSP) -IT security consultant

artako
Posts: 2
Joined: Fri Jul 15, 2022 5:54 pm

Re: 'Left and Right brake axis via lua code' problem

#3 Post by artako »

Hi jph, unfortunately your solution did not work. It also showed an error , because there is one closing bracket too much. I removed it, but to no avail.

User avatar
jph
Posts: 2099
Joined: Fri Apr 10, 2020 12:50 pm
Location: Somewhere over the rainbow..

Re: 'Left and Right brake axis via lua code' problem

#4 Post by jph »

Ah, an extraneous bracket .. :) .How are you assigning the hardware and to what ? - as for the lua code, if there is a problem with it I am sure the wise men will correct it ;)
“Everything in moderation, including moderation.”
“Experience is merely the name men gave to their mistakes.”
Joe (CISSP) -IT security consultant

Post Reply