-
Notifications
You must be signed in to change notification settings - Fork 0
/
flipswitch.h
63 lines (55 loc) · 1.86 KB
/
flipswitch.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#ifndef FLIPSWITCH_H
#define FLIPSWITCH_H
// for syntax highlighting purposes
#include "usb_api.h"
#include <Bounce.h>
// hardware objects
Bounce tModeOff(28, 10); // Transponder rotary switch Mode selector...
Bounce tModeSby(29, 10);
Bounce tModeOn(30, 10);
Bounce tModeAlt(31, 10);
Bounce tModeTest(32, 10);
// X-Plane objects
FlightSimCommand TransponderOFF;
FlightSimCommand TransponderSTDBY;
FlightSimCommand TransponderON;
FlightSimCommand TransponderALT;
FlightSimCommand TransponderTEST;
// setup function is called once when Teensy boots up
void setup_flipswitch()
{
// initialize hardware pins
pinMode(28, INPUT_PULLUP);
pinMode(29, INPUT_PULLUP);
pinMode(30, INPUT_PULLUP);
pinMode(31, INPUT_PULLUP);
pinMode(32, INPUT_PULLUP);
// configure the X-Plane variables
TransponderOFF = XPlaneRef("sim/transponder/transponder_off");
TransponderSTDBY = XPlaneRef("sim/transponder/transponder_standby");
TransponderON = XPlaneRef("sim/transponder/transponder_on");
TransponderALT = XPlaneRef("sim/transponder/transponder_alt");
TransponderTEST = XPlaneRef("sim/transponder/transponder_test");
}
// loop function is called repeteadtly as long as Teensy is powered
void loop_flipswitch()
{
// read state of input pins and set corresponding
// state in X-Pane variable
if (tModeOff.update())
if (tModeOff.read() == LOW)
TransponderOFF.once();
if (tModeSby.update())
if (tModeSby.read() == LOW)
TransponderSTDBY.once();
if (tModeOn.update())
if (tModeOn.read() == LOW)
TransponderON.once();
if (tModeAlt.update())
if (tModeAlt.read() == LOW)
TransponderALT.once();
if (tModeTest.update())
if (tModeTest.read() == LOW)
TransponderTEST.once();
}
#endif // FLIPSWITCH_H