-
Notifications
You must be signed in to change notification settings - Fork 0
/
oled_display.cpp
148 lines (108 loc) · 4.06 KB
/
oled_display.cpp
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
136
137
138
139
140
141
142
143
144
145
146
147
148
#include "oled_display.h"
#include "Arduino.h"
#include "beacons.h"
#include "runtime_state.h"
OledDisplay::OledDisplay(SSD1306 *display) {
_display = display;
}
void OledDisplay::init() {
_display->init();
_display->setFont(ArialMT_Plain_10);
}
void OledDisplay::loop() {
page();
}
void OledDisplay::setPage(uint8_t page) {
_page = page;
}
void OledDisplay::page() {
static uint32_t lastUpdate = 0;
//Do not allow for OLED to be updated too often
if (lastUpdate > 0 && millis() - lastUpdate < 200 && _forceDisplay == false) {
return;
}
_forceDisplay = false;
switch (_page) {
case OLED_PAGE_BEACON_LIST:
renderPageBeaconList();
break;
case OLED_PAGE_I_AM_A_BEACON:
renderPageIamBeacon();
break;
}
lastUpdate = millis();
}
void OledDisplay::renderHeader(String title) {
_display->setFont(ArialMT_Plain_10);
_display->drawString(0, 0, title);
// _display->drawString(90, 0, String(gps.satellites.value()) + " sats");
}
void OledDisplay::renderPageBeaconList() {
_display->clear();
renderHeader("Beacon " + String(beacons.currentBeaconIndex + 1) + "/" + String(beacons.count()));
if (beacons.count() > 0) {
_display->setFont(ArialMT_Plain_10);
Beacon *beacon = beacons.getBeacon(beacons.currentBeaconId);
_display->drawString(0, 10, "ID: " + String(beacon->getId(), HEX));
_display->drawString(70, 10, "RSSI: " + String(beacon->getRssi()));
int lastContact = (millis() - beacon->getLastContactMillis()) / 1000;
String contactString = "";
if (lastContact > 60) {
contactString = String((int)(lastContact / 60)) + "min";
} else {
contactString = String(lastContact) + "s";
}
_display->drawString(70, 20, "T: -" + contactString);
if (STATE(RUNTIME_STATE_BEACON_LOCKED)) {
_display->drawString(0, 20, "Locked");
} else {
_display->drawString(0, 20, "Select beacon");
}
// if (STATE(RUNTIME_STATE_SET_WAYPOINT)) {
// _display->drawString(0, 34, "MSP command SET_WP");
// } else {
// _display->drawString(0, 34, "MSP command IDLE");
// }
// if (beacon->hasPos() && gps.satellites.value() > 5) {
// _display->setFont(ArialMT_Plain_16);
// double dst = TinyGPSPlus::distanceBetween(gps.location.lat(), gps.location.lng(), beacon->getLat(), beacon->getLon());
// _display->drawString(0, 34, "Dst: " + String(dst, 0) + "m");
// double courseTo =
// TinyGPSPlus::courseTo(
// gps.location.lat(),
// gps.location.lng(),
// beacon->getLat(),
// beacon->getLon());
// _display->setFont(ArialMT_Plain_10);
// _display->drawString(00, 20, "Course: " + String(TinyGPSPlus::cardinal(courseTo)));
// } else {
// _display->setFont(ArialMT_Plain_16);
// _display->drawString(0, 34, "No distance");
// }
// _display->setFont(ArialMT_Plain_10);
// _display->drawString(0, 54, String(beacon->getLat(), 5));
// _display->drawString(64, 54, String(beacon->getLon(), 5));
} else {
_display->setFont(ArialMT_Plain_16);
_display->drawString(0, 12, "No beacons");
}
_display->setFont(ArialMT_Plain_10);
if (uavNode.isValid()) {
_display->drawString(0, 48, "UAV OK");
} else {
_display->drawString(0, 48, "UAV -");
}
_display->drawString(48, 48, "GPS " + uavNode.gpsFix());
if (uavNode.isArmed()) {
_display->drawString(96, 48, "ARM");
}
_display->display();
}
void OledDisplay::renderPageIamBeacon() {
_display->clear();
renderHeader("I'm a beacon");
_display->drawString(0, 30, "TX mode");
// _display->drawString(0, 54, String(gps.location.lat(), 5));
// _display->drawString(64, 54, String(gps.location.lng(), 5));
_display->display();
}