Repository navigation
Expand file tree
/
Copy pathmain.cpp
More file actions
131 lines (118 loc) · 4.48 KB
/
Copy pathmain.cpp
File metadata and controls
131 lines (118 loc) · 4.48 KB
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
#include <Arduino.h>
#include "io.h"
#include "gps.h"
#include "conf.h"
#include "env.h"
HardwareSerial serialGPS(1);
uint8_t zoom_level = PIXEL_SIZE_DEF; /// @brief zoom_level = 1 corresponds aprox to 1 meter / pixel
Coord gps_coord; /// @brief Holds the current gps data
Point32 gps_pos_wc; /// @brief GPS position in world coordinates.
uint8_t mode = DEVMODE_NAV; /// @brief Current device mode
bool select_btn_pressed = false;
bool up_btn_pressed = false;
bool down_btn_pressed = false;
bool left_btn_pressed = false;
bool right_btn_pressed = false;
bool menu_btn_short_pressed = false;
bool menu_btn_long_pressed = false;
bool show_header_footer = true;
void setup()
{
#if CORE_DEBUG_LEVEL > 0
Serial.begin(115200);
LOGI("Starting...");
#endif
serialGPS.begin( 9600, SERIAL_8N1, GPS_TX, GPS_RX);
delay(50);
init_io(); // initialize GPIO's, display, power saving, etc
LOGI("Waiting for satellites...");
// serialGPS.println("$PMTK225,0*2B"); // set 'full on' mode
// serialGPS.println("$PMTK225,2,300,1000*1F"); // enable Periodic Mode (1-second interval, 300ms on-time)
serialGPS.println("$PMTK225,8*23"); // set 'Alwayslocate' mode
// disable extra NMEA sentences. Only enables the $GPGGA sentence (position data)
serialGPS.println("$PMTK314,0,1,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0*29");
gps_pos_wc = Point32( INIT_POS); // TODO: get last position from flash memory
delay(500);
refresh_display();
}
void loop()
{
check_buttons();
if( menu_btn_long_pressed) mode = DEVMODE_LOWPOW;
switch( mode){
case DEVMODE_NAV:
getPosition();
if( menu_btn_short_pressed) show_header_footer = !show_header_footer;
if( gps_coord.isValid && gps_coord.isUpdated){
LOGD("XXXX Fix?:%i, Sats:%i, isUpdated:%i", gps_coord.fixAcquired, gps_coord.satellites, gps_coord.isUpdated);
gps_pos_wc = gps_coord.getPoint32(); // center display in gps coord
refresh_display();
gps_coord.isUpdated = false;
}
if( select_btn_pressed && show_header_footer){ mode = DEVMODE_MOVE; }
break;
case DEVMODE_MOVE:
if( up_btn_pressed){ gps_pos_wc.y += 40*zoom_level; refresh_display(); }
if( down_btn_pressed){ gps_pos_wc.y -= 40*zoom_level; refresh_display(); }
if( left_btn_pressed){ gps_pos_wc.x -= 40*zoom_level; refresh_display(); }
if( right_btn_pressed){ gps_pos_wc.x += 40*zoom_level; refresh_display(); }
if( select_btn_pressed) mode = DEVMODE_ZOOM;
if( menu_btn_short_pressed){
mode = DEVMODE_NAV;
show_header_footer = false;
if( gps_coord.isValid) gps_pos_wc = gps_coord.getPoint32();
}
break;
case DEVMODE_ZOOM:
if( up_btn_pressed && zoom_level < MAX_ZOOM){
if( zoom_level < 4 ) zoom_level += 1;
else if( zoom_level < 8 ) zoom_level += 2;
else zoom_level += 4;
if( zoom_level > MAX_ZOOM) zoom_level = MAX_ZOOM;
refresh_display();
}
if( down_btn_pressed && zoom_level > 1){
if( zoom_level <= 4 ) zoom_level -= 1;
else if( zoom_level <= 8 ) zoom_level -= 2;
else zoom_level -= 4;
if( zoom_level < 1) zoom_level = 1;
refresh_display();
}
if( select_btn_pressed){
mode = DEVMODE_MOVE;
}
if( menu_btn_short_pressed){
mode = DEVMODE_NAV;
show_header_footer = false;
if( gps_coord.isValid) gps_pos_wc = gps_coord.getPoint32();
}
break;
case DEVMODE_LOWPOW: // TODO
ledcWrite(0, 0); // set display off
// sleep...
// esp_sleep_enable_timer_wakeup( 20 * 1000000);
serialGPS.println("$PMTK161,0*28"); // enter standby Mode
// serialGPS.println("$PMTK225,8*23"); // always locate mode
LOGI("esp_light_sleep_start");
delay(500); // debounce button
esp_light_sleep_start();
// ZZZZ...
// Wake up!
serialGPS.println("$PMTK225,0*2B"); // back to 'full on' mode
// serialGPS.println("$PMTK225,8*23"); // set 'Alwayslocate' mode
mode = DEVMODE_NAV;
delay(300); // debounce button
ledcWrite(0, 128); // set display 50%
refresh_display(); // Check if needed
break;
}
if( menu_btn_short_pressed || select_btn_pressed) refresh_display(); // TODO: refresh only header
up_btn_pressed = false;
down_btn_pressed = false;
left_btn_pressed = false;
right_btn_pressed = false;
select_btn_pressed = false;
select_btn_pressed = false;
menu_btn_short_pressed = false;
menu_btn_long_pressed = false;
}