Jelajahi Sumber

Auto-pause: unpause when speed exceeded a limit

k4be 1 tahun lalu
induk
melakukan
a3ffd26703
5 mengubah file dengan 62 tambahan dan 23 penghapusan
  1. 36 22
      soft/main.c
  2. 11 0
      soft/menu.c
  3. 1 0
      soft/menu.h
  4. 11 0
      soft/settings.c
  5. 3 1
      soft/settings.h

+ 36 - 22
soft/main.c

@@ -271,6 +271,41 @@ void close_files(unsigned char flush_logs) {
 	disk_ioctl(0, CTRL_POWER, 0);
 }
 
+static inline void auto_unpause(void) {
+	System.tracking_auto_paused = 0;
+	beep(50, 4);
+}
+
+static inline void auto_pause_activate(void) {
+	System.tracking_auto_paused = 1;
+	beep(50, 3);
+}
+
+static inline void auto_pause_process(void) {
+	if (System.tracking_paused || !get_flag(CONFFLAG_AUTO_PAUSE)) { /* remove auto-pause */
+		System.tracking_auto_paused = 0;
+		auto_pause.prev_distance = System.distance;
+		auto_pause.point_counter = 0;
+	} else {
+		if (System.speed >= System.conf.auto_pause_speed) { /* immediately unpause when set speed is exceeded */
+			auto_pause.point_counter = 0;
+			auto_unpause();
+		} 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)
+						auto_unpause(); /* unpause when distance not too low */
+				} else {
+					if (!System.tracking_auto_paused)
+						auto_pause_activate(); /* pause otherwise */
+				}
+				auto_pause.prev_distance = System.distance;
+			}
+		}
+	}
+}
+
 __flash const char __open_msg[] = "Open %s\r\n";
 
 /*-----------------------------------------------------------------------*/
@@ -411,28 +446,7 @@ int main (void)
 				}
 				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;
-						}
-					}					
+					auto_pause_process();				
 				}
 				wdt_reset();
 				if (FLAGS & F_SYNC) {

+ 11 - 0
soft/menu.c

@@ -43,6 +43,13 @@ void settings_display_u8_meters(unsigned char index) {
 	make_arrows();
 }
 
+void settings_display_u8_kmh(unsigned char index) {
+	unsigned char val = System.conf.conf_u8[index];
+	
+	xsprintf(disp.line2, PSTR("%d km/h"), (int)val);
+	make_arrows();
+}
+
 void settings_change_bool(struct menu_pos pos, unsigned char k) {
 	unsigned char index = pos.index;
 	unsigned char val = get_flag(index);
@@ -135,6 +142,10 @@ unsigned char menu(void) {
 			settings_display_u8_seconds(pos.index);
 			display_line1_as_string = 1;
 			break;
+		case MENU_DISPLAY_TYPE_U8_KMH:
+			settings_display_u8_kmh(pos.index);
+			display_line1_as_string = 1;
+			break;
 		default:	/* bad data */
 			break;
 	}

+ 1 - 0
soft/menu.h

@@ -14,6 +14,7 @@
 #define MENU_DISPLAY_TYPE_NAME_CSFUNCTION	4
 #define MENU_DISPLAY_TYPE_U8_METERS	5
 #define MENU_DISPLAY_TYPE_U8_SECONDS	6
+#define MENU_DISPLAY_TYPE_U8_KMH	7
 
 #define menu_push(x) { if(__menu_num<DATA_NUM) __menu_data[__menu_num++] = x; } // stack commands
 #define menu_pop() --__menu_num

+ 11 - 0
soft/settings.c

@@ -16,6 +16,7 @@ const __flash unsigned char limits_max_u8[] = {
 	[CONF_U8_AUTO_PAUSE_TIME] = 120,
 	[CONF_U8_AUTO_PAUSE_DIST] = 100,
 	[CONF_U8_MIN_SATS] = 12,
+	[CONF_U8_AUTO_PAUSE_SPEED] = 20,
 };
 
 const __flash unsigned char limits_min_u8[] = {
@@ -24,6 +25,7 @@ const __flash unsigned char limits_min_u8[] = {
 	[CONF_U8_AUTO_PAUSE_TIME] = 10,
 	[CONF_U8_AUTO_PAUSE_DIST] = 2,
 	[CONF_U8_MIN_SATS] = 4,
+	[CONF_U8_AUTO_PAUSE_SPEED] = 0,
 };
 
 const __flash unsigned char defaults_u8[] = {
@@ -32,6 +34,7 @@ const __flash unsigned char defaults_u8[] = {
 	[CONF_U8_AUTO_PAUSE_TIME] = 30,
 	[CONF_U8_AUTO_PAUSE_DIST] = 10,
 	[CONF_U8_MIN_SATS] = 5,
+	[CONF_U8_AUTO_PAUSE_SPEED] = 3,
 };
 
 unsigned char settings_load(void) { /* 0 - ok, 1 - error */
@@ -114,6 +117,7 @@ __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 char _msg_auto_pause_speed[] = "Autopau. predk.";
 __flash const char _msg_min_sats[] = "Minimum satelit";
 
 __flash const struct menu_pos settings_menu_list[] = {
@@ -130,6 +134,7 @@ __flash const struct menu_pos settings_menu_list[] = {
 	},
 	{
 		.type = MENU_TYPE_SETTING_U8,
+		.display_type = MENU_DISPLAY_TYPE_U8_SECONDS,
 		.name = _msg_auto_pause_time,
 		.index = CONF_U8_AUTO_PAUSE_TIME,
 	},
@@ -139,6 +144,12 @@ __flash const struct menu_pos settings_menu_list[] = {
 		.name = _msg_auto_pause_dist,
 		.index = CONF_U8_AUTO_PAUSE_DIST,
 	},
+	{
+		.type = MENU_TYPE_SETTING_U8,
+		.display_type = MENU_DISPLAY_TYPE_U8_KMH,
+		.name = _msg_auto_pause_speed,
+		.index = CONF_U8_AUTO_PAUSE_SPEED,
+	},
 	{
 		.type = MENU_TYPE_SETTING_BOOL,
 		.name = _msg_disable_filters,

+ 3 - 1
soft/settings.h

@@ -8,8 +8,9 @@
 #define CONF_U8_AUTO_PAUSE_TIME	2
 #define CONF_U8_AUTO_PAUSE_DIST	3
 #define CONF_U8_MIN_SATS	4
+#define CONF_U8_AUTO_PAUSE_SPEED	5
 
-#define CONF_U8_LAST		4
+#define CONF_U8_LAST		5
 
 /* flags list - max 31 */
 #define CONFFLAG_DISABLE_FILTERS	0
@@ -36,6 +37,7 @@ struct config_s {
 			unsigned char auto_pause_time;	// 2
 			unsigned char auto_pause_dist;	// 3
 			unsigned char min_sats;		// 4
+			unsigned char auto_pause_speed;	// 5
 		};
 	};
 	unsigned char flags[4];