Skip to content

Commit

Permalink
Updated to use the newer Furi mutex api.
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuel H authored and Samuel H committed Mar 20, 2023
1 parent 70ec58b commit 2d1d151
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
16 changes: 7 additions & 9 deletions i2ctools.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#include "i2ctools_i.h"

void i2ctools_draw_callback(Canvas* canvas, void* ctx) {
i2cTools* i2ctools = acquire_mutex((ValueMutex*)ctx, 25);
i2cTools* i2ctools = ctx;
if(furi_mutex_acquire(i2ctools->mutex, 200) != FuriStatusOk) {
return;
}

switch(i2ctools->main_view->current_view) {
case MAIN_VIEW:
Expand All @@ -23,7 +26,7 @@ void i2ctools_draw_callback(Canvas* canvas, void* ctx) {
default:
break;
}
release_mutex((ValueMutex*)ctx, i2ctools);
furi_mutex_release(i2ctools->mutex);
}

void i2ctools_input_callback(InputEvent* input_event, void* ctx) {
Expand All @@ -38,16 +41,11 @@ int32_t i2ctools_app(void* p) {

// Alloc i2ctools
i2cTools* i2ctools = malloc(sizeof(i2cTools));
ValueMutex i2ctools_mutex;
if(!init_mutex(&i2ctools_mutex, i2ctools, sizeof(i2cTools))) {
FURI_LOG_E(APP_NAME, "cannot create mutex\r\n");
free(i2ctools);
return -1;
}
i2ctools->mutex = furi_mutex_alloc(FuriMutexTypeNormal);

// Alloc viewport
i2ctools->view_port = view_port_alloc();
view_port_draw_callback_set(i2ctools->view_port, i2ctools_draw_callback, &i2ctools_mutex);
view_port_draw_callback_set(i2ctools->view_port, i2ctools_draw_callback, i2ctools);
view_port_input_callback_set(i2ctools->view_port, i2ctools_input_callback, event_queue);

// Register view port in GUI
Expand Down
1 change: 1 addition & 0 deletions i2ctools_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

// App datas
typedef struct {
FuriMutex* mutex;
ViewPort* view_port;
i2cMainView* main_view;

Expand Down

0 comments on commit 2d1d151

Please sign in to comment.