ibutton_worker.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /**
  2. * @file ibutton_worker.h
  3. *
  4. * iButton worker
  5. */
  6. #pragma once
  7. #include "ibutton_key.h"
  8. #ifdef __cplusplus
  9. extern "C" {
  10. #endif
  11. typedef enum {
  12. iButtonWorkerWriteOK,
  13. iButtonWorkerWriteSameKey,
  14. iButtonWorkerWriteNoDetect,
  15. iButtonWorkerWriteCannotWrite,
  16. } iButtonWorkerWriteResult;
  17. typedef void (*iButtonWorkerReadCallback)(void* context);
  18. typedef void (*iButtonWorkerWriteCallback)(void* context, iButtonWorkerWriteResult result);
  19. typedef void (*iButtonWorkerEmulateCallback)(void* context, bool emulated);
  20. typedef struct iButtonWorker iButtonWorker;
  21. /**
  22. * Allocate ibutton worker
  23. * @return iButtonWorker*
  24. */
  25. iButtonWorker* ibutton_worker_alloc();
  26. /**
  27. * Free ibutton worker
  28. * @param worker
  29. */
  30. void ibutton_worker_free(iButtonWorker* worker);
  31. /**
  32. * Start ibutton worker thread
  33. * @param worker
  34. */
  35. void ibutton_worker_start_thread(iButtonWorker* worker);
  36. /**
  37. * Stop ibutton worker thread
  38. * @param worker
  39. */
  40. void ibutton_worker_stop_thread(iButtonWorker* worker);
  41. /**
  42. * Set "read success" callback
  43. * @param worker
  44. * @param callback
  45. * @param context
  46. */
  47. void ibutton_worker_read_set_callback(
  48. iButtonWorker* worker,
  49. iButtonWorkerReadCallback callback,
  50. void* context);
  51. /**
  52. * Start read mode
  53. * @param worker
  54. * @param key
  55. */
  56. void ibutton_worker_read_start(iButtonWorker* worker, iButtonKey* key);
  57. /**
  58. * Set "write event" callback
  59. * @param worker
  60. * @param callback
  61. * @param context
  62. */
  63. void ibutton_worker_write_set_callback(
  64. iButtonWorker* worker,
  65. iButtonWorkerWriteCallback callback,
  66. void* context);
  67. /**
  68. * Start write mode
  69. * @param worker
  70. * @param key
  71. */
  72. void ibutton_worker_write_start(iButtonWorker* worker, iButtonKey* key);
  73. /**
  74. * Set "emulate success" callback
  75. * @param worker
  76. * @param callback
  77. * @param context
  78. */
  79. void ibutton_worker_emulate_set_callback(
  80. iButtonWorker* worker,
  81. iButtonWorkerEmulateCallback callback,
  82. void* context);
  83. /**
  84. * Start emulate mode
  85. * @param worker
  86. * @param key
  87. */
  88. void ibutton_worker_emulate_start(iButtonWorker* worker, iButtonKey* key);
  89. /**
  90. * Stop all modes
  91. * @param worker
  92. */
  93. void ibutton_worker_stop(iButtonWorker* worker);
  94. #ifdef __cplusplus
  95. }
  96. #endif