ソースを参照

Merge wav_player from https://github.com/xMasterX/all-the-plugins

# Conflicts:
#	wav_player/wav_player.c
Willy-JL 1 年間 前
コミット
73d51ebe59

+ 1 - 1
wav_player/application.fam

@@ -10,6 +10,6 @@ App(
     fap_category="Media",
     fap_icon_assets="images",
     fap_author="@DrZlo13 & (ported, fixed by @xMasterX), (improved by @LTVA1)",
-    fap_version="1.2",
+    fap_version="1.3",
     fap_description="Audio player for WAV files, recommended to convert files to unsigned 8-bit PCM stereo, but it may work with others too",
 )

+ 2 - 4
wav_player/wav_parser.h

@@ -3,12 +3,10 @@
 
 #include <furi.h>
 #include <furi_hal.h>
-#include <cli/cli.h>
 #include <gui/gui.h>
-#include <stm32wbxx_ll_dma.h>
 #include <dialogs/dialogs.h>
 #include <notification/notification_messages.h>
-#include <gui/view_dispatcher.h>
+#include <gui/view_holder.h>
 #include <toolbox/stream/file_stream.h>
 
 #include "wav_player_view.h"
@@ -67,7 +65,7 @@ typedef struct {
     bool play;
 
     WavPlayerView* view;
-    ViewDispatcher* view_dispatcher;
+    ViewHolder* view_holder;
     Gui* gui;
     NotificationApp* notification;
 

+ 27 - 15
wav_player/wav_player.c

@@ -1,12 +1,7 @@
 #include <furi.h>
 #include <furi_hal.h>
-#include <cli/cli.h>
 #include <gui/gui.h>
 #include <stm32wbxx_ll_dma.h>
-#include <dialogs/dialogs.h>
-#include <notification/notification_messages.h>
-#include <gui/view_dispatcher.h>
-#include <toolbox/stream/file_stream.h>
 #include "wav_player_hal.h"
 #include "wav_parser.h"
 #include "wav_player_view.h"
@@ -84,6 +79,23 @@ static void wav_player_dma_isr(void* ctx) {
     }
 }
 
+static void exit_callback(void* ctx) {
+    FuriMessageQueue* event_queue = ctx;
+
+    WavPlayerEvent event;
+    event.type = WavPlayerEventCtrlBack;
+    furi_message_queue_put(event_queue, &event, 0);
+}
+
+static bool thread_exit_signal_callback(uint32_t signal, void* arg, void* ctx) {
+    UNUSED(arg);
+    if(signal == FuriSignalExit) {
+        exit_callback(ctx);
+        return true;
+    }
+    return false;
+}
+
 static WavPlayerApp* app_alloc() {
     WavPlayerApp* app = malloc(sizeof(WavPlayerApp));
     app->samples_count_half = 1024 * 4;
@@ -99,24 +111,28 @@ static WavPlayerApp* app_alloc() {
     app->play = true;
 
     app->gui = furi_record_open(RECORD_GUI);
-    app->view_dispatcher = view_dispatcher_alloc();
+    app->view_holder = view_holder_alloc();
     app->view = wav_player_view_alloc();
 
     app->path = furi_string_alloc();
 
-    view_dispatcher_add_view(app->view_dispatcher, 0, wav_player_view_get_view(app->view));
-    view_dispatcher_attach_to_gui(app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen);
-    view_dispatcher_switch_to_view(app->view_dispatcher, 0);
+    view_holder_set_back_callback(app->view_holder, exit_callback, app->queue);
+    view_holder_attach_to_gui(app->view_holder, app->gui);
+    view_holder_set_view(app->view_holder, wav_player_view_get_view(app->view));
+    view_holder_send_to_front(app->view_holder);
 
     app->notification = furi_record_open(RECORD_NOTIFICATION);
     notification_message(app->notification, &sequence_display_backlight_enforce_on);
 
+    furi_thread_set_signal_callback(
+        furi_thread_get_current(), thread_exit_signal_callback, app->queue);
+
     return app;
 }
 
 static void app_free(WavPlayerApp* app) {
-    view_dispatcher_remove_view(app->view_dispatcher, 0);
-    view_dispatcher_free(app->view_dispatcher);
+    view_holder_set_view(app->view_holder, NULL);
+    view_holder_free(app->view_holder);
     wav_player_view_free(app->view);
     furi_record_close(RECORD_GUI);
 
@@ -341,10 +357,6 @@ static void ctrl_callback(WavPlayerCtrl ctrl, void* ctx) {
         event.type = WavPlayerEventCtrlOk;
         furi_message_queue_put(event_queue, &event, 0);
         break;
-    case WavPlayerCtrlBack:
-        event.type = WavPlayerEventCtrlBack;
-        furi_message_queue_put(event_queue, &event, 0);
-        break;
     default:
         break;
     }

+ 0 - 3
wav_player/wav_player_view.c

@@ -100,9 +100,6 @@ static bool wav_player_view_input_callback(InputEvent* event, void* context) {
             } else if(event->key == InputKeyOk) {
                 wav_player_view->callback(WavPlayerCtrlOk, wav_player_view->context);
                 consumed = true;
-            } else if(event->key == InputKeyBack) {
-                wav_player_view->callback(WavPlayerCtrlBack, wav_player_view->context);
-                consumed = true;
             }
         }
     }

+ 1 - 8
wav_player/wav_player_view.h

@@ -3,13 +3,7 @@
 
 #include <furi.h>
 #include <furi_hal.h>
-#include <cli/cli.h>
-#include <gui/gui.h>
-#include <stm32wbxx_ll_dma.h>
-#include <dialogs/dialogs.h>
-#include <notification/notification_messages.h>
-#include <gui/view_dispatcher.h>
-#include <toolbox/stream/file_stream.h>
+#include <gui/view.h>
 
 #ifdef __cplusplus
 extern "C" {
@@ -23,7 +17,6 @@ typedef enum {
     WavPlayerCtrlMoveL,
     WavPlayerCtrlMoveR,
     WavPlayerCtrlOk,
-    WavPlayerCtrlBack,
 } WavPlayerCtrl;
 
 typedef void (*WavPlayerCtrlCallback)(WavPlayerCtrl ctrl, void* context);