Skip to content

Commit

Permalink
Improve context object pointer handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
ezod committed Mar 12, 2023
1 parent 3334056 commit 397a8f1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
9 changes: 3 additions & 6 deletions gps.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ typedef struct

static void render_callback(Canvas* const canvas, void* context)
{
const GpsUart* gps_uart = context;
const GpsUart* gps_uart = (GpsUart*)context;
furi_mutex_acquire(gps_uart->mutex, FuriWaitForever);

canvas_set_font(canvas, FontPrimary);
Expand Down Expand Up @@ -66,17 +66,14 @@ int32_t gps_app(void* p)
FuriMessageQueue* event_queue = furi_message_queue_alloc(8, sizeof(PluginEvent));

GpsUart* gps_uart = gps_uart_enable();

if (!gps_uart->mutex)
if (gps_uart == NULL)
{
FURI_LOG_E("GPS", "cannot create mutex\r\n");
free(gps_uart);
return 255;
}

// set system callbacks
ViewPort* view_port = view_port_alloc();
view_port_draw_callback_set(view_port, render_callback, &gps_uart);
view_port_draw_callback_set(view_port, render_callback, gps_uart);
view_port_input_callback_set(view_port, input_callback, event_queue);

// open GUI and register view_port
Expand Down
10 changes: 8 additions & 2 deletions gps_uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,14 @@ GpsUart* gps_uart_enable()
{
GpsUart* gps_uart = malloc(sizeof(GpsUart));

gps_uart->mutex = furi_mutex_alloc(FuriMutexTypeNormal);
if (!gps_uart->mutex)
{
FURI_LOG_E("GPS", "cannot create mutex\r\n");
free(gps_uart);
return NULL;
}

gps_uart->status.valid = false;
gps_uart->status.latitude = 0.0;
gps_uart->status.longitude = 0.0;
Expand All @@ -173,8 +181,6 @@ GpsUart* gps_uart_enable()

gps_uart->notifications = furi_record_open(RECORD_NOTIFICATION);

gps_uart->mutex = furi_mutex_alloc(FuriMutexTypeNormal);

gps_uart->thread = furi_thread_alloc();
furi_thread_set_name(gps_uart->thread, "GpsUartWorker");
furi_thread_set_stack_size(gps_uart->thread, 1024);
Expand Down

0 comments on commit 397a8f1

Please sign in to comment.