Files
sonicare/uk_mbirth_sonicare.c
mbirth c1bc56500b Code cleanup
Signed-off-by: Markus Birth <markus@birth-online.de>
2026-03-30 01:13:35 +01:00

119 lines
3.5 KiB
C

#include "uk_mbirth_sonicare.h"
#include "nfc/nfc.h"
#include "nfc/nfc_device.h"
#include <nfc/protocols/mf_ultralight/mf_ultralight.h>
#include <dolphin/dolphin.h>
/* generated by fbt from .png files in images folder */
#include <uk_mbirth_sonicare_icons.h>
static bool sonicare_debug_custom_event_callback(void* context, uint32_t event) {
furi_assert(context);
Sonicare* app = context;
return scene_manager_handle_custom_event(app->scene_manager, event);
}
static bool sonicare_debug_back_event_callback(void* context) {
furi_assert(context);
Sonicare* app = context;
return scene_manager_handle_back_event(app->scene_manager);
}
static Sonicare* sonicare_alloc(void) {
Sonicare* app = malloc(sizeof(Sonicare));
app->storage = furi_record_open(RECORD_STORAGE);
app->dialogs = furi_record_open(RECORD_DIALOGS);
app->view_dispatcher = view_dispatcher_alloc();
app->scene_manager = scene_manager_alloc(&sonicare_scene_handlers, app);
view_dispatcher_set_event_callback_context(app->view_dispatcher, app);
view_dispatcher_set_custom_event_callback(app->view_dispatcher, sonicare_debug_custom_event_callback);
view_dispatcher_set_navigation_event_callback(app->view_dispatcher, sonicare_debug_back_event_callback);
// Open GUI record
app->gui = furi_record_open(RECORD_GUI);
// Open Notification record
app->notifications = furi_record_open(RECORD_NOTIFICATION);
// Submenu
app->submenu = submenu_alloc();
view_dispatcher_add_view(app->view_dispatcher, SonicareViewSubmenu, submenu_get_view(app->submenu));
// Widget
app->widget = widget_alloc();
view_dispatcher_add_view(app->view_dispatcher, SonicareViewWidget, widget_get_view(app->widget));
// Popup
app->popup = popup_alloc();
view_dispatcher_add_view(app->view_dispatcher, SonicareViewPopup, popup_get_view(app->popup));
// NFC
app->nfc = nfc_alloc();
app->nfc_device = nfc_device_alloc();
app->nfc_data = mf_ultralight_alloc();
return app;
}
static void sonicare_free(Sonicare* app) {
furi_assert(app);
// NFC
mf_ultralight_free(app->nfc_data);
nfc_device_free(app->nfc_device);
nfc_free(app->nfc);
// Popup
view_dispatcher_remove_view(app->view_dispatcher, SonicareViewPopup);
popup_free(app->popup);
// Widget
view_dispatcher_remove_view(app->view_dispatcher, SonicareViewWidget);
widget_free(app->widget);
// Submenu
view_dispatcher_remove_view(app->view_dispatcher, SonicareViewSubmenu);
submenu_free(app->submenu);
view_dispatcher_free(app->view_dispatcher);
scene_manager_free(app->scene_manager);
furi_record_close(RECORD_GUI);
app->gui = NULL;
furi_record_close(RECORD_NOTIFICATION);
app->notifications = NULL;
furi_record_close(RECORD_STORAGE);
furi_record_close(RECORD_DIALOGS);
free(app);
}
int32_t sonicare_app(void* p) {
Sonicare* app = sonicare_alloc();
UNUSED(p);
//char* args = p;
view_dispatcher_attach_to_gui(
app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen);
scene_manager_next_scene(app->scene_manager, SonicareSceneStart);
view_dispatcher_run(app->view_dispatcher);
sonicare_free(app);
return 0;
}
void sonicare_widget_callback(GuiButtonType result, InputType type, void* context) {
Sonicare* app = context;
if (type == InputTypeShort) {
view_dispatcher_send_custom_event(app->view_dispatcher, result);
}
}