Skip to content

Commit 76aa7cf

Browse files
committed
ui_task: initial gps page
1 parent ea13fa8 commit 76aa7cf

File tree

8 files changed

+74
-4
lines changed

8 files changed

+74
-4
lines changed

examples/companion_radio/ui-new/UITask.cpp

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ class HomeScreen : public UIScreen {
7575
RADIO,
7676
BLUETOOTH,
7777
ADVERT,
78+
#if UI_GPS_PAGE == 1
79+
GPS,
80+
#endif
7881
#if UI_SENSORS_PAGE == 1
7982
SENSORS,
8083
#endif
@@ -250,6 +253,47 @@ 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 UI_GPS_PAGE == 1
257+
} else if (_page == HomePage::GPS) {
258+
LocationProvider* nmea = sensors.getLocationProvider();
259+
int y = 18;
260+
display.setCursor(0, y);
261+
display.print(_task->getGPSState() ? "gps on" : "gps off");
262+
if (nmea == NULL) {
263+
y = y + 12;
264+
display.setCursor(0, y);
265+
display.print("Can't access GPS");
266+
} else {
267+
char buf[50];
268+
strcpy(buf, nmea->isValid()?"fix":"no fix");
269+
display.setCursor(
270+
display.width()-display.getTextWidth(buf)-1, y);
271+
display.print(buf);
272+
y = y + 12;
273+
display.setCursor(0,y);
274+
display.print("sat");
275+
sprintf(buf, "%d", nmea->satellitesCount());
276+
display.setCursor(
277+
display.width()-display.getTextWidth(buf)-1, y);
278+
display.print(buf);
279+
y = y + 12;
280+
display.setCursor(0,y);
281+
display.print("pos");
282+
sprintf(buf, "%.4f %.4f",
283+
nmea->getLatitude()/1000000., nmea->getLongitude()/1000000.);
284+
display.setCursor(
285+
display.width()-display.getTextWidth(buf)-1, y);
286+
display.print(buf);
287+
y = y + 12;
288+
display.setCursor(0,y);
289+
display.print("alt");
290+
sprintf(buf, "%.2f", nmea->getAltitude()/1000.);
291+
display.setCursor(
292+
display.width()-display.getTextWidth(buf)-1, y);
293+
display.print(buf);
294+
y = y + 12;
295+
}
296+
#endif
253297
#if UI_SENSORS_PAGE == 1
254298
} else if (_page == HomePage::SENSORS) {
255299
int y = 18;
@@ -364,6 +408,12 @@ class HomeScreen : public UIScreen {
364408
}
365409
return true;
366410
}
411+
#if UI_GPS_PAGE == 1
412+
if (c == KEY_ENTER && _page == HomePage::GPS) {
413+
_task->toggleGPS();
414+
return true;
415+
}
416+
#endif
367417
#if UI_SENSORS_PAGE == 1
368418
if (c == KEY_ENTER && _page == HomePage::SENSORS) {
369419
_task->toggleGPS();
@@ -773,6 +823,18 @@ char UITask::handleTripleClick(char c) {
773823
return c;
774824
}
775825

826+
bool UITask::getGPSState() {
827+
if (_sensors != NULL) {
828+
int num = _sensors->getNumSettings();
829+
for (int i = 0; i < num; i++) {
830+
if (strcmp(_sensors->getSettingName(i), "gps") == 0) {
831+
return !strcmp(_sensors->getSettingValue(i), "1");
832+
}
833+
}
834+
}
835+
return false;
836+
}
837+
776838
void UITask::toggleGPS() {
777839
if (_sensors != NULL) {
778840
// 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
};

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

variants/wio-tracker-l1-eink/platformio.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ build_flags = ${WioTrackerL1Eink.build_flags}
5555
; -D MESH_DEBUG=1
5656
-D UI_RECENT_LIST_SIZE=6
5757
-D UI_SENSORS_PAGE=1
58+
-D UI_GPS_PAGE=1
5859
build_src_filter = ${WioTrackerL1Eink.build_src_filter}
5960
+<helpers/nrf52/SerialBLEInterface.cpp>
6061
+<helpers/ui/MomentaryButton.cpp>

0 commit comments

Comments
 (0)