-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFlightSimOutputs.h
135 lines (105 loc) · 3.68 KB
/
FlightSimOutputs.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#ifndef _FLIGHTSIM_OUTPUTS_H
#define _FLIGHTSIM_OUTPUTS_H
#include <Arduino.h>
/*
* Data outputs for Midwest737Simulations Multi Output card
*
* (c) Jorg Neves Bliesener
*/
const uint8_t TEENSY_DIN_PIN = 5;
const uint8_t TEENSY_CLK_PIN = 2;
const uint8_t TEENSY_ENA_PIN = 4;
const uint8_t TEENSY_STB_PIN = 3;
const uint8_t NO_ENA_PIN = 0xff;
const bool SR_74HCT4094 = false;
const bool SR_74HCT595 = true;
const uint8_t DEBUG_OFF = 0;
const uint8_t DEBUG_OUTPUT = 1;
const uint8_t DEBUG_VALUE = 2;
const uint8_t NUMBER_OF_SHIFT_REGS = 6;
const uint8_t MAX_NUMBER_OF_CARDS = 8;
const uint8_t MAX_NUMBER_OF_SHIFT_REGS = MAX_NUMBER_OF_CARDS * NUMBER_OF_SHIFT_REGS;
const float DEFAULT_ON_THRESHOLD = 0.2;
class FlightSimOutputElement;
class MultiOutputBoard {
// The FLIGHTSIM_INTERFACE macro is defined in Teensy's runtime library, if it has been compiled with
// support for communications with X-Plane. Doesn't exist on the Arduino.
#ifdef FLIGHTSIM_INTERFACE
friend FlightSimOutputElement;
#endif
public:
MultiOutputBoard(const uint8_t numberOfShiftRegs = NUMBER_OF_SHIFT_REGS)
: MultiOutputBoard(TEENSY_DIN_PIN, TEENSY_CLK_PIN, TEENSY_STB_PIN, TEENSY_ENA_PIN, false, numberOfShiftRegs) {}
MultiOutputBoard(const uint8_t dinPin, const uint8_t clkPin, const uint8_t stbPin,
const uint8_t enaPin=NO_ENA_PIN, bool enaIsActiveLow=false,
const uint8_t numberOfShiftRegs = NUMBER_OF_SHIFT_REGS);
void setDinPin(uint8_t dinPin) { this->dinPin = dinPin; }
void setClkPin(uint8_t clkPin) { this->clkPin = clkPin; }
void setStbPin(uint8_t stbPin) { this->stbPin = stbPin; }
void setEnaPin(uint8_t enaPin, bool enaIsActiveLow=false) {
this->enaPin = enaPin;
this->enaIsActiveLow = enaIsActiveLow;
}
void printTime(Stream *s);
bool checkInitialized(const char *message, bool mustBeInitialized);
void begin();
void setData(size_t pinNumber, bool value);
bool getData(size_t pinNumber);
void sendData();
void sendDataIfChanged();
void loop();
static MultiOutputBoard *firstOutputBoard;
private:
uint8_t numberOfShiftRegs;
uint8_t dinPin;
uint8_t clkPin;
uint8_t stbPin;
uint8_t enaPin;
bool enaIsActiveLow;
bool initialized;
bool wasEnabled;
bool valueChanged;
uint8_t outputData[MAX_NUMBER_OF_SHIFT_REGS];
#ifdef FLIGHTSIM_INTERFACE
FlightSimOutputElement *firstOutput;
FlightSimOutputElement *lastOutput;
#endif
};
#ifdef FLIGHTSIM_INTERFACE
class FlightSimOutputElement {
friend MultiOutputBoard;
public:
FlightSimOutputElement(MultiOutputBoard *outBoard, size_t outputPin);
virtual ~FlightSimOutputElement() {}
void setDebug(uint8_t debugLevel) { this->debugLevel = debugLevel; }
MultiOutputBoard *board;
size_t outputPin;
protected:
uint8_t debugLevel;
bool isEnabled;
virtual void begin(size_t maxPinNumber);
private:
static FlightSimOutputElement *firstOrphan;
static FlightSimOutputElement *lastOrphan;
FlightSimOutputElement *next;
virtual void forceUpdate() {}
};
class FlightSimDigitalOutput : public FlightSimOutputElement {
public:
FlightSimDigitalOutput(size_t outputPin, float onThreshold=DEFAULT_ON_THRESHOLD, bool isInverted=false);
FlightSimDigitalOutput(MultiOutputBoard *outputBoard, size_t outputPin, float onThreshold=DEFAULT_ON_THRESHOLD, bool isInverted=false);
virtual ~FlightSimDigitalOutput() {}
void setDataref(const _XpRefStr_ *positionDataref);
void valueChanged(float newValue);
FlightSimDigitalOutput & operator =(const _XpRefStr_ *s) { setDataref(s); return *this; }
void setThreshold(float threshold) { this->onThreshold = threshold; }
private:
const _XpRefStr_ *datarefName;
FlightSimFloat dataref;
float onThreshold;
bool isInverted;
virtual void begin(size_t maxPinNumber);
virtual void forceUpdate();
};
#endif
#endif // _FLIGHTSIM_OUTPUTS_H