소스 검색

Add auto-pausing (not fully functional yet)

k4be 1 년 전
부모
커밋
be5932b383
8개의 변경된 파일120개의 추가작업 그리고 17개의 파일을 삭제
  1. 6 2
      soft/display.c
  2. 2 1
      soft/gpx.c
  3. 26 2
      soft/main.c
  4. 6 0
      soft/main.h
  5. 30 5
      soft/menu.c
  6. 2 0
      soft/menu.h
  7. 38 3
      soft/settings.c
  8. 10 4
      soft/settings.h

+ 6 - 2
soft/display.c

@@ -118,6 +118,7 @@ __flash const char _tracking_paused[] =	"Wstrzymano!";
 __flash const char _tracking_resumed[] =	"Wznowiono!";
 __flash const char _point_saved[] =		"Zapisano!";
 __flash const char _point_not_saved[] =	"Nie zapisano!";
+__flash const char _logging_auto_paused[] = "Autom. wstrzym.";
 
 void display_event(unsigned char event) { /* overrides display with current messages */
 	switch (event) {
@@ -170,10 +171,13 @@ void display_event(unsigned char event) { /* overrides display with current mess
 
 void disp_func_main_default(void) {
 	if (FLAGS & F_FILEOPEN) {
-		if (System.tracking_paused)
+		if (System.tracking_paused) {
 			strcpy_P(disp.line1, _logging_paused);
-		else
+		} else if (System.tracking_auto_paused) {
+			strcpy_P(disp.line1, _logging_auto_paused);
+		} else {
 			strcpy_P(disp.line1, _logging_active);
+		}
 	} else
 		strcpy_P(disp.line1, _card_ok);
 

+ 2 - 1
soft/gpx.c

@@ -125,8 +125,9 @@ void gpx_save_single_point(struct location_s *loc) {
 unsigned char gpx_write(struct location_s *loc, FIL *file) {
 	unsigned int bw;
 	const char *time;
+	unsigned char paused = System.tracking_paused || System.tracking_auto_paused;
 
-	if (System.tracking_paused) {
+	if (paused) {
 		if (!gpx.paused) {
 			strcpy_P(buf, xml_trkseg_end);
 			gpx.paused = 1;

+ 26 - 2
soft/main.c

@@ -43,6 +43,7 @@ FIL system_log;				/* System log file */
 char Line[100];				/* Line buffer */
 time_t utc;					/* current time */
 struct location_s location;
+struct auto_pause_s auto_pause;
 
 void start_bootloader(void) {
 	typedef void (*do_reboot_t)(void);
@@ -408,8 +409,31 @@ int main (void)
 					System.status = STATUS_FILE_WRITE_ERROR;
 					break;
 				}
-				if (System.location_valid == LOC_VALID_NEW) /* a new point */
+				if (System.location_valid == LOC_VALID_NEW) { /* a new point */
 					gpx_process_point(&location, &gpx_file);
+					/* auto-pausing */
+					if (System.tracking_paused || !get_flag(CONFFLAG_AUTO_PAUSE)) {
+						System.tracking_auto_paused = 0;
+						auto_pause.prev_distance = System.distance;
+						auto_pause.point_counter = 0;
+					} else {
+						if (++auto_pause.point_counter >= System.conf.auto_pause_time) {
+							auto_pause.point_counter = 0;
+							if ((System.distance - auto_pause.prev_distance)/100 > System.conf.auto_pause_dist) {
+								if (System.tracking_auto_paused) {
+									System.tracking_auto_paused = 0;
+									beep(50, 4);
+								}
+							} else {
+								if (!System.tracking_auto_paused) {
+									System.tracking_auto_paused = 1;
+									beep(50, 3);
+								}
+							}
+							auto_pause.prev_distance = System.distance;
+						}
+					}					
+				}
 				wdt_reset();
 				if (FLAGS & F_SYNC) {
 					if (f_sync(&gps_log)) {
@@ -470,7 +494,7 @@ int main (void)
 				wdt_enable(WDTO_4S);
 				FLAGS |= F_FILEOPEN;
 				System.status = STATUS_OK;
-				beep(50, System.tracking_paused?5:2);		/* Two beeps. Start logging. */
+				beep(50, System.tracking_paused?8:2);		/* Two beeps. Start logging. */
 				display_event(DISPLAY_EVENT_FILE_OPEN);
 				continue;
 			}

+ 6 - 0
soft/main.h

@@ -148,6 +148,7 @@ struct system_s {
 	unsigned gps_initialized:1;
 	unsigned gps_only:1;
 	unsigned tracking_paused:1;
+	unsigned tracking_auto_paused:1;
 	unsigned open_new_file:1;
 };
 
@@ -158,6 +159,11 @@ struct location_s {
 	time_t time;
 };
 
+struct auto_pause_s {
+	unsigned char point_counter;
+	unsigned long int prev_distance;
+};
+
 extern volatile struct system_s System;
 extern struct location_s location;
 extern time_t utc;

+ 30 - 5
soft/menu.c

@@ -8,22 +8,39 @@ unsigned char __menu_num; // Menu stack variables
 struct menu_struct __menu_data[DATA_NUM];
 __flash const char _NULL_STRING[] = "(NULL)";
 
+void make_arrows(void) {
+	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 settings_display_bool(unsigned char index) {
 	unsigned char val = get_flag(index);
 	if (val)
 		strcpy_P(disp.line2, PSTR("< Tak > "));
 	else
 		strcpy_P(disp.line2, PSTR("< Nie > "));
-	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 */
+	make_arrows();
 }
 
 void settings_display_u8(unsigned char index) {
 	unsigned char val = System.conf.conf_u8[index];
 	
 	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 */
+	make_arrows();
+}
+
+void settings_display_u8_seconds(unsigned char index) {
+	unsigned char val = System.conf.conf_u8[index];
+	
+	xsprintf(disp.line2, PSTR("%d s"), (int)val);
+	make_arrows();
+}
+
+void settings_display_u8_meters(unsigned char index) {
+	unsigned char val = System.conf.conf_u8[index];
+	
+	xsprintf(disp.line2, PSTR("%d m"), (int)val);
+	make_arrows();
 }
 
 void settings_change_bool(struct menu_pos pos, unsigned char k) {
@@ -43,7 +60,7 @@ void settings_change_u8(struct menu_pos pos, unsigned char k) {
 	unsigned char val = System.conf.conf_u8[index];
 
 	if (k == K_LEFT) {
-		if (val)
+		if (val > limits_min_u8[index])
 			val--;
 	}
 
@@ -110,6 +127,14 @@ unsigned char menu(void) {
 			display_line1_as_string = 1;
 			strcpy_P(disp.line2, pos.csdisplay());
 			break;
+		case MENU_DISPLAY_TYPE_U8_METERS: /* maybe use postfixes instead? */
+			settings_display_u8_meters(pos.index);
+			display_line1_as_string = 1;
+			break;
+		case MENU_DISPLAY_TYPE_U8_SECONDS:
+			settings_display_u8_seconds(pos.index);
+			display_line1_as_string = 1;
+			break;
 		default:	/* bad data */
 			break;
 	}

+ 2 - 0
soft/menu.h

@@ -12,6 +12,8 @@
 #define MENU_DISPLAY_TYPE_FUNCTION	2
 #define MENU_DISPLAY_TYPE_NAME_FUNCTION	3
 #define MENU_DISPLAY_TYPE_NAME_CSFUNCTION	4
+#define MENU_DISPLAY_TYPE_U8_METERS	5
+#define MENU_DISPLAY_TYPE_U8_SECONDS	6
 
 #define menu_push(x) { if(__menu_num<DATA_NUM) __menu_data[__menu_num++] = x; } // stack commands
 #define menu_pop() --__menu_num

+ 38 - 3
soft/settings.c

@@ -11,8 +11,24 @@ EEMEM struct config_s config_eep;
 EEMEM unsigned char config_crc;
 
 const __flash unsigned char limits_max_u8[] = {
-	[CONF_U8_GNSS_MODE] = 5,
+	[CONF_U8_GNSS_MODE] = GNSS_MODE_BEIDOU,
 	[CONF_U8_SKIP_POINTS] = 120,
+	[CONF_U8_AUTO_PAUSE_TIME] = 120,
+	[CONF_U8_AUTO_PAUSE_DIST] = 100,
+};
+
+const __flash unsigned char limits_min_u8[] = {
+	[CONF_U8_GNSS_MODE] = GNSS_MODE_GPS_GLONASS_GALILEO,
+	[CONF_U8_SKIP_POINTS] = 0,
+	[CONF_U8_AUTO_PAUSE_TIME] = 10,
+	[CONF_U8_AUTO_PAUSE_DIST] = 2,
+};
+
+const __flash unsigned char defaults_u8[] = {
+	[CONF_U8_GNSS_MODE] = GNSS_MODE_GPS_GLONASS_GALILEO,
+	[CONF_U8_SKIP_POINTS] = 15,
+	[CONF_U8_AUTO_PAUSE_TIME] = 30,
+	[CONF_U8_AUTO_PAUSE_DIST] = 10,
 };
 
 unsigned char settings_load(void) { /* 0 - ok, 1 - error */
@@ -40,9 +56,9 @@ unsigned char settings_load(void) { /* 0 - ok, 1 - error */
 unsigned char check_config_data(void) { /* 0 - ok, 1 - error */
 	unsigned char i, ret=0;
 	for (i=0; i<=CONF_U8_LAST; i++) {
-		if (System.conf.conf_u8[i] > limits_max_u8[i]) {
+		if (System.conf.conf_u8[i] > limits_max_u8[i] || System.conf.conf_u8[i] < limits_min_u8[i]) {
 			ret = 1;
-			System.conf.conf_u8[i] = 0;
+			System.conf.conf_u8[i] = defaults_u8[i];
 		}
 	}
 	return ret;
@@ -91,6 +107,9 @@ __flash const char _msg_gnss_type[] = "Rodzaj GNSS";
 __flash const char _msg_skip_points[] = "Pomin punkty";
 __flash const char _msg_logging_after_boot[] = "Zapis po wlacz.";
 __flash const char _msg_back[] = "< Powrot";
+__flash const char _msg_auto_pause[] = "Autopauza";
+__flash const char _msg_auto_pause_time[] = "Autopauza czas";
+__flash const char _msg_auto_pause_dist[] = "Autopauza odleg";
 
 __flash const struct menu_pos settings_menu_list[] = {
 	{
@@ -99,6 +118,22 @@ __flash const struct menu_pos settings_menu_list[] = {
 		.name = _msg_back,
 		.allow_back = 1,
 	},
+	{
+		.type = MENU_TYPE_SETTING_BOOL,
+		.name = _msg_auto_pause,
+		.index = CONFFLAG_AUTO_PAUSE,
+	},
+	{
+		.type = MENU_TYPE_SETTING_U8,
+		.name = _msg_auto_pause_time,
+		.index = CONF_U8_AUTO_PAUSE_TIME,
+	},
+	{
+		.type = MENU_TYPE_SETTING_U8,
+		.display_type = MENU_DISPLAY_TYPE_U8_METERS,
+		.name = _msg_auto_pause_dist,
+		.index = CONF_U8_AUTO_PAUSE_DIST,
+	},
 	{
 		.type = MENU_TYPE_SETTING_BOOL,
 		.name = _msg_disable_filters,

+ 10 - 4
soft/settings.h

@@ -5,15 +5,18 @@
 /* u8 list - max 15 */
 #define CONF_U8_GNSS_MODE	0
 #define CONF_U8_SKIP_POINTS	1
+#define CONF_U8_AUTO_PAUSE_TIME	2
+#define CONF_U8_AUTO_PAUSE_DIST	3
 
-#define CONF_U8_LAST		1
+#define CONF_U8_LAST		3
 
 /* flags list - max 31 */
 #define CONFFLAG_DISABLE_FILTERS	0
 #define CONFFLAG_ENABLE_SBAS		1
 #define CONFFLAG_LOGGING_AFTER_BOOT	2
+#define CONFFLAG_AUTO_PAUSE			3
 
-#define CONFFLAG_LAST				2
+#define CONFFLAG_LAST				3
 
 /* GNSS modes */
 #define GNSS_MODE_GPS_GLONASS_GALILEO	0
@@ -27,14 +30,17 @@ struct config_s {
 	union {
 		unsigned char conf_u8[16];
 		struct {
-			unsigned char gnss_mode; // 0
-			unsigned char skip_points; // 1
+			unsigned char gnss_mode;	// 0
+			unsigned char skip_points;	// 1
+			unsigned char auto_pause_time;	// 2
+			unsigned char auto_pause_dist;	// 3
 		};
 	};
 	unsigned char flags[4];
 };
 
 extern const __flash unsigned char limits_max_u8[];
+extern const __flash unsigned char limits_min_u8[];
 extern __flash const char *gnss_names[];
 extern __flash const struct menu_struct settings_menu;