AM 3.0 v37: user prop

Discuss suspected bugs with other users and Sim Innovations Staff

Moderators: russ, Ralph

Post Reply
Message
Author
JackZ
Posts: 2267
Joined: Mon Feb 22, 2016 1:02 pm

AM 3.0 v37: user prop

#1 Post by JackZ »

Hi

I tried to implement user prop in the DR400 airspeed gauge with no avail.

In Create mode, the INFO lines returned is correct, but when added to a test panel, the Gauge properties panel displays: "This instrument has no user properties".
When I quit AM then restart, there appears only one property (the last one defined, ie user_prop_add_enum).???

Maybe I did something wrong? Here's the begining of the code:

Code: Select all

-------------------------------------------
-- DR400 Airpeed indicator with vibrating needle
--     Jacques ZAHAR 08/2017
--    sur une idée de CGOA Benoît (Aircockpit)

--          VERSION AIR MANAGER 3.0 ONLY
---------------------------------------------------
-- Let's give our instrument two properties
warn_user_prop = user_prop_add_real("Warning Speed Limit", 2.2, 3.0, 4.2, "Speed limit where the warning light should be visible")
alert_user_prop = user_prop_add_real("Alert Speed Limit", 4.3, 4.3, 5.6, "Speed limit where the alert light should be visible")

-- We can check here what the user has configured
print("The warning alarm is set to " .. user_prop_get(warn_user_prop) )
print("The Alert alarm is set to " .. user_prop_get(alert_user_prop) )

-- Let's give our instrument two properties
screws_prop = user_prop_add_boolean("Show screws", false, "Show the screws")
bezel_prop  = user_prop_add_boolean("Show bezel", true, "Show the bezel")

-- We can check here what the user has configured
print("Show the screw graphics: ",user_prop_get(screws_prop) )
print("Show the bezel graphics: ",user_prop_get(bezel_prop) )

-- Let's give our instrument two properties
choice_prop = user_prop_add_enum("Lighting effect", "None,Day,Dusk,Night,Auto", "Auto", "You can choose a type lighting effect for the gauge (default is automatic depending on the period of the day)")

-- We can check here what the user has configured
print("Selected choice: " .. user_prop_get(choice_prop) )
-- CUSTOMIZATION VARIABLES ------
display_bezel=true
-- sample Values for a modern single engine (Cessna, Piper, Robin)
frequency=40 -- increase the 40 value to slow down the overall vibrations for "slow running" engines (up to 100 max)
vibmax=80 --beginning of max vibrations in %power
valmax=0.05 -- range of max vibration values
vibmid=30 --beginning of medium vibrations in %power
valmid=0.07
viblow=0.5 -- low idle
vallow=0.09
I also noticed two things:

1- First It appears that there is a syntax error in the Wiki, as the following line (directly copied from the sample given in the Wiki) throws an error
-- Let's give our instrument two properties
screws_prop = user_prop_add_boolean("Show screws", true, "Show the screws")
bezel_prop = user_prop_add_boolean("Show bezel", true, "Show the bezel")

-- We can check here what the user has configured
print("Show the screw graphics: " .. user_prop_get(screws_prop) ) <---- ERROR trying to concatenate a boolean and a string
print("Show the bezel graphics: " .. user_prop_get(bezel_prop) ) <---- ERROR trying to concatenate a boolean and a string

I solved these by replacing the concatenation operator ".." by a comma "," as follows:
print("Show the screw graphics: ", user_prop_get(screws_prop) )
print("Show the bezel graphics: ", user_prop_get(bezel_prop) )

2- There is no way to modify/input the user properties in Create Mode, which makes it very difficult to implement user properties in the early phase of development. If a modification is made on a user property, one has to completely close and restart AM to have the instrument updated in Panel mode. Not very practical in the development phase IMHO.


Jacques
My YouTube Chanel on the A320 (Real SOPs by an Airline Pilot IRL):
https://www.youtube.com/playlist?list=P ... 0Q6SBASRqJ

User avatar
Ralph
Posts: 7933
Joined: Tue Oct 27, 2015 7:02 pm
Location: De Steeg
Contact:

Re: AM 3.0 v37: user prop

#2 Post by Ralph »

You can test your properties by setting the initial/default property state/value. So for the show bezels for example it's 'true', change that to 'false' and you're done.

The wiki is updated, this example works:
https://siminnovations.com/wiki/index.p ... dd_boolean

JackZ
Posts: 2267
Joined: Mon Feb 22, 2016 1:02 pm

Re: AM 3.0 v37: user prop

#3 Post by JackZ »

Actually, in Create/Edit Mode, i have no problem to display in the INFO the properties using the print() function

What puzzles me is that only ONE user prop is displayed in the Panel Tab (see picture), though 6 user prop have been declared in the code. Only the latter property in the code (choice_prop=user_prop_add_enum) is displayed, I don't know why.
Capture10.PNG
Here's the code where the 6 user prop are declared in a row:

Code: Select all

-- Let's give our instrument a property
title_prop = user_prop_add_string("Title", "Default title", "Text that shows up at the top of the instrument")

-- We can check here what the user has configured
print("Title: " .. user_prop_get(title_prop) )

-- Let's give our instrument two properties
warn_user_prop = user_prop_add_real("Warning Speed Limit", 2.2, 3.0, 4.2, "Speed limit where the warning light should be visible")
alert_user_prop = user_prop_add_real("Alert Speed Limit", 4.3, 4.3, 5.6, "Speed limit where the alert light should be visible")

-- We can check here what the user has configured
print("The warning alarm is set to " .. user_prop_get(warn_user_prop) )
print("The Alert alarm is set to " .. user_prop_get(alert_user_prop) )

-- Let's give our instrument two properties
screws_prop = user_prop_add_boolean("Show screws", true, "Show the screws")
bezel_prop  = user_prop_add_boolean("Show bezel", true, "Show the bezel")

-- We can check here what the user has configured
print("Show the screw graphics: ",user_prop_get(screws_prop) )
print("Show the bezel graphics: ",user_prop_get(bezel_prop) )

-- Let's give our instrument two properties
choice_prop = user_prop_add_enum("Lighting effect", "None,Day,Dusk,Night,Auto", "Auto", "You can choose a lighting effect for the gauge (Default : Automatic lighting depending on the period of the day)")

-- We can check here what the user has configured
print("Selected choice: " .. user_prop_get(choice_prop) )
Jacques
My YouTube Chanel on the A320 (Real SOPs by an Airline Pilot IRL):
https://www.youtube.com/playlist?list=P ... 0Q6SBASRqJ

User avatar
Corjan
Posts: 2941
Joined: Thu Nov 19, 2015 9:04 am

Re: AM 3.0 v37: user prop

#4 Post by Corjan »

Hi,


From a technical standpoint, AM has to 'scan' the instrument to find out what user properties have been defined in the lua code.
On boot, it will run all the installed instruments, all API calls are replaced by dummy implementations.

I kinda deliberately did not add this scan in the development process (create/edit tab), since this might mix up user properties in the first tab because things are still kinda in flux while developing.
It would be nice if the first tab would stay in sync though, maybe sync the user properties every time an instrument is started in the create/edit tab maybe...

Anyways, for now I don't think it is a big deal, I have added it to our internal TODO list, so it will stay on the radar.

I ran your code, and with the latest development version the user properties show up fine. I'm planning on creating a new AM BETA tomorrow. So could you check again with that version, I might have fixed it somehow without knowing :)


Corjan

User avatar
Ralph
Posts: 7933
Joined: Tue Oct 27, 2015 7:02 pm
Location: De Steeg
Contact:

Re: AM 3.0 v37: user prop

#5 Post by Ralph »

Works perfectly here. It's better if you post the complete instrument.
Also, did you reboot Air Manager before you checked this?

JackZ
Posts: 2267
Joined: Mon Feb 22, 2016 1:02 pm

Re: AM 3.0 v37: user prop

#6 Post by JackZ »

@Ralph: Yes I rebooted AM many times of course.
@Corjan: Don't worry, will try the beta 38 and maybe this will be fixed. 8-)

Thanks to you two guys

Jacques
My YouTube Chanel on the A320 (Real SOPs by an Airline Pilot IRL):
https://www.youtube.com/playlist?list=P ... 0Q6SBASRqJ

User avatar
Ralph
Posts: 7933
Joined: Tue Oct 27, 2015 7:02 pm
Location: De Steeg
Contact:

Re: AM 3.0 v37: user prop

#7 Post by Ralph »

I've tried it with beta 37. Maybe it goes wrong in combination with the rest of the code. Can you post the complete instrument?

JackZ
Posts: 2267
Joined: Mon Feb 22, 2016 1:02 pm

Re: AM 3.0 v37: user prop

#8 Post by JackZ »

Here's the code if you want to try, based on the DR400 gauge:
Only the last property is displayed (choice_prop), even when restarting AM.
Tested with version v39.

Code: Select all

-------------------------------------------
-- DR400 Airpeed indicator with vibrating needle
--     Jacques ZAHAR 08/2017
--    sur une idée de CGOA Benoît (Aircockpit)

--      VERSION AIR MANAGER 3.0 ONLY
---------------------------------------------------
-- Let's give our instrument a property
title_prop = user_prop_add_string("Title", "Default title", "Text that shows up at the top of the instrument")

-- We can check here what the user has configured
print("Title: " .. user_prop_get(title_prop) )

-- Let's give our instrument two properties
warn_user_prop = user_prop_add_real("Warning Speed Limit", 2.2, 3.0, 4.2, "Speed limit where the warning light should be visible")
alert_user_prop = user_prop_add_real("Alert Speed Limit", 4.3, 4.3, 5.6, "Speed limit where the alert light should be visible")

-- We can check here what the user has configured
print("The warning alarm is set to " .. user_prop_get(warn_user_prop) )
print("The Alert alarm is set to " .. user_prop_get(alert_user_prop) ) 


-- Let's give our instrument two properties
screws_prop = user_prop_add_boolean("Show screws", true, "Show the screws")
bezel_prop  = user_prop_add_boolean("Show bezel", true, "Show the bezel")

-- We can check here what the user has configured
print("Show the screw graphics: ",user_prop_get(screws_prop) )
print("Show the bezel graphics: ",user_prop_get(bezel_prop) )

-- Let's give our instrument two properties
choice_prop = user_prop_add_enum("Lighting effect", "None,Day,Dusk,Night,Auto", "Auto", "You can choose a lighting effect for the gauge (Default : Automatic lighting depending on the period of the day)")

-- We can check here what the user has configured
print("Selected choice: " .. user_prop_get(choice_prop) )
-- CUSTOMIZATION VARIABLES ------
display_bezel=bezel_prop
-- sample Values for a modern single engine (Cessna, Piper, Robin)
frequency=40 -- increase the 40 value to slow down the overall vibrations for "slow running" engines (up to 100 max)
vibmax=80 --beginning of max vibrations in %power
valmax=0.05 -- range of max vibration values
vibmid=30 --beginning of medium vibrations in %power
valmid=0.07
viblow=0.5 -- low idle
vallow=0.09

-- sample Values for a WWI Fighter
-- frequency=60 -- increase the 40 value to slow down the overall vibrations for "slow running" engines (up to 100 max)
-- vibmax=90 --beginning of max vibrations in %power
-- valmax=0.5 -- range of max vibration values
-- vibmid=30 --beginning of medium vibrations in %power
-- valmid=1
-- viblow=0.25 -- low idle
-- vallow=2

-- sample values for a WW1 Fighter
-- frequency=70 -- increase the 40 value to slow down the overall vibrations for "slow running" engines (up to 100 max)
-- vibmax=75 --beginning of max vibrations in %power
-- valmax=4 -- range of max vibration values
-- vibmid=40 --beginning of medium vibrations in %power
-- valmid=2.5
-- viblow=0.1 --low idle
-- vallow=3.5
----------------------------------------------
img_add_fullscreen("fond.png")
img_neddle = img_add_fullscreen("aiguille.png")
if display_bezel==true then
	img_add_fullscreen("bezel.png")
end
img_rotate(img_neddle, 0)

local needleairspeed=0
local rand=1
local val=0
local vibrationlvl=0

-------------- Variation de luminosité en fonction de l'éclairage---------
D_mask = img_add_fullscreen("masque_Day.png")
K_mask = img_add_fullscreen("masque_Dusk.png")
N_mask = img_add_fullscreen("masque_Night.png")

 function new_light_FSX(tension,light,ambiance)
	local panel_lighted= nil
	panel_lighted= tension>14 and light
	img_visible(D_mask,panel_lighted == false and ambiance==1)
	img_visible(K_mask,panel_lighted == false and ambiance==2)
	img_visible(N_mask,panel_lighted == false and ambiance==3)
end



fsx_variable_subscribe("ELECTRICAL MAIN BUS VOLTAGE","Volts","LIGHT PANEL","Bool" ,"TIME OF DAY","Enum",new_light_FSX)

---------- Gestion des vibrations aiguille
function vibrate(soundrpm)

	if soundrpm<0.1 then 
	vibrationlvl=0
	else vibrationlvl=soundrpm
	end
end
function vibrate_xp(rpm)

	if rpm<0.1 then 
	vibrationlvl=0
	else vibrationlvl=rpm
	end
end

function timer_callback() -- function called every 40 mseconds,
	rand=-rand -- offset value of the needle, alternatively to the left or to the right 
	--setting up of the amplitude of vibrations depending of the % of sound produced, since engien vibration is not reliable (Change val values to taste!)
	if vibrationlvl>vibmax then  -- high rpm, small amplitude
		val=valmax
	elseif vibrationlvl>vibmid then -- medium range rpm, larger amplitude of needle movements
		val=valmid
	elseif vibrationlvl>viblow then --slow rpm, smaller amplitude of needle movements
			 val=vallow
	else -- engine stopped, no needle movements
			val=0
    end
    
    needlepos=needleairspeed+(rand*val) -- calculation of the needle movement
	if  needleairspeed>=150 then
	img_rotate(img_neddle, (needlepos-150)*2.15+287)
	elseif needleairspeed>=130 then
	img_rotate(img_neddle, (needlepos-130)*2.55+236)
	elseif needleairspeed>80 then
	--img_rotate(img_neddle, (needlepos-90)*2.4+140)
	img_rotate(img_neddle, (needlepos-80)*2.436+114)
	elseif needleairspeed>=40 then
	img_rotate(img_neddle, (needlepos-40)*2.25+23)
	elseif needleairspeed>=30 then
	img_rotate(img_neddle, (needlepos-30)*1.6+7)
	else
	img_rotate(img_neddle, (needlepos))
	end
end

-- 30-->-173
-- 40-->-157
function PT_airspeed(airspeed)
    -- rotate the needle only if airspeed is above 25kts
	needleairspeed = var_cap(airspeed,0, 170)
	if needleairspeed<30 then needleairspeed=0 end

end

xpl_dataref_subscribe("sim/cockpit2/gauges/indicators/airspeed_kts_pilot", "FLOAT", PT_airspeed)

fsx_variable_subscribe("AIRSPEED INDICATED", "knots", PT_airspeed)
-- init the needle
fsx_variable_subscribe("GENERAL ENG COMBUSTION SOUND PERCENT:1","percent",vibrate)
-- init the needle
PT_airspeed(0)

timer_start(0,frequency,timer_callback) 
Jacques
My YouTube Chanel on the A320 (Real SOPs by an Airline Pilot IRL):
https://www.youtube.com/playlist?list=P ... 0Q6SBASRqJ

Post Reply