Merge branch 'fz-dev' into dev

This commit is contained in:
MX 2022-12-30 16:34:20 +03:00
commit 6eb6297ab7
No known key found for this signature in database
GPG Key ID: 6C4C311DFD4B4AB5
6 changed files with 88 additions and 52 deletions

View File

@ -1,7 +1,6 @@
#include "../lfrfid_i.h"
typedef struct {
FuriString* menu_item_name[LFRFIDProtocolMax];
uint32_t line_sel;
} SaveTypeCtx;
@ -16,26 +15,28 @@ void lfrfid_scene_save_type_on_enter(void* context) {
Submenu* submenu = app->submenu;
SaveTypeCtx* state = malloc(sizeof(SaveTypeCtx));
FuriString* protocol_string = furi_string_alloc();
for(uint8_t i = 0; i < LFRFIDProtocolMax; i++) {
if((strcmp(
protocol_dict_get_manufacturer(app->dict, i),
protocol_dict_get_name(app->dict, i)) != 0) &&
(strcmp(protocol_dict_get_manufacturer(app->dict, i), "N/A") != 0)) {
state->menu_item_name[i] = furi_string_alloc_printf(
furi_string_printf(
protocol_string,
"%s %s",
protocol_dict_get_manufacturer(app->dict, i),
protocol_dict_get_name(app->dict, i));
} else {
state->menu_item_name[i] =
furi_string_alloc_printf("%s", protocol_dict_get_name(app->dict, i));
furi_string_printf(protocol_string, "%s", protocol_dict_get_name(app->dict, i));
}
submenu_add_item(
submenu,
furi_string_get_cstr(state->menu_item_name[i]),
furi_string_get_cstr(protocol_string),
i,
lfrfid_scene_save_type_submenu_callback,
app);
}
furi_string_free(protocol_string);
submenu_set_selected_item(
submenu, scene_manager_get_scene_state(app->scene_manager, LfRfidSceneSaveType));
@ -74,13 +75,7 @@ void lfrfid_scene_save_type_on_exit(void* context) {
submenu_reset(app->submenu);
for(uint8_t i = 0; i < LFRFIDProtocolMax; i++) {
furi_string_free(state->menu_item_name[i]);
}
uint32_t line_sel = state->line_sel;
free(state);
scene_manager_set_scene_state(app->scene_manager, LfRfidSceneSaveType, line_sel);
}

View File

@ -51,23 +51,18 @@ void nfc_scene_mf_desfire_app_on_enter(void* context) {
nfc_scene_mf_desfire_app_submenu_callback,
nfc);
uint16_t cap = NFC_TEXT_STORE_SIZE;
char* buf = nfc->text_store;
FuriString* label = furi_string_alloc();
int idx = SubmenuIndexDynamic;
for(MifareDesfireFile* file = app->file_head; file; file = file->next) {
int size = snprintf(buf, cap, "File %d", file->id);
if(size < 0 || size >= cap) {
FURI_LOG_W(
TAG,
"Exceeded NFC_TEXT_STORE_SIZE when preparing file id strings; menu truncated");
break;
}
char* label = buf;
cap -= size + 1;
buf += size + 1;
furi_string_printf(label, "File %d", file->id);
submenu_add_item(
nfc->submenu, label, idx++, nfc_scene_mf_desfire_app_submenu_callback, nfc);
nfc->submenu,
furi_string_get_cstr(label),
idx++,
nfc_scene_mf_desfire_app_submenu_callback,
nfc);
}
furi_string_free(label);
view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewMenu);
}

View File

@ -33,21 +33,18 @@ void nfc_scene_mf_desfire_data_on_enter(void* context) {
nfc_scene_mf_desfire_data_submenu_callback,
nfc);
uint16_t cap = NFC_TEXT_STORE_SIZE;
char* buf = nfc->text_store;
FuriString* label = furi_string_alloc();
int idx = SubmenuIndexDynamic;
for(MifareDesfireApplication* app = data->app_head; app; app = app->next) {
int size = snprintf(buf, cap, "App %02x%02x%02x", app->id[0], app->id[1], app->id[2]);
if(size < 0 || size >= cap) {
FURI_LOG_W(
TAG, "Exceeded NFC_TEXT_STORE_SIZE when preparing app id strings; menu truncated");
break;
}
char* label = buf;
cap -= size + 1;
buf += size + 1;
submenu_add_item(submenu, label, idx++, nfc_scene_mf_desfire_data_submenu_callback, nfc);
furi_string_printf(label, "App %02x%02x%02x", app->id[0], app->id[1], app->id[2]);
submenu_add_item(
submenu,
furi_string_get_cstr(label),
idx++,
nfc_scene_mf_desfire_data_submenu_callback,
nfc);
}
furi_string_free(label);
if(state >= MifareDesfireDataStateItem) {
submenu_set_selected_item(

View File

@ -9,17 +9,48 @@ struct Submenu {
};
typedef struct {
const char* label;
FuriString* label;
uint32_t index;
SubmenuItemCallback callback;
void* callback_context;
} SubmenuItem;
ARRAY_DEF(SubmenuItemArray, SubmenuItem, M_POD_OPLIST);
static void SubmenuItem_init(SubmenuItem* item) {
item->label = furi_string_alloc();
item->index = 0;
item->callback = NULL;
item->callback_context = NULL;
}
static void SubmenuItem_init_set(SubmenuItem* item, const SubmenuItem* src) {
item->label = furi_string_alloc_set(src->label);
item->index = src->index;
item->callback = src->callback;
item->callback_context = src->callback_context;
}
static void SubmenuItem_set(SubmenuItem* item, const SubmenuItem* src) {
furi_string_set(item->label, src->label);
item->index = src->index;
item->callback = src->callback;
item->callback_context = src->callback_context;
}
static void SubmenuItem_clear(SubmenuItem* item) {
furi_string_free(item->label);
}
ARRAY_DEF(
SubmenuItemArray,
SubmenuItem,
(INIT(API_2(SubmenuItem_init)),
SET(API_6(SubmenuItem_set)),
INIT_SET(API_6(SubmenuItem_init_set)),
CLEAR(API_2(SubmenuItem_clear))))
typedef struct {
SubmenuItemArray_t items;
const char* header;
FuriString* header;
size_t position;
size_t window_position;
} SubmenuModel;
@ -36,9 +67,9 @@ static void submenu_view_draw_callback(Canvas* canvas, void* _model) {
canvas_clear(canvas);
if(model->header) {
if(!furi_string_empty(model->header)) {
canvas_set_font(canvas, FontPrimary);
canvas_draw_str(canvas, 4, 11, model->header);
canvas_draw_str(canvas, 4, 11, furi_string_get_cstr(model->header));
}
canvas_set_font(canvas, FontSecondary);
@ -48,8 +79,8 @@ static void submenu_view_draw_callback(Canvas* canvas, void* _model) {
for(SubmenuItemArray_it(it, model->items); !SubmenuItemArray_end_p(it);
SubmenuItemArray_next(it)) {
const size_t item_position = position - model->window_position;
const size_t items_on_screen = model->header ? 3 : 4;
uint8_t y_offset = model->header ? 16 : 0;
const size_t items_on_screen = furi_string_empty(model->header) ? 4 : 3;
uint8_t y_offset = furi_string_empty(model->header) ? 0 : 16;
if(item_position < items_on_screen) {
if(position == model->position) {
@ -134,7 +165,7 @@ Submenu* submenu_alloc() {
SubmenuItemArray_init(model->items);
model->position = 0;
model->window_position = 0;
model->header = NULL;
model->header = furi_string_alloc();
},
true);
@ -145,7 +176,13 @@ void submenu_free(Submenu* submenu) {
furi_assert(submenu);
with_view_model(
submenu->view, SubmenuModel * model, { SubmenuItemArray_clear(model->items); }, true);
submenu->view,
SubmenuModel * model,
{
furi_string_free(model->header);
SubmenuItemArray_clear(model->items);
},
true);
view_free(submenu->view);
free(submenu);
}
@ -170,7 +207,7 @@ void submenu_add_item(
SubmenuModel * model,
{
item = SubmenuItemArray_push_new(model->items);
item->label = label;
furi_string_set_str(item->label, label);
item->index = index;
item->callback = callback;
item->callback_context = callback_context;
@ -188,7 +225,7 @@ void submenu_reset(Submenu* submenu) {
SubmenuItemArray_reset(model->items);
model->position = 0;
model->window_position = 0;
model->header = NULL;
furi_string_reset(model->header);
},
true);
}
@ -221,7 +258,7 @@ void submenu_set_selected_item(Submenu* submenu, uint32_t index) {
model->window_position -= 1;
}
const size_t items_on_screen = model->header ? 3 : 4;
const size_t items_on_screen = furi_string_empty(model->header) ? 4 : 3;
if(items_size <= items_on_screen) {
model->window_position = 0;
@ -240,7 +277,7 @@ void submenu_process_up(Submenu* submenu) {
submenu->view,
SubmenuModel * model,
{
const size_t items_on_screen = model->header ? 3 : 4;
const size_t items_on_screen = furi_string_empty(model->header) ? 4 : 3;
const size_t items_size = SubmenuItemArray_size(model->items);
if(model->position > 0) {
@ -263,7 +300,7 @@ void submenu_process_down(Submenu* submenu) {
submenu->view,
SubmenuModel * model,
{
const size_t items_on_screen = model->header ? 3 : 4;
const size_t items_on_screen = furi_string_empty(model->header) ? 4 : 3;
const size_t items_size = SubmenuItemArray_size(model->items);
if(model->position < items_size - 1) {
@ -303,5 +340,14 @@ void submenu_set_header(Submenu* submenu, const char* header) {
furi_assert(submenu);
with_view_model(
submenu->view, SubmenuModel * model, { model->header = header; }, true);
submenu->view,
SubmenuModel * model,
{
if(header == NULL) {
furi_string_reset(model->header);
} else {
furi_string_set_str(model->header, header);
}
},
true);
}

View File

@ -1,5 +1,5 @@
entry,status,name,type,params
Version,+,11.4,,
Version,+,11.5,,
Header,+,applications/services/bt/bt_service/bt.h,,
Header,+,applications/services/cli/cli.h,,
Header,+,applications/services/cli/cli_vcp.h,,
@ -178,6 +178,7 @@ Header,+,lib/subghz/transmitter.h,,
Header,+,lib/toolbox/args.h,,
Header,+,lib/toolbox/crc32_calc.h,,
Header,+,lib/toolbox/dir_walk.h,,
Header,+,lib/toolbox/float_tools.h,,
Header,+,lib/toolbox/hmac_sha256.h,,
Header,+,lib/toolbox/manchester_decoder.h,,
Header,+,lib/toolbox/manchester_encoder.h,,
@ -925,6 +926,7 @@ Function,+,flipper_format_write_int32,_Bool,"FlipperFormat*, const char*, const
Function,+,flipper_format_write_string,_Bool,"FlipperFormat*, const char*, FuriString*"
Function,+,flipper_format_write_string_cstr,_Bool,"FlipperFormat*, const char*, const char*"
Function,+,flipper_format_write_uint32,_Bool,"FlipperFormat*, const char*, const uint32_t*, const uint16_t"
Function,+,float_is_equal,_Bool,"float, float"
Function,-,flockfile,void,FILE*
Function,-,floor,double,double
Function,-,floorf,float,float

1 entry status name type params
2 Version + 11.4 11.5
3 Header + applications/services/bt/bt_service/bt.h
4 Header + applications/services/cli/cli.h
5 Header + applications/services/cli/cli_vcp.h
178 Header + lib/toolbox/args.h
179 Header + lib/toolbox/crc32_calc.h
180 Header + lib/toolbox/dir_walk.h
181 Header + lib/toolbox/float_tools.h
182 Header + lib/toolbox/hmac_sha256.h
183 Header + lib/toolbox/manchester_decoder.h
184 Header + lib/toolbox/manchester_encoder.h
926 Function + flipper_format_write_string _Bool FlipperFormat*, const char*, FuriString*
927 Function + flipper_format_write_string_cstr _Bool FlipperFormat*, const char*, const char*
928 Function + flipper_format_write_uint32 _Bool FlipperFormat*, const char*, const uint32_t*, const uint16_t
929 Function + float_is_equal _Bool float, float
930 Function - flockfile void FILE*
931 Function - floor double double
932 Function - floorf float float

View File

@ -20,6 +20,7 @@ env.Append(
File("args.h"),
File("saved_struct.h"),
File("version.h"),
File("float_tools.h"),
File("tar/tar_archive.h"),
File("stream/stream.h"),
File("stream/file_stream.h"),