Bravo pour moi ça marche impeccable
un grand



j'ai plus qu'a essayer de comprendre comment y affecter un bouton externe avec FSUIPC.
Bonne soirée à tous et bon GROG jacques
Bruno
Il n'y a pas besoin de souscrire à la position du sélecteur de carburant, puisque cet afficheur ne gère pas les sélecteurs de carburant. La jauge affiche simplement la valeur choisie suivant la position du bouton sélectionné.
Papagolf a écrit:Bonsoir a Tous
Bravo pour moi ça marche impeccable
un grand![]()
à ceux qui se sont décarcassés pour cette jauge (et les autres aussi
)
j'ai plus qu'a essayer de comprendre comment y affecter un bouton externe avec FSUIPC.
Bonne soirée à tous et bon GROG jacques
Bruno
-------------------------------------------------------------------------
-- Multi tanks quantity vintage display gauge for the C47 (DC3)
-- FSX/P3D version only
-- J. Vandenheede 02/2018
-------------------------------------------------------------------------
-- Customization variables
-------------------------------------------------------------------------
-- Set the maximum fuel quantity (full) in gallons here:
local gbl_max_fuel = 200
-- position of the knob at startup of the gauge(0 to 3 , counting clockwise)
local knob_position = 0 --0: left main, 1: right main, 2: right aux, 3: left aux
-------------------------------------------------------------------------
-- end of customization variables - do not modify code beyond this point!
-------------------------------------------------------------------------
-- Global variables used for smooth movement of the needle --
local gbl_target_fuel = 0 -- target position of the needle
local gbl_cur_fuel = 0 -- current position of the needle
local gbl_factor = 0.06 -- acceleration factor
-- misc vars
Fuel_Quantity=0
master_batt_on=false
Fuel_qty={} -- array used to store the 4 tanks quantities
--Images--
img_add_fullscreen("Reservoir_ DC3.png")
img_needle_L = img_add("aiguille_Reservoir_ DC3.png", 28, 226, nil, nil)
img_add_fullscreen("Cache_fuel DC3.png")
-- 4 images are created for each one of the knob's position to properly display the shadows
mask_Bouton19=img_add("Bouton_Reservoir_LeftMain.png", 130, 513, nil, nil)
mask_Bouton20=img_add("Bouton_Reservoir_RightMain.png", 130, 513, nil, nil)
mask_Bouton4=img_add("Bouton_Reservoir_LeftAux.png", 130, 513, nil, nil)
mask_Bouton5=img_add("Bouton_Reservoir_RightAux.png", 130, 513, nil, nil)
----------------------------------------------
-- each tank quantity is stored in a temp variable array, with index varying with to the knob's position (0 to 3)
function Fuel_Tank_Quantity(Quantity_L_Main ,Quantity_R_Main ,Quantity_L_Aux ,Quantity_R_Aux)
Fuel_qty[0]=Quantity_L_Main
Fuel_qty[1]=Quantity_R_Main
Fuel_qty[2]=Quantity_R_Aux
Fuel_qty[3]=Quantity_L_Aux
end
-- smooth needle movement routine
function timer_callback()
-- Rotate needle image
img_rotate(img_needle_L, 120 / 200 *(gbl_cur_fuel))
-- Calculate the current fuel needle position
gbl_cur_fuel = gbl_cur_fuel + ((gbl_target_fuel - gbl_cur_fuel) * gbl_factor)
end
-------------------------
-- it's an electrical gauge: displays zero when Master Batt is off
function batt_state(batt)
master_batt_on=batt
if master_batt_on==false then
gbl_target_fuel=0
else
gbl_target_fuel=Fuel_qty[knob_position]
end
end
--Fuel_Quantity to display is retrieved from the current knob position,
-- and the proper knob image is displayed accordingly
function knob(direction)
sound_play(knobclick)
knob_position = knob_position + direction -- direction is either +1/-1
if knob_position <0 then knob_position=3 end
if knob_position >3 then knob_position=0 end
--print (knob_position)
img_visible(mask_Bouton19, false)-- left main: pos 0
img_visible(mask_Bouton20, false)--right main : pos 1
img_visible(mask_Bouton5, false)-- right aux: pos 2
img_visible(mask_Bouton4, false)-- left aux: pos 3
if knob_position == 0 then
Fuel_Quantity = Fuel_qty[0]--Fuel_Quantity_L_Main
img_visible(mask_Bouton19, true)
elseif knob_position == 1 then
Fuel_Quantity = Fuel_qty[1]--Fuel_Quantity_R_Main
img_visible(mask_Bouton20, true)
elseif knob_position == 2 then
Fuel_Quantity = Fuel_qty[2]--Fuel_Quantity_R_Aux
img_visible(mask_Bouton5, true)
elseif knob_position == 3 then
Fuel_Quantity = Fuel_qty[3]--Fuel_Quantity_L_Aux
img_visible(mask_Bouton4, true)
end
if master_batt_on==false then
gbl_target_fuel=0
else
gbl_target_fuel = var_cap(Fuel_Quantity , 0, gbl_max_fuel)
end
end
-- function knob is called once at startup with no movement (0), to set the knob position and display it
knob(0)
-- Knob creation
dial_knob = dial_add (nil,50,420,300,300,knob) -- a rotating knob is created without any image (nil) for mouse operation
--dial_click_rotate(dial_knob, 90) -- disregard, unused
---------------------------------------------------------------------
-- subscribes
fsx_variable_subscribe(
"FUEL TANK LEFT MAIN QUANTITY", "Gallons",
"FUEL TANK RIGHT MAIN QUANTITY", "Gallons",
"FUEL TANK LEFT AUX QUANTITY", "Gallons",
"FUEL TANK RIGHT AUX QUANTITY", "Gallons", Fuel_Tank_Quantity)
fsx_variable_subscribe("ELECTRICAL MASTER BATTERY","Boolean",batt_state)
-- Timer used for smooth needle movement --
tmr_update = timer_start(0, 50, timer_callback)
JacquesZ a écrit:Bon. comme j'avais un peu honte de fournir un code aussi dégueu, et comme tu es encore faible Jacquesvoici le code "nettoyé" et commenté vite fait (je sais, je devrais être en train de faire autre chose, mais AM est une vraie came...
)-
On peut changer la position de départ du bouton en changeant la variable dans le code.
Tu n'as plus qu'à créer quatres images du bouton avec les ombres dans le bon sens, et ce sera parfait.
J'aime beaucoup l'encadrement "vieilli" de la jauge avec les traces d'usure!
- Code: Tout sélectionner
-------------------------------------------------------------------------
-- Multi tanks quantity vintage display gauge for the C47 (DC3)
-- FSX/P3D version only
-- J. Vandenheede 02/2018
-------------------------------------------------------------------------
-- Customization variables
-------------------------------------------------------------------------
-- Set the maximum fuel quantity (full) in gallons here:
local gbl_max_fuel = 200
-- position of the knob at startup of the gauge(0 to 3 , counting clockwise)
local knob_position = 0 --0: left main, 1: right main, 2: right aux, 3: left aux
-------------------------------------------------------------------------
-- end of customization variables - do not modify code beyond this point!
-------------------------------------------------------------------------
-- Global variables used for smooth movement of the needle --
local gbl_target_fuel = 0 -- target position of the needle
local gbl_cur_fuel = 0 -- current position of the needle
local gbl_factor = 0.06 -- acceleration factor
-- misc vars
Fuel_Quantity=0
master_batt_on=false
Fuel_qty={} -- array used to store the 4 tanks quantities
--Images--
img_add_fullscreen("Reservoir_ DC3.png")
img_needle_L = img_add("aiguille_Reservoir_ DC3.png", 28, 226, nil, nil)
img_add_fullscreen("Cache_fuel DC3.png")
-- 4 images are created for each one of the knob's position to properly display the shadows
mask_Bouton19=img_add("Bouton_Reservoir_LeftMain.png", 130, 513, nil, nil)
mask_Bouton20=img_add("Bouton_Reservoir_RightMain.png", 130, 513, nil, nil)
mask_Bouton4=img_add("Bouton_Reservoir_LeftAux.png", 130, 513, nil, nil)
mask_Bouton5=img_add("Bouton_Reservoir_RightAux.png", 130, 513, nil, nil)
----------------------------------------------
-- each tank quantity is stored in a temp variable array, with index varying with to the knob's position (0 to 3)
function Fuel_Tank_Quantity(Quantity_L_Main ,Quantity_R_Main ,Quantity_L_Aux ,Quantity_R_Aux)
Fuel_qty[0]=Quantity_L_Main
Fuel_qty[1]=Quantity_R_Main
Fuel_qty[2]=Quantity_R_Aux
Fuel_qty[3]=Quantity_L_Aux
end
-- smooth needle movement routine
function timer_callback()
-- Rotate needle image
img_rotate(img_needle_L, 120 / 200 *(gbl_cur_fuel))
-- Calculate the current fuel needle position
gbl_cur_fuel = gbl_cur_fuel + ((gbl_target_fuel - gbl_cur_fuel) * gbl_factor)
end
-------------------------
-- it's an electrical gauge: displays zero when Master Batt is off
function batt_state(batt)
master_batt_on=batt
if master_batt_on==false then
gbl_target_fuel=0
else
gbl_target_fuel=Fuel_qty[knob_position]
end
end
--Fuel_Quantity to display is retrieved from the current knob position,
-- and the proper knob image is displayed accordingly
function knob(direction)
sound_play(knobclick)
knob_position = knob_position + direction -- direction is either +1/-1
if knob_position <0 then knob_position=3 end
if knob_position >3 then knob_position=0 end
--print (knob_position)
img_visible(mask_Bouton19, false)-- left main: pos 0
img_visible(mask_Bouton20, false)--right main : pos 1
img_visible(mask_Bouton5, false)-- right aux: pos 2
img_visible(mask_Bouton4, false)-- left aux: pos 3
if knob_position == 0 then
Fuel_Quantity = Fuel_qty[0]--Fuel_Quantity_L_Main
img_visible(mask_Bouton19, true)
elseif knob_position == 1 then
Fuel_Quantity = Fuel_qty[1]--Fuel_Quantity_R_Main
img_visible(mask_Bouton20, true)
elseif knob_position == 2 then
Fuel_Quantity = Fuel_qty[2]--Fuel_Quantity_R_Aux
img_visible(mask_Bouton5, true)
elseif knob_position == 3 then
Fuel_Quantity = Fuel_qty[3]--Fuel_Quantity_L_Aux
img_visible(mask_Bouton4, true)
end
if master_batt_on==false then
gbl_target_fuel=0
else
gbl_target_fuel = var_cap(Fuel_Quantity , 0, gbl_max_fuel)
end
end
-- function knob is called once at startup with no movement (0), to set the knob position and display it
knob(0)
-- Knob creation
dial_knob = dial_add (nil,50,420,300,300,knob) -- a rotating knob is created without any image (nil) for mouse operation
--dial_click_rotate(dial_knob, 90) -- disregard, unused
---------------------------------------------------------------------
-- subscribes
fsx_variable_subscribe(
"FUEL TANK LEFT MAIN QUANTITY", "Gallons",
"FUEL TANK RIGHT MAIN QUANTITY", "Gallons",
"FUEL TANK LEFT AUX QUANTITY", "Gallons",
"FUEL TANK RIGHT AUX QUANTITY", "Gallons", Fuel_Tank_Quantity)
fsx_variable_subscribe("ELECTRICAL MASTER BATTERY","Boolean",batt_state)
-- Timer used for smooth needle movement --
tmr_update = timer_start(0, 50, timer_callback)
Jacques
Retourner vers LUA, Linda, Macros & gauges Air Manager
Utilisateurs parcourant ce forum: Aucun utilisateur enregistré et 6 invités