2021-05-06 11:45:52 +03:00
|
|
|
#include "encoder-hid-h10301.h"
|
2021-05-18 11:37:47 +03:00
|
|
|
#include "protocols/protocol-hid-h10301.h"
|
2021-05-04 16:21:16 +03:00
|
|
|
#include <furi.h>
|
|
|
|
|
2021-05-06 11:45:52 +03:00
|
|
|
void EncoderHID_H10301::init(const uint8_t* data, const uint8_t data_size) {
|
2021-05-18 11:37:47 +03:00
|
|
|
ProtocolHID10301 hid;
|
|
|
|
hid.encode(data, data_size, reinterpret_cast<uint8_t*>(&card_data), sizeof(card_data) * 3);
|
2021-05-05 10:50:19 +03:00
|
|
|
|
2021-05-04 16:21:16 +03:00
|
|
|
card_data_index = 0;
|
2021-05-05 10:50:19 +03:00
|
|
|
bit_index = 0;
|
|
|
|
}
|
|
|
|
|
2021-05-06 11:45:52 +03:00
|
|
|
void EncoderHID_H10301::write_bit(bool bit, uint8_t position) {
|
2021-05-05 10:50:19 +03:00
|
|
|
write_raw_bit(bit, position + 0);
|
|
|
|
write_raw_bit(!bit, position + 1);
|
|
|
|
}
|
|
|
|
|
2021-05-06 11:45:52 +03:00
|
|
|
void EncoderHID_H10301::write_raw_bit(bool bit, uint8_t position) {
|
2021-05-05 10:50:19 +03:00
|
|
|
if(bit) {
|
|
|
|
card_data[position / 32] |= 1UL << (31 - (position % 32));
|
|
|
|
} else {
|
|
|
|
card_data[position / 32] &= ~(1UL << (31 - (position % 32)));
|
|
|
|
}
|
2021-05-04 16:21:16 +03:00
|
|
|
}
|
|
|
|
|
2021-05-06 11:45:52 +03:00
|
|
|
void EncoderHID_H10301::get_next(bool* polarity, uint16_t* period, uint16_t* pulse) {
|
2021-05-05 10:50:19 +03:00
|
|
|
// hid 0 is 6 cycles by 8 clocks
|
|
|
|
const uint8_t hid_0_period = 8;
|
|
|
|
const uint8_t hid_0_count = 6;
|
|
|
|
// hid 1 is 5 cycles by 10 clocks
|
|
|
|
const uint8_t hid_1_period = 10;
|
|
|
|
const uint8_t hid_1_count = 5;
|
|
|
|
|
|
|
|
bool bit = (card_data[card_data_index / 32] >> (31 - (card_data_index % 32))) & 1;
|
|
|
|
|
2021-05-04 16:21:16 +03:00
|
|
|
*polarity = true;
|
2021-05-05 10:50:19 +03:00
|
|
|
if(bit) {
|
|
|
|
*period = hid_1_period;
|
|
|
|
*pulse = hid_1_period / 2;
|
|
|
|
|
|
|
|
bit_index++;
|
|
|
|
if(bit_index >= hid_1_count) {
|
|
|
|
bit_index = 0;
|
|
|
|
card_data_index++;
|
|
|
|
if(card_data_index >= (32 * card_data_max)) {
|
|
|
|
card_data_index = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
*period = hid_0_period;
|
|
|
|
*pulse = hid_0_period / 2;
|
|
|
|
|
|
|
|
bit_index++;
|
|
|
|
if(bit_index >= hid_0_count) {
|
|
|
|
bit_index = 0;
|
|
|
|
card_data_index++;
|
|
|
|
if(card_data_index >= (32 * card_data_max)) {
|
|
|
|
card_data_index = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-05-04 16:21:16 +03:00
|
|
|
}
|