Chat app update, EspNow v2 & GPS Info (#460)

This commit is contained in:
Shadowtrance
2026-01-27 02:32:57 +10:00
committed by GitHub
parent dfe2c865d1
commit 10381b10cd
18 changed files with 1547 additions and 124 deletions
+21 -4
View File
@@ -37,7 +37,7 @@ void GpsService::addGpsDevice(const std::shared_ptr<GpsDevice>& device) {
GpsDeviceRecord record = {.device = device};
if (getState() == State::On) { // Ignore during OnPending due to risk of data corruptiohn
if (getState() == State::On) { // Ignore during OnPending due to risk of data corruption
startGpsDevice(record);
}
@@ -50,7 +50,7 @@ void GpsService::removeGpsDevice(const std::shared_ptr<GpsDevice>& device) {
GpsDeviceRecord* record = findGpsRecord(device);
if (getState() == State::On) { // Ignore during OnPending due to risk of data corruptiohn
if (getState() == State::On) { // Ignore during OnPending due to risk of data corruption
stopGpsDevice(*record);
}
@@ -87,6 +87,10 @@ bool GpsService::startGpsDevice(GpsDeviceRecord& record) {
record.satelliteSubscriptionId = device->subscribeGga([this](hal::Device::Id deviceId, auto& record) {
mutex.lock();
if (record.fix_quality > 0) {
ggaRecord = record;
ggaTime = kernel::getTicks();
}
onGgaSentence(deviceId, record);
mutex.unlock();
});
@@ -156,14 +160,16 @@ bool GpsService::startReceiving() {
addGpsDevice(device);
}
// Reset times before starting devices to avoid race with incoming data
rmcTime = 0;
ggaTime = 0;
bool started_one_or_more = false;
for (auto& record: deviceRecords) {
started_one_or_more |= startGpsDevice(record);
}
rmcTime = 0;
if (started_one_or_more) {
setState(State::On);
return true;
@@ -186,6 +192,7 @@ void GpsService::stopReceiving() {
}
rmcTime = 0;
ggaTime = 0;
setState(State::Off);
}
@@ -227,6 +234,16 @@ bool GpsService::getCoordinates(minmea_sentence_rmc& rmc) const {
}
}
bool GpsService::getGga(minmea_sentence_gga& gga) const {
auto lock = mutex.asScopedLock();
lock.lock();
if (getState() == State::On && ggaTime != 0 && !hasTimeElapsed(kernel::getTicks(), ggaTime, kernel::secondsToTicks(10))) {
gga = ggaRecord;
return true;
}
return false;
}
std::shared_ptr<GpsService> findGpsService() {
auto service = findServiceById(manifest.id);
assert(service != nullptr);