cli_gps: remove callbacks and add generic sensor set/get.

This commit is contained in:
Florent de Lamotte 2025-10-06 10:25:10 +02:00
parent e4f2d63b0a
commit 7be65c148e
4 changed files with 74 additions and 76 deletions

View file

@ -758,62 +758,6 @@ void MyMesh::removeNeighbor(const uint8_t *pubkey, int key_len) {
#endif
}
void MyMesh::gpsGetStatus(char * reply) {
LocationProvider * l = sensors.getLocationProvider();
if (l != NULL) {
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 (enabled) {
sprintf(reply, "on, %s, %s, %d sats",
active?"active":"deactivated",
fix?"fix":"no fix",
sats);
} else {
strcpy(reply, "off");
}
} else {
strcpy(reply, "Can't find GPS");
}
}
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() {
gpsSetState(false);
}
void MyMesh::gpsSyncTime() {
LocationProvider * l = sensors.getLocationProvider();
if (l != NULL) {
l->syncTime();
}
}
void MyMesh::saveIdentity(const mesh::LocalIdentity &new_id) {
self_id = new_id;
#if defined(NRF52_PLATFORM) || defined(STM32_PLATFORM)

View file

@ -142,9 +142,6 @@ 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);
@ -179,12 +176,6 @@ public:
void formatNeighborsReply(char *reply) override;
void removeNeighbor(const uint8_t* pubkey, int key_len) override;
// Gps mgmt cli callbacks
void gpsGetStatus(char * reply) override;
void gpsStart() override;
void gpsStop() override;
void gpsSyncTime() override;
mesh::LocalIdentity& getSelfId() override { return self_id; }
void saveIdentity(const mesh::LocalIdentity& new_id) override;