rfid_timer_emulator.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #include "rfid_timer_emulator.h"
  2. RfidTimerEmulator::RfidTimerEmulator() {
  3. }
  4. RfidTimerEmulator::~RfidTimerEmulator() {
  5. std::map<LfrfidKeyType, EncoderGeneric*>::iterator it;
  6. for(it = encoders.begin(); it != encoders.end(); ++it) {
  7. delete it->second;
  8. }
  9. encoders.clear();
  10. }
  11. void RfidTimerEmulator::start(LfrfidKeyType type, const uint8_t* data, uint8_t data_size) {
  12. if(encoders.count(type)) {
  13. current_encoder = encoders.find(type)->second;
  14. if(data_size >= lfrfid_key_get_type_data_count(type)) {
  15. current_encoder->init(data, data_size);
  16. furi_hal_rfid_tim_emulate(125000);
  17. furi_hal_rfid_pins_emulate();
  18. furi_hal_rfid_tim_emulate_start(RfidTimerEmulator::timer_update_callback, this);
  19. }
  20. } else {
  21. // not found
  22. }
  23. }
  24. void RfidTimerEmulator::stop() {
  25. furi_hal_rfid_tim_emulate_stop();
  26. furi_hal_rfid_tim_reset();
  27. furi_hal_rfid_pins_reset();
  28. }
  29. void RfidTimerEmulator::timer_update_callback(void* ctx) {
  30. RfidTimerEmulator* _this = static_cast<RfidTimerEmulator*>(ctx);
  31. bool result;
  32. bool polarity;
  33. uint16_t period;
  34. uint16_t pulse;
  35. do {
  36. _this->current_encoder->get_next(&polarity, &period, &pulse);
  37. result = _this->pulse_joiner.push_pulse(polarity, period, pulse);
  38. } while(result == false);
  39. _this->pulse_joiner.pop_pulse(&period, &pulse);
  40. furi_hal_rfid_set_emulate_period(period - 1);
  41. furi_hal_rfid_set_emulate_pulse(pulse);
  42. }