Browse Source

make get_line preemptive to improve UI latency

k4be 1 year ago
parent
commit
f13305eb6c
1 changed files with 14 additions and 7 deletions
  1. 14 7
      soft/nmea.c

+ 14 - 7
soft/nmea.c

@@ -13,13 +13,14 @@
 /*  Get a line received from GPS module               */
 /*  Get a line received from GPS module               */
 /*----------------------------------------------------*/
 /*----------------------------------------------------*/
 
 
-UINT get_line (		/* 0:Brownout or timeout, >0: Number of bytes received. */
+uint16_t get_line (		/* 0:line incomplete or timed out, >0: Number of bytes received. */
 	char *buff,
 	char *buff,
-	UINT sz_buf
+	uint16_t sz_buf
 )
 )
 {
 {
 	char c;
 	char c;
-	UINT i = 0;
+	static uint16_t i = 0;
+	uint16_t ret_len;
 
 
 	set_timer(recv_timeout, 1000);
 	set_timer(recv_timeout, 1000);
 
 
@@ -29,6 +30,8 @@ UINT get_line (		/* 0:Brownout or timeout, >0: Number of bytes received. */
 			return 0;	/* A brownout is detected */
 			return 0;	/* A brownout is detected */
 		if (timer_expired(recv_timeout))
 		if (timer_expired(recv_timeout))
 			return 0; /* timeout; continue the main loop */
 			return 0; /* timeout; continue the main loop */
+		if (System.keypress) /* process user keypress */
+			return 0;
 		if (!uart0_test()) {
 		if (!uart0_test()) {
 			sleep();
 			sleep();
 			continue;
 			continue;
@@ -42,12 +45,16 @@ UINT get_line (		/* 0:Brownout or timeout, >0: Number of bytes received. */
 		}
 		}
 		buff[i++] = c;
 		buff[i++] = c;
 		uart1_put(c);
 		uart1_put(c);
-		if (i >= sz_buf)
+		if (i >= sz_buf - 1) /* keep one byte for terminating character */
 			i = 0;	/* Buffer overflow (abort this line) */
 			i = 0;	/* Buffer overflow (abort this line) */
 	}
 	}
-	uart1_put('\r');
-	uart1_put('\n');
-	return i;
+	ret_len = i;
+	i = 0;
+	if (ret_len > 0) {
+		uart1_put('\r');
+		uart1_put('\n');
+	}
+	return ret_len;
 }
 }
 
 
 /* Compare sentence header string */
 /* Compare sentence header string */