-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathflightsimdisplay.ino
109 lines (93 loc) · 2.92 KB
/
flightsimdisplay.ino
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
/*
Inspired by Spad.Next Serial Interface v1 Simple Autopilot by Les O'Reilly .
Using Adafruit Feather with 3.5" Touch Wing.
Display is 'passive' with exception of touch to change radio and
Button inputs are separate using a Leo Bodnar BBI-32.
Current version is extensively using the SUBCRIBE patten in Spad.Next Serial.
Data Values used can be found in messaging.cpp; it is using Simconnect values
to improve compatibility.
Display is based on the B612 font (https://github.com/polarsys/b612), converted for
use with Adafruit GFX using fontconvert.
*/
#include "featherwing_touch.hh"
#include "state.hh"
#include "display.hh"
#include "messaging.hh"
#include "lights.hh"
Display disp{};
LightController lights{};
CommsController comms{};
struct State state;
void setup()
{
// 115200 is typically the maximum speed for serial over USB
Serial.begin(115200);
// Initialize the Display including Touch
disp.initDisplay();
// Attach my application's user-defined callback methods
comms.attachCommandCallbacks();
// Initialize Lights
lights.initLights();
}
// Start up the Main Loop Function
void loop()
{
// Process incoming serial data, and perform callbacks
comms.processInputData();
// If device is configured, powered and initalized, then
// process touches and perform updates to display and lights.
if (state.configured && state.power && state.display_static && state.isReady())
{
if ((millis() - state.last_touch) > TS_DOUBLETOUCH_DELAY)
{
TouchEvent te = disp.processTouch();
if (te.event != TouchEventType::NO_TOUCH)
{
switch (te.event)
{
case TouchEventType::NAV_BUTTON:
comms.updateRadioSource(te.value);
break;
case TouchEventType::CRS_BUTTON:
comms.updateCourseSource(te.value);
disp.updateHeadingLabel();
break;
case TouchEventType::BARO_BUTTON:
comms.updateBaroMode(te.value);
disp.updateBarometerLabel(te.value);
break;
}
state.last_touch = millis();
}
}
else
{
disp.clearTouch();
}
disp.redraw();
lights.update();
if (state.debug)
disp.printMem();
}
// If virtual power is on, but the screen layout is not printed,
// then print the static layout and update course label and redraw
// data values.
else if (state.configured && state.power && !state.display_static && state.isReady())
{
disp.printStatic();
disp.updateHeadingLabel();
disp.updateVSLabel();
disp.updateIASLabel();
disp.updateBarometerLabel(state.nav.baro_mode_sel);
disp.updateHeadingLabel();
disp.redraw(true);
}
// If virtual power is off, but the off splash is not printed,
// then print the off splash.
else if (state.configured && !state.power && !state.display_off && state.isReady())
{
disp.printSplash(F("-"));
lights.update();
state.display_off = true;
}
} // End of the Main Loop