key_reader.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #pragma once
  2. #include <stdint.h>
  3. #include <furi.h>
  4. #include "cyfral_decoder.h"
  5. #pragma once
  6. #include "metakom_decoder.h"
  7. #include "../ibutton_key.h"
  8. #include <one_wire_master.h>
  9. #include <one_wire_slave.h>
  10. class KeyReader {
  11. public:
  12. enum class Error : uint8_t {
  13. EMPTY,
  14. CRC_ERROR,
  15. NOT_ARE_KEY,
  16. OK,
  17. };
  18. void start();
  19. void stop();
  20. KeyReader::Error read(iButtonKey* key);
  21. KeyReader(OneWireMaster* onewire_master);
  22. ~KeyReader();
  23. private:
  24. bool read_key(iButtonKeyType* key_type, uint8_t* data, uint8_t data_size);
  25. bool verify_key(iButtonKeyType key_type, const uint8_t* const data, uint8_t data_size);
  26. // cyfral and metakom readers data
  27. void comparator_trigger_callback(void* hcomp, void* comp_ctx);
  28. void (*comparator_callback_pointer)(void* hcomp, void* comp_ctx);
  29. void start_comaparator(void);
  30. void stop_comaparator(void);
  31. uint32_t last_dwt_value;
  32. CyfralDecoder cyfral_decoder;
  33. MetakomDecoder metakom_decoder;
  34. // mode
  35. uint32_t read_mode_switch_time;
  36. enum class ReadMode : uint8_t {
  37. CYFRAL_METAKOM,
  38. DALLAS,
  39. };
  40. ReadMode read_mode;
  41. // one wire
  42. OneWireMaster* onewire_master;
  43. void switch_to(ReadMode mode);
  44. void switch_mode_if_needed();
  45. };