How to use "ASOBO_Add_Binding_Helper"

I have a switch that controls a line between a battery bus and another bus. This switch acts as the battery switch since the battery is always connected to some things, regardless of switch position, and the default behaviour is to turn the battery off at the source.

I have this switch working and controlling the line with the EX1 templates, but I was hoping to bind the default Battery key events to this switch as well.

Can the “ASOBO_Add_Binding_Helper” be used to do this? If not is my only option redoing the switch with a custom Input event?

If I can use the “ASOBO_Add_Binding_Helper”, how does it work? i tried adding it to the main component with an event ID but that caused a build error.

Code currently is:

Behaviour.xml

	<Component ID="BATTERY_SWITCH"> 
		<UseTemplate Name="ASOBO_CT_Switch_Template">
            <IN_BASE_NAME>Battery_Switch</IN_BASE_NAME>
            <IE_NAME>Battery_Switch</IE_NAME>
			<IE_TYPE>ELECTRICAL</IE_TYPE>
			<ANIM_LAG>500</ANIM_LAG>
			<UseParametersFn Name="ASOBO_Add_Cover_Helper">
        		<SaveParameters ID="Append_With_Cover">
            		<IN_BASE_NAME>Battery_Switch_Cover</IN_BASE_NAME>
					<ANIM_LAG>500</ANIM_LAG>
					<INVERT_ANIM>TRUE</INVERT_ANIM>
            	</SaveParameters>
        	</UseParametersFn>
 <!--doesnt work
			<UseParametersFn Name="ASOBO_Add_Binding_Helper">
			    <Parameters Type="Default">
					<EVENT_ID>MASTER_BATTERY_SET</EVENT_ID>
				</Parameters>
			</UseParametersFn>
 doesnt work -->
            <GET_SETTINGS>OFF_ON_Settings</GET_SETTINGS>
			<GET_SETTINGS_CONFIG>AS707_Battery_Switch_Settings_Config</GET_SETTINGS_CONFIG>
            <FORCE_POSITION_WHEN_COVER_CLOSED>ON</FORCE_POSITION_WHEN_COVER_CLOSED>
        </UseTemplate>
	</Component>

Behaviour_Config.xml

	<ParametersFn Name="OFF_ON_Settings">
        <ReturnParameters>
            <UseParametersFn Name="ASOBO_Auto_Define_Positions_And_Tooltips_Helper">
                <POS_0>OFF</POS_0>
                <POS_1>ON</POS_1>
            </UseParametersFn>
        </ReturnParameters>
    </ParametersFn>

Behaviour_Config_Prog.xml

	<ParametersFn Name="AS707_Battery_Switch_Settings_Config">
        <Parameters Type="Override">
			<LINE_ID>'J9_bus_to_P6_Ess_28V_DC_Bus'_n</LINE_ID>
		</Parameters>
        <Parameters Type="Default">
		    <UseParametersFn Name="ASOBO_Line_Connection_Parameters"/>
        </Parameters>
        <ReturnParameters>
            <UseParametersFn Name="ASOBO_Auto_Define_XStates_Variant_Helper"/>
            <UseParametersFn Name="ASOBO_Watch_Simvar_Helper">
                <SIMVAR>#SIMVAR_CONNECTION#</SIMVAR>
            </UseParametersFn>
            <!-- Check position -->
            <POS_OFF_CHECK>#GET_CONNECTION# !</POS_OFF_CHECK>
            <POS_ON_CHECK>#GET_CONNECTION#</POS_ON_CHECK>
            <!-- Set position -->
            <POS_OFF_CODE>0 #SET_CONNECTION#</POS_OFF_CODE>
            <POS_ON_CODE>1 #SET_CONNECTION#</POS_ON_CODE>
        </ReturnParameters>
    </ParametersFn>

Inserting into Behaviour_Config_Prog.xml fixes the build, but also isn’t doing what I thought it would do. Any help or pointing in the right direction would be greatly appreciated.

    <ParametersFn Name="AS707_Battery_Switch_Settings_Config">
        <Parameters Type="Override">
			<LINE_ID>'J9_bus_to_P6_Ess_28V_DC_Bus'_n</LINE_ID>
		</Parameters>
        <Parameters Type="Default">
		    <UseParametersFn Name="ASOBO_Line_Connection_Parameters"/>
        </Parameters>
        <ReturnParameters>
            <UseParametersFn Name="ASOBO_Auto_Define_XStates_Variant_Helper"/>
            <UseParametersFn Name="ASOBO_Watch_Simvar_Helper">
                <SIMVAR>#SIMVAR_CONNECTION#</SIMVAR>
            </UseParametersFn>
            <UseParametersFn Name="ASOBO_Add_Binding_Helper">
				<EVENT_ID>TOGGLE_MASTER_BATTERY</EVENT_ID>
                <BINDING_EVENT>TOGGLE</BINDING_EVENT>
                <PARAM_0>#GET_CONNECTION# 0 &gt; if{ 0 } els{ 1 }</PARAM_0>
			</UseParametersFn>
            <!-- Check position -->
            <POS_OFF_CHECK>#GET_CONNECTION# !</POS_OFF_CHECK>
            <POS_ON_CHECK>#GET_CONNECTION#</POS_ON_CHECK>
            <!-- Set position -->
            <POS_OFF_CODE>0 #SET_CONNECTION#</POS_OFF_CODE>
            <POS_ON_CODE>1 #SET_CONNECTION#</POS_ON_CODE>
        </ReturnParameters>
    </ParametersFn>

I think I was going about this the wrong way, using the ASOBO_Procedure_Template seems to be the proper way, with theBind_Key_Events procedure.

But for some reason, the “Toggle” event won’t bind, is there anything obvious I’m missing?

			<UseTemplate Name="ASOBO_Procedure_Template">
				<IE_NAME>Bind_Key_Events_Battery</IE_NAME>
				<PROCEDURE_ID>Bind_Key_Events</PROCEDURE_ID>
				<EVENT_ID>MASTER_BATTERY</EVENT_ID>
				<CODE>
					p0 if{ (&gt;B:ELECTRICAL_BATTERY_SWITCH_ON) } els{ (&gt;B:COMMON_ELECTRICAL_BATTERY_SWITCH_COVER_OPEN) (&gt;B:ELECTRICAL_BATTERY_SWITCH_OFF) }	
				</CODE>
				<VALUE>(B:ELECTRICAL_BATTERY_SWITCH)</VALUE>
			</UseTemplate>

The issue here is that you’ve got BINDING_EVENT set to TOGGLE - this isn’t a valid binding event.
You can use either SET, INC or DEC. In this case you just want to set the value to either 0 or 1, so you would use set. You could also use the ASOBO_Add_Set_Binding_Helper parameterfn

Thanks, I see where i was going wrong using that method.

With the procedure method I can also see the issue. The stock “Master Battery” toggle Key event is different to the standard events. Its called TOGGLE_MASTER_BATTERY. Where the template is expecting a toggle event to be MASTER_BATTERY_TOGGLE

Adding a second Procedure just for the toggle event has solved the issue

			<UseTemplate Name="ASOBO_Procedure_Template">
				<IE_NAME>Bind_Key_Events_Battery_Toggle</IE_NAME>
				<PROCEDURE_ID>Bind_Key_Event</PROCEDURE_ID>
				<EVENT_ID>TOGGLE_MASTER_BATTERY</EVENT_ID>
				<CODE>
					p0 if{ (&gt;B:ELECTRICAL_BATTERY_SWITCH_ON) } els{ (&gt;B:COMMON_ELECTRICAL_BATTERY_SWITCH_COVER_OPEN) (&gt;B:ELECTRICAL_BATTERY_SWITCH_OFF) }
				</CODE>
				<SaveParameters ID="Procedure_Bind_Key_Events_Battery_Toggle_Parameters" Append="Override">
					<IE_SET_ARG_COUNT>1</IE_SET_ARG_COUNT>
					<SET_PARAM_0>p0</SET_PARAM_0>
					<SET_PARAM_0_TYPE>Float</SET_PARAM_0_TYPE>
					<SET_PARAM_0_IS_DYNAMIC>True</SET_PARAM_0_IS_DYNAMIC>
				</SaveParameters>
				<PARAM_0>(B:ELECTRICAL_BATTERY_SWITCH) !</PARAM_0>
				<PARAM_0_IS_DYNAMIC>True</PARAM_0_IS_DYNAMIC>
			</UseTemplate>

This would look nicer if I stuck to the first method, but this works fine too.
Now the master battery key commands are intercepted and move my custom battery switch without affecting the true master battery switch.