uhf_worker.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #include "uhf_data.h"
  2. #include "uhf_worker.h"
  3. int32_t uhf_worker_task(void* ctx) {
  4. UNUSED(ctx);
  5. return 0;
  6. }
  7. UHFWorker* uhf_worker_alloc() {
  8. UHFWorker* uhf_worker = (UHFWorker*)malloc(sizeof(UHFWorker));
  9. uhf_worker->thread = furi_thread_alloc_ex("UHFWorker", 8 * 1024, uhf_worker_task, uhf_worker);
  10. uhf_worker->data = uhf_response_data_alloc();
  11. uhf_worker->callback = NULL;
  12. uhf_worker->ctx = NULL;
  13. return uhf_worker;
  14. }
  15. void uhf_worker_change_state(UHFWorker* worker, UHFWorkerState state) {
  16. worker->state = state;
  17. }
  18. void uhf_worker_start(
  19. UHFWorker* uhf_worker,
  20. UHFWorkerState state,
  21. UHFWorkerCallback callback,
  22. void* ctx) {
  23. uhf_worker->state = state;
  24. uhf_worker->callback = callback;
  25. uhf_worker->ctx = ctx;
  26. furi_thread_start(uhf_worker->thread);
  27. }
  28. void uhf_worker_stop(UHFWorker* uhf_worker) {
  29. furi_assert(uhf_worker);
  30. furi_assert(uhf_worker->thread);
  31. if(furi_thread_get_state(uhf_worker->thread) != FuriThreadStateStopped) {
  32. uhf_worker_change_state(uhf_worker, UHFWorkerStateStop);
  33. furi_thread_join(uhf_worker->thread);
  34. }
  35. }
  36. void uhf_worker_free(UHFWorker* uhf_worker) {
  37. furi_assert(uhf_worker);
  38. furi_thread_free(uhf_worker->thread);
  39. uhf_data_free((UHFData*)uhf_worker->data);
  40. free(uhf_worker);
  41. }