Browse Source

Add elevation support. Discard distance data when paused.
Some header refactoring.

k4be 2 days ago
parent
commit
0904570d7b
5 changed files with 47 additions and 7 deletions
  1. 33 6
      soft/gpx.c
  2. 1 0
      soft/gpx.h
  3. 2 0
      soft/main.c
  4. 2 0
      soft/main.h
  5. 9 1
      soft/nmea.c

+ 33 - 6
soft/gpx.c

@@ -1,12 +1,20 @@
+#ifdef PC_BUILD
+#include "../gps-test-tool/main.h"
+#else
+#include "main.h"
+#endif
+
+/* These are now included via main.h */
+#ifndef PC_BUILD
 #include <string.h>
 #include <avr/pgmspace.h>
 #include "xprintf.h"
 #include "math.h"
-#include "main.h"
 #include "gpx.h"
 #include "ff.h"
 #include "settings.h"
 #include "timec.h"
+#endif
 
 #define KALMAN_Q	8.5e-6
 #define KALMAN_R	4e-5
@@ -153,8 +161,7 @@ unsigned char gpx_write(struct location_s *loc, FIL *file) {
 				System.pause_time += utc - System.current_pause_start;
 		}
 		time = get_iso_time(loc->time, 0);
-		xsprintf(buf, PSTR("\t\t\t<trkpt lat=\"%.8f\" lon=\"%.8f\">\n\t\t\t\t<time>%s</time>\n"), loc->lat, loc->lon, time);
-		/* alt */
+		xsprintf(buf, PSTR("\t\t\t<trkpt lat=\"%.8f\" lon=\"%.8f\">\n\t\t\t\t<ele>%.2f</ele>\n\t\t\t\t<time>%s</time>\n"), loc->lat, loc->lon, loc->alt, time);
 		strcat_P(buf, PSTR("\t\t\t</trkpt>\n"));
 	}
 
@@ -197,10 +204,13 @@ void gpx_process_point(struct location_s *loc, FIL *file){
 
 		gpx_write(loc, file);
 
-		/* Calculate distance from filtered points */
+		/* Calculate distance and elevation from filtered points */
 		if (gpx.last_distance_point.lat != 0) {
+			float ele_change;
 			dist = distance(&gpx.last_distance_point, &filtered_loc);
 			add_distance(dist);
+			ele_change = filtered_loc.alt - gpx.last_distance_point.alt;
+			add_elevation(ele_change);
 		}
 		gpx.last_distance_point = filtered_loc;
 
@@ -242,10 +252,13 @@ void gpx_process_point(struct location_s *loc, FIL *file){
 
 		xputs_P(PSTR("ACCEPT\r\n"));
 
-		/* Calculate distance for accepted point */
+		/* Calculate distance and elevation for accepted point */
 		if (gpx.last_distance_point.lat != 0) {
+			float ele_change;
 			dist = distance(&gpx.last_distance_point, ptr);
 			add_distance(dist);
+			ele_change = ptr->alt - gpx.last_distance_point.alt;
+			add_elevation(ele_change);
 		}
 		gpx.last_distance_point = *ptr;
 
@@ -312,8 +325,22 @@ float distance(struct location_s *pos1, struct location_s *pos2){
 }
 
 void add_distance(float dist) {
-	if (!gpx.paused)
+	unsigned char paused = System.tracking_paused || System.tracking_auto_paused;
+	if (!paused)
 		System.distance += (dist+0.005)*100.0;
 	xprintf(PSTR("Distance: %f m; sum: %f m\r\n"), dist, System.distance/100.0);
 }
 
+void add_elevation(float ele_change) {
+	unsigned char paused = System.tracking_paused || System.tracking_auto_paused;
+	if (!paused) {
+		if (ele_change > 0) {
+			System.elevation_gain += (ele_change+0.05)*10.0;
+		} else if (ele_change < 0) {
+			System.elevation_loss += (-ele_change+0.05)*10.0;
+		}
+	}
+	xprintf(PSTR("Elevation change: %f m; gain: %f m, loss: %f m\r\n"),
+		ele_change, System.elevation_gain/10.0, System.elevation_loss/10.0);
+}
+

+ 1 - 0
soft/gpx.h

@@ -10,5 +10,6 @@ unsigned char gpx_close(FIL *file);
 void gpx_process_point(struct location_s *loc, FIL *file);
 void gpx_save_single_point(struct location_s *loc);
 void add_distance(float dist);
+void add_elevation(float ele_change);
 unsigned char is_paused(void);
 

+ 2 - 0
soft/main.c

@@ -320,6 +320,8 @@ static inline void auto_pause_process(void) {
 
 void reset_counters(void) {
 	System.distance = 0;
+	System.elevation_gain = 0;
+	System.elevation_loss = 0;
 	System.time_start = 0;
 	System.current_pause_start = 0;
 	System.pause_time = 0;

+ 2 - 0
soft/main.h

@@ -159,6 +159,8 @@ struct system_s {
 	unsigned char keypress;
 	unsigned char working_mode;
 	unsigned long int distance; // cm
+	unsigned long int elevation_gain; // dm (decimeters, 0.1m resolution)
+	unsigned long int elevation_loss; // dm (decimeters, 0.1m resolution)
 	unsigned char speed; // km/h
 	time_t time_start;
 	time_t current_pause_start;

+ 9 - 1
soft/nmea.c

@@ -1,3 +1,11 @@
+#ifdef PC_BUILD
+#include "../gps-test-tool/main.h"
+#else
+#include "main.h"
+#endif
+
+/* These are now included via main.h */
+#ifndef PC_BUILD
 #include <avr/wdt.h>
 #include <stddef.h>
 #include <string.h>
@@ -5,10 +13,10 @@
 #include <ctype.h>
 #include <avr/sleep.h>
 #include "nmea.h"
-#include "main.h"
 #include "uart0.h"
 #include "uart1.h"
 #include "xprintf.h"
+#endif
 
 /*----------------------------------------------------*/
 /*  Get a line received from GPS module               */