|
|
@@ -0,0 +1,48 @@
|
|
|
+#include "uhf_data.h"
|
|
|
+#include "uhf_worker.h"
|
|
|
+
|
|
|
+int32_t uhf_worker_task(void* ctx) {
|
|
|
+ UNUSED(ctx);
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
+UHFWorker* uhf_worker_alloc() {
|
|
|
+ UHFWorker* uhf_worker = (UHFWorker*)malloc(sizeof(UHFWorker));
|
|
|
+ uhf_worker->thread = furi_thread_alloc_ex("UHFWorker", 8 * 1024, uhf_worker_task, uhf_worker);
|
|
|
+ uhf_worker->data = uhf_response_data_alloc();
|
|
|
+ uhf_worker->callback = NULL;
|
|
|
+ uhf_worker->ctx = NULL;
|
|
|
+ return uhf_worker;
|
|
|
+}
|
|
|
+
|
|
|
+void uhf_worker_change_state(UHFWorker* worker, UHFWorkerState state) {
|
|
|
+ worker->state = state;
|
|
|
+}
|
|
|
+
|
|
|
+void uhf_worker_start(
|
|
|
+ UHFWorker* uhf_worker,
|
|
|
+ UHFWorkerState state,
|
|
|
+ UHFWorkerCallback callback,
|
|
|
+ void* ctx) {
|
|
|
+ uhf_worker->state = state;
|
|
|
+ uhf_worker->callback = callback;
|
|
|
+ uhf_worker->ctx = ctx;
|
|
|
+ furi_thread_start(uhf_worker->thread);
|
|
|
+}
|
|
|
+
|
|
|
+void uhf_worker_stop(UHFWorker* uhf_worker) {
|
|
|
+ furi_assert(uhf_worker);
|
|
|
+ furi_assert(uhf_worker->thread);
|
|
|
+
|
|
|
+ if(furi_thread_get_state(uhf_worker->thread) != FuriThreadStateStopped) {
|
|
|
+ uhf_worker_change_state(uhf_worker, UHFWorkerStateStop);
|
|
|
+ furi_thread_join(uhf_worker->thread);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void uhf_worker_free(UHFWorker* uhf_worker) {
|
|
|
+ furi_assert(uhf_worker);
|
|
|
+ furi_thread_free(uhf_worker->thread);
|
|
|
+ uhf_data_free((UHFData*)uhf_worker->data);
|
|
|
+ free(uhf_worker);
|
|
|
+}
|