Skip to content

Commit

Permalink
add automatic 5v power in gps app
Browse files Browse the repository at this point in the history
  • Loading branch information
xMasterX committed Oct 10, 2023
1 parent dbd100e commit 9cb005d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion application.fam
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ App(
fap_icon="gps_10px.png",
fap_category="GPIO",
fap_author="@ezod & @xMasterX",
fap_version="1.1",
fap_version="1.2",
fap_description="Works with GPS modules via UART, using NMEA protocol.",
)
13 changes: 13 additions & 0 deletions gps.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "constants.h"

#include <furi.h>
#include <furi_hal_power.h>
#include <gui/gui.h>
#include <string.h>

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

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

uint8_t attempts = 0;
bool otg_was_enabled = furi_hal_power_is_otg_enabled();
while(!furi_hal_power_is_otg_enabled() && attempts++ < 5) {
furi_hal_power_enable_otg();
furi_delay_ms(10);
}
furi_delay_ms(200);

GpsUart* gps_uart = gps_uart_enable();

gps_uart->mutex = furi_mutex_alloc(FuriMutexTypeNormal);
Expand Down Expand Up @@ -195,5 +204,9 @@ int32_t gps_app(void* p) {
furi_mutex_free(gps_uart->mutex);
gps_uart_disable(gps_uart);

if(furi_hal_power_is_otg_enabled() && !otg_was_enabled) {
furi_hal_power_disable_otg();
}

return 0;
}

0 comments on commit 9cb005d

Please sign in to comment.