Jelajahi Sumber

Add ocarina from https://github.com/xMasterX/all-the-plugins

git-subtree-dir: ocarina
git-subtree-mainline: 1981f4fbeebf469e0e6ddada5f3f45b1e8eea278
git-subtree-split: 597d8de131f6a801e5f2cb0ccb8c491d89508472
Willy-JL 2 tahun lalu
induk
melakukan
9f94fb64aa
7 mengubah file dengan 156 tambahan dan 0 penghapusan
  1. 1 0
      ocarina/.gitsubtree
  2. 4 0
      ocarina/README.md
  3. 17 0
      ocarina/application.fam
  4. TEMPAT SAMPAH
      ocarina/icons/music_10px.png
  5. TEMPAT SAMPAH
      ocarina/img/1.png
  6. TEMPAT SAMPAH
      ocarina/music_10px.png
  7. 134 0
      ocarina/ocarina.c

+ 1 - 0
ocarina/.gitsubtree

@@ -0,0 +1 @@
+https://github.com/xMasterX/all-the-plugins dev apps_source_code/ocarina

+ 4 - 0
ocarina/README.md

@@ -0,0 +1,4 @@
+# flipperzero-ocarina
+A basic Ocarina (of Time) for the Flipper Zero.
+
+Controls are the same as the N64 version of the Ocarina of Time, the Ok button takes the place of the A button

+ 17 - 0
ocarina/application.fam

@@ -0,0 +1,17 @@
+App(
+    appid="ocarina",
+    name="Ocarina",
+    apptype=FlipperAppType.EXTERNAL,
+    entry_point="ocarina_app",
+    cdefines=["APP_OCARINA"],
+    requires=["gui"],
+    stack_size=1 * 1024,
+    order=30,
+    fap_icon="icons/music_10px.png",
+    fap_category="Media",
+    fap_icon_assets="icons",
+    fap_author="@invalidna-me",
+    fap_weburl="https://github.com/invalidna-me/flipperzero-ocarina",
+    fap_version="1.1",
+    fap_description="A basic Ocarina (of Time), Controls are the same as the N64 version of the Ocarina of Time",
+)

TEMPAT SAMPAH
ocarina/icons/music_10px.png


TEMPAT SAMPAH
ocarina/img/1.png


TEMPAT SAMPAH
ocarina/music_10px.png


+ 134 - 0
ocarina/ocarina.c

@@ -0,0 +1,134 @@
+#include <furi.h>
+#include <furi_hal.h>
+#include <gui/gui.h>
+#include <input/input.h>
+#include <stdlib.h>
+
+#define NOTE_UP 587.33f
+#define NOTE_LEFT 493.88f
+#define NOTE_RIGHT 440.00f
+#define NOTE_DOWN 349.23
+#define NOTE_OK 293.66f
+
+typedef struct {
+    FuriMutex* model_mutex;
+
+    FuriMessageQueue* event_queue;
+
+    ViewPort* view_port;
+    Gui* gui;
+} Ocarina;
+
+void draw_callback(Canvas* canvas, void* ctx) {
+    Ocarina* ocarina = ctx;
+    furi_check(furi_mutex_acquire(ocarina->model_mutex, FuriWaitForever) == FuriStatusOk);
+
+    //canvas_draw_box(canvas, ocarina->model->x, ocarina->model->y, 4, 4);
+    canvas_draw_frame(canvas, 0, 0, 128, 64);
+    canvas_draw_str(canvas, 50, 10, "Ocarina");
+    canvas_draw_str(canvas, 30, 20, "OK button for A");
+
+    furi_mutex_release(ocarina->model_mutex);
+}
+
+void input_callback(InputEvent* input, void* ctx) {
+    Ocarina* ocarina = ctx;
+    // Puts input onto event queue with priority 0, and waits until completion.
+    furi_message_queue_put(ocarina->event_queue, input, FuriWaitForever);
+}
+
+Ocarina* ocarina_alloc() {
+    Ocarina* instance = malloc(sizeof(Ocarina));
+
+    instance->model_mutex = furi_mutex_alloc(FuriMutexTypeNormal);
+
+    instance->event_queue = furi_message_queue_alloc(8, sizeof(InputEvent));
+
+    instance->view_port = view_port_alloc();
+    view_port_draw_callback_set(instance->view_port, draw_callback, instance);
+    view_port_input_callback_set(instance->view_port, input_callback, instance);
+
+    instance->gui = furi_record_open("gui");
+    gui_add_view_port(instance->gui, instance->view_port, GuiLayerFullscreen);
+
+    return instance;
+}
+
+void ocarina_free(Ocarina* instance) {
+    view_port_enabled_set(instance->view_port, false); // Disabsles our ViewPort
+    gui_remove_view_port(instance->gui, instance->view_port); // Removes our ViewPort from the Gui
+    furi_record_close("gui"); // Closes the gui record
+    view_port_free(instance->view_port); // Frees memory allocated by view_port_alloc
+    furi_message_queue_free(instance->event_queue);
+
+    furi_mutex_free(instance->model_mutex);
+
+    if(furi_hal_speaker_is_mine()) {
+        furi_hal_speaker_stop();
+        furi_hal_speaker_release();
+    }
+
+    free(instance);
+}
+
+int32_t ocarina_app(void* p) {
+    UNUSED(p);
+
+    Ocarina* ocarina = ocarina_alloc();
+
+    InputEvent event;
+    for(bool processing = true; processing;) {
+        // Pops a message off the queue and stores it in `event`.
+        // No message priority denoted by NULL, and 100 ticks of timeout.
+        FuriStatus status = furi_message_queue_get(ocarina->event_queue, &event, 100);
+        furi_check(furi_mutex_acquire(ocarina->model_mutex, FuriWaitForever) == FuriStatusOk);
+
+        float volume = 1.0f;
+        if(status == FuriStatusOk) {
+            if(event.type == InputTypePress) {
+                switch(event.key) {
+                case InputKeyUp:
+                    if(furi_hal_speaker_is_mine() || furi_hal_speaker_acquire(1000)) {
+                        furi_hal_speaker_start(NOTE_UP, volume);
+                    }
+                    break;
+                case InputKeyDown:
+                    if(furi_hal_speaker_is_mine() || furi_hal_speaker_acquire(1000)) {
+                        furi_hal_speaker_start(NOTE_DOWN, volume);
+                    }
+                    break;
+                case InputKeyLeft:
+                    if(furi_hal_speaker_is_mine() || furi_hal_speaker_acquire(1000)) {
+                        furi_hal_speaker_start(NOTE_LEFT, volume);
+                    }
+                    break;
+                case InputKeyRight:
+                    if(furi_hal_speaker_is_mine() || furi_hal_speaker_acquire(1000)) {
+                        furi_hal_speaker_start(NOTE_RIGHT, volume);
+                    }
+                    break;
+                case InputKeyOk:
+                    if(furi_hal_speaker_is_mine() || furi_hal_speaker_acquire(1000)) {
+                        furi_hal_speaker_start(NOTE_OK, volume);
+                    }
+                    break;
+                case InputKeyBack:
+                    processing = false;
+                    break;
+                default:
+                    break;
+                }
+            } else if(event.type == InputTypeRelease) {
+                if(furi_hal_speaker_is_mine()) {
+                    furi_hal_speaker_stop();
+                    furi_hal_speaker_release();
+                }
+            }
+        }
+
+        furi_mutex_release(ocarina->model_mutex);
+        view_port_update(ocarina->view_port); // signals our draw callback
+    }
+    ocarina_free(ocarina);
+    return 0;
+}