• Which the release of FS2020 we see an explosition of activity on the forun and of course we are very happy to see this. But having all questions about FS2020 in one forum becomes a bit messy. So therefore we would like to ask you all to use the following guidelines when posting your questions:

    • Tag FS2020 specific questions with the MSFS2020 tag.
    • Questions about making 3D assets can be posted in the 3D asset design forum. Either post them in the subforum of the modelling tool you use or in the general forum if they are general.
    • Questions about aircraft design can be posted in the Aircraft design forum
    • Questions about airport design can be posted in the FS2020 airport design forum. Once airport development tools have been updated for FS2020 you can post tool speciifc questions in the subforums of those tools as well of course.
    • Questions about terrain design can be posted in the FS2020 terrain design forum.
    • Questions about SimConnect can be posted in the SimConnect forum.

    Any other question that is not specific to an aspect of development or tool can be posted in the General chat forum.

    By following these guidelines we make sure that the forums remain easy to read for everybody and also that the right people can find your post to answer it.

FSXA Alternator Switch with Reset

n4gix

Resource contributor
Messages
11,674
Country
unitedstates
I need to code alternator switches for the KA-350i. These are three position switches with the top position spring loaded, off/on/reset.

How it works is the pilot would move the switch to on, then reset. The switch springs back to the on position, and brings the alternator on-line. Should the alternator go off-line due to an overload or other problem, using reset should bring it on-line again.

I've beat my head for several days and have been unsuccessful. :banghead:

The 3d switch is scripted like this:
Code:
  <PartInfo>
    <Name>B350i_L_Generator</Name>
    <AnimLength>10</AnimLength>
    <Animation>
      <Parameter>
        <Code>
          (L:B350i_L_Generator,enum) 5 *
        </Code>
      </Parameter>
    </Animation>
    <MouseRect>
      <Cursor>Hand</Cursor>
      <MouseFlags>LeftSingle+LeftRelease+RightSingle+Wheel</MouseFlags>
      <CallbackCode>
        (M:Event) 'RightSingle' scmp 0 ==
        (M:Event) 'WheelDown' scmp 0 == or
        if{ (L:B350i_L_Generator, enum) -- 0 max (>L:B350i_L_Generator, enum) }
        (M:Event) 'LeftSingle' scmp 0 ==
        (M:Event) 'WheelUp' scmp 0 == or
        if{ (L:B350i_L_Generator, enum) ++  2 min (>L:B350i_L_Generator, enum) }
        1 (>L:XMLSND1,bool)
      </CallbackCode>
    </MouseRect>
  </PartInfo>
I want to have the 'logic' in a separate XML gauge for easier development. The following is what I've tried last, and it simply will not work. The bloody toggle event keeps firing constantly despite the 'controlling variables...'
Code:
<!-- GENERATOR LOGIC -->
 
<!-- RESET LEFT -->
(L:B350i_L_Generator,enum) 2 ==
(L:B350i_L_GenReset,enum) 0 == and
if{ 1 (>L:B350i_L_GenReset,enum) 1 (>L:B350i_L_Generator,enum) }
 
<!-- ON LEFT -->
(L:B350i_L_Generator,enum) 1 ==
(L:B350i_L_GenReset,enum) 1 == and
(A:GENERAL ENG MASTER ALTERNATOR:1,enum) 0 == and
if{ (>K:TOGGLE_ALTERNATOR1) }
 
<!-- OFF LEFT -->
(L:B350i_L_Generator,enum) 0 ==
if{ 0 (>L:B350i_L_GenReset,enum) }
 
(L:B350i_L_Generator,enum) 0 ==
(L:B350i_L_GenReset,enum) 0 == and
(A:GENERAL ENG MASTER ALTERNATOR:1,enum) 1 == and
if{ (>K:TOGGLE_ALTERNATOR1) }
 
<!-- END GENERATOR LOGIC -->
 
Bill, you could try:

Code:
      <MouseFlags>LeftSingle+LeftRelease+RightSingle</MouseFlags>
      <CallbackCode>
        (M:Event) 'RightSingle' scmp 0 ==
        if{ (L:B350i_L_Generator, enum) -- 0 max (>L:B350i_L_Generator, enum) }
        (M:Event) 'LeftSingle' scmp 0 ==
        if{ (L:B350i_L_Generator, enum) ++  2 min (>L:B350i_L_Generator, enum) }
        (M:Event) 'LeftRelease' scmp 0 ==
        if{ 1 (>L:B350i_L_Generator, enum) }
        1 (>L:XMLSND1,bool)
      </CallbackCode>

Remove the Wheel flag, as it does conflict with a "release" action.


then:

Code:
<!-- LEFT Init Values on aircraft Load -->
    .....
    (A:GENERAL ENG MASTER ALTERNATOR:1,enum) 1 ==
    if{ 1 (>L:B350i_L_Generator,enum) }
   ...put here control variable
   
<!-- RESET LEFT -->
(L:B350i_L_Generator,enum) 2 ==
(A:GENERAL ENG MASTER ALTERNATOR:1,enum) 1 == and
if{ (>K:TOGGLE_ALTERNATOR1) }

<!-- ON LEFT -->
(L:B350i_L_Generator,enum) 1 ==
(A:GENERAL ENG MASTER ALTERNATOR:1,enum) 0 == and
if{ (>K:TOGGLE_ALTERNATOR1) }

<!-- OFF LEFT -->
(L:B350i_L_Generator,enum) 0 ==
(A:GENERAL ENG MASTER ALTERNATOR:1,enum) 1 == and
if{ (>K:TOGGLE_ALTERNATOR1) }

Please check the AVar is the proper one for that event.
I believe should work, or almost :rolleyes:

Tom

EDIT: actually the logic is a bit more complex than that. When engine starts, even though the switch is in the ON position, the generator won't come online until it is reset.
(A:GENERAL ENG MASTER ALTERNATOR:n,enum) returns the position of the generator switch (ON= 1 OFF=0) and (A:GENERAL ENG GENERATOR ACTIVE:n,enum) returns the current status of the generator (1=online 0=offline). I think you should take both into account at some point.
 
Last edited:
Got to be coming from somewhere else Bill.
I copied your logic block into a test gauge, and got no repeating events.
Copying your mouse code into a test gauge seems to result in requiring two clicks in either direction to get a change in alternator state.
 
This one is in the same vein. It is a four position switch that behaves a bit like a joystick with the centre position being the neutral point. Two positions are "spring loaded" and have to be held in that position while he valve indicator opens/closes. A Third position parks the switch partially opening the spill valves. At a certain height the spill valve indicator crosslines and the switch returns to the centre neutral position.

Code:
<Gauge Name="LEFT SPILL VALVE" Version="1.0">
<Update>
(L:SetSpill,bool) 0 ==
   if{
      2 (>L:SPILL, number) 100 (>L:spill_segment,enum)
      1 (>L:SetSpill, bool)
   }
</Update>

   <Element>
      <Select>
         <Value>(L:SPILLSWITCH,number)</Value>
         <Case Value="0">
            <Image Name="L_spill_off.bmp"/>
         </Case>
         <Case Value="1">
            <Image Name="L_spill_shut.bmp"/>
         </Case>
         <Case Value="2">
            <Image Name="L_spill_norm.bmp"/>
         </Case>
         <Case Value="3">
            <Image Name="L_spill_spill.bmp"/>
         </Case>
      </Select>
   </Element>

  <Mouse>
<Tooltip>Left Spill Valve %((L:spill_segment,enum) near)%!d!%%</Tooltip>
      <Area Left="0" Top="22" Right="13" Bottom="39">
         <Cursor Type="Hand"/>
         <Click Kind="LeftSingle+LeftRelease" Repeat="Yes">
            (M:Event) 'LeftSingle' scmp 0 == if{ 0 (>L:SPILL,number) 1 (>L:SPILLSWITCH,number) (L:spill_segment,enum) 0 &gt;
if{ (L:spill_segment,enum) -- (>L:spill_segment,enum) } }
         (M:Event) 'LeftRelease' scmp 0 == if{ 0 (>L:SPILL,number) 0 (>L:SPILLSWITCH,number) (L:spill_segment,enum) 0 &gt;
if{ (L:spill_segment,enum) -- (>L:spill_segment,enum) } }
        </Click>
      </Area>

      <Area Top="0" Bottom="12">
         <Cursor Type="Hand"/>
         <Click>1 (>L:SPILL,number) 73 (>L:spill_segment,enum) 2 (>L:SPILLSWITCH,number) 1 (>L:Sound_click,enum)</Click>
      </Area>
      <Area Left="14" Top="22" Right="25" Bottom="39">
         <Cursor Type="Hand"/>
         <Click Kind="LeftSingle+LeftRelease" Repeat="Yes">
            (M:Event) 'LeftSingle' scmp 0 == if{ 2 (>L:SPILL,number) 3 (>L:SPILLSWITCH,number) (L:spill_segment,enum) 100 &lt;
if{ (L:spill_segment,enum) ++ (>L:spill_segment,enum) } }
          (M:Event) 'LeftRelease' scmp 0 == if{ 2 (>L:SPILL,number) 0 (>L:SPILLSWITCH,number) (L:spill_segment,enum) 100 &lt;
if{ (L:spill_segment,enum) ++ (>L:spill_segment,enum) } }
        </Click>
      </Area>

   </Mouse>
</Gauge>
 
@Tom: Actually that is the purpose of the (L:B350i_L_GenReset,enum) variable. This should be set 'true' only if the switch is moved to the "Reset" position momentarily.

When the switch snaps back to the "ON" position, if the alternator is off-line and the reset flag is "true" then the K:event to toggle the alternator "on" should fire. At the same time, the "reset variable" should be set "false". This will allow one to use the Reset position if needed to reset the alternator having been tripped off-line.

When the switch is moved to the "off" position, if the alternator is on-line the K:event is fired to turn it off, and the Reset variable is once again set "false" just to be on the safe side. ;)

@Doug: I found out that a large part of my problem(s) were the result of "too many lines" in my logic gauge. I need to clear out some of the unnecessary detritus left over from the B737-200 project to eliminate this issue. :rolleyes:

@Everyone: I need to send a note to L-M and beg them to either eliminate these bloody useless 'toggle events' or at least provide separate "on" and "off" events for them! :scratchch
 
Ok... if the switch is in the RESET position, the generator will be taken offline. After holding the switch for a couple of seconds, returning it to the ON position brings the generator online, if the engine is running. Moving the switch to the OFF position takes the generator offline. Low engine speed (I forget exact level, will find it for you) will also shut down the generator.
 
(A:GENERAL ENG MASTER ALTERNATOR:n,enum) returns the position of the generator switch (ON= 1 OFF=0) and (A:GENERAL ENG GENERATOR ACTIVE:n,enum) returns the current status of the generator (1=online 0=offline). I think you should take both into account at some point.
This is a prime example of unnecessary redundancy, which leads to confusion and angst:
  • GENERAL ENG MASTER ALTERNATOR:index
  • GENERAL ENG GENERATOR SWITCH:index
  • GENERAL ENG GENERATOR ACTIVE:index
Three bloody A:vars all of which report precisely the same information. Under what possible conditions will the latter two ever be different?
 
Same with LIGHT LANDING and LANDING LIGHTS ON. The latter doesn't even evaluate to "1" when the bloody lights are on!
Yet, I still can't reliably determine with an A: var if a system has failed or not...GAH!
 
Three bloody A:vars all of which report precisely the same information. Under what possible conditions will the latter two ever be different?

  • GENERAL ENG MASTER ALTERNATOR:index
  • GENERAL ENG GENERATOR SWITCH:index
both simulates the position of generator switch ON/OFF

  • GENERAL ENG GENERATOR ACTIVE:index
simulates the STATUS of the generator.

1 = ON -> providing power (with engine ON and switch ON)
0 = OFF -> off line (with engine ON and switch OFF or engine OFF no matter the position of the switch)


Tom
 
This is a prime example of unnecess redundancy, which leads to confusion and angst:
  • GENERAL ENG MASTER ALTERNATOR:index
  • GENERAL ENG GENERATOR SWITCH:index
  • GENERAL ENG GENERATOR ACTIVE:index
Three bloody A:vars all of which report precisely the same information. Under what possible conditions will the latter two ever be different?
There is a difference between a generator and an alternator both mechanically and electronically. The alternator will produce more current at low RPM. Wether LM is taking this into account I don't know.
 
ALTERNATOR and GENERATOR variables means the same both in FSX and P3D.

Tom
 
Back
Top