mirror of
https://github.com/meshcore-dev/MeshCore.git
synced 2026-04-20 22:13:47 +00:00
cli_gps: use sensormanger to toggle gps on/off to keep state coherent
This commit is contained in:
parent
0502bc370d
commit
e4f2d63b0a
4 changed files with 36 additions and 15 deletions
|
|
@ -761,11 +761,15 @@ void MyMesh::removeNeighbor(const uint8_t *pubkey, int key_len) {
|
|||
void MyMesh::gpsGetStatus(char * reply) {
|
||||
LocationProvider * l = sensors.getLocationProvider();
|
||||
if (l != NULL) {
|
||||
bool status = l->isActive();
|
||||
bool sync = l->isValid();
|
||||
bool enabled = l->isEnabled(); // is EN pin on ?
|
||||
bool active = gpsGetState(); // is enabled at SensorManager level ?
|
||||
bool fix = l->isValid(); // has fix ?
|
||||
int sats = l->satellitesCount();
|
||||
if (status) {
|
||||
sprintf(reply, "on, %s, %d sats", sync?"fix":"no fix", sats);
|
||||
if (enabled) {
|
||||
sprintf(reply, "on, %s, %s, %d sats",
|
||||
active?"active":"deactivated",
|
||||
fix?"fix":"no fix",
|
||||
sats);
|
||||
} else {
|
||||
strcpy(reply, "off");
|
||||
}
|
||||
|
|
@ -774,19 +778,33 @@ void MyMesh::gpsGetStatus(char * reply) {
|
|||
}
|
||||
}
|
||||
|
||||
void MyMesh::gpsStart() {
|
||||
LocationProvider * l = sensors.getLocationProvider();
|
||||
if (l != NULL) {
|
||||
l->begin();
|
||||
l->reset();
|
||||
bool MyMesh::gpsGetState() {
|
||||
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 MyMesh::gpsSetState(bool value) {
|
||||
// toggle GPS on/off
|
||||
int num = sensors.getNumSettings();
|
||||
for (int i = 0; i < num; i++) {
|
||||
if (strcmp(sensors.getSettingName(i), "gps") == 0) {
|
||||
sensors.setSettingValue("gps", value?"1":"0");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MyMesh::gpsStart() {
|
||||
gpsSetState(true);
|
||||
}
|
||||
|
||||
void MyMesh::gpsStop() {
|
||||
LocationProvider * l = sensors.getLocationProvider();
|
||||
if (l != NULL) {
|
||||
l->stop();
|
||||
}
|
||||
gpsSetState(false);
|
||||
}
|
||||
|
||||
void MyMesh::gpsSyncTime() {
|
||||
|
|
|
|||
|
|
@ -142,6 +142,9 @@ protected:
|
|||
void onPeerDataRecv(mesh::Packet* packet, uint8_t type, int sender_idx, const uint8_t* secret, uint8_t* data, size_t len) override;
|
||||
bool onPeerPathRecv(mesh::Packet* packet, int sender_idx, const uint8_t* secret, uint8_t* path, uint8_t path_len, uint8_t extra_type, uint8_t* extra, uint8_t extra_len) override;
|
||||
|
||||
bool gpsGetState();
|
||||
void gpsSetState(bool value);
|
||||
|
||||
public:
|
||||
MyMesh(mesh::MainBoard& board, mesh::Radio& radio, mesh::MillisecondClock& ms, mesh::RNG& rng, mesh::RTCClock& rtc, mesh::MeshTables& tables);
|
||||
|
||||
|
|
|
|||
|
|
@ -21,5 +21,5 @@ public:
|
|||
virtual void begin() = 0;
|
||||
virtual void stop() = 0;
|
||||
virtual void loop() = 0;
|
||||
virtual bool isActive() = 0;
|
||||
virtual bool isEnabled() = 0;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -78,7 +78,7 @@ public :
|
|||
}
|
||||
}
|
||||
|
||||
bool isActive() override {
|
||||
bool isEnabled() override {
|
||||
// directly read the enable pin if present as gps can be
|
||||
// activated/deactivated outside of here ...
|
||||
if (_pin_en != -1) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue