Skip to content

Commit 3912bbd

Browse files
authored
Merge pull request #821 from fdlamotte/ui_gps_page
ui_task: initial gps page
2 parents 8d8b9a6 + 18bfc2d commit 3912bbd

File tree

8 files changed

+70
-5
lines changed

8 files changed

+70
-5
lines changed

examples/companion_radio/ui-new/UITask.cpp

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ class HomeScreen : public UIScreen {
7575
RADIO,
7676
BLUETOOTH,
7777
ADVERT,
78+
#if ENV_INCLUDE_GPS == 1
79+
GPS,
80+
#endif
7881
#if UI_SENSORS_PAGE == 1
7982
SENSORS,
8083
#endif
@@ -170,7 +173,7 @@ class HomeScreen : public UIScreen {
170173

171174
// curr page indicator
172175
int y = 14;
173-
int x = display.width() / 2 - 25;
176+
int x = display.width() / 2 - 5 * (HomePage::Count-1);
174177
for (uint8_t i = 0; i < HomePage::Count; i++, x += 10) {
175178
if (i == _page) {
176179
display.fillRect(x-1, y-1, 3, 3);
@@ -250,6 +253,34 @@ class HomeScreen : public UIScreen {
250253
display.setColor(DisplayDriver::GREEN);
251254
display.drawXbm((display.width() - 32) / 2, 18, advert_icon, 32, 32);
252255
display.drawTextCentered(display.width() / 2, 64 - 11, "advert: " PRESS_LABEL);
256+
#if ENV_INCLUDE_GPS == 1
257+
} else if (_page == HomePage::GPS) {
258+
LocationProvider* nmea = sensors.getLocationProvider();
259+
int y = 18;
260+
display.drawTextLeftAlign(0, y, _task->getGPSState() ? "gps on" : "gps off");
261+
if (nmea == NULL) {
262+
y = y + 12;
263+
display.drawTextLeftAlign(0, y, "Can't access GPS");
264+
} else {
265+
char buf[50];
266+
strcpy(buf, nmea->isValid()?"fix":"no fix");
267+
display.drawTextRightAlign(display.width()-1, y, buf);
268+
y = y + 12;
269+
display.drawTextLeftAlign(0, y, "sat");
270+
sprintf(buf, "%d", nmea->satellitesCount());
271+
display.drawTextRightAlign(display.width()-1, y, buf);
272+
y = y + 12;
273+
display.drawTextLeftAlign(0, y, "pos");
274+
sprintf(buf, "%.4f %.4f",
275+
nmea->getLatitude()/1000000., nmea->getLongitude()/1000000.);
276+
display.drawTextRightAlign(display.width()-1, y, buf);
277+
y = y + 12;
278+
display.drawTextLeftAlign(0, y, "alt");
279+
sprintf(buf, "%.2f", nmea->getAltitude()/1000.);
280+
display.drawTextRightAlign(display.width()-1, y, buf);
281+
y = y + 12;
282+
}
283+
#endif
253284
#if UI_SENSORS_PAGE == 1
254285
} else if (_page == HomePage::SENSORS) {
255286
int y = 18;
@@ -364,6 +395,12 @@ class HomeScreen : public UIScreen {
364395
}
365396
return true;
366397
}
398+
#if ENV_INCLUDE_GPS == 1
399+
if (c == KEY_ENTER && _page == HomePage::GPS) {
400+
_task->toggleGPS();
401+
return true;
402+
}
403+
#endif
367404
#if UI_SENSORS_PAGE == 1
368405
if (c == KEY_ENTER && _page == HomePage::SENSORS) {
369406
_task->toggleGPS();
@@ -773,6 +810,18 @@ char UITask::handleTripleClick(char c) {
773810
return c;
774811
}
775812

813+
bool UITask::getGPSState() {
814+
if (_sensors != NULL) {
815+
int num = _sensors->getNumSettings();
816+
for (int i = 0; i < num; i++) {
817+
if (strcmp(_sensors->getSettingName(i), "gps") == 0) {
818+
return !strcmp(_sensors->getSettingValue(i), "1");
819+
}
820+
}
821+
}
822+
return false;
823+
}
824+
776825
void UITask::toggleGPS() {
777826
if (_sensors != NULL) {
778827
// toggle GPS on/off

examples/companion_radio/ui-new/UITask.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ class UITask : public AbstractUITask {
7171
bool isButtonPressed() const;
7272

7373
void toggleBuzzer();
74+
bool getGPSState();
7475
void toggleGPS();
7576

7677

src/helpers/SensorManager.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#pragma once
22

33
#include <CayenneLPP.h>
4+
#include "sensors/LocationProvider.h"
45

56
#define TELEM_PERM_BASE 0x01 // 'base' permission includes battery
67
#define TELEM_PERM_LOCATION 0x02
@@ -21,4 +22,5 @@ class SensorManager {
2122
virtual const char* getSettingName(int i) const { return NULL; }
2223
virtual const char* getSettingValue(int i) const { return NULL; }
2324
virtual bool setSettingValue(const char* name, const char* value) { return false; }
25+
virtual LocationProvider* getLocationProvider() { return NULL; }
2426
};

src/helpers/sensors/EnvironmentSensorManager.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class EnvironmentSensorManager : public SensorManager {
3939
public:
4040
#if ENV_INCLUDE_GPS
4141
EnvironmentSensorManager(LocationProvider &location): _location(&location){};
42+
LocationProvider* getLocationProvider() { return _location; }
4243
#else
4344
EnvironmentSensorManager(){};
4445
#endif

src/helpers/sensors/LocationProvider.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ class LocationProvider {
1717
virtual bool isValid() = 0;
1818
virtual long getTimestamp() = 0;
1919
virtual void sendSentence(const char * sentence);
20-
virtual void reset();
21-
virtual void begin();
22-
virtual void stop();
23-
virtual void loop();
20+
virtual void reset() = 0;
21+
virtual void begin() = 0;
22+
virtual void stop() = 0;
23+
virtual void loop() = 0;
2424
};

src/helpers/ui/DisplayDriver.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,15 @@ class DisplayDriver {
3232
setCursor(mid_x - w/2, y);
3333
print(str);
3434
}
35+
virtual void drawTextRightAlign(int x_anch, int y, const char* str) {
36+
int w = getTextWidth(str);
37+
setCursor(x_anch - w, y);
38+
print(str);
39+
}
40+
virtual void drawTextLeftAlign(int x_anch, int y, const char* str) {
41+
setCursor(x_anch, y);
42+
print(str);
43+
}
3544

3645
// convert UTF-8 characters to displayable block characters for compatibility
3746
virtual void translateUTF8ToBlocks(char* dest, const char* src, size_t dest_size) {

variants/lilygo_techo/platformio.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ build_flags = ${nrf52_base.build_flags}
2929
-D ENV_INCLUDE_BME280=1
3030
-D GPS_BAUD_RATE=9600
3131
-D PIN_GPS_EN=GPS_EN
32+
-D PIN_GPS_RESET_ACTIVE=LOW
3233
-D TELEM_BME280_ADDRESS=0x77
3334
-D DISPLAY_CLASS=GxEPDDisplay
3435
-D BACKLIGHT_BTN=PIN_BUTTON2
@@ -92,6 +93,7 @@ build_flags =
9293
-D OFFLINE_QUEUE_SIZE=256
9394
-D UI_RECENT_LIST_SIZE=9
9495
-D UI_SENSORS_PAGE=1
96+
-D UI_GPS_PAGE=1
9597
; -D MESH_PACKET_LOGGING=1
9698
; -D MESH_DEBUG=1
9799
-D AUTO_SHUTDOWN_MILLIVOLTS=3300

variants/t1000-e/target.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class T1000SensorManager: public SensorManager {
2828
const char* getSettingName(int i) const override;
2929
const char* getSettingValue(int i) const override;
3030
bool setSettingValue(const char* name, const char* value) override;
31+
LocationProvider* getLocationProvider() { return _nmea; }
3132
};
3233

3334
#ifdef DISPLAY_CLASS

0 commit comments

Comments
 (0)