key-store.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #include "key-store.h"
  2. #include <furi.h>
  3. uint16_t KeyStore::get_key_count() {
  4. return store.size();
  5. }
  6. uint8_t KeyStore::add_key() {
  7. store.push_back(iButtonKey());
  8. return get_key_count() - 1;
  9. }
  10. void KeyStore::set_key_type(uint8_t index, iButtonKeyType type) {
  11. iButtonKey* key = get_key(index);
  12. key->set_type(type);
  13. }
  14. void KeyStore::set_key_name(uint8_t index, char* name) {
  15. iButtonKey* key = get_key(index);
  16. char* orphan = strdup(name);
  17. key->set_name(orphan);
  18. }
  19. void KeyStore::set_key_data(uint8_t index, uint8_t* data, uint8_t data_size) {
  20. iButtonKey* key = get_key(index);
  21. key->set_data(data, data_size);
  22. }
  23. iButtonKeyType KeyStore::get_key_type(uint8_t index) {
  24. iButtonKey* key = get_key(index);
  25. return key->get_key_type();
  26. }
  27. const char* KeyStore::get_key_name(uint8_t index) {
  28. iButtonKey* key = get_key(index);
  29. return key->get_name();
  30. }
  31. uint8_t* KeyStore::get_key_data(uint8_t index) {
  32. iButtonKey* key = get_key(index);
  33. return key->get_data();
  34. }
  35. void KeyStore::remove_key(uint8_t index) {
  36. furi_check(index >= 0);
  37. furi_check(index < get_key_count());
  38. auto item = std::next(store.begin(), index);
  39. store.erase(item);
  40. }
  41. KeyStore::KeyStore() {
  42. store.push_back(iButtonKey(
  43. iButtonKeyType::KeyDallas, "Dallas_1", 0x01, 0x41, 0xCE, 0x67, 0x0F, 0x00, 0x00, 0xB6));
  44. store.push_back(iButtonKey(
  45. iButtonKeyType::KeyDallas, "Dallas_2", 0x01, 0xFD, 0x0E, 0x84, 0x01, 0x00, 0x00, 0xDB));
  46. store.push_back(iButtonKey(
  47. iButtonKeyType::KeyCyfral, "Cyfral_1", 0xA6, 0xD2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00));
  48. store.push_back(iButtonKey(
  49. iButtonKeyType::KeyMetakom, "Metakom_1", 0xB1, 0x2E, 0x47, 0xB2, 0x00, 0x00, 0x00, 0x00));
  50. }
  51. KeyStore::~KeyStore() {
  52. }
  53. iButtonKey* KeyStore::get_key(uint8_t index) {
  54. furi_check(index >= 0);
  55. furi_check(index < get_key_count());
  56. return &(*std::next(store.begin(), index));
  57. }