|
|
@@ -1,140 +0,0 @@
|
|
|
-#include <gui/canvas.h>
|
|
|
-#include <gui/modules/menu.h>
|
|
|
-#include <gui/modules/submenu.h>
|
|
|
-#include <gui/modules/variable_item_list.h>
|
|
|
-
|
|
|
-/* generated by fbt from .png files in images folder */
|
|
|
-#include <tone_gen_icons.h>
|
|
|
-
|
|
|
-#include "app_context.h"
|
|
|
-#include "tone_gen.h"
|
|
|
-
|
|
|
-#include "scenes/starting_scene.h"
|
|
|
-#include "scenes/playback_scene.h"
|
|
|
-#include "scenes/settings_scene.h"
|
|
|
-
|
|
|
-/** collection of all scene on_enter handlers - in the same order as their enum */
|
|
|
-void (*const scene_on_enter_handlers[])(void*) = {
|
|
|
- scene_on_enter_starting_scene,
|
|
|
- scene_on_enter_playback_scene,
|
|
|
- scene_on_enter_settings_scene,
|
|
|
-};
|
|
|
-
|
|
|
-/** collection of all scene on event handlers - in the same order as their enum */
|
|
|
-bool (*const scene_on_event_handlers[])(void*, SceneManagerEvent) = {
|
|
|
- scene_on_event_starting_scene,
|
|
|
- scene_on_event_playback_scene,
|
|
|
- scene_on_event_settings_scene,
|
|
|
-};
|
|
|
-
|
|
|
-/** collection of all scene on exit handlers - in the same order as their enum */
|
|
|
-void (*const scene_on_exit_handlers[])(void*) = {
|
|
|
- scene_on_exit_starting_scene,
|
|
|
- scene_on_exit_playback_scene,
|
|
|
- scene_on_exit_settings_scene,
|
|
|
-};
|
|
|
-
|
|
|
-const SceneManagerHandlers scene_event_handlers = {
|
|
|
- .on_enter_handlers = scene_on_enter_handlers,
|
|
|
- .on_event_handlers = scene_on_event_handlers,
|
|
|
- .on_exit_handlers = scene_on_exit_handlers,
|
|
|
- .scene_num = ToneGenAppScene_count};
|
|
|
-
|
|
|
-int setupViews(struct AppContext_t** appContext) {
|
|
|
- // Create views
|
|
|
- FURI_LOG_I(TAG, "Creating views");
|
|
|
- struct View_t* sharedMenuView = malloc(sizeof(struct View_t));
|
|
|
- sharedMenuView->viewData = menu_alloc();
|
|
|
- sharedMenuView->viewId = ToneGenAppView_SharedMenu;
|
|
|
- sharedMenuView->type = MENU;
|
|
|
-
|
|
|
- struct View_t* submenuView = malloc(sizeof(struct View_t));
|
|
|
- submenuView->viewData = submenu_alloc();
|
|
|
- submenuView->viewId = ToneGenAppView_Submenu;
|
|
|
- submenuView->type = SUBMENU;
|
|
|
-
|
|
|
- struct View_t* playbackView = malloc(sizeof(struct View_t));
|
|
|
- playbackView->viewData = view_alloc();
|
|
|
- playbackView->viewId = ToneGenAppView_PlaybackView;
|
|
|
- playbackView->type = VIEW;
|
|
|
-
|
|
|
- FURI_LOG_I(TAG, "creating var-item-list view");
|
|
|
- struct View_t* variableItemListView = malloc(sizeof(struct View_t));
|
|
|
- FURI_LOG_I(TAG, "allocating view data");
|
|
|
- variableItemListView->viewData = variable_item_list_alloc();
|
|
|
- FURI_LOG_I(TAG, "setting view id");
|
|
|
- variableItemListView->viewId = ToneGenAppView_VariableItemList;
|
|
|
- FURI_LOG_I(TAG, "setting view type");
|
|
|
- variableItemListView->type = VARIABLE_ITEM_LIST;
|
|
|
- FURI_LOG_I(TAG, "moving on");
|
|
|
-
|
|
|
- // Add views to the app context to be managed there
|
|
|
- FURI_LOG_I(TAG, "Adding views to app context");
|
|
|
- AppContextStatus result = addViewToAppContext(appContext, sharedMenuView);
|
|
|
- if(result != APP_CONTEXT_OK) {
|
|
|
- FURI_LOG_E(TAG, "There was a problem adding the view %d!", sharedMenuView->viewId);
|
|
|
- return -1;
|
|
|
- }
|
|
|
-
|
|
|
- result = addViewToAppContext(appContext, submenuView);
|
|
|
- if(result != APP_CONTEXT_OK) {
|
|
|
- FURI_LOG_E(TAG, "There was a problem adding the view %d!", submenuView->viewId);
|
|
|
- return -1;
|
|
|
- }
|
|
|
-
|
|
|
- result = addViewToAppContext(appContext, playbackView);
|
|
|
- if(result != APP_CONTEXT_OK) {
|
|
|
- FURI_LOG_E(TAG, "There was a problem adding the view %d!", playbackView->viewId);
|
|
|
- return -1;
|
|
|
- }
|
|
|
-
|
|
|
- FURI_LOG_I(TAG, "Adding variable item list view");
|
|
|
- result = addViewToAppContext(appContext, variableItemListView);
|
|
|
- if(result != APP_CONTEXT_OK) {
|
|
|
- FURI_LOG_E(TAG, "There was a problem adding the view %d!", variableItemListView->viewId);
|
|
|
- return -1;
|
|
|
- }
|
|
|
-
|
|
|
- // On the playback view, ensure we only allocate for the model once
|
|
|
- FURI_LOG_I(TAG, "allocating view model for playback");
|
|
|
- view_allocate_model(playbackView->viewData, ViewModelTypeLockFree, sizeof(struct ToneData_t));
|
|
|
-
|
|
|
- return 0;
|
|
|
-}
|
|
|
-
|
|
|
-int32_t tone_gen_app(void* p) {
|
|
|
- UNUSED(p);
|
|
|
-
|
|
|
- FURI_LOG_I(TAG, "Tone gen app starting...");
|
|
|
-
|
|
|
- struct AppContext_t* appContext;
|
|
|
- AppContextStatus result =
|
|
|
- initializeAppContext(&appContext, ToneGenAppView_count, &scene_event_handlers);
|
|
|
-
|
|
|
- if(result == APP_CONTEXT_OK) {
|
|
|
- appContext->additionalData = malloc(sizeof(struct ToneData_t));
|
|
|
- ((struct ToneData_t*)appContext->additionalData)->animationOffset = 0;
|
|
|
- ((struct ToneData_t*)appContext->additionalData)->frequency = 440;
|
|
|
- ((struct ToneData_t*)appContext->additionalData)->waveType = SINE;
|
|
|
- ((struct ToneData_t*)appContext->additionalData)->volume = 1.0f;
|
|
|
-
|
|
|
- result = setupViews(&appContext);
|
|
|
- if(result == 0) {
|
|
|
- // set the scene and launch the main loop
|
|
|
- FURI_LOG_D(TAG, "Setting the scene");
|
|
|
- Gui* gui = furi_record_open(RECORD_GUI);
|
|
|
- view_dispatcher_attach_to_gui(
|
|
|
- appContext->view_dispatcher, gui, ViewDispatcherTypeFullscreen);
|
|
|
- scene_manager_next_scene(appContext->scene_manager, ToneGenAppScene_Starting);
|
|
|
- FURI_LOG_D(TAG, "Starting the view dispatcher");
|
|
|
- view_dispatcher_run(appContext->view_dispatcher);
|
|
|
- }
|
|
|
-
|
|
|
- // free all memory
|
|
|
- FURI_LOG_D(TAG, "Ending the app");
|
|
|
- furi_record_close(RECORD_GUI);
|
|
|
- freeAppContext(&appContext);
|
|
|
- return 0;
|
|
|
- }
|
|
|
- return -1;
|
|
|
-}
|