flipperzero-firmware/applications/ibutton/helpers/key_reader.h
あく c4a0847c99
FuriHal: replace HAL with LL in RFID Part 1. Drop F6. (#1049)
* FuriHal: new speaker HAL
* FuriHal: drop PWM
* FuriHal: move COMP1 to LL
* FuriHal: move COMP1 to LL backport to F6
* FuriHal: remove missing gpio_rfid_carrier from F6
* FurHal: use LL for system controls in flash HAL
* Drop F6 source tree
* Drop F6 from GitHub workflow
* Tie USE_FULL_ASSERT with APP_UNIT_TESTS
* Speaker: return to old volume calculation
* FreeRTOS: move TCB header to glue

Co-authored-by: DrZlo13 <who.just.the.doctor@gmail.com>
2022-03-23 20:59:20 +03:00

55 lines
1.3 KiB
C++

#pragma once
#include <stdint.h>
#include <furi.h>
#include "cyfral_decoder.h"
#pragma once
#include "metakom_decoder.h"
#include "../ibutton_key.h"
#include <one_wire_master.h>
#include <one_wire_slave.h>
class KeyReader {
public:
enum class Error : uint8_t {
EMPTY,
CRC_ERROR,
NOT_ARE_KEY,
OK,
};
void start();
void stop();
KeyReader::Error read(iButtonKey* key);
KeyReader(OneWireMaster* onewire_master);
~KeyReader();
private:
bool read_key(iButtonKeyType* key_type, uint8_t* data, uint8_t data_size);
bool verify_key(iButtonKeyType key_type, const uint8_t* const data, uint8_t data_size);
// cyfral and metakom readers data
void comparator_trigger_callback(bool level, void* comp_ctx);
void (*comparator_callback_pointer)(bool level, void* comp_ctx);
void start_comaparator(void);
void stop_comaparator(void);
uint32_t last_dwt_value;
CyfralDecoder cyfral_decoder;
MetakomDecoder metakom_decoder;
// mode
uint32_t read_mode_switch_time;
enum class ReadMode : uint8_t {
CYFRAL_METAKOM,
DALLAS,
};
ReadMode read_mode;
// one wire
OneWireMaster* onewire_master;
void switch_to(ReadMode mode);
void switch_mode_if_needed();
};