• 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.

3 way spring-loaded switch

Messages
4
Country
unitedkingdom
Hi all

Quick question for the programming-gods... I would like to know if there is a simple way to create a 3-Way Spring-loaded toggle switch?

The switch I'd like to convert to a 'Return-to-Centre' switch, is a gauge test switch that is currently set-up as a left/right click rocker switch (switch operation simply spins all the fuel needles to show empty on Left click and full on right click), but I'd ideally like the switch to then return to centre automatically and my needles return to show their tanks normal quantities after the just one click.
Code:
    <PartInfo>
        <Name>fuel_test_switch</Name>
        <AnimLength>100</AnimLength>
        <Animation>
            <Parameter>
                <Code>50 (L:fuel_test_switch, bool) 50 * + </Code>
                <Lag>400</Lag>
            </Parameter>
        </Animation>
        <MouseRect>
            <Cursor>Hand</Cursor>
            <TooltipText>Fuel Gauge Test</TooltipText>
          <MouseFlags>LeftSingle+RightSingle</MouseFlags>
        <CallbackCode>
          (M:Event) 'LeftSingle' scmp  0 == if{ (L:fuel_test_switch, bool) -- -1 max (>L:fuel_test_switch, bool) }
          (M:Event) 'RightSingle' scmp 0 == if{ (L:fuel_test_switch, bool) ++ 1 min (>L:fuel_test_switch, bool) }
             (L:fuel_test_switch, bool) -1 == if{ -310 (>L:tank_gauge_test, gallons) }
             (L:fuel_test_switch, bool)  0 == if{ 0 (>L:tank_gauge_test, gallons) }
             (L:fuel_test_switch, bool)  1 == if{ 310 (>L:tank_gauge_test, gallons) }
         </CallbackCode>
        </MouseRect>
    </PartInfo>

I've tried in vain to marry up the above coding with the CallbackCode of P3D modeldef's G-Force rest (P:local time, seconds) 0.5 + (>L:G_reset) - but however I try to work this in I can't get it to work!

If this is possible, any help would be greatly appreciated. If not I'll stick with rocker...

Regards

Mike
 
Hi. Just use:

Code:
<MouseFlags>LeftSingle+RightSingle+Release</MouseFlags>
<CallbackCode>
      (M:Event) 'LeftSingle' scmp  0 ==
      if{ -1 (>L:fuel_test_switch, bool) -310 (>L:tank_gauge_test, gallons) }
      (M:Event) 'RightSingle' scmp  0 ==
      if{ 1 (>L:fuel_test_switch, bool) 310 (>L:tank_gauge_test, gallons) }
      (M:Event) 'Release' scmp  0 ==
      if{ 0 (>L:fuel_test_switch, bool) 0 (>L:tank_gauge_test, gallons) }
</CallbackCode>

And that's it.

Tom
 
Here is a complex three way switch in FS9. It works a bit like a joystick. Centre=neutral top = locked SW and SE hold open until spill valve is open or clsed then release to centre. The lock open is reset to neutral when cabin pressure reaches about 2,500 (controlled by another gauge).
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>
 
Many thanks to you BOTH for your quick replies - I really appreciate the answers. Vololiberista I assume that coding is for a panel? - Unfortunately it was way beyond my comprehension!o_O. Tom you helped me to see the light with the 'Release' command... unsure why I didn't think of it myself now! oh well... I have now got the switch working perfectly with Release commands added in the following CallbackCode:
Code:
        <CallbackCode>
          (M:Event) 'LeftSingle'   scmp 0 == if{ -1 (>L:fuel_test_switch, bool) -310 (>L:tank_gauge_test, gallons) }
          (M:Event) 'RightSingle'  scmp 0 == if{  1 (>L:fuel_test_switch, bool)  310 (>L:tank_gauge_test, gallons) }
          (M:Event) 'LeftRelease'  scmp 0 ==
          (M:Event) 'RightRelease' scmp 0 == or
          (M:Event) 'LeftDrag'     scmp 0 == or
          (M:Event) 'RightDrag'    scmp 0 == or
          (M:Event) 'Leave'        scmp 0 == or if{ 0 (>L:fuel_test_switch, bool) 0 (>L:tank_gauge_test, gallons) }
         </CallbackCode>
Many thanks again to you both, this is at least one less headache with the model.

Regards

Mike
 
Glad you got it working!

You can even make the code shorter by adding a quit operator :

Code:
<CallbackCode>
   (M:Event) 'LeftSingle' scmp 0 ==
   if{ -1 (>L:fuel_test_switch, bool) -310 (>L:tank_gauge_test, gallons)  quit }
   (M:Event) 'RightSingle' scmp 0 ==
   if{ 1 (>L:fuel_test_switch, bool) 310 (>L:tank_gauge_test, gallons) quit }
   0 (>L:fuel_test_switch, bool) 0 (>L:tank_gauge_test, gallons)
</CallbackCode>

I wouldn't spring back with Drag commands, because there would be times when you need to move the cursor (if zooming, for example) while keeping the switch position.

Tom
 
Back
Top