From 85a129b89f18c0d9f713fa80e2d24a5b9af42c52 Mon Sep 17 00:00:00 2001 From: Georgii Surkov <37121527+gsurkov@users.noreply.github.com> Date: Wed, 11 May 2022 18:47:01 +0300 Subject: [PATCH] [FL-2528] Fix iButton crash on successful emulation #1220 --- lib/one_wire/ibutton/ibutton_worker.c | 11 +++++++++++ lib/one_wire/ibutton/ibutton_worker_i.h | 1 + lib/one_wire/ibutton/ibutton_worker_modes.c | 4 +--- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/one_wire/ibutton/ibutton_worker.c b/lib/one_wire/ibutton/ibutton_worker.c index 74734e75..82c3d688 100644 --- a/lib/one_wire/ibutton/ibutton_worker.c +++ b/lib/one_wire/ibutton/ibutton_worker.c @@ -9,6 +9,7 @@ typedef enum { iButtonMessageRead, iButtonMessageWrite, iButtonMessageEmulate, + iButtonMessageNotifyEmulate, } iButtonMessageType; typedef struct { @@ -145,6 +146,11 @@ void ibutton_worker_switch_mode(iButtonWorker* worker, iButtonWorkerMode mode) { ibutton_worker_modes[worker->mode_index].start(worker); } +void ibutton_worker_notify_emulate(iButtonWorker* worker) { + iButtonMessage message = {.type = iButtonMessageNotifyEmulate}; + furi_check(osMessageQueuePut(worker->messages, &message, 0, 0) == osOK); +} + void ibutton_worker_set_key_p(iButtonWorker* worker, iButtonKey* key) { worker->key_p = key; } @@ -183,6 +189,11 @@ static int32_t ibutton_worker_thread(void* thread_context) { ibutton_worker_set_key_p(worker, message.data.key); ibutton_worker_switch_mode(worker, iButtonWorkerEmulate); break; + case iButtonMessageNotifyEmulate: + if(worker->emulate_cb) { + worker->emulate_cb(worker->cb_ctx, true); + } + break; } } else if(status == osErrorTimeout) { ibutton_worker_modes[worker->mode_index].tick(worker); diff --git a/lib/one_wire/ibutton/ibutton_worker_i.h b/lib/one_wire/ibutton/ibutton_worker_i.h index ae2d4dc3..93755481 100644 --- a/lib/one_wire/ibutton/ibutton_worker_i.h +++ b/lib/one_wire/ibutton/ibutton_worker_i.h @@ -73,6 +73,7 @@ struct iButtonWorker { extern const iButtonWorkerModeType ibutton_worker_modes[]; void ibutton_worker_switch_mode(iButtonWorker* worker, iButtonWorkerMode mode); +void ibutton_worker_notify_emulate(iButtonWorker* worker); #ifdef __cplusplus } diff --git a/lib/one_wire/ibutton/ibutton_worker_modes.c b/lib/one_wire/ibutton/ibutton_worker_modes.c index ff5ba351..5ee76862 100644 --- a/lib/one_wire/ibutton/ibutton_worker_modes.c +++ b/lib/one_wire/ibutton/ibutton_worker_modes.c @@ -184,9 +184,7 @@ void ibutton_worker_mode_read_stop(iButtonWorker* worker) { static void onewire_slave_callback(void* context) { furi_assert(context); iButtonWorker* worker = context; - if(worker->emulate_cb != NULL) { - worker->emulate_cb(worker->cb_ctx, true); - } + ibutton_worker_notify_emulate(worker); } void ibutton_worker_emulate_dallas_start(iButtonWorker* worker) {