i have a problem with the Inter-instrument communication ( si_variable_* ) and i am sure that there is some of you who can sort out my missunderstanding of the concept itself.
I have two instruments ( Battery Panel and EICAS )
Battery Panel
Code: Select all
----------------------------------------------------------
-- Global variables Battery and Avionics --
----------------------------------------------------------
sivar_elec_sys_op = si_variable_create ( "si_electrical_systems_operative", "INT", 0)
sivar_eicas_page_selected = si_variable_create ( "si_eicas_page_selected", "STRING", "BOOT")
Code: Select all
--------------------------------------------------------------
-- Electrical Power available?
--------------------------------------------------------------
function callback_elec_power ( battery, crosstie, avionics, voltage, elec_sys_op, eicas_page_selected )
if battery[1] == 1 and crosstie == 1 and avionics == 1 and voltage[1] >= 20
or battery[2] == 1 and crosstie == 1 and avionics == 1 and voltage[2] >= 20
then
si_variable_write ( sivar_elec_sys_op, 1 )
si_variable_write ( sivar_eicas_page_selected, "NORM" )
else
si_variable_write ( sivar_elec_sys_op, 0 )
si_variable_write ( sivar_eicas_page_selected, "BOOT" )
end
print("Page is : " .. eicas_page_selected)
end
variable_subscribe( "XPLANE", "sim/cockpit/electrical/battery_array_on" , "INT[8]" ,
"XPLANE", "sim/cockpit2/electrical/cross_tie" , "INT" ,
"XPLANE", "sim/cockpit2/switches/avionics_power_on", "INT",
"XPLANE", "sim/cockpit2/electrical/battery_voltage_actual_volts", "FLOAT[8]",
"SI", "si_electrical_systems_operative", "INT",
"SI", "si_eicas_page_selected", "STRING",
callback_elec_power )
The second instrument does not create the si_vars again, but uses them of course and creates some itself:
One Switch and one callback as example
EICAS
Code: Select all
----------------------------------------------------------
-- Global variables EICAS --
----------------------------------------------------------
-- Provided by Battery and Avionics
-- sivar_elec_sys_op = si_variable_create ( "si_electrical_systems_operative", "INT", 0)
-- sivar_eicas_page_selected = si_variable_create ( "si_eicas_page_selected", "STRING", "")
-- Self provided si_vars
sivar_checklist_selected = si_variable_create ( "si_switches_eicas_checklist_selected", "STRING", "NONE")
sivar_checklist_active_page = si_variable_create ( "si_switches_eicas_checklist_active_page", "INT", 0)
sivar_checklist_pages_total = si_variable_create ( "si_switches_eicas_checklist_pages_total", "INT", 0)
Code: Select all
--------------------------------------------------------------
-- Switch 100_NORM --
--------------------------------------------------------------
function click_100_norm ()
si_variable_write (sivar_eicas_page_selected, "NORM") -- ERROR
request_callback ( callback_100_norm )
end
switch_eicas_norm = switch_add ( "btn_norm.png", "btn_norm_active.png", 50, 1020, 80, 40, click_100_norm)
Code: Select all
--------------------------------------------------------------
-- Callback 100_NORM --
--------------------------------------------------------------
function callback_100_norm ( elec_sys_op, eicas_page_selected, eicas_checklist_selected, eicas_checklist_active_page, eicas_checklist_pages_total )
if elec_sys_op == 1 and eicas_page_selected == "NORM" then
switch_set_position ( switch_eicas_norm, 1 )
visible ( group_100_norm, 1 )
else
switch_set_position ( switch_eicas_norm, 0 )
visible ( group_100_norm, 0 )
si_variable_write (sivar_eicas_page_selected, "NOT-NORM") -- ERROR
end
end
variable_subscribe( "SI", "si_electrical_systems_operative", "INT",
"SI", "si_eicas_page_selected", "STRING",
"SI", "si_switches_eicas_checklist_selected", "STRING",
"SI", "si_switches_eicas_checklist_active_page", "INT",
"SI", "si_switches_eicas_checklist_pages_total", "INT",
callback_100_norm )
Argument 'var_id(1)' in function 'si_variable_write' is nil, which is not allowed
Argument 'var_id(1)' in function 'si_variable_write' is not a valid reference, which is not allowed
and so on.
Thanks Stefan