[FL-1371] New LF-RFID app. Second encounter. (#547)

* File worker: file operations helper.
* Notification app: removed yield
* File worker: write operations, calls to system file widgets
* App ibutton: use file worker
* Lfrfid: generic key loading, add path helper and hex conversion to lib
* FileWorker: plain C verison
* FileWorker: add to lib.mk
* FileWorker: add to C sources, instead of CPP
* Lfrfid: save scene
* App lfrfid: add key scene, saved key menu
* App lfrfid: saved key info scene
* App lfrfid: delete key scene
This commit is contained in:
SG
2021-06-30 22:02:46 +10:00
committed by GitHub
parent e8211226f3
commit 7a13391b2b
44 changed files with 1637 additions and 446 deletions

View File

@@ -1,4 +1,5 @@
#include "args.h"
#include "hex.h"
size_t args_get_first_word_length(string_t args) {
size_t ws = string_search_char(args, ' ');
@@ -27,28 +28,13 @@ bool args_read_string_and_trim(string_t args, string_t word) {
return true;
}
bool args_char_to_hex_nibble(char c, uint8_t* nibble) {
if((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f')) {
if((c >= '0' && c <= '9')) {
*nibble = c - '0';
} else if((c >= 'A' && c <= 'F')) {
*nibble = c - 'A' + 10;
} else {
*nibble = c - 'a' + 10;
}
return true;
} else {
return false;
}
}
bool args_char_to_hex(char hi_nibble, char low_nibble, uint8_t* byte) {
uint8_t hi_nibble_value = 0;
uint8_t low_nibble_value = 0;
bool result = false;
if(args_char_to_hex_nibble(hi_nibble, &hi_nibble_value)) {
if(args_char_to_hex_nibble(low_nibble, &low_nibble_value)) {
if(hex_char_to_hex_nibble(hi_nibble, &hi_nibble_value)) {
if(hex_char_to_hex_nibble(low_nibble, &low_nibble_value)) {
result = true;
*byte = (hi_nibble_value << 4) | low_nibble_value;
}

View File

@@ -46,15 +46,6 @@ size_t args_get_first_word_length(string_t args);
*/
size_t args_length(string_t args);
/**
* @brief Convert ASCII hex value to nibble
*
* @param c ASCII character
* @param nibble nibble pointer, output
* @return bool conversion status
*/
bool args_char_to_hex_nibble(char c, uint8_t* nibble);
/**
* @brief Convert ASCII hex values to byte
*

16
lib/args/hex.c Normal file
View File

@@ -0,0 +1,16 @@
#include "hex.h"
bool hex_char_to_hex_nibble(char c, uint8_t* nibble) {
if((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f')) {
if((c >= '0' && c <= '9')) {
*nibble = c - '0';
} else if((c >= 'A' && c <= 'F')) {
*nibble = c - 'A' + 10;
} else {
*nibble = c - 'a' + 10;
}
return true;
} else {
return false;
}
}

20
lib/args/hex.h Normal file
View File

@@ -0,0 +1,20 @@
#pragma once
#include "stdint.h"
#include "stdbool.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Convert ASCII hex value to nibble
*
* @param c ASCII character
* @param nibble nibble pointer, output
* @return bool conversion status
*/
bool hex_char_to_hex_nibble(char c, uint8_t* nibble);
#ifdef __cplusplus
}
#endif

20
lib/args/path.c Normal file
View File

@@ -0,0 +1,20 @@
#include "path.h"
void path_extract_filename_no_ext(const char* path, string_t filename) {
string_set(filename, path);
size_t start_position = string_search_rchar(filename, '/');
size_t end_position = string_search_rchar(filename, '.');
if(start_position == STRING_FAILURE) {
start_position = 0;
} else {
start_position += 1;
}
if(end_position == STRING_FAILURE) {
end_position = string_size(filename);
}
string_mid(filename, start_position, end_position - start_position);
}

18
lib/args/path.h Normal file
View File

@@ -0,0 +1,18 @@
#pragma once
#include "m-string.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Extract filename without extension from path.
*
* @param path path string
* @param filename output filename string. Must be initialized before.
*/
void path_extract_filename_no_ext(const char* path, string_t filename);
#ifdef __cplusplus
}
#endif