-
Notifications
You must be signed in to change notification settings - Fork 1
/
constants.h
303 lines (261 loc) · 10.7 KB
/
constants.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
#pragma once // Please format this file with clang before check-in to GitHub
// ------- Identity for splash screen and console --------
#define PROGRAM_TITLE "TimeGPS"
#define PROGRAM_VERSION "v1.14"
#define PROGRAM_LINE1 "Barry K7BWH"
#define PROGRAM_LINE2 "John KM7O"
#define PROGRAM_COMPILED __DATE__ " " __TIME__
#define PROGRAM_FILE __FILE__
#define PROGRAM_GITHUB "https://github.com/barry-ha/Griduino"
// ------- Select testing features ---------
// #define SCOPE_OUTPUT A0 // use this for performance measurements with oscilloscope
// #define ECHO_GPS // use this to see GPS detailed info on IDE console for debug
// #define SHOW_SCREEN_BORDER // use this to outline the screen's displayable area
// #define SHOW_SCREEN_CENTERLINE // use this visual aid to help layout the screen
// #define SHOW_IGNORED_PRESSURE // use this to see barometric pressure readings that are out of range and therefore ignored
// ------- TFT screen definitions ---------
#define gScreenWidth 320 // screen pixels wide
#define gScreenHeight 240 // screen pixels high \
// we use #define here instead of reading it from "tft.width()" because this \
// screen layout is specifically designed for landscape orientation on 3.2" ILI9341
#define gBoxWidth 180 // grid square width as shown on display, pixels
#define gBoxHeight 160 // grid square height as shown on display, pixels
// ------- Physical constants ---------
const float gridWidthDegrees = 2.0; // horiz E-W size of one grid square, degrees
const float gridHeightDegrees = 1.0; // vert N-S size of one grid square, degrees
const double minLong = gridWidthDegrees / gBoxWidth; // longitude degrees from one pixel to the next (minimum visible movement)
const double minLat = gridHeightDegrees / gBoxHeight; // latitude degrees from one pixel to the next
#define feetPerMeters (3.28084) // altitude conversion
#define mphPerKnots (1.15078) // speed conversion
#define mphPerMetersPerSecond (0.44704) // speed conversion
const double degreesPerRadian = 57.2957795; // conversion factor = (360 degrees)/(2 pi radians)
#define SECS_PER_1MIN ((time_t)(60UL))
#define SECS_PER_5MIN ((time_t)(300UL))
#define SECS_PER_10MIN ((time_t)(600UL))
#define SECS_PER_15MIN ((time_t)(900UL))
#define DEFAULT_SEALEVEL_PASCALS (101740.0)
#define DEFAULT_SEALEVEL_HPA (1017.40)
#define FIRST_RELEASE_YEAR (2019) // this date can help filter out bogus GPS timestamps
#define FIRST_RELEASE_MONTH (12)
#define FIRST_RELEASE_DAY (19)
// ----- load/save configuration using SDRAM
// #define EXTERNAL_FLASH_USE_QSPI // 2020-02-11 added by BarryH, since it seems to be missing from
// c:\Users\barry\AppData\Local\Arduino15\packages\adafruit\hardware\samd\1.5.7\variants\feather_m4\variant.h
#define CONFIG_FOLDER "/Griduino"
// ----- alias names for SCREEN_ROTATION
enum {
LANDSCAPE = 1, // 1=landscape
FLIPPED_LANDSCAPE = 3, // 3=landscape 180-degrees
};
// ----- alias names for fGetDataSource()
enum {
eGPSRECEIVER = 1, // use the GPS receiver hardware
eGPSSIMULATOR, // use a GPS simulator
};
// ----- alias names for setFontSize()
enum {
eFONTGIANT = 36,
eFONTBIG = 24,
eFONTSMALL = 12,
eFONTSMALLEST = 9,
eFONTSYSTEM = 0,
eFONTUNSPEC = -1,
};
// ------- NeoPixel brightness ---------
const int MAXBRIGHT = 255; // = 100% brightness = maximum allowed on individual LED
const int BRIGHT = 32; // = tolerably bright indoors
const int HALFBR = 20; // = half of tolerably bright
const int OFF = 0; // = turned off
// ----- Griduino color scheme
// RGB 565 true color: https://chrishewett.com/blog/true-rgb565-colour-picker/
#define BACKGROUND 0x00A // a little darker than ILI9341_NAVY
#define cBACKGROUND 0x00A // 0, 0, 10 = darker than ILI9341_NAVY, but not black
#define cGRIDNAME ILI9341_GREEN //
#define cLABEL ILI9341_GREEN //
#define cDISTANCE ILI9341_YELLOW //
#define cVALUE ILI9341_YELLOW // 255, 255, 0
#define cVALUEFAINT 0xbdc0 // darker than cVALUE
#define cDISABLED 0x7bee // 125, 125, 115 = gray for disabled screen item
#define cHIGHLIGHT ILI9341_WHITE //
#define cBUTTONFILL ILI9341_NAVY //
#define cBUTTONOUTLINE 0x0514 // was ILI9341_CYAN
#define cTITLE ILI9341_GREEN //
#define cTEXTCOLOR 0x67FF // rgb(102,255,255) = hsl(180,100,70%)
#define cCYAN ILI9341_CYAN // rgb(0,255,255) = hsl(180,100,50%)
#define cFAINT 0x0555 // rgb(0,168,168) = hsl(180,100,33%) = blue, between CYAN and DARKCYAN
#define cFAINTER 0x04B2 // rgb(0,128,128) = hsl(180,100,29%) = blue, between CYAN and DARKCYAN
#define cBOXDEGREES 0x0410 // rgb(0,128,128) = hsl(180,100,25%) = blue, between CYAN and DARKCYAN
#define cBUTTONLABEL ILI9341_YELLOW //
#define cCOMPASS ILI9341_BLUE // a little darker than cBUTTONOUTLINE
#define cSTATUS 0xFC10 // 255, 128, 128 = lavender
#define cWARN 0xF844 // brighter than ILI9341_RED but not pink
#define cTOUCHTARGET ILI9341_RED // outline touch-sensitive areas
// plot vehicle and breadcrumb trail
#define cBREADCRUMB ILI9341_CYAN //
#define cVEHICLE 0xef7d // light gray (white is too bright)
// barometric pressure graph
#define cSCALECOLOR ILI9341_DARKGREEN // pressure graph, I tried yellow but it's too bright
#define cGRAPHCOLOR ILI9341_WHITE // graphed line of baro pressure
#define cDARKPURPLE 0x2809 // debug: 2809 = very dark purple
#define cDARKRED 0x4000 // debug: 4000 = very dark red
#define cDARKBROWN 0x49A0 // debug: 49A0 = dark orange
#define cDARKGREEN 0x01A0 // debug: #0x01A0 = very dark green
// ------------ typedef's
struct Point {
int x, y;
};
struct PointGPS {
public:
double lat, lng;
};
#include <TimeLib.h> // time_t=seconds since Jan 1, 1970, https://github.com/PaulStoffregen/Time
class BaroReading {
public:
float pressure; // in millibars, from BMP388 sensor
time_t time; // in GMT, from realtime clock
};
struct TwoPoints {
int x1, y1;
int x2, y2;
uint16_t color;
};
struct Rect {
Point ul;
Point size;
bool contains(const Point touch) {
if ((ul.x <= touch.x) && (touch.x <= ul.x + size.x) && (ul.y <= touch.y) && (touch.y <= ul.y + size.y)) {
return true;
} else {
return false;
}
}
};
struct Route { // screen coordinates
uint16_t x, y;
};
struct Label {
char text[26];
int x, y;
uint16_t color;
};
typedef void (*simpleFunction)();
struct Button {
char text[26];
int x, y;
int w, h;
int radius;
uint16_t color;
simpleFunction function;
};
struct TimeButton {
// TimeButton is like Button, but has a larger specifiable hit target
// This allows very small buttons with a large sensitive area to make it easy to press
char text[26];
int x, y;
int w, h;
Rect hitTarget;
int radius;
uint16_t color;
simpleFunction function;
};
struct FunctionButton {
// FunctionButton is like Button, but has a larger specifiable hit target
// It's also like TimeButton, but specifies the function by enum, rather than pointer to function
// and this allows its usage in classes derived from "class View"
char text[26]; // one line of text, centered
int x, y; // fillRoundRect ul corner
int w, h; // fillRoundRect size
Rect hitTarget; // touch-sensitive area
int radius; // radio button size
uint16_t color; // text color
int functionIndex; // button identifier
};
// Breadcrumb record types
#define rGPS "GPS"
#define rPOWERUP "PUP"
#define rPOWERDOWN "PDN"
#define rFIRSTVALIDTIME "TIM"
#define rLOSSOFSIGNAL "LOS"
#define rACQUISITIONOFSIGNAL "AOS"
#define rRESET "\0\0\0"
#define rVALIDATE rGPS rPOWERUP rPOWERDOWN rFIRSTVALIDTIME rLOSSOFSIGNAL rACQUISITIONOFSIGNAL
// Breadcrumb data definition for circular buffer
class Location {
public:
char recordType[4]; // GPS, power-up, first valid time, etc
PointGPS loc; // has-a lat/long, degrees
time_t timestamp; // has-a GMT time
uint8_t numSatellites; // number of satellites in use (not the same as in view)
float speed; // current speed over ground in MPH
float direction; // direction of travel, degrees from true north
float altitude; // altitude, meters above MSL
public:
void reset() {
recordType[0] = 0;
loc.lat = loc.lng = 0.0;
timestamp = 0;
numSatellites = 0;
speed = 0.0;
direction = altitude = 0.0;
}
bool isEmpty() const {
// we take advantage of the fact that all unused records
// will have reset their recordType field to zeroes, ie, rRESET
return (strlen(recordType) == 0);
}
static bool isValidRecordType(const char *rec) {
// check for "should not happen" situations
if (strstr(rVALIDATE, rec)) {
return true;
} else {
return false;
}
}
bool isGPS() const {
return (strncmp(recordType, rGPS, sizeof(recordType)) == 0);
}
bool isPUP() const {
return (strncmp(recordType, rPOWERUP, sizeof(recordType)) == 0);
}
bool isFirstValidTime() const {
return (strncmp(recordType, rFIRSTVALIDTIME, sizeof(recordType)) == 0);
}
bool isLossOfSignal() const {
return (strncmp(recordType, rLOSSOFSIGNAL, sizeof(recordType)) == 0);
}
bool isAcquisitionOfSignal() const {
return (strncmp(recordType, rACQUISITIONOFSIGNAL, sizeof(recordType)) == 0);
}
// print ourself - a sanity check
void printLocation(const char *comment = NULL) { // debug
Serial.println(". Rec, ___Date___ __Time__, (__Lat__, __Long__), Alt, Spd, Dir, Sats");
char out[128];
Serial.print(". ");
Serial.print(recordType);
Serial.print(", ");
// timestamp
TimeElements time; // https://github.com/PaulStoffregen/Time
breakTime(timestamp, time);
snprintf(out, sizeof(out), "%02d-%02d-%02d %02d:%02d:%02d, ",
time.Year + 1970, time.Month, time.Day, time.Hour, time.Minute, time.Second);
Serial.print(out);
// lat/long
Serial.print("(");
Serial.print(loc.lat, 4);
Serial.print(", ");
Serial.print(loc.lng, 4);
Serial.print("), ");
// alt, speed dir sats
Serial.print(altitude, 1); // meters
Serial.print(", ");
Serial.print(speed, 1); // mph
Serial.print(", ");
Serial.print(direction, 1); // degrees
Serial.print(", ");
Serial.print(numSatellites);
Serial.println();
if (comment) {
Serial.println(comment);
}
}
};