8 static const char *
const TAG =
"wiegand";
9 static const char *
const KEYS =
"0123456789*#";
30 this->d0_pin_->setup();
31 this->store_.d0 = this->d0_pin_->to_isr();
32 this->d1_pin_->setup();
33 this->store_.d1 = this->d1_pin_->to_isr();
40 uint64_t mask = 1LL << start;
41 for (
int i = 0; i <
length; i++, mask <<= 1) {
50 uint64_t mask = 1LL << start;
51 for (
int i = 0; i <
length; i++, mask <<= 1) {
59 if (this->store_.done)
61 if (
millis() - this->store_.last_bit_time < 100)
63 uint8_t
count = this->store_.count;
64 uint64_t
value = this->store_.value;
65 this->store_.count = 0;
66 this->store_.value = 0;
67 this->store_.done =
true;
68 ESP_LOGV(TAG,
"received %d-bit value: %llx", count, value);
69 for (
auto *trigger : this->raw_triggers_)
70 trigger->trigger(count, value);
72 std::string tag =
to_string((value >> 1) & 0xffffff);
73 ESP_LOGD(TAG,
"received 26-bit tag: %s", tag.c_str());
75 ESP_LOGW(TAG,
"invalid parity");
78 for (
auto *trigger : this->tag_triggers_)
79 trigger->trigger(tag);
80 }
else if (count == 34) {
81 std::string tag =
to_string((value >> 1) & 0xffffffff);
82 ESP_LOGD(TAG,
"received 34-bit tag: %s", tag.c_str());
84 ESP_LOGW(TAG,
"invalid parity");
87 for (
auto *trigger : this->tag_triggers_)
88 trigger->trigger(tag);
89 }
else if (count == 37) {
90 std::string tag =
to_string((value >> 1) & 0x7ffffffff);
91 ESP_LOGD(TAG,
"received 37-bit tag: %s", tag.c_str());
93 ESP_LOGW(TAG,
"invalid parity");
96 for (
auto *trigger : this->tag_triggers_)
97 trigger->trigger(tag);
98 }
else if (count == 4) {
99 for (
auto *trigger : this->key_triggers_)
100 trigger->trigger(value);
102 uint8_t key = KEYS[
value];
103 this->send_key_(key);
105 }
else if (count == 8) {
106 if ((value ^ 0xf0) >> 4 == (value & 0xf)) {
108 for (
auto *trigger : this->key_triggers_)
109 trigger->trigger(value);
111 uint8_t key = KEYS[
value];
112 this->send_key_(key);
116 ESP_LOGD(TAG,
"received unknown %d-bit value: %llx", count, value);
121 ESP_LOGCONFIG(TAG,
"Wiegand reader:");
122 LOG_PIN(
" D0 pin: ", this->d0_pin_);
123 LOG_PIN(
" D1 pin: ", this->d1_pin_);
bool check_eparity(uint64_t value, int start, int length)
uint32_t IRAM_ATTR HOT millis()
void dump_config() override
static void d0_gpio_intr(WiegandStore *arg)
std::string to_string(int value)
bool check_oparity(uint64_t value, int start, int length)
Implementation of SPI Controller mode.
static void d1_gpio_intr(WiegandStore *arg)
volatile uint32_t last_bit_time