key_writer.h 795 B

1234567891011121314151617181920212223242526272829303132333435
  1. #pragma once
  2. #include "../ibutton_key.h"
  3. #include <one_wire_master.h>
  4. class KeyWriter {
  5. public:
  6. enum class Error : uint8_t {
  7. OK,
  8. SAME_KEY,
  9. NO_DETECT,
  10. CANNOT_WRITE,
  11. };
  12. KeyWriter(OneWireMaster* onewire_master);
  13. ~KeyWriter();
  14. KeyWriter::Error write(iButtonKey* key);
  15. void start();
  16. void stop();
  17. private:
  18. OneWireMaster* onewire_master;
  19. KeyWriter::Error write_internal(iButtonKey* key);
  20. bool compare_key_ds1990(iButtonKey* key);
  21. // write strategy
  22. bool write_1990_1(iButtonKey* key);
  23. bool write_1990_2(iButtonKey* key);
  24. bool write_TM2004(iButtonKey* key);
  25. bool write_TM01(iButtonKey* key);
  26. void onewire_write_one_bit(bool value, uint32_t delay = 10000);
  27. void write_byte_ds1990(uint8_t data);
  28. };