How to stop continuous FlightSim updates. Tennsy++2

Status
Not open for further replies.

P Dobson

Active member
Need a bit of help, I have written code which communicates with X-Plane11 via USB Flight Sim Controls. The problem I have is that the current code gets updates on X-Plane "heading" every program cycle. I actually only need "heading" when I update "CourseBug" to be equal to "heading".

This is part of a larger code set and I am trying to keep communications with X-Plane to a minimum. Continuous "heading" updates are just a waste of USB bandwidth most of the time.

Cheers Pete D.

Code enclosed.
 

Attachments

  • LHLong_reset_test.ino
    1.6 KB · Views: 64
You should use the Bounce library to read the button, rather than digitalRead(). Then it's easy to respond to only the change, sending only 1 update when it happens.

Look at File > Examples > Teensy > USB_Keyboard > Buttons for an example.
 
Hi Paul, thanks very much for your input. I looked at both Bounce and Bounce2 but decided it was better for me to look for trailing edge detection (does not appear in my test code) using the following sort of code for each button (of which there are many), then the Delay() does become the de-bounce time.

LHButton = digitalRead(18); //Left Hand Control Knob Push.
if (LHButton == HIGH && lastLHButton == LOW) {
ModeLH = ModeLH + 1;
if (ModeLH > 3) {
ModeLH = 1;
}
}
lastLHButton = LHButton;

This seems to work well for all the different buttons I have. The test code itself works OK in as much as I wanted the LHButton to remain pressed for 200 program cycles (approx. 2 seconds) before the headingbug is made equal to the Heading.

My real question was controlling the flow of data to and from X-Plane. I think I may have answered my own question and am now thinking of making "FlightSim.Update()" conditional rather than run every program cycle. In my set up I know when I want to talk to X-Plane and when I want to get data from it, so I can decide when to communicate with X-Plane. I believe though that this would control all communications between Teensy and X-Plane?? It would be nice if there was a way of requesting data from X-plane (Output from X-Plane) and separately sending data to X-Plane (Input to X-Plane). But I guess these two aspects are not separate-able??

Wishing you a Happy New Year and thanks for your support.

BR Pete D.
 
Hi Paul, It seems that allowing "FlightSim.Update()" just once is enough to start communications with X-Plane continuously. So on one program cycle I allowed "FlightSim.Update()" and then on subsequent cycles I did not allow "FlightSim.Update()" but still communications continue. So My idea does not seem to work. Is there any other way of controlling communications with X-Plane??

BR Peter D.
 

Attachments

  • LHLong_reset_test.ino
    1.7 KB · Views: 42
Status
Not open for further replies.
Back
Top