Night panels and lighting

Peer support for Air Manager desktop users

Moderators: russ, Ralph

Post Reply
Message
Author
a533
Posts: 49
Joined: Fri Apr 09, 2021 3:25 pm

Night panels and lighting

#1 Post by a533 »

Hi,

This is my first post, greetings to everyone. This a picture of the aircraft I fly in real word:

Image

and this is the panel I have made for Xplane with Air Manager, using the real picture as background and modifying gauges (instruments) to mach the real word colors and shapes.

Image

and this is the hardware I use, some of it homemade. All the switches and radios work

Image

First of all I want to congratulate the Siminnovations team, if they read this forum, for the excellent work they have made.

Now I want to make the night panel and I have some doubts.

I have made this panel to make some tests.

Image

You can download the panel here:

https://datos.qrouting.com/Simulador/Ai ... _test.siff

The necessary instruments from here:

https://datos.qrouting.com/Simulador/Ai ... ments.siff

Import the previous files and install in a “Custom Display” of 330 Width by 650 Height and if for some reason it does not show the background click “select image” and select the PNG you can download from here.

https://datos.qrouting.com/Simulador/Ai ... ground.png

Important: You have to be connected to a running Xplane for the panel to work.

Checking “Adjust darkness manually” you can use the knob to adjust the outside darkness from 0 (daylight) to 1 (night). If you uncheck this option, the panel reads the darkness from Xplane, dataref

"sim/graphics/misc/light_attenuation", "FLOAT"

As you turn the knob you can see that the panel darkens until it becomes almost back. If you turn the “panel light” you can see that the panel lights up and you can see the instruments again.

Now I have to go through all the instruments in the other panel and group the nodes into two categories:

1. Nodes that light up then you turn the panel lights (altimeter, airspeed indication, etc)
2. Nodes that don’t light up (switches, some text, etc)

As this imply some work, before I start I would like to know if this is the right approach or if there is I easier way to do this. Any advice will be most welcome.

Thank you and regards.



This is the code of the main panel:

Code: Select all

---------------------------------------------
-- --panel night test panel                --
---------------------------------------------                       



my_canvas_black = canvas_add(0,0,330,650)
my_canvas_red = canvas_add(0,0,330,650)

  canvas_draw(my_canvas_black, function()
     _rect(0,0,330,650)
     _fill( "#000000", 1 ) 
  end)
canvas_draw(my_canvas_red, function()
     _rect(0,0,330,650)
     _fill( "#9D3B2A", 1 )  -- era 841705
  end)


function dim_change(adf2,panel_lights)
   
   if panel_lights == 1 then
		opacity( my_canvas_black , 0 )
		opacity( my_canvas_red , var_cap(adf2/100,0,1) ) 
	else
		opacity( my_canvas_black , var_cap(adf2/100,0, 0.7 ) ) -- maximum for red layer 
		opacity( my_canvas_red , 0 )
	end
		
	
end

xpl_dataref_subscribe(	"sim/cockpit2/radios/actuators/adf2_standby_frequency_hz", "INT" , 
						"sim/cockpit2/switches/spot_light_on" , "INT"  , dim_change )


And this is the code of “knob” instrument.

Code: Select all

---------------------------------------------
-- night-dial instrument                   --
---------------------------------------------                       



---------------------------------------------
--   Properties                            --
---------------------------------------------
prop_BG = user_prop_add_boolean("Background",true,"Display background?")


---------------------------------------------
--   Init                                  --
---------------------------------------------
xpl_dataref_write("sim/cockpit2/radios/actuators/adf2_standby_frequency_hz", "INT", 0 )
aq_dim = 0
manually = false

    local settings = { { 0 , 0   },
                   { 0.31 , 0 },
                   { 0.91 , 0.80 },
                   { 1 , .95 }, }




---------------------------------------------
--   Load and display images in Z-order    --
--   Loaded images selectable with prop    --
---------------------------------------------
txt_id1 = txt_add("D="..aq_dim, "size:30px; font:GOST Common.ttf; color: #fb2c00; halign: left;", 10, 110, 150, 50)
txt_id2 = txt_add("Panel Light", "size:30px; font:GOST Common.ttf; color: #DDDBCC; halign: left;", 130, 100, 150, 50)
txt_id3 = txt_add("Adjust darkness manually", "size:20px; font:GOST Common.ttf; color: #DDDBCC; halign: left;", 55, 160, 250, 50)
txt_id4 = txt_add("Sim", "size:30px; font:GOST Common.ttf; color: #fb2c00; halign: left;", 18, 24, 250, 50)
txt_id5 = txt_add("0.0", "size:30px; font:GOST Common.ttf; color: #fb2c00; halign: left;", 18, 57, 250, 50)



---------------------------------------------
--   Functions                             --
---------------------------------------------
function new_dim(obsset)
	if obsset == -1 then
		aq_dim = aq_dim-1
	else
		aq_dim = aq_dim+1
	end	
	aq_dim = var_cap( aq_dim,0,90) -- maximum 90% darkness
    xpl_dataref_write("sim/cockpit2/radios/actuators/adf2_standby_frequency_hz", "INT",  aq_dim )
end

function callback_panel_lights(position, direction)
   if position == 0 then
	xpl_dataref_write("sim/cockpit2/switches/spot_light_on", "INT", 1 )
  end

  if position == 1 then
	xpl_dataref_write("sim/cockpit2/switches/spot_light_on", "INT", 0 )
  end

end

function callback_manually(position, direction)
   if position == 0 then
	manually = true
	switch_set_position(switch_manually, 1)
	visible( dial_OBS , true )
	visible( txt_id4 , false )
	visible( txt_id5 , false )
  end

  if position == 1 then
	manually = false
	switch_set_position(switch_manually, 0)
	visible( dial_OBS , false )
	visible( txt_id4 , true )
	visible( txt_id5 , true )
	request_callback(sim_light_change)
  end

end



function dim_change(adf2,spot_light)
	if adf2 == nil then
		adf2 = 0
	end
	txt_set(txt_id1, "D=".. string.format("%01.1f", adf2/100 ) )
    if spot_light == 1 then
		opacity( lighted_group , 1 )
		opacity( non_lighted_group , 1-var_cap(adf2/100,0,1) ) 
	else
		opacity( lighted_group , var_cap(1-adf2/100,0,1) )
		opacity( non_lighted_group , 1-var_cap(adf2/100,0, 1) )
	end
  if spot_light == 0 then
    switch_set_position(switch_panel_lights, 0)
  end

  if spot_light == 1 then
    switch_set_position(switch_panel_lights, 1)
  end
end

 
 function sim_light_change( sim_light )
	if not manually then
		aq_dim = math.floor( interpolate_linear(settings, sim_light ) * 100 ) 
		txt_set(txt_id5,  string.format("%01.1f", aq_dim/100 ) )
		xpl_dataref_write("sim/cockpit2/radios/actuators/adf2_standby_frequency_hz", "INT", aq_dim ) 
	end
end

---------------------------------------------
--   Controls Add                          --
---------------------------------------------

dial_OBS = dial_add("headingbug.png", 0, 0, 100, 100, 10, new_dim)
switch_panel_lights = switch_add("switch_down.png", "switch_up.png", 150,10,75,75,callback_panel_lights)
switch_manually = switch_add("check_off.png", "check_on.png", 14,152,32,32,callback_manually)

request_callback(dim_change)
callback_manually( fif( manually ,  0 , 1 ), 0)

lighted_group = group_add(dial_OBS)
non_lighted_group = group_add(txt_id2,switch_panel_lights)
--   nodes neither in "lighted_group" nor "non_lighted_group" remain always light on 

---------------------------------------------
--   Simulator Subscriptions               --
---------------------------------------------
 xpl_dataref_subscribe(	"sim/cockpit2/radios/actuators/adf2_standby_frequency_hz", "INT" ,	
						"sim/cockpit2/switches/spot_light_on" , "INT"   , dim_change )

xpl_dataref_subscribe(	"sim/graphics/misc/light_attenuation", "FLOAT"	, sim_light_change )

---------------------------------------------
-- END    Night-Dial                       --
---------------------------------------------                       

a533
Posts: 49
Joined: Fri Apr 09, 2021 3:25 pm

Re: Night panels and lighting

#2 Post by a533 »

This is a video of the test panel. If you connect it to xplane you can press Shift+L in xplane to advance the time in the day and see how the panel goes dark. Or press Shift+K to go the time earlier.

new version of the video

https://youtu.be/s-WgE5moFdU

Regards

Post Reply