Functions per callback?

Help creating logic scripts for Air Manager Instruments

Moderators: russ, Ralph

Message
Author
User avatar
skymed
Posts: 46
Joined: Thu Mar 26, 2020 6:29 pm
Location: East Coast, Canada.

Re: Functions per callback?

#11 Post by skymed »

This is my result and it works thanks to you guys. Its to output a digital readout of a PT6 engine in Torque PSI, which is a tad convoluted but hey. Can it be condensed further?

Code: Select all

--add background image
img_add_fullscreen ("powerbk.png")

--define output text size, colour and location on back ground image. Need 3 colours because of 3 parameters I will use to make each one visible as needed

txt_shp1 = txt_add( "0.0", "size:60px; color: green; halign:center;valign:center;", 50, 10, 150, 90)
txt_shp2 = txt_add( "0.0", "size:60px; color: goldenrod; halign:center;valign:center;", 50, 10, 150, 90)
txt_shp3 = txt_add( "0.0", "size:60px; color: red; halign:center;valign:center;", 50, 10, 150, 90)
txt_shp4 = txt_add( "0.0", "size:60px; color: green; halign:center;valign:center;", 300, 10, 150, 90)
txt_shp5 = txt_add( "0.0", "size:60px; color: goldenrod; halign:center;valign:center;", 300, 10, 150, 90)
txt_shp6 = txt_add( "0.0", "size:60px; color: red; halign:center;valign:center;", 300, 10, 150, 90)


--[[convert output from torque callback --eng_torque-- of newton meters to foot pounds Left Engine. Since the ouput of the callback is a FLOAT[8]
 xplane has the ability to have 8 engines and the left one on a twin is engine 1 The right eng is 2  so we perform the same caluclation for each engine]]


  
function eng_torque(trq_nms)

-- Convert to foot pounds

trq_fpsL=trq_nms[1] * 0.73756 --engine 1

--convert foot pounds to psi
--
trq_psiL=trq_fpsL/30.57
  
--Call the text

txt_set (txt_shp1, string.format("%02.01f", trq_psiL) )
txt_set (txt_shp2, string.format("%02.01f", trq_psiL) )
txt_set (txt_shp3, string.format("%02.01f", trq_psiL) )

-- Make the coloured text visible pertinent to tq psi value

 visible(txt_shp1, trq_psiL < 40)
 visible(txt_shp2, trq_psiL >= 40)
 visible(txt_shp3, trq_psiL >= 50)
 
 
 
 --do it all again for the right Engine

trq_fpsR=trq_nms[2] * 0.73756 --engine 2

--convert foot pounds to psi

trq_psiR=trq_fpsR/30.57
  

txt_set (txt_shp4, string.format("%02.01f", trq_psiR) )
txt_set (txt_shp5, string.format("%02.01f", trq_psiR) )
txt_set (txt_shp6, string.format("%02.01f", trq_psiR) )


 visible(txt_shp4, trq_psiR < 40)
  visible(txt_shp5, trq_psiR >= 40)
 visible(txt_shp6, trq_psiR >= 50)
 

 -- I use the prints in the AM console to validate what I should see on the gauge.

  print(trq_psiL)
 print(trq_psiR)
 
  end
  


-- Data bus subscribe

xpl_dataref_subscribe("sim/flightmodel/engine/ENGN_TRQ", "FLOAT[8]", eng_torque)



User avatar
Sling
Posts: 5241
Joined: Mon Sep 11, 2017 2:37 pm
Contact:

Re: Functions per callback?

#12 Post by Sling »

I suppose you could put all the calculation inline in the txt_set() functions and use if...else to only set the text on the one that is going to be visible. Why set text on something that’s not even going to be shown.

Other than that not too shabby. :D

Post Reply