Skip to content

Commit 97c6116

Browse files
authored
Updated firmware references (#88)
* * Updated firmware references * Updated code to make it compatible with latest firmware changes * Dropped useless check
1 parent 44df62c commit 97c6116

File tree

3 files changed

+44
-38
lines changed

3 files changed

+44
-38
lines changed

totp_app.c

+30-30
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@
2323
#define IDLE_TIMEOUT 60000
2424

2525
static void render_callback(Canvas* const canvas, void* ctx) {
26-
PluginState* plugin_state = acquire_mutex((ValueMutex*)ctx, 25);
27-
if(plugin_state != NULL) {
26+
furi_assert(ctx);
27+
PluginState* plugin_state = ctx;
28+
if (furi_mutex_acquire(plugin_state->mutex, 25) == FuriStatusOk) {
2829
totp_scene_director_render(canvas, plugin_state);
30+
furi_mutex_release(plugin_state->mutex);
2931
}
30-
31-
release_mutex((ValueMutex*)ctx, plugin_state);
3232
}
3333

3434
static void input_callback(InputEvent* input_event, FuriMessageQueue* event_queue) {
@@ -102,6 +102,12 @@ static bool totp_plugin_state_init(PluginState* const plugin_state) {
102102
return false;
103103
}
104104

105+
plugin_state->mutex = furi_mutex_alloc(FuriMutexTypeNormal);
106+
if (plugin_state->mutex == NULL) {
107+
FURI_LOG_E(LOGGING_TAG, "Cannot create mutex\r\n");
108+
return false;
109+
}
110+
105111
return true;
106112
}
107113

@@ -123,6 +129,8 @@ static void totp_plugin_state_free(PluginState* plugin_state) {
123129
if(plugin_state->crypto_verify_data != NULL) {
124130
free(plugin_state->crypto_verify_data);
125131
}
132+
133+
furi_mutex_free(plugin_state->mutex);
126134
free(plugin_state);
127135
}
128136

@@ -137,13 +145,6 @@ int32_t totp_app() {
137145
return 254;
138146
}
139147

140-
ValueMutex state_mutex;
141-
if(!init_mutex(&state_mutex, plugin_state, sizeof(PluginState))) {
142-
FURI_LOG_E(LOGGING_TAG, "Cannot create mutex\r\n");
143-
totp_plugin_state_free(plugin_state);
144-
return 255;
145-
}
146-
147148
TotpCliContext* cli_context = totp_cli_register_command_handler(plugin_state, event_queue);
148149
totp_scene_director_init_scenes(plugin_state);
149150
if(!totp_activate_initial_scene(plugin_state)) {
@@ -157,7 +158,7 @@ int32_t totp_app() {
157158

158159
// Set system callbacks
159160
ViewPort* view_port = view_port_alloc();
160-
view_port_draw_callback_set(view_port, render_callback, &state_mutex);
161+
view_port_draw_callback_set(view_port, render_callback, plugin_state);
161162
view_port_input_callback_set(view_port, input_callback, event_queue);
162163

163164
// Open GUI and register view_port
@@ -169,26 +170,26 @@ int32_t totp_app() {
169170
while(processing) {
170171
FuriStatus event_status = furi_message_queue_get(event_queue, &event, 100);
171172

172-
PluginState* plugin_state_m = acquire_mutex_block(&state_mutex);
173-
174-
if(event_status == FuriStatusOk) {
175-
if(event.type == EventTypeKey) {
176-
last_user_interaction_time = furi_get_tick();
173+
if (furi_mutex_acquire(plugin_state->mutex, FuriWaitForever) == FuriStatusOk) {
174+
if(event_status == FuriStatusOk) {
175+
if(event.type == EventTypeKey) {
176+
last_user_interaction_time = furi_get_tick();
177+
}
178+
179+
if(event.type == EventForceCloseApp) {
180+
processing = false;
181+
} else {
182+
processing = totp_scene_director_handle_event(&event, plugin_state);
183+
}
184+
} else if(
185+
plugin_state->pin_set && plugin_state->current_scene != TotpSceneAuthentication &&
186+
furi_get_tick() - last_user_interaction_time > IDLE_TIMEOUT) {
187+
totp_scene_director_activate_scene(plugin_state, TotpSceneAuthentication, NULL);
177188
}
178189

179-
if(event.type == EventForceCloseApp) {
180-
processing = false;
181-
} else {
182-
processing = totp_scene_director_handle_event(&event, plugin_state_m);
183-
}
184-
} else if(
185-
plugin_state_m->pin_set && plugin_state_m->current_scene != TotpSceneAuthentication &&
186-
furi_get_tick() - last_user_interaction_time > IDLE_TIMEOUT) {
187-
totp_scene_director_activate_scene(plugin_state_m, TotpSceneAuthentication, NULL);
190+
view_port_update(view_port);
191+
furi_mutex_release(plugin_state->mutex);
188192
}
189-
190-
view_port_update(view_port);
191-
release_mutex(&state_mutex, plugin_state_m);
192193
}
193194

194195
totp_cli_unregister_command_handler(cli_context);
@@ -199,7 +200,6 @@ int32_t totp_app() {
199200
gui_remove_view_port(plugin_state->gui, view_port);
200201
view_port_free(view_port);
201202
furi_message_queue_free(event_queue);
202-
delete_mutex(&state_mutex);
203203
totp_plugin_state_free(plugin_state);
204204
return 0;
205205
}

types/plugin_state.h

+5
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,9 @@ typedef struct {
8787
* @brief Notification method
8888
*/
8989
NotificationMethod notification_method;
90+
91+
/**
92+
* @brief Main rendering loop mutex
93+
*/
94+
FuriMutex* mutex;
9095
} PluginState;

workers/type_code/type_code.c

+9-8
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ static void totp_type_code_worker_type_code(TotpTypeCodeWorkerContext* context)
5757
}
5858

5959
static int32_t totp_type_code_worker_callback(void* context) {
60-
ValueMutex context_mutex;
61-
if(!init_mutex(&context_mutex, context, sizeof(TotpTypeCodeWorkerContext))) {
60+
FuriMutex* context_mutex = furi_mutex_alloc(FuriMutexTypeNormal);
61+
if(context_mutex == NULL) {
6262
return 251;
6363
}
6464

@@ -70,15 +70,16 @@ static int32_t totp_type_code_worker_callback(void* context) {
7070
furi_check((flags & FuriFlagError) == 0); //-V562
7171
if(flags & TotpTypeCodeWorkerEventStop) break;
7272

73-
TotpTypeCodeWorkerContext* h_context = acquire_mutex_block(&context_mutex);
74-
if(flags & TotpTypeCodeWorkerEventType) {
75-
totp_type_code_worker_type_code(h_context);
76-
}
73+
if (furi_mutex_acquire(context_mutex, FuriWaitForever) == FuriStatusOk) {
74+
if(flags & TotpTypeCodeWorkerEventType) {
75+
totp_type_code_worker_type_code(context);
76+
}
7777

78-
release_mutex(&context_mutex, h_context);
78+
furi_mutex_release(context_mutex);
79+
}
7980
}
8081

81-
delete_mutex(&context_mutex);
82+
furi_mutex_free(context_mutex);
8283

8384
return 0;
8485
}

0 commit comments

Comments
 (0)