2023-03-02 13:23:33 +00:00
|
|
|
#include "ibutton_key_i.h"
|
2024-03-19 14:43:52 +00:00
|
|
|
#include <furi.h>
|
2022-03-29 13:01:56 +00:00
|
|
|
|
|
|
|
struct iButtonKey {
|
2023-03-02 13:23:33 +00:00
|
|
|
iButtonProtocolId protocol_id;
|
|
|
|
iButtonProtocolData* protocol_data;
|
|
|
|
size_t protocol_data_size;
|
2022-03-29 13:01:56 +00:00
|
|
|
};
|
|
|
|
|
2023-03-02 13:23:33 +00:00
|
|
|
iButtonKey* ibutton_key_alloc(size_t data_size) {
|
2022-03-29 13:01:56 +00:00
|
|
|
iButtonKey* key = malloc(sizeof(iButtonKey));
|
2023-03-02 13:23:33 +00:00
|
|
|
|
|
|
|
key->protocol_id = iButtonProtocolIdInvalid;
|
|
|
|
key->protocol_data = malloc(data_size);
|
|
|
|
key->protocol_data_size = data_size;
|
|
|
|
|
2022-03-29 13:01:56 +00:00
|
|
|
return key;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ibutton_key_free(iButtonKey* key) {
|
2024-03-19 14:43:52 +00:00
|
|
|
furi_check(key);
|
|
|
|
|
2023-03-02 13:23:33 +00:00
|
|
|
free(key->protocol_data);
|
2022-03-29 13:01:56 +00:00
|
|
|
free(key);
|
|
|
|
}
|
|
|
|
|
2023-03-02 13:23:33 +00:00
|
|
|
void ibutton_key_reset(iButtonKey* key) {
|
2024-03-19 14:43:52 +00:00
|
|
|
furi_check(key);
|
|
|
|
|
2023-03-02 13:23:33 +00:00
|
|
|
key->protocol_id = iButtonProtocolIdInvalid;
|
2024-03-19 14:43:52 +00:00
|
|
|
|
2023-03-02 13:23:33 +00:00
|
|
|
memset(key->protocol_data, 0, key->protocol_data_size);
|
2022-03-29 13:01:56 +00:00
|
|
|
}
|
|
|
|
|
2023-03-02 13:23:33 +00:00
|
|
|
iButtonProtocolId ibutton_key_get_protocol_id(const iButtonKey* key) {
|
2024-03-19 14:43:52 +00:00
|
|
|
furi_check(key);
|
|
|
|
|
2023-03-02 13:23:33 +00:00
|
|
|
return key->protocol_id;
|
2022-03-29 13:01:56 +00:00
|
|
|
}
|
|
|
|
|
2023-03-02 13:23:33 +00:00
|
|
|
void ibutton_key_set_protocol_id(iButtonKey* key, iButtonProtocolId protocol_id) {
|
2024-03-19 14:43:52 +00:00
|
|
|
furi_check(key);
|
2023-03-02 13:23:33 +00:00
|
|
|
key->protocol_id = protocol_id;
|
2022-03-29 13:01:56 +00:00
|
|
|
}
|
|
|
|
|
2023-03-02 13:23:33 +00:00
|
|
|
iButtonProtocolData* ibutton_key_get_protocol_data(const iButtonKey* key) {
|
|
|
|
return key->protocol_data;
|
2022-03-29 13:01:56 +00:00
|
|
|
}
|
|
|
|
|
2023-03-02 13:23:33 +00:00
|
|
|
size_t ibutton_key_get_protocol_data_size(const iButtonKey* key) {
|
|
|
|
return key->protocol_data_size;
|
2022-05-06 13:37:10 +00:00
|
|
|
}
|