
Jacques V

PILRIDER a écrit:En fait, je suis obligé d'agrandir l'HSI car autrement les boutons seraient dans la lunette du tableau de bord.
JC
---------------------------------------------------------------
-- BENDIX/KING CROWN SILVER KING SERIE --
-- KI525A HSI (ELECTRICAL) --
-- version 1.3
-- (fixed loc Scale position at startup)
-- (new variable to display or not the Bezel)
-- J. ZAHAR 04/2016 --
-- based on original by MacnFly (Thanks Mac!) --
-- Modeled using the user manual of the real instrument --
-- includes failure flags when power OFF --
-- FSX and Xplane version
---------------------------------------------------------------
---------------------------------------------------------------
-- DISPLAY VARIABLES SECTION --
-- Set to True or False according to taste --
---------------------------------------------------------------
display_frame=false -- displays the rectangular frame
display_screws=false -- displays the mounting screws
display_bezel=false -- displays the external bezel
display_dials=false -- displays the dials
FSX_HSI_source=0 -- NAV source for the HSI (FSX only!)--> 0:NAV1, 1:NAV2, 2:GPS (no GS)
gyro_spinup_duration=15000 -- time (in msec) before elec gyro is at full speed when master switch has been switched ON (default 10-15 sec)
---------------------------------------------------------------
-- END OF DISPLAY VARIABLES SECTION --
-- DO NOT MODIFIY CODE PAST THIS POINT !!! --
---------------------------------------------------------------
-- Global variables
is_failed=false
gbl_cur_hdef=0
gbl_cur_vdef=119
gbl_cur_bearing=0
gbl_target_hdef=0
gbl_target_vdef=20
gbl_target_bearing=0
gbl_factor1= 0.25
gbl_factor2= 0.25
gbl_factor3= 0.3
-- DIAL FUNCTIONS --
function new_obs(obsset)
if obsset == -1 then
if FSX_HSI_source==0 then --NAV1
xpl_command("sim/radios/obs1_down")
fsx_event("VOR1_OBI_DEC")
end
if FSX_HSI_source==1 then -- NAV2
xpl_command("sim/radios/obs2_down")
fsx_event("VOR2_OBI_DEC")
end
if FSX_HSI_source==2 then -- GPS
xpl_command("sim/radios/obs1_down")
fsx_event("VOR1_OBI_DEC")
end
elseif obsset == 1 then
if FSX_HSI_source==0 then
xpl_command("sim/radios/obs1_up")
fsx_event("VOR1_OBI_INC")
end
if FSX_HSI_source==1 then
xpl_command("sim/radios/obs2_up")
fsx_event("VOR2_OBI_INC")
end
if FSX_HSI_source==2 then
xpl_command("sim/radios/obs1_up")
fsx_event("VOR1_OBI_INC")
end
end
end
function new_heading(headingset)
if headingset == -1 then
xpl_command("sim/autopilot/heading_down")
fsx_event("HEADING_BUG_DEC")
elseif headingset == 1 then
xpl_command("sim/autopilot/heading_up")
fsx_event("HEADING_BUG_INC")
end
end
-- GRAPHICS --
if display_frame==true then
img_add_fullscreen("HSI_background frame.png")
end
img_add_fullscreen("HSI_background.png")
img_rose = img_add_fullscreen("HSI_compas rose.png")
img_bug = img_add_fullscreen("HSI_headingbug.png")
img_neddle = img_add_fullscreen("HSI_Needle arrow.png")
img_center_to = img_add_fullscreen("HSI_to flag.png")
img_center_from = img_add_fullscreen("HSI_from flag.png")
img_center = img_add_fullscreen("HSI_loc scale.png")
img_center_neddle = img_add_fullscreen("HSI_Needle center.png")
img_hdg_flag = img_add_fullscreen("HSI_flag HDG right.png")
img_nav_flag = img_add_fullscreen("HSI_flag NAV left.png")
img_add_fullscreen("HSI_inner bezel.png")
img_glideslope_markers = img_add_fullscreen("HSI_ILS bugs.png")--,0,-100,512,512)
img_add_fullscreen("HSI_inner bezel2.png")
if display_screws==true then
img_add_fullscreen("HSI_Bezel ext.png")
end
if display_screws==true then
img_add_fullscreen("HSI_screws.png")
end
--img_add_fullscreen("HSIguidelines.png")--guidelines (used for debugging)
-- Default visibility --
visible(img_hdg_flag, false)
visible(img_nav_flag, false)
-- FUNCTIONS --
function removes_HDG_flag() -- removes NAV flag after gyro_spinup_duration
visible(img_hdg_flag, false)
end
function PT_hsi(heading,source,crs,nav1hdef,nav2hdef,gpshdef,nav1vdef,nav2vdef,
gpsvdef,nav1display,nav2display, glideslopeflag, headingbug, nav1_fromto, nav2_fromto, gps_fromto, failed,has_power)
-- HDG flag
if (failed==1 or has_power==0) then --partial panel failure or master switch is off or main electrical bus is off
visible(img_hdg_flag,true)-- show HDG flag immediately
visible(img_nav_flag, true )
is_failed=true --instrument is off
else -- power is on
if is_failed==true then -- gauge powering up? we start a timer to let the gyro spinning before removing the flag
running=timer_running(gyro_startup_timer) -- if timer is already started do nothing
if running==false then
gyro_startup_timer=timer_start(gyro_spinup_duration,nil,removes_HDG_flag)--wait for gyro_spinup_duration before removing flag
end
is_failed=false
end
-- gbl_cur_bearing=gbl_target_bearing
end
if is_failed==true then --instrument is powered off
nav1display=0
nav2display=0
nav1hdef=0
nav1vdef=0
nav1_fromto=0
nav2hdef=0
nav2vdef=0
nav2_fromto=0
gpshdef=0
gpsvdef=0
gps_fromto=0
glideslopeflag=0
gbl_target_bearing=gbl_cur_bearing
end--if is_failed
-- global variables setting before calling of timer_callback()
gbl_target_bearing=-heading+crs
gbl_target_bug=headingbug
-- Rotate compas card
img_rotate(img_rose, -heading)
-- Rotate heading bug
img_rotate(img_bug, headingbug - heading)
img_rotate(img_center, gbl_target_bearing)
img_rotate(img_center_to, gbl_target_bearing)
img_rotate(img_center_from, gbl_target_bearing)
if source == 0 then -- NAV1
gbl_target_hdef=nav1hdef
gbl_target_vdef=nav1vdef
end
if source == 1 then -- NAV2
gbl_target_hdef=nav2hdef
gbl_target_vdef=nav2vdef
end
if source == 2 then -- GPS
gbl_target_hdef=gpshdef
gbl_target_vdef=gpsvdef
end
-- flags to/from
to = ((source == 0 and nav1_fromto == 1) or (source == 1 and nav2_fromto == 1) or (source == 2 and gps_fromto == 1))
from = ((source == 0 and nav1_fromto == 2) or (source == 1 and nav2_fromto == 2) or (source == 2 and gps_fromto == 2))
visible(img_center_to, (to == true and glideslopeflag==0))
visible(img_center_from, (from == true and glideslopeflag==0))
-- GS bugs
if glideslopeflag == 1 then -- GS signal received
--visible(img_glideslope_markers, true)
--gbl_target_vdef=-2
else
--visible(img_glideslope_markers, false)
gbl_target_vdef=-3.5 -- sends the bugs out of view
end
-- NAV flag when no valid VOR or localizer
visible(img_nav_flag, (source == 0 and nav1display == 0) or (source == 1 and nav2display == 0))
end
-- function to slowly move CDI center needle to current CDI deviation --
-- Thanks Ralph and Corjan for the trick! --
function timer_callback()
-- CDI needle
img_rotate(img_neddle, gbl_cur_bearing)
img_rotate(img_center_neddle, gbl_cur_bearing)
-- Calculation of center CDI needle position in pixels according to current needle bearing (actually bearing=course-heading)
navhdef = var_cap(gbl_cur_hdef, -4, 2.5) --horizontal deflection of CDI needle in ° (-2.5,2.5°)
dh = navhdef * math.cos((gbl_cur_bearing)*math.pi/180)* 41 -- 41 : distance in pixels between 2 dots
dv = navhdef * math.sin((gbl_cur_bearing)*math.pi/180)* 41
--Move center CDI needle
move(img_center_neddle, dh, dv, nil, nil)
--Move GS needle
navvdef = var_cap(gbl_cur_vdef, -4, 4)--vertical deflection of GS bugs in °
--dm = (navvdef * 41)-119 -- 40 : distance in pixels between 2 vertical dots
dm = (navvdef * 41) -- 40 : distance in pixels between 2 vertical dots
move(img_glideslope_markers, nil, dm , nil, nil)
--Calculation of current CDI deflection in ° with respect to target deflection position
-- currrent position is decreased/increased by "gbl_factor" every function call until reaching target position within 0.001 degrees
raw_diff = (gbl_target_hdef - gbl_cur_hdef) -- compute the delta of position
diff = fif(raw_diff,raw_diff,(raw_diff)*-1) -- chooses the sign of delta
gbl_cur_hdef = fif(math.abs(diff) < 0.001, gbl_target_hdef, gbl_cur_hdef + (diff * gbl_factor1) )-- chooses the greatest value
--Calculation of current GS deflection in ° with respect to target deflection position
raw_diff = (gbl_target_vdef - gbl_cur_vdef)
diff = fif(raw_diff,raw_diff, (raw_diff) * -1)
gbl_cur_vdef = fif(math.abs(diff) < 0.001, gbl_target_vdef, gbl_cur_vdef + (diff * gbl_factor2) )
-------------
gbl_cur_bearing=gbl_target_bearing
-- calculation for rotating needle (unused)
-- raw_diff = (360 + gbl_target_heading - gbl_cur_heading) %360
-- diff = fif(raw_diff < 180, raw_diff, (360 - raw_diff) * -1)
-- gbl_cur_heading = fif(math.abs(diff) < 0.001, gbl_target_heading, gbl_cur_heading + (diff * gbl_factor3) )
end
-- function to adapt FSX parameters to Xplane function
function PT_hsi_FSX(heading, obs, vertical, horizontal, nav_fromto, has_glide, headingbug, partial_panel, master)
if (master==false ) then
has_bus_power=0
else
has_bus_power=1
end
if (partial_panel==1) then
fail=1
else
fail=0
end
glideslope = fif(has_glide, 1, 0) --from FSX boolean to integer (Xplane style)
vertical = 2 / 119 * vertical -- GS range from -119 to + 119 in FSX
horizontal = 2 / 127 * horizontal -- CDI range from -127 to + 127 in FSX
PT_hsi(heading, 0, obs, horizontal, 0, 0, vertical, 0, 0, nav_fromto, 0, glideslope, headingbug, nav_fromto, 0, 0, fail,has_bus_power)
--function PT_hsi(heading,source,crs,nav1hdef,nav2hdef,gpshdef,nav1vdef,nav2vdef,gpsvdef,nav1display,nav2display, glideslopeflag, headingbug, nav1_fromto, nav2_fromto, gps_fromto, fail,has_bus_power)
end
-- DIAL ADD --
if display_dials==true then
dial_OBS = dial_add("dialhsi.png", 18, 368, 85, 85, new_obs)
dial_BUG = dial_add("headingbug.png", 409, 368, 85, 85, new_heading)
dial_click_rotate(dial_OBS, 5)
dial_click_rotate(dial_BUG, 5)
end
if FSX_HSI_source==0 then -- NAV1 (default)
fsx_variable_subscribe("HEADING INDICATOR", "Degrees",--"PLANE HEADING DEGREES GYRO", "Degrees",
"NAV OBS:1", "Degrees",
"NAV GSI:1", "Number",
"NAV CDI:1", "Number",
"NAV TOFROM:1", "Enum",
"NAV HAS GLIDE SLOPE:1", "Bool",
"AUTOPILOT HEADING LOCK DIR", "Degrees",
"PARTIAL PANEL ELECTRICAL", "Enum",-- failure of electrical bus
"ELECTRICAL MASTER BATTERY","Bool",PT_hsi_FSX)-- master switch
end
if FSX_HSI_source==1 then -- NAV2
fsx_variable_subscribe("HEADING INDICATOR", "Degrees",--"PLANE HEADING DEGREES GYRO", "Degrees",
"NAV OBS:2", "Degrees",
"NAV GSI:2", "Number",
"NAV CDI:2", "Number",
"NAV TOFROM:2", "Enum",
"NAV HAS GLIDE SLOPE:2", "Bool",
"AUTOPILOT HEADING LOCK DIR", "Degrees",
"PARTIAL PANEL ELECTRICAL", "Enum",-- failure of electrical bus
"ELECTRICAL MASTER BATTERY","Bool",PT_hsi_FSX)-- master switch
end
if FSX_HSI_source==2 then -- GPS
fsx_variable_subscribe("HEADING INDICATOR", "Degrees",--"PLANE HEADING DEGREES GYRO", "Degrees",
"NAV OBS:1", "Degrees",
"HSI GSI NEEDLE", "Number",
"HSI CDI NEEDLE", "Number",
"HSI TF FLAGS", "Enum",
"HSI GSI NEEDLE VALID", "Bool",
"AUTOPILOT HEADING LOCK DIR", "Degrees",
"PARTIAL PANEL ELECTRICAL", "Enum",-- failure of electrical bus
"ELECTRICAL MASTER BATTERY","Bool",PT_hsi_FSX)-- master switch
end
xpl_dataref_subscribe("sim/cockpit2/gauges/indicators/heading_electric_deg_mag_pilot", "FLOAT",-- electrical, not vacuum
"sim/cockpit2/radios/actuators/HSI_source_select_pilot", "INT",
"sim/cockpit2/radios/actuators/hsi_obs_deg_mag_pilot", "FLOAT",
"sim/cockpit2/radios/indicators/nav1_hdef_dots_pilot", "FLOAT",
"sim/cockpit2/radios/indicators/nav2_hdef_dots_pilot", "FLOAT",
"sim/cockpit2/radios/indicators/gps_hdef_dots_pilot", "FLOAT",
"sim/cockpit2/radios/indicators/nav1_vdef_dots_pilot", "FLOAT",
"sim/cockpit2/radios/indicators/nav2_vdef_dots_pilot", "FLOAT",
"sim/cockpit2/radios/indicators/gps_vdef_dots_pilot", "FLOAT",
"sim/cockpit2/radios/indicators/nav1_display_horizontal", "INT",
"sim/cockpit2/radios/indicators/nav2_display_horizontal", "INT",
"sim/cockpit2/radios/indicators/hsi_display_horizontal_pilot", "INT",
"sim/cockpit2/autopilot/heading_dial_deg_mag_pilot", "FLOAT",
"sim/cockpit/radios/nav1_fromto", "INT",
"sim/cockpit/radios/nav2_fromto", "INT",
"sim/cockpit/radios/gps_fromto", "INT",
"sim/operations/failures/rel_esys","INT", -- failure of main bus
"sim/cockpit/electrical/battery_on", "INT", PT_hsi) -- master switch on
-- Timers
-- Thanks Ralph and Corjan !--
tmr_update = timer_start(0, 50,timer_callback)-- moves the CDI needle every 0.05 second by calling the timer_callback() function
JacquesZ a écrit:Et hop, version spéciale du HSI pour toi!
Retourner vers Vos circuits électroniques fait maisons et PIC
Utilisateurs parcourant ce forum: Aucun utilisateur enregistré et 2 invités