Explorar o código

update gps uart

MX %!s(int64=2) %!d(string=hai) anos
pai
achega
dbd100e560
Modificáronse 3 ficheiros con 25 adicións e 10 borrados
  1. 4 0
      constants.h
  2. 16 7
      gps.c
  3. 5 3
      gps_uart.h

+ 4 - 0
constants.h

@@ -0,0 +1,4 @@
+#pragma once
+
+#define KNOTS_TO_KPH 1.852
+#define KNOTS_TO_MPH 1.15078

+ 16 - 7
gps.c

@@ -1,4 +1,5 @@
 #include "gps_uart.h"
+#include "constants.h"
 
 #include <furi.h>
 #include <gui/gui.h>
@@ -37,11 +38,20 @@ static void render_callback(Canvas* const canvas, void* context) {
         canvas_draw_str_aligned(canvas, 96, 18, AlignCenter, AlignBottom, buffer);
         snprintf(buffer, 64, "%.1f", (double)gps_uart->status.course);
         canvas_draw_str_aligned(canvas, 21, 40, AlignCenter, AlignBottom, buffer);
-        if(!gps_uart->speed_in_kms) {
+
+        switch(gps_uart->speed_units) {
+        case KPH:
+            snprintf(buffer, 64, "%.2f km", (double)(gps_uart->status.speed * KNOTS_TO_KPH));
+            break;
+        case MPH:
+            snprintf(buffer, 64, "%.2f mi", (double)(gps_uart->status.speed * KNOTS_TO_MPH));
+            break;
+        case KNOTS:
+        default:
             snprintf(buffer, 64, "%.2f kn", (double)gps_uart->status.speed);
-        } else {
-            snprintf(buffer, 64, "%.2f km", (double)(gps_uart->status.speed * 1.852));
+            break;
         }
+
         canvas_draw_str_aligned(canvas, 64, 40, AlignCenter, AlignBottom, buffer);
         snprintf(
             buffer,
@@ -153,10 +163,9 @@ int32_t gps_app(void* p) {
                         view_port_update(view_port);
                         break;
                     case InputKeyRight:
-                        if(gps_uart->speed_in_kms) {
-                            gps_uart->speed_in_kms = false;
-                        } else {
-                            gps_uart->speed_in_kms = true;
+                        gps_uart->speed_units++;
+                        if(gps_uart->speed_units == INVALID) {
+                            gps_uart->speed_units = KNOTS;
                         }
                         break;
                     case InputKeyBack:

+ 5 - 3
gps_uart.h

@@ -5,8 +5,8 @@
 
 #define RX_BUF_SIZE 1024
 
-static const int gps_baudrates[5] = {9600, 19200, 38400, 57600, 115200};
-static int current_gps_baudrate = 0;
+static const int gps_baudrates[6] = {4800, 9600, 19200, 38400, 57600, 115200};
+static int current_gps_baudrate = 1;
 
 typedef struct {
     bool valid;
@@ -23,6 +23,8 @@ typedef struct {
     int time_seconds;
 } GpsStatus;
 
+typedef enum { KNOTS, KPH, MPH, INVALID } SpeedUnit;
+
 typedef struct {
     FuriMutex* mutex;
     FuriThread* thread;
@@ -33,7 +35,7 @@ typedef struct {
     uint32_t baudrate;
     bool changing_baudrate;
     bool backlight_on;
-    bool speed_in_kms;
+    SpeedUnit speed_units;
 
     GpsStatus status;
 } GpsUart;