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

fix uart related plugins to disable expansion protocol

MX 1 год назад
Родитель
Сommit
db2eff08ff
1 измененных файлов с 12 добавлено и 0 удалено
  1. 12 0
      hc_sr04.c

+ 12 - 0
hc_sr04.c

@@ -11,6 +11,7 @@
 #include <gui/elements.h>
 #include <notification/notification.h>
 #include <notification/notification_messages.h>
+#include <expansion/expansion.h>
 
 typedef enum {
     EventTypeTick,
@@ -176,6 +177,10 @@ static void hc_sr04_measure(PluginState* const plugin_state) {
 }
 
 int32_t hc_sr04_app() {
+    // Disable expansion protocol to avoid interference with UART Handle
+    Expansion* expansion = furi_record_open(RECORD_EXPANSION);
+    expansion_disable(expansion);
+
     FuriMessageQueue* event_queue = furi_message_queue_alloc(8, sizeof(PluginEvent));
 
     PluginState* plugin_state = malloc(sizeof(PluginState));
@@ -194,6 +199,9 @@ int32_t hc_sr04_app() {
         furi_hal_power_suppress_charge_exit();
         furi_message_queue_free(event_queue);
         free(plugin_state);
+        // Return previous state of expansion
+        expansion_enable(expansion);
+        furi_record_close(RECORD_EXPANSION);
         return 255;
     }
 
@@ -270,5 +278,9 @@ int32_t hc_sr04_app() {
     furi_mutex_free(plugin_state->mutex);
     free(plugin_state);
 
+    // Return previous state of expansion
+    expansion_enable(expansion);
+    furi_record_close(RECORD_EXPANSION);
+
     return 0;
 }