From 046fb6323525c6ec416dcea651c3a09620410561 Mon Sep 17 00:00:00 2001 From: Alexander Kopachov Date: Thu, 9 Mar 2023 13:10:29 +0100 Subject: [PATCH] Updated firmware references (#88) * * Updated firmware references * Updated code to make it compatible with latest firmware changes * Dropped useless check --- flipperzero-firmware_official_dev | 2 +- totp/totp_app.c | 60 +++++++++++++++--------------- totp/types/plugin_state.h | 5 +++ totp/workers/type_code/type_code.c | 17 +++++---- 4 files changed, 45 insertions(+), 39 deletions(-) diff --git a/flipperzero-firmware_official_dev b/flipperzero-firmware_official_dev index 9ae58f5462b..50ef5deefc2 160000 --- a/flipperzero-firmware_official_dev +++ b/flipperzero-firmware_official_dev @@ -1 +1 @@ -Subproject commit 9ae58f5462b1a4d8efba88e0ac24cd1fff83ede6 +Subproject commit 50ef5deefc2f6b4dc1a5c89432e7a03094e9ba7d diff --git a/totp/totp_app.c b/totp/totp_app.c index f791e99de66..7b764f854d6 100644 --- a/totp/totp_app.c +++ b/totp/totp_app.c @@ -23,12 +23,12 @@ #define IDLE_TIMEOUT 60000 static void render_callback(Canvas* const canvas, void* ctx) { - PluginState* plugin_state = acquire_mutex((ValueMutex*)ctx, 25); - if(plugin_state != NULL) { + furi_assert(ctx); + PluginState* plugin_state = ctx; + if (furi_mutex_acquire(plugin_state->mutex, 25) == FuriStatusOk) { totp_scene_director_render(canvas, plugin_state); + furi_mutex_release(plugin_state->mutex); } - - release_mutex((ValueMutex*)ctx, plugin_state); } static void input_callback(InputEvent* input_event, FuriMessageQueue* event_queue) { @@ -102,6 +102,12 @@ static bool totp_plugin_state_init(PluginState* const plugin_state) { return false; } + plugin_state->mutex = furi_mutex_alloc(FuriMutexTypeNormal); + if (plugin_state->mutex == NULL) { + FURI_LOG_E(LOGGING_TAG, "Cannot create mutex\r\n"); + return false; + } + return true; } @@ -123,6 +129,8 @@ static void totp_plugin_state_free(PluginState* plugin_state) { if(plugin_state->crypto_verify_data != NULL) { free(plugin_state->crypto_verify_data); } + + furi_mutex_free(plugin_state->mutex); free(plugin_state); } @@ -137,13 +145,6 @@ int32_t totp_app() { return 254; } - ValueMutex state_mutex; - if(!init_mutex(&state_mutex, plugin_state, sizeof(PluginState))) { - FURI_LOG_E(LOGGING_TAG, "Cannot create mutex\r\n"); - totp_plugin_state_free(plugin_state); - return 255; - } - TotpCliContext* cli_context = totp_cli_register_command_handler(plugin_state, event_queue); totp_scene_director_init_scenes(plugin_state); if(!totp_activate_initial_scene(plugin_state)) { @@ -157,7 +158,7 @@ int32_t totp_app() { // Set system callbacks ViewPort* view_port = view_port_alloc(); - view_port_draw_callback_set(view_port, render_callback, &state_mutex); + view_port_draw_callback_set(view_port, render_callback, plugin_state); view_port_input_callback_set(view_port, input_callback, event_queue); // Open GUI and register view_port @@ -169,26 +170,26 @@ int32_t totp_app() { while(processing) { FuriStatus event_status = furi_message_queue_get(event_queue, &event, 100); - PluginState* plugin_state_m = acquire_mutex_block(&state_mutex); - - if(event_status == FuriStatusOk) { - if(event.type == EventTypeKey) { - last_user_interaction_time = furi_get_tick(); + if (furi_mutex_acquire(plugin_state->mutex, FuriWaitForever) == FuriStatusOk) { + if(event_status == FuriStatusOk) { + if(event.type == EventTypeKey) { + last_user_interaction_time = furi_get_tick(); + } + + if(event.type == EventForceCloseApp) { + processing = false; + } else { + processing = totp_scene_director_handle_event(&event, plugin_state); + } + } else if( + plugin_state->pin_set && plugin_state->current_scene != TotpSceneAuthentication && + furi_get_tick() - last_user_interaction_time > IDLE_TIMEOUT) { + totp_scene_director_activate_scene(plugin_state, TotpSceneAuthentication, NULL); } - if(event.type == EventForceCloseApp) { - processing = false; - } else { - processing = totp_scene_director_handle_event(&event, plugin_state_m); - } - } else if( - plugin_state_m->pin_set && plugin_state_m->current_scene != TotpSceneAuthentication && - furi_get_tick() - last_user_interaction_time > IDLE_TIMEOUT) { - totp_scene_director_activate_scene(plugin_state_m, TotpSceneAuthentication, NULL); + view_port_update(view_port); + furi_mutex_release(plugin_state->mutex); } - - view_port_update(view_port); - release_mutex(&state_mutex, plugin_state_m); } totp_cli_unregister_command_handler(cli_context); @@ -199,7 +200,6 @@ int32_t totp_app() { gui_remove_view_port(plugin_state->gui, view_port); view_port_free(view_port); furi_message_queue_free(event_queue); - delete_mutex(&state_mutex); totp_plugin_state_free(plugin_state); return 0; } diff --git a/totp/types/plugin_state.h b/totp/types/plugin_state.h index 0aad2e125c6..dee50030527 100644 --- a/totp/types/plugin_state.h +++ b/totp/types/plugin_state.h @@ -87,4 +87,9 @@ typedef struct { * @brief Notification method */ NotificationMethod notification_method; + + /** + * @brief Main rendering loop mutex + */ + FuriMutex* mutex; } PluginState; diff --git a/totp/workers/type_code/type_code.c b/totp/workers/type_code/type_code.c index 3eb59047a85..11583d57a32 100644 --- a/totp/workers/type_code/type_code.c +++ b/totp/workers/type_code/type_code.c @@ -57,8 +57,8 @@ static void totp_type_code_worker_type_code(TotpTypeCodeWorkerContext* context) } static int32_t totp_type_code_worker_callback(void* context) { - ValueMutex context_mutex; - if(!init_mutex(&context_mutex, context, sizeof(TotpTypeCodeWorkerContext))) { + FuriMutex* context_mutex = furi_mutex_alloc(FuriMutexTypeNormal); + if(context_mutex == NULL) { return 251; } @@ -70,15 +70,16 @@ static int32_t totp_type_code_worker_callback(void* context) { furi_check((flags & FuriFlagError) == 0); //-V562 if(flags & TotpTypeCodeWorkerEventStop) break; - TotpTypeCodeWorkerContext* h_context = acquire_mutex_block(&context_mutex); - if(flags & TotpTypeCodeWorkerEventType) { - totp_type_code_worker_type_code(h_context); - } + if (furi_mutex_acquire(context_mutex, FuriWaitForever) == FuriStatusOk) { + if(flags & TotpTypeCodeWorkerEventType) { + totp_type_code_worker_type_code(context); + } - release_mutex(&context_mutex, h_context); + furi_mutex_release(context_mutex); + } } - delete_mutex(&context_mutex); + furi_mutex_free(context_mutex); return 0; }