Przeglądaj źródła

Display time in a more readable format

k4be 4 dni temu
rodzic
commit
825d2e2059
1 zmienionych plików z 27 dodań i 2 usunięć
  1. 27 2
      soft/display.c

+ 27 - 2
soft/display.c

@@ -236,18 +236,43 @@ void disp_func_ele_sat(void) {
 		strcat_P(disp.line2, PSTR(", DGPS"));
 }
 
+static void format_time(char *buf, unsigned int seconds) {
+	unsigned int hours;
+	unsigned char mins, secs;
+
+	hours = seconds / 3600;
+	mins = (seconds % 3600) / 60;
+	secs = seconds % 60;
+
+	if (seconds < 60) {
+		/* Under 1 minute: show seconds only */
+		xsprintf(buf, PSTR("%us"), secs);
+	} else if (seconds < 3600) {
+		/* Under 1 hour: show minutes and seconds */
+		xsprintf(buf, PSTR("%um%02us"), mins, secs);
+	} else if (hours < 10) {
+		/* Under 10 hours: show full format */
+		xsprintf(buf, PSTR("%uh%02um%02us"), hours, mins, secs);
+	} else {
+		/* 10 hours or more: drop seconds to save space */
+		xsprintf(buf, PSTR("%uh%02um"), hours, mins);
+	}
+}
+
 void disp_distance_and_time(void) {
 	unsigned int time = get_logging_time();
 	xsprintf(disp.line1, PSTR("%.2f km"), (float)System.distance / 100000.0);
 	if (time) {
-		xsprintf(disp.line2, PSTR("t=%u s"), time);
+		strcpy(disp.line2, "t=");
+		format_time(disp.line2 + 2, time);
 	} else {
 		disp_line2(PSTR("Czas nieznany"));
 	}
 }
 
 void disp_pause_time(void) {
-	xsprintf(disp.line1, PSTR("Pauza: %u s"), get_pause_time());
+	strcpy_P(disp.line1, PSTR("Pauza: "));
+	format_time(disp.line1 + 7, get_pause_time());
 	disp.line2[0] = '\0';
 }