ibutton_worker.h 2.4 KB

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