Skip to content

Commit 20898f1

Browse files
authored
Update gps.c
1 parent 967c911 commit 20898f1

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

gps.c

+22-8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include "constants.h"
33

44
#include <furi.h>
5+
#include <furi_hal_power.h>
56
#include <gui/gui.h>
67
#include <string.h>
78

@@ -41,14 +42,14 @@ static void render_callback(Canvas* const canvas, void* context) {
4142

4243
switch(gps_uart->speed_units) {
4344
case KPH:
44-
snprintf(buffer, 64, "%.2f km", (double)(gps_uart->status.speed * KNOTS_TO_KPH));
45+
snprintf(buffer, 64, "%.2f Km/h", (double)(gps_uart->status.speed * KNOTS_TO_KPH));
4546
break;
4647
case MPH:
47-
snprintf(buffer, 64, "%.2f mi", (double)(gps_uart->status.speed * KNOTS_TO_MPH));
48+
snprintf(buffer, 64, "%.2f Mi/h", (double)(gps_uart->status.speed * KNOTS_TO_MPH));
4849
break;
4950
case KNOTS:
5051
default:
51-
snprintf(buffer, 64, "%.2f kn", (double)gps_uart->status.speed);
52+
snprintf(buffer, 64, "%.2f Kn", (double)gps_uart->status.speed);
5253
break;
5354
}
5455

@@ -94,6 +95,14 @@ int32_t gps_app(void* p) {
9495

9596
FuriMessageQueue* event_queue = furi_message_queue_alloc(8, sizeof(PluginEvent));
9697

98+
uint8_t attempts = 0;
99+
bool otg_was_enabled = furi_hal_power_is_otg_enabled();
100+
while(!furi_hal_power_is_otg_enabled() && attempts++ < 5) {
101+
furi_hal_power_enable_otg();
102+
furi_delay_ms(10);
103+
}
104+
furi_delay_ms(200);
105+
97106
GpsUart* gps_uart = gps_uart_enable();
98107

99108
gps_uart->mutex = furi_mutex_alloc(FuriMutexTypeNormal);
@@ -159,6 +168,8 @@ int32_t gps_app(void* p) {
159168

160169
gps_uart_init_thread(gps_uart);
161170
gps_uart->changing_baudrate = true;
171+
furi_mutex_release(gps_uart->mutex);
172+
view_port_update(view_port);
162173
break;
163174
case InputKeyRight:
164175
gps_uart->speed_units++;
@@ -175,11 +186,10 @@ int32_t gps_app(void* p) {
175186
}
176187
}
177188
}
178-
179-
view_port_update(view_port);
180-
furi_mutex_release(gps_uart->mutex);
181-
182-
if(gps_uart->changing_baudrate) {
189+
if(!gps_uart->changing_baudrate) {
190+
furi_mutex_release(gps_uart->mutex);
191+
view_port_update(view_port);
192+
} else {
183193
furi_delay_ms(1000);
184194
gps_uart->changing_baudrate = false;
185195
}
@@ -194,5 +204,9 @@ int32_t gps_app(void* p) {
194204
furi_mutex_free(gps_uart->mutex);
195205
gps_uart_disable(gps_uart);
196206

207+
if(furi_hal_power_is_otg_enabled() && !otg_was_enabled) {
208+
furi_hal_power_disable_otg();
209+
}
210+
197211
return 0;
198212
}

0 commit comments

Comments
 (0)