Przeglądaj źródła

Add external infrared board support

RocketGod 1 rok temu
rodzic
commit
16082f59eb
3 zmienionych plików z 57 dodań i 9 usunięć
  1. 42 8
      infrared_controller.c
  2. 13 1
      infrared_controller.h
  3. 2 0
      laser_tag_app.c

+ 42 - 8
infrared_controller.c

@@ -3,6 +3,9 @@
 #include <infrared_worker.h>
 #include <infrared_worker.h>
 #include <infrared_signal.h>
 #include <infrared_signal.h>
 #include <notification/notification_messages.h>
 #include <notification/notification_messages.h>
+#include <furi_hal_gpio.h>
+#include <furi_hal_power.h>
+#include <furi_hal_infrared.h>
 
 
 #define TAG "InfraredController"
 #define TAG "InfraredController"
 
 
@@ -15,16 +18,47 @@ const NotificationSequence sequence_hit = {
     NULL,
     NULL,
 };
 };
 
 
-struct InfraredController {
-    LaserTagTeam team;
-    InfraredWorker* worker;
-    bool worker_rx_active;
-    InfraredSignal* signal;
-    NotificationApp* notification;
-    bool hit_received;
-    bool processing_signal;
+const NotificationSequence sequence_bloop = {
+    &message_note_g3,
+    &message_delay_50,
+    &message_sound_off,
+    NULL,
 };
 };
 
 
+extern const NotificationSequence sequence_short_beep;
+
+static bool external_board_connected = false;
+
+static void infrared_setup_external_board(bool enable) {
+    if(enable) {
+        furi_hal_gpio_init(&gpio_ext_pa7, GpioModeOutputPushPull, GpioPullNo, GpioSpeedVeryHigh);
+        furi_hal_power_enable_otg();
+        furi_hal_infrared_set_tx_output(FuriHalInfraredTxPinExtPA7);
+    } else {
+        furi_hal_gpio_init(&gpio_ext_pa7, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
+        furi_hal_power_disable_otg();
+        furi_hal_infrared_set_tx_output(FuriHalInfraredTxPinInternal);
+    }
+}
+
+void update_infrared_board_status(InfraredController* controller) {
+    if(!controller || !controller->notification) return;
+
+    FuriHalInfraredTxPin detected_pin = furi_hal_infrared_detect_tx_output();
+
+    if(detected_pin == FuriHalInfraredTxPinExtPA7 && !external_board_connected) {
+        external_board_connected = true;
+        infrared_setup_external_board(true);
+        notification_message(controller->notification, &sequence_short_beep);
+        FURI_LOG_I(TAG, "External infrared board connected and powered.");
+    } else if(detected_pin == FuriHalInfraredTxPinInternal && external_board_connected) {
+        external_board_connected = false;
+        infrared_setup_external_board(false);
+        notification_message(controller->notification, &sequence_bloop);
+        FURI_LOG_I(TAG, "External infrared board disconnected and power disabled.");
+    }
+}
+
 static void infrared_rx_callback(void* context, InfraredWorkerSignal* received_signal) {
 static void infrared_rx_callback(void* context, InfraredWorkerSignal* received_signal) {
     FURI_LOG_I(TAG, "RX callback triggered");
     FURI_LOG_I(TAG, "RX callback triggered");
 
 

+ 13 - 1
infrared_controller.h

@@ -1,15 +1,27 @@
 #pragma once
 #pragma once
 
 
 #include <stdbool.h>
 #include <stdbool.h>
+#include <notification/notification.h>
+#include <infrared_worker.h>
+#include <infrared_signal.h>
 #include "game_state.h"
 #include "game_state.h"
 
 
-typedef struct InfraredController InfraredController;
+typedef struct InfraredController {
+    LaserTagTeam team;
+    InfraredWorker* worker;
+    bool worker_rx_active;
+    InfraredSignal* signal;
+    NotificationApp* notification;
+    bool hit_received;
+    bool processing_signal;
+} InfraredController;
 
 
 InfraredController* infrared_controller_alloc();
 InfraredController* infrared_controller_alloc();
 void infrared_controller_free(InfraredController* controller);
 void infrared_controller_free(InfraredController* controller);
 void infrared_controller_set_team(InfraredController* controller, LaserTagTeam team);
 void infrared_controller_set_team(InfraredController* controller, LaserTagTeam team);
 void infrared_controller_send(InfraredController* controller);
 void infrared_controller_send(InfraredController* controller);
 bool infrared_controller_receive(InfraredController* controller);
 bool infrared_controller_receive(InfraredController* controller);
+void update_infrared_board_status(InfraredController* controller);
 void infrared_controller_pause(InfraredController* controller);
 void infrared_controller_pause(InfraredController* controller);
 void infrared_controller_resume(InfraredController* controller);
 void infrared_controller_resume(InfraredController* controller);
 
 

+ 2 - 0
laser_tag_app.c

@@ -361,6 +361,8 @@ int32_t laser_tag_app(void* p) {
     while(running) {
     while(running) {
         FURI_LOG_D(TAG, "Start of main loop iteration");
         FURI_LOG_D(TAG, "Start of main loop iteration");
 
 
+        update_infrared_board_status(app->ir_controller);
+
         FuriStatus status = furi_message_queue_get(app->event_queue, &event, 100);
         FuriStatus status = furi_message_queue_get(app->event_queue, &event, 100);
         if(status == FuriStatusOk) {
         if(status == FuriStatusOk) {
             FURI_LOG_D(TAG, "Received input event: type=%d, key=%d", event.type, event.key);
             FURI_LOG_D(TAG, "Received input event: type=%d, key=%d", event.type, event.key);