mirror of
https://github.com/hrydgard/ppsspp.git
synced 2024-11-23 05:19:56 +00:00
Location: add HDOP; change speed to km/h; change altitude from geoid to sea level
The speed is now close to the value obtained on original hardware but the altitude on original hardawre is too imprecise to tell if we're good
This commit is contained in:
parent
8203c79e43
commit
83277680da
@ -141,9 +141,10 @@ void GPS::setGpsTime(time_t *time) {
|
||||
gpsData.second = (short)gpsTime->tm_sec;
|
||||
}
|
||||
|
||||
void GPS::setGpsData(float latitude, float longitude, float altitude, float speed, float bearing, long long gpsTime) {
|
||||
void GPS::setGpsData(long long gpsTime, float hdop, float latitude, float longitude, float altitude, float speed, float bearing) {
|
||||
setGpsTime((time_t*)&gpsTime);
|
||||
|
||||
gpsData.hdop = hdop;
|
||||
gpsData.latitude = latitude;
|
||||
gpsData.longitude = longitude;
|
||||
gpsData.altitude = altitude;
|
||||
|
@ -65,7 +65,7 @@ typedef struct {
|
||||
namespace GPS {
|
||||
void init();
|
||||
void setGpsTime(time_t *time);
|
||||
void setGpsData(float latitude, float longitude, float altitude, float speed, float bearing, long long time);
|
||||
void setGpsData(long long time, float hdop, float latitude, float longitude, float altitude, float speed, float bearing);
|
||||
void setSatInfo(short index, unsigned char id, unsigned char elevation, short azimuth, unsigned char snr, unsigned char good);
|
||||
GpsData *getGpsData();
|
||||
SatData *getSatData();
|
||||
|
@ -952,8 +952,8 @@ extern "C" jint Java_org_ppsspp_ppsspp_NativeApp_getSelectedCamera(JNIEnv *, jcl
|
||||
}
|
||||
|
||||
extern "C" void JNICALL Java_org_ppsspp_ppsspp_NativeApp_setGpsDataAndroid(JNIEnv *, jclass,
|
||||
jfloat latitude, jfloat longitude, jfloat altitude, jfloat speed, jfloat bearing, jlong time) {
|
||||
GPS::setGpsData(latitude, longitude, altitude, speed, bearing, time);
|
||||
jlong time, jfloat hdop, jfloat latitude, jfloat longitude, jfloat altitude, jfloat speed, jfloat bearing) {
|
||||
GPS::setGpsData(time, hdop, latitude, longitude, altitude, speed, bearing);
|
||||
}
|
||||
|
||||
extern "C" void JNICALL Java_org_ppsspp_ppsspp_NativeApp_setSatInfoAndroid(JNIEnv *, jclass,
|
||||
|
@ -12,10 +12,12 @@ import android.util.Log;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
class LocationHelper implements LocationListener, GpsStatus.Listener {
|
||||
class LocationHelper implements LocationListener, GpsStatus.Listener, GpsStatus.NmeaListener {
|
||||
private static final String TAG = LocationHelper.class.getSimpleName();
|
||||
private LocationManager mLocationManager;
|
||||
private boolean mLocationEnable;
|
||||
private float mAltitudeAboveSeaLevel = 0f;
|
||||
private float mHdop = 0f;
|
||||
|
||||
LocationHelper(Context context) {
|
||||
mLocationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
|
||||
@ -33,6 +35,7 @@ class LocationHelper implements LocationListener, GpsStatus.Listener {
|
||||
mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 0, this);
|
||||
mLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 1000, 0, this);
|
||||
mLocationManager.addGpsStatusListener(this);
|
||||
mLocationManager.addNmeaListener(this);
|
||||
mLocationEnable = true;
|
||||
} catch (SecurityException e) {
|
||||
Log.e(TAG, "Cannot start location updates: " + e.toString());
|
||||
@ -52,17 +55,20 @@ class LocationHelper implements LocationListener, GpsStatus.Listener {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* LocationListener
|
||||
*/
|
||||
|
||||
@Override
|
||||
public void onLocationChanged(Location location) {
|
||||
long time = location.getTime() / 1000; // ms to s !!
|
||||
float latitude = (float) location.getLatitude();
|
||||
float longitude = (float) location.getLongitude();
|
||||
// Android altitude is in meters above the WGS 84 reference ellipsoid
|
||||
float altitude = (float) location.getAltitude();
|
||||
float speed = location.getSpeed();
|
||||
float speed = location.getSpeed() * 3.6f; // m/s to km/h !!
|
||||
float bearing = location.getBearing();
|
||||
long time = location.getTime() / 1000; // ms to s !!
|
||||
|
||||
NativeApp.setGpsDataAndroid(latitude, longitude, altitude, speed, bearing, time);
|
||||
NativeApp.setGpsDataAndroid(time, mHdop, latitude, longitude, mAltitudeAboveSeaLevel, speed, bearing);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -78,6 +84,10 @@ class LocationHelper implements LocationListener, GpsStatus.Listener {
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* GpsStatus.Listener
|
||||
*/
|
||||
|
||||
@Override
|
||||
public void onGpsStatusChanged(int i) {
|
||||
switch (i) {
|
||||
@ -110,4 +120,24 @@ class LocationHelper implements LocationListener, GpsStatus.Listener {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* GpsStatus.Listener
|
||||
*/
|
||||
|
||||
@Override
|
||||
public void onNmeaReceived(long timestamp, String nmea) {
|
||||
String[] tokens = nmea.split(",");
|
||||
Log.e(TAG, nmea);
|
||||
if (tokens.length < 10 || !tokens[0].equals("$GPGGA")) {
|
||||
return;
|
||||
}
|
||||
if (!tokens[8].isEmpty()) {
|
||||
mHdop = Float.valueOf(tokens[8]);
|
||||
}
|
||||
if (!tokens[9].isEmpty()) {
|
||||
mAltitudeAboveSeaLevel = Float.valueOf(tokens[9]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -52,7 +52,7 @@ public class NativeApp {
|
||||
public static native String queryConfig(String queryName);
|
||||
|
||||
public static native int getSelectedCamera();
|
||||
public static native void setGpsDataAndroid(float latitude, float longitude, float altitude, float speed, float bearing, long time);
|
||||
public static native void setGpsDataAndroid(long time, float hdop, float latitude, float longitude, float altitude, float speed, float bearing);
|
||||
public static native void setSatInfoAndroid(short index, short id, short elevation, short azimuth, short snr, short good);
|
||||
public static native void pushCameraImageAndroid(byte[] image);
|
||||
}
|
||||
|
@ -698,10 +698,12 @@ void stopLocation() {
|
||||
}
|
||||
|
||||
-(void) SetGpsDataIOS:(CLLocation *)newLocation {
|
||||
NSLog(@"SetGpsDataIOS: speed: %f", newLocation.speed); // m/s
|
||||
GPS::setGpsData(newLocation.coordinate.latitude, newLocation.coordinate.longitude,
|
||||
newLocation.altitude, 0 /* speed */, 0 /* bearing */,
|
||||
(long long)newLocation.timestamp.timeIntervalSince1970);
|
||||
GPS::setGpsData((long long)newLocation.timestamp.timeIntervalSince1970,
|
||||
newLocation.horizontalAccuracy/5.0,
|
||||
newLocation.coordinate.latitude, newLocation.coordinate.longitude,
|
||||
newLocation.altitude,
|
||||
MAX(newLocation.speed * 3.6, 0.0), /* m/s to km/h */
|
||||
0 /* bearing */);
|
||||
}
|
||||
|
||||
@end
|
||||
|
Loading…
Reference in New Issue
Block a user