mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-12-26 02:25:50 +01:00
Bangle.js: Additional values for GPS event (#3026)
This tries to use bearing and number of satellites if available. ~~Bangle.js watch currently sets course=NaN in it's implementation of the GPS event handler, so to be of use this needs a small change there as well: [https://github.com/espruino/BangleApps/pull/2504](https://github.com/espruino/BangleApps/pull/2504)~~ Change has been merged. Please advise on needed changes or oversights, thanks :) Co-authored-by: Martin Boonk <martin@boonk.info> Reviewed-on: https://codeberg.org/Freeyourgadget/Gadgetbridge/pulls/3026 Co-authored-by: halemmerich <halemmerich@noreply.codeberg.org> Co-committed-by: halemmerich <halemmerich@noreply.codeberg.org>
This commit is contained in:
parent
56ec206f5b
commit
90771891a5
@ -27,6 +27,7 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
@ -58,7 +59,7 @@ public class GBLocationManager {
|
||||
return;
|
||||
}
|
||||
|
||||
GB.createGpsNotification(context, providers.size() + 1);
|
||||
GB.createGpsNotification(context, providers.size());
|
||||
|
||||
final GBLocationListener locationListener = new GBLocationListener(eventHandler);
|
||||
final AbstractLocationProvider locationProvider;
|
||||
@ -99,25 +100,34 @@ public class GBLocationManager {
|
||||
if (!providers.containsKey(eventHandler)) return;
|
||||
Map<LocationProviderType, AbstractLocationProvider> providerMap = providers.get(eventHandler);
|
||||
if (gpsType == null) {
|
||||
Set<LocationProviderType> toBeRemoved = new HashSet<>();
|
||||
for (LocationProviderType providerType: providerMap.keySet()) {
|
||||
if (!providerMap.containsKey(providerType)) return;
|
||||
stopProvider(context, providerMap.get(providerType));
|
||||
toBeRemoved.add(providerType);
|
||||
}
|
||||
toBeRemoved.forEach(c->{providerMap.remove(c);});
|
||||
} else {
|
||||
stopProvider(context, providerMap.get(gpsType));
|
||||
providerMap.remove(gpsType);
|
||||
}
|
||||
LOG.debug("Remaining providers: " + providers.size());
|
||||
if (providers.get(eventHandler).size() == 0)
|
||||
providers.remove(eventHandler);
|
||||
updateNotification(context);
|
||||
}
|
||||
|
||||
private static void updateNotification(final Context context){
|
||||
if (!providers.isEmpty()) {
|
||||
GB.createGpsNotification(context, providers.size());
|
||||
} else {
|
||||
GB.removeGpsNotification(context);
|
||||
}
|
||||
}
|
||||
|
||||
private static void stopProvider(final Context context, AbstractLocationProvider locationProvider) {
|
||||
if (locationProvider != null) {
|
||||
LOG.warn("EventHandler not registered");
|
||||
|
||||
locationProvider.stop(context);
|
||||
}
|
||||
|
||||
if (!providers.isEmpty()) {
|
||||
GB.createGpsNotification(context, providers.size());
|
||||
} else {
|
||||
GB.removeGpsNotification(context);
|
||||
}
|
||||
}
|
||||
|
||||
public static void stopAll(final Context context) {
|
||||
|
@ -194,7 +194,8 @@ public class BangleJSDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
|
||||
|
||||
private void stopLocationUpdate() {
|
||||
GBLocationManager.stop(getContext(), this, null);
|
||||
LOG.info("Stop location updates");
|
||||
GBLocationManager.stop(getContext(), this);
|
||||
gpsUpdateSetup = false;
|
||||
}
|
||||
|
||||
@ -929,8 +930,17 @@ public class BangleJSDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
int intervalLength = devicePrefs.getInt(PREF_DEVICE_GPS_UPDATE_INTERVAL, 10000);
|
||||
LOG.info("Setup location listener with an update interval of " + intervalLength + " ms");
|
||||
|
||||
GBLocationManager.start(getContext(), this, LocationProviderType.GPS, intervalLength);
|
||||
GBLocationManager.start(getContext(), this, LocationProviderType.NETWORK, intervalLength);
|
||||
try {
|
||||
GBLocationManager.start(getContext(), this, LocationProviderType.GPS, intervalLength);
|
||||
} catch (IllegalArgumentException e) {
|
||||
LOG.warn("GPS provider could not be started", e);
|
||||
}
|
||||
|
||||
try {
|
||||
GBLocationManager.start(getContext(), this, LocationProviderType.NETWORK, intervalLength);
|
||||
} catch (IllegalArgumentException e) {
|
||||
LOG.warn("NETWORK provider could not be started", e);
|
||||
}
|
||||
} else {
|
||||
LOG.debug("Phone gps data update is deactivated in the settings");
|
||||
}
|
||||
@ -947,9 +957,14 @@ public class BangleJSDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
o.put("lon", location.getLongitude());
|
||||
o.put("alt", location.getAltitude());
|
||||
o.put("speed", location.getSpeed());
|
||||
o.put("course", 0);
|
||||
if (location.hasBearing()) o.put("course", location.getBearing());
|
||||
o.put("time", new Date().getTime());
|
||||
o.put("satellites", 0);
|
||||
if (location.getExtras() != null) {
|
||||
LOG.debug("Found number of satellites: " + location.getExtras().getInt("satellites", -1));
|
||||
o.put("satellites",location.getExtras().getInt("satellites"));
|
||||
} else {
|
||||
o.put("satellites", 0);
|
||||
}
|
||||
o.put("hdop", location.getAccuracy());
|
||||
o.put("externalSource", true);
|
||||
LOG.debug("Sending gps valu: " + o.toString());
|
||||
|
Loading…
Reference in New Issue
Block a user