Procházet zdrojové kódy

Stop counting time and distance when paused

k4be před 1 rokem
rodič
revize
4d742b3206
7 změnil soubory, kde provedl 53 přidání a 6 odebrání
  1. 11 4
      soft/display.c
  2. 1 0
      soft/display.h
  3. 10 2
      soft/gpx.c
  4. 1 0
      soft/gpx.h
  5. 19 0
      soft/main.c
  6. 5 0
      soft/main.h
  7. 6 0
      soft/working_modes.c

+ 11 - 4
soft/display.c

@@ -237,18 +237,25 @@ void disp_func_ele_sat(void) {
 }
 
 void disp_distance_and_time(void) {
+	unsigned int time = get_logging_time();
 	xsprintf(disp.line1, PSTR("%.2f km"), (float)System.distance / 100000.0);
-	if (utc > 0 && System.time_start > 0) {
-		xsprintf(disp.line2, PSTR("t=%u s"), (unsigned int)(utc - System.time_start));
+	if (time) {
+		xsprintf(disp.line2, PSTR("t=%u s"), time);
 	} else {
 		disp_line2(PSTR("Czas nieznany"));
 	}
 }
 
+void disp_pause_time(void) {
+	xsprintf(disp.line1, PSTR("Pauza: %u s"), get_pause_time());
+	disp.line2[0] = '\0';
+}
+
 void disp_speed(void) {
+	unsigned int time = get_logging_time();
 	disp_line1(PSTR("Predkosc:"));
-	if (utc > 0 && System.time_start > 0) {
-		xsprintf(disp.line2, PSTR("%.2f km/h"), (float)System.distance / (float)(utc - System.time_start) * 0.036);
+	if (time) {
+		xsprintf(disp.line2, PSTR("%.2f km/h"), (float)System.distance / (float)(time) * 0.036); /* convert seconds to hours */
 	} else {
 		disp_line2(PSTR("nieznana"));
 	}

+ 1 - 0
soft/display.h

@@ -29,4 +29,5 @@ void disp_distance_and_time(void);
 void disp_speed(void);
 void disp_time(void);
 void disp_func_temperature(void);
+void disp_pause_time(void);
 

+ 10 - 2
soft/gpx.c

@@ -47,7 +47,7 @@ struct avg_store_s {
 	time_t time;
 };
 
-static struct {
+static struct gpx_s {
 	struct prev_points_s prev_points;
 	unsigned char avg_count;
 	unsigned char paused;
@@ -122,6 +122,10 @@ void gpx_save_single_point(struct location_s *loc) {
 	}
 }
 
+unsigned char is_paused(void) {
+	return gpx.paused;
+}
+
 unsigned char gpx_write(struct location_s *loc, FIL *file) {
 	unsigned int bw;
 	const char *time;
@@ -132,6 +136,7 @@ unsigned char gpx_write(struct location_s *loc, FIL *file) {
 			strcpy_P(buf, xml_trkseg_end);
 			gpx.paused = 1;
 			gpx.point_count = 0;
+			System.current_pause_start = utc;
 		} else {
 			return 0; /* nothing to store */
 		}
@@ -140,6 +145,8 @@ unsigned char gpx_write(struct location_s *loc, FIL *file) {
 			strcpy_P(buf, xml_trkseg_start);
 			f_write(file, buf, strlen(buf), &bw);
 			gpx.paused = 0;
+			if (System.current_pause_start)
+				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);
@@ -286,7 +293,8 @@ float distance(struct location_s *pos1, struct location_s *pos2){
 }
 
 void add_distance(float dist) {
-	System.distance += (dist+0.005)*100.0;
+	if (!gpx.paused)
+		System.distance += (dist+0.005)*100.0;
 	xprintf(PSTR("Distance: %f m; sum: %f m\r\n"), dist, System.distance/100.0);
 }
 

+ 1 - 0
soft/gpx.h

@@ -10,4 +10,5 @@ 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);
+unsigned char is_paused(void);
 

+ 19 - 0
soft/main.c

@@ -312,6 +312,25 @@ static inline void auto_pause_process(void) {
 	auto_pause.prev_distance = System.distance;
 }
 
+void reset_counters(void) {
+	System.distance = 0;
+	System.current_pause_start = 0;
+	System.pause_time = 0;
+}
+
+time_t get_pause_time(void) {
+	time_t res = System.pause_time;
+	if (is_paused() && System.current_pause_start)
+		res += utc - System.current_pause_start;
+	return res;
+}
+
+unsigned int get_logging_time(void) {
+	if (!utc || !System.time_start)
+		return 0;
+	return utc - System.time_start - get_pause_time();
+}
+
 __flash const char __open_msg[] = "Open %s\r\n";
 
 /*-----------------------------------------------------------------------*/

+ 5 - 0
soft/main.h

@@ -150,6 +150,8 @@ struct system_s {
 	unsigned long int distance; // cm
 	unsigned char speed; // km/h
 	time_t time_start;
+	time_t current_pause_start;
+	time_t pause_time;
 	unsigned temperature_ok:1;
 	unsigned satellites_used:5;
 	unsigned location_valid:2;
@@ -203,4 +205,7 @@ char *get_iso_time(time_t time, unsigned char local);
 void close_files(unsigned char flush_logs);
 unsigned char getkey(void);
 void sleep(void);
+void reset_counters(void);
+time_t get_pause_time(void);
+unsigned int get_logging_time(void);
 

+ 6 - 0
soft/working_modes.c

@@ -133,6 +133,12 @@ __flash const struct menu_pos default_menu_list[] = {
 		.display = disp_speed,
 		.func = enter_main_menu,
 	},
+	{
+		.type = MENU_TYPE_FUNCTION,
+		.display_type = MENU_DISPLAY_TYPE_FUNCTION,
+		.display = disp_pause_time,
+		.func = enter_main_menu,
+	},
 	{
 		.type = MENU_TYPE_FUNCTION,
 		.display_type = MENU_DISPLAY_TYPE_FUNCTION,