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

WAV Player: Migrate to View Holder

Fixes input not working after the Event Loop was introduced to the firmware
Silent 1 год назад
Родитель
Сommit
22b8b38824
5 измененных файлов с 35 добавлено и 39 удалено
  1. 1 1
      application.fam
  2. 2 4
      wav_parser.h
  3. 27 15
      wav_player.c
  4. 4 11
      wav_player_view.c
  5. 1 8
      wav_player_view.h

+ 1 - 1
application.fam

@@ -9,6 +9,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_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;
 } WavPlayerApp;

+ 27 - 15
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"
@@ -79,6 +74,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;
@@ -94,22 +106,26 @@ 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();
 
-    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);
 
@@ -332,10 +348,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;
     }

+ 4 - 11
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;
             }
         }
     }
@@ -134,20 +131,17 @@ View* wav_player_view_get_view(WavPlayerView* wav_view) {
 
 void wav_player_view_set_volume(WavPlayerView* wav_view, float volume) {
     furi_assert(wav_view);
-    with_view_model(
-        wav_view->view, WavPlayerViewModel * model, { model->volume = volume; }, true);
+    with_view_model(wav_view->view, WavPlayerViewModel * model, { model->volume = volume; }, true);
 }
 
 void wav_player_view_set_start(WavPlayerView* wav_view, size_t start) {
     furi_assert(wav_view);
-    with_view_model(
-        wav_view->view, WavPlayerViewModel * model, { model->start = start; }, true);
+    with_view_model(wav_view->view, WavPlayerViewModel * model, { model->start = start; }, true);
 }
 
 void wav_player_view_set_end(WavPlayerView* wav_view, size_t end) {
     furi_assert(wav_view);
-    with_view_model(
-        wav_view->view, WavPlayerViewModel * model, { model->end = end; }, true);
+    with_view_model(wav_view->view, WavPlayerViewModel * model, { model->end = end; }, true);
 }
 
 void wav_player_view_set_current(WavPlayerView* wav_view, size_t current) {
@@ -158,8 +152,7 @@ void wav_player_view_set_current(WavPlayerView* wav_view, size_t current) {
 
 void wav_player_view_set_play(WavPlayerView* wav_view, bool play) {
     furi_assert(wav_view);
-    with_view_model(
-        wav_view->view, WavPlayerViewModel * model, { model->play = play; }, true);
+    with_view_model(wav_view->view, WavPlayerViewModel * model, { model->play = play; }, true);
 }
 
 void wav_player_view_set_chans(WavPlayerView* wav_view, uint16_t chn) {

+ 1 - 8
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);