Просмотр исходного кода

add automatic 5v power in gps app

MX 2 лет назад
Родитель
Сommit
fe748fefb4
2 измененных файлов с 14 добавлено и 1 удалено
  1. 1 1
      base_pack/gps_nmea_uart/application.fam
  2. 13 0
      base_pack/gps_nmea_uart/gps.c

+ 1 - 1
base_pack/gps_nmea_uart/application.fam

@@ -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 - 0
base_pack/gps_nmea_uart/gps.c

@@ -2,6 +2,7 @@
 #include "constants.h"
 
 #include <furi.h>
+#include <furi_hal_power.h>
 #include <gui/gui.h>
 #include <string.h>
 
@@ -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);
@@ -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;
 }