mirror of
https://github.com/meshcore-dev/MeshCore.git
synced 2026-11-23 00:47:58 +00:00
gps: adapt ui-new and the sensor managers
This commit is contained in:
1 parent
fa7ca3f418
commit
3fd36e7ac6
9 files changed
+53
-18
No files matched your search
@@ -86,6 +86,30 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
#if ENV_INCLUDE_GPS == 1
|
||||
// exact period with the largest unit that divides it: "30s", "5m", "2h"
|
||||
static void formatGpsPeriod(char* buf, size_t size, uint32_t seconds) {
|
||||
if (seconds % 3600 == 0) {
|
||||
snprintf(buf, size, "%luh", (unsigned long)(seconds / 3600));
|
||||
} else if (seconds % 60 == 0) {
|
||||
snprintf(buf, size, "%lum", (unsigned long)(seconds / 60));
|
||||
} else {
|
||||
snprintf(buf, size, "%lus", (unsigned long)seconds);
|
||||
}
|
||||
}
|
||||
|
||||
// age of the last fix, rounded down to a single unit: "45s", "12m", "3h"
|
||||
static void formatFixAge(char* buf, size_t size, uint32_t seconds) {
|
||||
if (seconds < 60) {
|
||||
snprintf(buf, size, "%lus", (unsigned long)seconds);
|
||||
} else if (seconds < 3600) {
|
||||
snprintf(buf, size, "%lum", (unsigned long)(seconds / 60));
|
||||
} else {
|
||||
snprintf(buf, size, "%luh", (unsigned long)(seconds / 3600));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
class HomeScreen : public UIScreen {
|
||||
enum HomePage {
|
||||
FIRST,
|
||||
@@ -393,14 +417,26 @@ public:
|
||||
int y = 18;
|
||||
bool gps_state = _task->getGPSState();
|
||||
bool hw_gps_state = nmea != NULL && nmea->isHardwareEnabled();
|
||||
if (nmea != NULL && nmea->hasHardwareEnableState()) {
|
||||
if (gps_state != hw_gps_state) {
|
||||
strcpy(buf, gps_state ? "gps off(hw)" : "gps off(sw)");
|
||||
} else {
|
||||
strcpy(buf, gps_state ? "gps on" : "gps off");
|
||||
uint32_t period = nmea != NULL ? nmea->getGpsPeriod() : 0;
|
||||
char fix_buf[12] = "";
|
||||
if (nmea != NULL) {
|
||||
uint32_t fix_age = nmea->getLastFixAge();
|
||||
if (fix_age == UINT32_MAX) {
|
||||
strcpy(fix_buf, "no fix");
|
||||
} else {
|
||||
formatFixAge(fix_buf, sizeof(fix_buf), fix_age);
|
||||
}
|
||||
}
|
||||
if (nmea != NULL && nmea->hasHardwareEnableState() && gps_state != hw_gps_state) {
|
||||
strcpy(buf, gps_state ? "gps off(hw)" : "gps off(sw)");
|
||||
} else if (!gps_state) {
|
||||
strcpy(buf, "gps off");
|
||||
} else if (period == 0) {
|
||||
strcpy(buf, "gps on");
|
||||
} else {
|
||||
strcpy(buf, gps_state ? "gps on" : "gps off");
|
||||
char per[12];
|
||||
formatGpsPeriod(per, sizeof(per), period);
|
||||
snprintf(buf, sizeof(buf), "%s (%s)", nmea != NULL && nmea->isActive() ? "active" : "sleep", per);
|
||||
}
|
||||
display.setColor(UIColor::primary_txt);
|
||||
display.drawTextLeftAlign(0, y, buf);
|
||||
@@ -410,8 +446,7 @@ public:
|
||||
display.drawTextLeftAlign(0, y, "Can't access GPS");
|
||||
} else {
|
||||
display.setColor(UIColor::primary_txt);
|
||||
strcpy(buf, nmea->isValid()?"fix":"no fix");
|
||||
display.drawTextRightAlign(display.width()-1, y, buf);
|
||||
display.drawTextRightAlign(display.width()-1, y, fix_buf);
|
||||
y = y + 12;
|
||||
display.setColor(UIColor::secondary_txt);
|
||||
display.drawTextLeftAlign(0, y, "sat");
|
||||
|
||||
@@ -66,7 +66,7 @@ void SolarSensorManager::loop() {
|
||||
_location->loop();
|
||||
|
||||
if (millis() > next_gps_update) {
|
||||
if (_location->isValid()) {
|
||||
if (_location->isGpsOn() && _location->hasValidFix()) {
|
||||
node_lat = ((double)_location->getLatitude())/1000000.;
|
||||
node_lon = ((double)_location->getLongitude())/1000000.;
|
||||
node_altitude = ((double)_location->getAltitude()) / 1000.0;
|
||||
|
||||
@@ -82,7 +82,7 @@ void HWTSensorManager::loop() {
|
||||
_location->loop();
|
||||
|
||||
if (millis() > next_gps_update) {
|
||||
if (_location->isEnabled() && _location->isValid()) {
|
||||
if (_location->isGpsOn() && _location->hasValidFix()) {
|
||||
node_lat = ((double)_location->getLatitude())/1000000.;
|
||||
node_lon = ((double)_location->getLongitude())/1000000.;
|
||||
node_altitude = ((double)_location->getAltitude()) / 1000.0;
|
||||
|
||||
@@ -64,8 +64,8 @@ bool MASensorManager::querySensors(uint8_t requester_permissions, CayenneLPP& te
|
||||
void MASensorManager::loop() {
|
||||
static long next_gps_update = 0;
|
||||
_location->loop();
|
||||
if(millis() > next_gps_update && _location->isEnabled()) {
|
||||
if(_location->isValid()) {
|
||||
if(millis() > next_gps_update && _location->isGpsOn()) {
|
||||
if(_location->hasValidFix()) {
|
||||
node_lat = ((double)_location->getLatitude()) / 1000000.;
|
||||
node_lon = ((double)_location->getLongitude()) / 1000000.;
|
||||
node_altitude = ((double)_location->getAltitude()) / 1000.0;
|
||||
|
||||
@@ -70,7 +70,7 @@ void MeshTrackerX1SensorManager::loop() {
|
||||
_nmea->loop();
|
||||
|
||||
if (millis() > next_gps_update) {
|
||||
if (_nmea->isEnabled() && _nmea->isValid()) {
|
||||
if (_nmea->isGpsOn() && _nmea->hasValidFix()) {
|
||||
node_lat = ((double)_nmea->getLatitude())/1000000.;
|
||||
node_lon = ((double)_nmea->getLongitude())/1000000.;
|
||||
node_altitude = ((double)_nmea->getAltitude()) / 1000.0;
|
||||
|
||||
@@ -10,7 +10,7 @@ public:
|
||||
}
|
||||
|
||||
void begin() override {
|
||||
if (isEnabled()) return;
|
||||
if (isActive()) return;
|
||||
|
||||
digitalWrite(PIN_GPS_STANDBY, HIGH);
|
||||
NmeaGpsDriver::begin();
|
||||
|
||||
@@ -62,14 +62,14 @@ bool NanoG2UltraSensorManager::querySensors(uint8_t requester_permissions, Cayen
|
||||
void NanoG2UltraSensorManager::loop() {
|
||||
static long next_gps_update = 0;
|
||||
|
||||
if (!_location->isEnabled()) {
|
||||
if (!_location->isGpsOn()) {
|
||||
return; // GPS is not active, skip further processing
|
||||
}
|
||||
|
||||
_location->loop();
|
||||
|
||||
if (millis() > next_gps_update) {
|
||||
if (_location->isEnabled() && _location->isValid()) {
|
||||
if (_location->isGpsOn() && _location->hasValidFix()) {
|
||||
node_lat = ((double)_location->getLatitude()) / 1000000.;
|
||||
node_lon = ((double)_location->getLongitude()) / 1000000.;
|
||||
node_altitude = ((double)_location->getAltitude()) / 1000.0;
|
||||
|
||||
@@ -113,7 +113,7 @@ void T1000SensorManager::loop() {
|
||||
_nmea->loop();
|
||||
|
||||
if (millis() > next_gps_update) {
|
||||
if (_nmea->isEnabled() && _nmea->isValid()) {
|
||||
if (_nmea->isGpsOn() && _nmea->hasValidFix()) {
|
||||
node_lat = ((double)_nmea->getLatitude())/1000000.;
|
||||
node_lon = ((double)_nmea->getLongitude())/1000000.;
|
||||
node_altitude = ((double)_nmea->getAltitude()) / 1000.0;
|
||||
|
||||
@@ -58,7 +58,7 @@ void ThinkNodeM1SensorManager::loop() {
|
||||
_location->loop();
|
||||
|
||||
if (millis() > next_gps_update) {
|
||||
if (_location->isEnabled() && _location->isValid()) {
|
||||
if (_location->isGpsOn() && _location->hasValidFix()) {
|
||||
node_lat = ((double)_location->getLatitude())/1000000.;
|
||||
node_lon = ((double)_location->getLongitude())/1000000.;
|
||||
node_altitude = ((double)_location->getAltitude()) / 1000.0;
|
||||
|
||||
Reference in new issue
Block a user