Răsfoiți Sursa

Display distance, time and speed

k4be 2 ani în urmă
părinte
comite
9c26ee0cb6
7 a modificat fișierele cu 55 adăugiri și 4 ștergeri
  1. 20 0
      soft/display.c
  2. 4 2
      soft/display.h
  3. 10 0
      soft/gpx.c
  4. 1 0
      soft/main.h
  5. 14 0
      soft/settings.c
  6. 4 2
      soft/settings.h
  7. 2 0
      soft/working_modes.c

+ 20 - 0
soft/display.c

@@ -178,6 +178,24 @@ void disp_func_ele_sat(__attribute__ ((unused)) unsigned char changed) {
 		strcat_P(disp.line2, PSTR(", DGPS"));
 }
 
+void disp_distance_and_time(__attribute__ ((unused)) unsigned char changed) {
+	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));
+	} else {
+		strcpy_P(disp.line2, PSTR("Czas nieznany"));
+	}
+}
+
+void disp_speed(__attribute__ ((unused)) unsigned char changed) {
+	strcpy_P(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);
+	} else {
+		strcpy_P(disp.line2, PSTR("nieznana"));
+	}
+}
+
 void disp_func_main_menu(__attribute__ ((unused)) unsigned char changed) {
 	display_main_menu_item();
 }
@@ -197,6 +215,8 @@ void (*__flash const disp_funcs[])(unsigned char) = {
 	[DISPLAY_STATE_MAIN_DEFAULT] = disp_func_main_default,
 	[DISPLAY_STATE_COORD] = disp_func_coord,
 	[DISPLAY_STATE_ELE_SAT] = disp_func_ele_sat,
+	[DISPLAY_STATE_DIST_TIME] = disp_distance_and_time,
+	[DISPLAY_STATE_SPEED] = disp_speed,
 	[DISPLAY_STATE_MAIN_MENU] = disp_func_main_menu,
 	[DISPLAY_STATE_SETTINGS_MENU] = disp_func_settings_menu,
 };

+ 4 - 2
soft/display.h

@@ -11,8 +11,10 @@
 #define DISPLAY_STATE_MAIN_DEFAULT	8
 #define DISPLAY_STATE_COORD	9
 #define DISPLAY_STATE_ELE_SAT	10
-#define DISPLAY_STATE_MAIN_MENU	11
-#define DISPLAY_STATE_SETTINGS_MENU	12
+#define DISPLAY_STATE_DIST_TIME	11
+#define DISPLAY_STATE_SPEED	12
+#define DISPLAY_STATE_MAIN_MENU	13
+#define DISPLAY_STATE_SETTINGS_MENU	14
 
 struct disp_s {
 	char line1[16];

+ 10 - 0
soft/gpx.c

@@ -51,6 +51,7 @@ static struct {
 	struct prev_points_s prev_points;
 	unsigned char avg_count;
 	unsigned char paused;
+	unsigned char point_count;
 	struct avg_store_s avg_store;
 	struct location_s last_saved;
 	struct kalman_s kalman[2];
@@ -129,6 +130,7 @@ unsigned char gpx_write(struct location_s *loc, FIL *file) {
 		if (!gpx.paused) {
 			strcpy_P(buf, xml_trkseg_end);
 			gpx.paused = 1;
+			gpx.point_count = 0;
 		} else {
 			return 0; /* nothing to store */
 		}
@@ -161,6 +163,11 @@ void gpx_process_point(struct location_s *loc, FIL *file){
 	float lon_est, lon_err, lat_est, lat_err, dist = NAN;
 	struct location_s *ptr;
 	struct location_s nloc;
+
+	if (gpx.point_count < System.conf.skip_points) { /* Skipping initial points */
+		gpx.point_count++;
+		return;
+	}
 	
 	if (get_flag(CONFFLAG_DISABLE_FILTERS)) {
 		xputs_P(PSTR("Write with filters disabled\r\n"));
@@ -228,8 +235,11 @@ void gpx_process_point(struct location_s *loc, FIL *file){
 			gpx_write(&nloc, file);
 		}
 	}
+	if (System.time_start == 0)
+		System.time_start = utc;
 	if (isnan(dist))
 		return;
+	/* FIXME distance is always calculated from unfiltered data and never paused! */
 	add_distance(dist);
 }
 

+ 1 - 0
soft/main.h

@@ -141,6 +141,7 @@ struct system_s {
 	unsigned char keypress;
 	unsigned char working_mode;
 	unsigned long int distance; // cm
+	time_t time_start;
 	unsigned temperature_ok:1;
 	unsigned satellites_used:5;
 	unsigned location_valid:2;

+ 14 - 0
soft/settings.c

@@ -11,6 +11,7 @@ EEMEM unsigned char config_crc;
 
 const __flash unsigned char limits_max_u8[] = {
 	[CONF_U8_GNSS_MODE] = 5,
+	[CONF_U8_SKIP_POINTS] = 120,
 };
 
 unsigned char settings_load(void) { /* 0 - ok, 1 - error */
@@ -123,6 +124,12 @@ void settings_bool_disp_default(unsigned char val) {
 	strcat_P(disp.line2, HAVE_PREV_SETTING_POSITION?PSTR(" \x02"):PSTR("  ")); /* up arrow */
 }
 
+void settings_u8_disp_default(unsigned char val) {
+	xsprintf(disp.line2, PSTR("%d"), (int)val);
+	strcat_P(disp.line2, HAVE_NEXT_SETTING_POSITION?PSTR(" \x01"):PSTR("  ")); /* down arrow */
+	strcat_P(disp.line2, HAVE_PREV_SETTING_POSITION?PSTR(" \x02"):PSTR("  ")); /* up arrow */
+}
+
 void display_gnss_mode(unsigned char val) {
 	strcpy_P(disp.line2, gnss_names[val]);
 }
@@ -132,6 +139,7 @@ void display_gnss_mode(unsigned char val) {
 __flash const char _msg_disable_filters[] = "Nie filtruj";
 __flash const char _msg_enable_sbas[] = "Szukaj SBAS";
 __flash const char _msg_gnss_type[] = "Rodzaj GNSS";
+__flash const char _msg_skip_points[] = "Pomin punkty";
 __flash const char _msg_back[] = "< Powrot";
 
 __flash const struct settings_menu_pos_s settings_menu[SETTINGS_MENU_MAXPOS+1] = {
@@ -145,6 +153,12 @@ __flash const struct settings_menu_pos_s settings_menu[SETTINGS_MENU_MAXPOS+1] =
 		.index = CONFFLAG_DISABLE_FILTERS,
 		.display = settings_bool_disp_default,
 	},
+	{
+		.type = SETTINGS_TYPE_U8,
+		.name = _msg_skip_points,
+		.index = CONF_U8_SKIP_POINTS,
+		.display = settings_u8_disp_default,
+	},
 	{
 		.type = SETTINGS_TYPE_BOOL,
 		.name = _msg_enable_sbas,

+ 4 - 2
soft/settings.h

@@ -4,8 +4,9 @@
 
 /* u8 list - max 15 */
 #define CONF_U8_GNSS_MODE	0
+#define CONF_U8_SKIP_POINTS	1
 
-#define CONF_U8_LAST		0
+#define CONF_U8_LAST		1
 
 /* flags list - max 31 */
 #define CONFFLAG_DISABLE_FILTERS	0
@@ -28,13 +29,14 @@
 #define HAVE_NEXT_SETTING_POSITION (mp.settings_menu_pos < SETTINGS_MENU_MAXPOS)
 #define HAVE_PREV_SETTING_POSITION (mp.settings_menu_pos > 0)
 
-#define SETTINGS_MENU_MAXPOS	3
+#define SETTINGS_MENU_MAXPOS	4
 
 struct config_s {
 	union {
 		unsigned char conf_u8[16];
 		struct {
 			unsigned char gnss_mode; // 0
+			unsigned char skip_points; // 1
 		};
 	};
 	unsigned char flags[4];

+ 2 - 0
soft/working_modes.c

@@ -13,6 +13,8 @@ __flash const unsigned char main_display_modes[] = {
 	DISPLAY_STATE_MAIN_DEFAULT,
 	DISPLAY_STATE_COORD,
 	DISPLAY_STATE_ELE_SAT,
+	DISPLAY_STATE_DIST_TIME,
+	DISPLAY_STATE_SPEED,
 };
 
 const char *enter_settings_get_name(void) {