flipperzero-firmware/applications/ibutton/ibutton_key.cpp
あく 389ff92cc1
Naming and coding style convention, new linter tool. (#945)
* Makefile, Scripts: new linter
* About: remove ID from IC
* Firmware: remove double define for DIVC/DIVR
* Scripts: check folder names too. Docker: replace syntax check with make lint.
* Reformat Sources and Migrate to new file naming convention
* Docker: symlink clang-format-12 to clang-format
* Add coding style guide
2022-01-05 19:10:18 +03:00

96 lines
2.2 KiB
C++

#include "ibutton_key.h"
#include <furi.h>
uint8_t iButtonKey::get_size() {
return IBUTTON_KEY_DATA_SIZE;
}
void iButtonKey::set_data(uint8_t* _data, uint8_t _data_count) {
furi_check(_data_count > 0);
furi_check(_data_count <= get_size());
memset(data, 0, get_size());
memcpy(data, _data, _data_count);
}
void iButtonKey::clear_data() {
memset(data, 0, get_size());
}
uint8_t* iButtonKey::get_data() {
return data;
}
uint8_t iButtonKey::get_type_data_size() {
return get_type_data_size_by_type(type);
}
void iButtonKey::set_name(const char* _name) {
strlcpy(name, _name, IBUTTON_KEY_NAME_SIZE);
}
char* iButtonKey::get_name() {
return name;
}
void iButtonKey::set_type(iButtonKeyType _key_type) {
type = _key_type;
}
iButtonKeyType iButtonKey::get_key_type() {
return type;
}
const char* iButtonKey::get_key_type_string_by_type(iButtonKeyType key_type) {
switch(key_type) {
case iButtonKeyType::KeyCyfral:
return "Cyfral";
break;
case iButtonKeyType::KeyMetakom:
return "Metakom";
break;
case iButtonKeyType::KeyDallas:
return "Dallas";
break;
default:
furi_crash("Invalid iButton type");
return "";
break;
}
}
bool iButtonKey::get_key_type_by_type_string(const char* type_string, iButtonKeyType* key_type) {
if(strcmp(type_string, get_key_type_string_by_type(iButtonKeyType::KeyCyfral)) == 0) {
*key_type = iButtonKeyType::KeyCyfral;
} else if(strcmp(type_string, get_key_type_string_by_type(iButtonKeyType::KeyMetakom)) == 0) {
*key_type = iButtonKeyType::KeyMetakom;
} else if(strcmp(type_string, get_key_type_string_by_type(iButtonKeyType::KeyDallas)) == 0) {
*key_type = iButtonKeyType::KeyDallas;
} else {
return false;
}
return true;
}
uint8_t iButtonKey::get_type_data_size_by_type(iButtonKeyType key_type) {
uint8_t size = 0;
switch(key_type) {
case iButtonKeyType::KeyCyfral:
size = 2;
break;
case iButtonKeyType::KeyMetakom:
size = 4;
break;
case iButtonKeyType::KeyDallas:
size = 8;
break;
}
return size;
}
iButtonKey::iButtonKey() {
}