Skip to content

Commit

Permalink
Updated firmware references (#88)
Browse files Browse the repository at this point in the history
* * Updated firmware references

* Updated code to make it compatible with latest firmware changes

* Dropped useless check
  • Loading branch information
akopachov authored Mar 9, 2023
1 parent e0ad188 commit 046fb63
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 39 deletions.
2 changes: 1 addition & 1 deletion flipperzero-firmware_official_dev
60 changes: 30 additions & 30 deletions totp/totp_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}

Expand All @@ -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);
}

Expand All @@ -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)) {
Expand All @@ -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
Expand All @@ -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);
Expand All @@ -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;
}
5 changes: 5 additions & 0 deletions totp/types/plugin_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,9 @@ typedef struct {
* @brief Notification method
*/
NotificationMethod notification_method;

/**
* @brief Main rendering loop mutex
*/
FuriMutex* mutex;
} PluginState;
17 changes: 9 additions & 8 deletions totp/workers/type_code/type_code.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
}
Expand Down

0 comments on commit 046fb63

Please sign in to comment.