Commits

Anonymous committed e73f134

Add GPS logging

Comments (0)

Files changed (1)

src/to/rcpt/icarus/IcarusLogger.java

 	List<SensorEventAdapter> sensorlogs;
 	private LocationManager gps;
 	private String provider;
+	private PrintWriter gpsfile;
 	
 	public IcarusLogger(Context context) {
 		// TODO: abstract setup code with IcarusMission
 	
 	public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
 		if (isChecked) {
-			gps.requestLocationUpdates(provider, 0, 0, this);
+			startGpsLogging();
 			for(SensorEventAdapter s: sensorlogs) {
 				s.startLogging();
 			}
 		} else {
-			gps.removeUpdates(this);
+			stopGpsLogging();
 			for(SensorEventAdapter s: sensorlogs) {
 				s.stopLogging();
 			}
 		}
 	}
 
-	public void onLocationChanged(Location location) {
-		// TODO Auto-generated method stub
-		
+	public void startGpsLogging() {
+		try {
+			File f = new File("/sdcard", provider);
+			try {
+				f.createNewFile();
+			} catch(IOException e) {
+				throw new RuntimeException(e);
+			}
+			gpsfile = new PrintWriter(new FileOutputStream(f, true));
+		} catch(FileNotFoundException e) {
+			throw new RuntimeException(e);
+		}
+		gps.requestLocationUpdates(provider, 0, 0, this);
+	}
+	
+	public void stopGpsLogging() {
+		gps.removeUpdates(this);
+		gpsfile.close();
+	}
+	
+	public void onLocationChanged(Location l) {
+		String update = l.getTime() + " " + l.getLatitude() + "," + l.getLongitude() + " " + l.getAltitude();
+		gpsfile.println(update);
 	}
 
 	public void onProviderDisabled(String provider) {