diff --git a/examples/companion_radio/ui-new/UITask.cpp b/examples/companion_radio/ui-new/UITask.cpp index 248b9bd5..c3da0643 100644 --- a/examples/companion_radio/ui-new/UITask.cpp +++ b/examples/companion_radio/ui-new/UITask.cpp @@ -75,6 +75,9 @@ class HomeScreen : public UIScreen { RADIO, BLUETOOTH, ADVERT, +#if ENV_INCLUDE_GPS == 1 + GPS, +#endif #if UI_SENSORS_PAGE == 1 SENSORS, #endif @@ -170,7 +173,7 @@ public: // curr page indicator int y = 14; - int x = display.width() / 2 - 25; + int x = display.width() / 2 - 5 * (HomePage::Count-1); for (uint8_t i = 0; i < HomePage::Count; i++, x += 10) { if (i == _page) { display.fillRect(x-1, y-1, 3, 3); @@ -250,6 +253,34 @@ public: display.setColor(DisplayDriver::GREEN); display.drawXbm((display.width() - 32) / 2, 18, advert_icon, 32, 32); display.drawTextCentered(display.width() / 2, 64 - 11, "advert: " PRESS_LABEL); +#if ENV_INCLUDE_GPS == 1 + } else if (_page == HomePage::GPS) { + LocationProvider* nmea = sensors.getLocationProvider(); + int y = 18; + display.drawTextLeftAlign(0, y, _task->getGPSState() ? "gps on" : "gps off"); + if (nmea == NULL) { + y = y + 12; + display.drawTextLeftAlign(0, y, "Can't access GPS"); + } else { + char buf[50]; + strcpy(buf, nmea->isValid()?"fix":"no fix"); + display.drawTextRightAlign(display.width()-1, y, buf); + y = y + 12; + display.drawTextLeftAlign(0, y, "sat"); + sprintf(buf, "%d", nmea->satellitesCount()); + display.drawTextRightAlign(display.width()-1, y, buf); + y = y + 12; + display.drawTextLeftAlign(0, y, "pos"); + sprintf(buf, "%.4f %.4f", + nmea->getLatitude()/1000000., nmea->getLongitude()/1000000.); + display.drawTextRightAlign(display.width()-1, y, buf); + y = y + 12; + display.drawTextLeftAlign(0, y, "alt"); + sprintf(buf, "%.2f", nmea->getAltitude()/1000.); + display.drawTextRightAlign(display.width()-1, y, buf); + y = y + 12; + } +#endif #if UI_SENSORS_PAGE == 1 } else if (_page == HomePage::SENSORS) { int y = 18; @@ -364,6 +395,12 @@ public: } return true; } +#if ENV_INCLUDE_GPS == 1 + if (c == KEY_ENTER && _page == HomePage::GPS) { + _task->toggleGPS(); + return true; + } +#endif #if UI_SENSORS_PAGE == 1 if (c == KEY_ENTER && _page == HomePage::SENSORS) { _task->toggleGPS(); @@ -773,6 +810,18 @@ char UITask::handleTripleClick(char c) { return c; } +bool UITask::getGPSState() { + if (_sensors != NULL) { + int num = _sensors->getNumSettings(); + for (int i = 0; i < num; i++) { + if (strcmp(_sensors->getSettingName(i), "gps") == 0) { + return !strcmp(_sensors->getSettingValue(i), "1"); + } + } + } + return false; +} + void UITask::toggleGPS() { if (_sensors != NULL) { // toggle GPS on/off diff --git a/examples/companion_radio/ui-new/UITask.h b/examples/companion_radio/ui-new/UITask.h index 5a087eeb..c24d33a4 100644 --- a/examples/companion_radio/ui-new/UITask.h +++ b/examples/companion_radio/ui-new/UITask.h @@ -71,6 +71,7 @@ public: bool isButtonPressed() const; void toggleBuzzer(); + bool getGPSState(); void toggleGPS(); diff --git a/src/helpers/SensorManager.h b/src/helpers/SensorManager.h index 0e4bc27d..1ace6220 100644 --- a/src/helpers/SensorManager.h +++ b/src/helpers/SensorManager.h @@ -1,6 +1,7 @@ #pragma once #include +#include "sensors/LocationProvider.h" #define TELEM_PERM_BASE 0x01 // 'base' permission includes battery #define TELEM_PERM_LOCATION 0x02 @@ -21,4 +22,5 @@ public: virtual const char* getSettingName(int i) const { return NULL; } virtual const char* getSettingValue(int i) const { return NULL; } virtual bool setSettingValue(const char* name, const char* value) { return false; } + virtual LocationProvider* getLocationProvider() { return NULL; } }; diff --git a/src/helpers/sensors/EnvironmentSensorManager.h b/src/helpers/sensors/EnvironmentSensorManager.h index 3302d6f6..09c6cae4 100644 --- a/src/helpers/sensors/EnvironmentSensorManager.h +++ b/src/helpers/sensors/EnvironmentSensorManager.h @@ -39,6 +39,7 @@ protected: public: #if ENV_INCLUDE_GPS EnvironmentSensorManager(LocationProvider &location): _location(&location){}; + LocationProvider* getLocationProvider() { return _location; } #else EnvironmentSensorManager(){}; #endif diff --git a/src/helpers/sensors/LocationProvider.h b/src/helpers/sensors/LocationProvider.h index f51eea28..f93dec48 100644 --- a/src/helpers/sensors/LocationProvider.h +++ b/src/helpers/sensors/LocationProvider.h @@ -17,8 +17,8 @@ public: virtual bool isValid() = 0; virtual long getTimestamp() = 0; virtual void sendSentence(const char * sentence); - virtual void reset(); - virtual void begin(); - virtual void stop(); - virtual void loop(); + virtual void reset() = 0; + virtual void begin() = 0; + virtual void stop() = 0; + virtual void loop() = 0; }; diff --git a/src/helpers/ui/DisplayDriver.h b/src/helpers/ui/DisplayDriver.h index 32839edc..ec63c191 100644 --- a/src/helpers/ui/DisplayDriver.h +++ b/src/helpers/ui/DisplayDriver.h @@ -32,6 +32,15 @@ public: setCursor(mid_x - w/2, y); print(str); } + virtual void drawTextRightAlign(int x_anch, int y, const char* str) { + int w = getTextWidth(str); + setCursor(x_anch - w, y); + print(str); + } + virtual void drawTextLeftAlign(int x_anch, int y, const char* str) { + setCursor(x_anch, y); + print(str); + } // convert UTF-8 characters to displayable block characters for compatibility virtual void translateUTF8ToBlocks(char* dest, const char* src, size_t dest_size) { diff --git a/variants/lilygo_techo/platformio.ini b/variants/lilygo_techo/platformio.ini index 75a101e9..e2172b1d 100644 --- a/variants/lilygo_techo/platformio.ini +++ b/variants/lilygo_techo/platformio.ini @@ -29,6 +29,7 @@ build_flags = ${nrf52_base.build_flags} -D ENV_INCLUDE_BME280=1 -D GPS_BAUD_RATE=9600 -D PIN_GPS_EN=GPS_EN + -D PIN_GPS_RESET_ACTIVE=LOW -D TELEM_BME280_ADDRESS=0x77 -D DISPLAY_CLASS=GxEPDDisplay -D BACKLIGHT_BTN=PIN_BUTTON2 @@ -92,6 +93,7 @@ build_flags = -D OFFLINE_QUEUE_SIZE=256 -D UI_RECENT_LIST_SIZE=9 -D UI_SENSORS_PAGE=1 + -D UI_GPS_PAGE=1 ; -D MESH_PACKET_LOGGING=1 ; -D MESH_DEBUG=1 -D AUTO_SHUTDOWN_MILLIVOLTS=3300 diff --git a/variants/t1000-e/target.h b/variants/t1000-e/target.h index 6ac0d3a6..27351b94 100644 --- a/variants/t1000-e/target.h +++ b/variants/t1000-e/target.h @@ -28,6 +28,7 @@ public: const char* getSettingName(int i) const override; const char* getSettingValue(int i) const override; bool setSettingValue(const char* name, const char* value) override; + LocationProvider* getLocationProvider() { return _nmea; } }; #ifdef DISPLAY_CLASS