is there a flightsimcommand limit of only 12?

Status
Not open for further replies.

billrh

New member
Hello. I am building my second switch panel for x-plane. My first switch panel has 4 switches and 5 encoders and works fine.
The new panel has 14 switches with 30 possible switch settings . My first 12 switch settings work but the rest don't. After a lot of experimentation I've discovered that only the first 12 FlightSimCommands work. If I move other switch commands to be one of the first 12, they will now work and anything past the 12th command does not work. If I swap the order of the IF statements within the Loop there is no change.
I've put Serial.println statements into the IF statements to insure the program is working. I can see that the execution occurs (the IF is executed when the switch is changed), but the command does not show up on x-plane when using Show Communications although I can see the first 12.
I shortened the code down to 18 possible switch settings with the same results.

I'm running x-plane 10.25 on a mac, latest version of OSX and using a Teensy 3.1.

Any ideas?
-Bill


Here is the compile info:
Binary sketch size: 16,400 bytes (of a 262,144 byte maximum)
Estimated memory use: 4,552 bytes (of a 65,536 byte maximum)

Here is the code:

Code:
#include <Bounce.h>

/* 
  Panel #1 for x_plane setup. Includes engine, electrical and de-ice switches
*/

Bounce engStartR = Bounce (15, 5);
Bounce engStartL = Bounce (16, 5);
Bounce engStopR  = Bounce (14, 5);
Bounce engStopL  = Bounce (17, 5);
Bounce autoIgnL  = Bounce (11, 5);
Bounce autoIgnR  = Bounce (10, 5);
Bounce batt      = Bounce (9, 5);
Bounce gen1      = Bounce (3, 5);
Bounce gen2      = Bounce (2, 5);
Bounce inv       = Bounce (8, 5);
Bounce avion     = Bounce (7, 5);

FlightSimCommand startEng1;
FlightSimCommand startEng2;
FlightSimCommand stopEng1;
FlightSimCommand stopEng2;
FlightSimCommand ignArmOn1;
FlightSimCommand ignArmOn2;
FlightSimCommand ignArmOff1;
FlightSimCommand ignArmOff2;
FlightSimCommand batteryOn1;
FlightSimCommand batteryOff1;
FlightSimCommand genOn1;
FlightSimCommand genOff1;  //beyond this point the commands are not sent to x-plane
FlightSimCommand genOn2;
FlightSimCommand genOff2;
FlightSimCommand invertersOn;
FlightSimCommand invertersOff;  
FlightSimCommand avionicsOn;
FlightSimCommand avionicsOff;

void setup() {
  pinMode(0, INPUT_PULLUP);
  pinMode(1, INPUT_PULLUP);
  pinMode(2, INPUT_PULLUP);
  pinMode(3, INPUT_PULLUP);
  pinMode(4, INPUT_PULLUP);
  pinMode(5, INPUT_PULLUP);
  pinMode(6, INPUT_PULLUP);
  pinMode(7, INPUT_PULLUP);
  pinMode(8, INPUT_PULLUP);
  pinMode(9, INPUT_PULLUP);
  pinMode(10, INPUT_PULLUP);
  pinMode(11, INPUT_PULLUP);
  pinMode(14, INPUT_PULLUP);
  pinMode(15, INPUT_PULLUP);
  pinMode(16, INPUT_PULLUP);
  pinMode(17, INPUT_PULLUP);
  
    // link commands to xplane 
  startEng1 = XPlaneRef ("sim/starters/engage_starter_1");
  startEng2 = XPlaneRef ("sim/starters/engage_starter_2");
  stopEng1  = XPlaneRef ("sim/starters/shut_down_1");
  stopEng2  = XPlaneRef ("sim/starters/shut_down_2");
  ignArmOn1   = XPlaneRef ("sim/igniters/igniter_arm_on_1");
  ignArmOn2   = XPlaneRef ("sim/igniters/igniter_arm_on_2");
  ignArmOff1 = XPlaneRef ("sim/igniters/igniter_arm_off_1");
  ignArmOff2 = XPlaneRef ("sim/igniters/igniter_arm_off_2");
  batteryOn1  = XPlaneRef ("sim/electrical/battery_1_on");
  batteryOff1 = XPlaneRef ("sim/electrical/battery_1_off"); 
  genOn1    = XPlaneRef ("sim/electrical/generator_1_on");
  genOn2    = XPlaneRef ("sim/electrical/generator_2_on");
  genOff1   = XPlaneRef ("sim/electrical/generator_1_off");
  genOff2   = XPlaneRef ("sim/electrical/generator_2_off");
  invertersOn = XPlaneRef ("sim/electrical/inverters_on");
  invertersOff = XPlaneRef ("sim/electrical/inverters_off");
  avionicsOn = XPlaneRef ("sim/systems/avionics_on");
  avionicsOff = XPlaneRef ("sim/systems/avionics_off");

     
  // start the serial port. Will use this to ouput to the serial monitor while debugging
  Serial.begin(9600);
}

void loop() {
  FlightSim.update();
  if (FlightSim.isEnabled()) {

    // read status of all the switches
    if (engStartL.update()) {
      if (engStartL.fallingEdge()) {
        startEng1=1;
      } else {
        startEng1=0;
      }
    }
    if (engStartR.update()) {
      if (engStartR.fallingEdge()) {
        startEng2=1;
      } else {
        startEng2=0;
      }
    }    
    if (engStopL.update()) {
      if (engStopL.fallingEdge()) {
        stopEng1=1;
      } else {
        stopEng1=0;
      }
    }
    if (engStopR.update()) {
      if (engStopR.fallingEdge()) {
        stopEng2=1;
      } else {
        stopEng2=0;
      }
    }
    if (autoIgnL.update()) {
      if (autoIgnL.fallingEdge()) {
        ignArmOn1=1;
        ignArmOff1=0;
      } else {
        ignArmOn1=0;
        ignArmOff1=1;
      }
    }
    if (autoIgnR.update()) {
      if (autoIgnR.fallingEdge()) {
        ignArmOn2=1;
        ignArmOff2=0;
      } else {
        ignArmOn2=0;
        ignArmOff2=1;
      }
    }
    if (batt.update()) {
      if (batt.fallingEdge()) {
        batteryOn1=1;       // battery on
        batteryOff1=0;
      } else {
        batteryOn1=0;       // battery on
        batteryOff1=1;
      }
    }
    if (gen2.update()) { Serial.println ("gen2 on");
      if (gen2.fallingEdge()) {
        genOn2=1;       // gen1 on
        genOff2=0;
      } else {
        genOn2=0;       // gen1 on
        genOff2=1;
      }
    }
    if (gen1.update()) {
      if (gen1.fallingEdge()) {
        genOn1=1;       // gen1 on
        genOff1=0;
      } else {
        genOn1=0;       // gen1 on
        genOff1=1;
      }
    }

    if (inv.update()) {
      if (inv.fallingEdge()) {
        invertersOn=1;       // inverters on
        invertersOff=0;
      } else {
        invertersOn=0;       // inverters on
        invertersOff=1;
      }
    }
  }
}
 
Last edited:
On a whim I decided to go ahead and hook the switch panel/Teensy up to my main flightsim computer which is a Windows 7 system. The Teensy has the same code but it works perfectly. All of the 30 switch settings work. So I'm still baffled by what was happening on my Mac but it's working now on the Windows system so I'm happy.
As I use the Mac to proof my Teensy code before I instal anything new on the main flightsim computer, I'd still like to know what might be going wrong. So if any of you know, please pass it on.
Thanks.
 
I am having a similar problem and it seems to occur when the Xplane DataRefs are to long.

for example XPlaneRef("sim/cockpit2/gauges/actuators/artificial_horizon_adjust_deg_pilot"); is not being sent but if I shorten the dataref it is sent but of course it does not exist but atleast it is being sent.
 
If you use the plugin's Show Communications feature in X-Plane, do you see any communication for the 13th command? Maybe try on both PC and Mac to compare?
 
Billrh,

I tested your code with a Teensy 3.0 and XPlane 10.36 on a Macbook Air in 32 and 64 bits with the new version of the plugin that I posted on github (see other thread). I just added the missing lines to control avionics with the avion Bounce button and everything worked fine. I was able to control all 18 datarefs as expected, shorting pins 2, 3, 7, 8, 9, 10, 11, 14, 15, 16 and 17 to ground.

Everything that should appear on the Show Communication log is there. Same result on Linux and Windows.

Can you try with the plugin published on github (https://github.com/jbliesener/X-Plane_Plugin, there is a binary version, ready to install, in the "target" directory) and let me know?

Also, do you experience a crash when you exit from X-Plane? That was one of the things I tried to resolve with my version of the plugin. Does it work for you?
 
Last edited:
Jorg, aka jblesener

Just wanted to report that with the latest version of the plugin, I can confirm that it functions perfectly with long datarefs and with ZERO fps loss using 11 Teensy's now in my SIM.
Thank you so much!!!!

Rob
 
Good to know, Rob. If anybody's interested, the code is available in two Github repositories:



Both are required to handle long datarefs. There are also some other improvements like fixing the exit-crash on OSX and parameters to the callback-function.

I have sent a pull request to Paul and maybe he'll incorporate the changes into his official distributions.
 
Status
Not open for further replies.
Back
Top