mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-05-12 16:58:36 -07:00
Array use refactor
Move all arrays to allocating actual data rather than pointers to simplify construction and destruction. Also moved to M_EACH for iterating over arrays for less boilerplate code. Also did some function renaming for extra clarity. root_area is now a node type for simplified area traversal (coming soon).
This commit is contained in:
@@ -19,24 +19,24 @@ void nfc_scene_felica_info_select_on_enter(void* context) {
|
||||
uint8_t i = 1;
|
||||
if(state->selected_system == NULL || state->selected_system->code == LITE_SYSTEM_CODE) {
|
||||
submenu_set_header(submenu, "Systems");
|
||||
FelicaSystemList_it_t it;
|
||||
for(FelicaSystemList_it(it, data->systems); !FelicaSystemList_end_p(it);
|
||||
FelicaSystemList_next(it)) {
|
||||
FelicaSystem* current_system = *FelicaSystemList_ref(it);
|
||||
FuriString* system_name = felica_get_system_name(current_system);
|
||||
submenu_add_item(
|
||||
submenu,
|
||||
furi_string_get_cstr(system_name),
|
||||
i++,
|
||||
nfc_scene_felica_info_select_submenu_callback,
|
||||
nfc);
|
||||
furi_string_free(system_name);
|
||||
}
|
||||
for
|
||||
M_EACH(current_system, data->systems, FelicaSystemArray_t) {
|
||||
FuriString* system_name = felica_get_system_name(current_system);
|
||||
submenu_add_item(
|
||||
submenu,
|
||||
furi_string_get_cstr(system_name),
|
||||
i++,
|
||||
nfc_scene_felica_info_select_submenu_callback,
|
||||
nfc);
|
||||
furi_string_free(system_name);
|
||||
}
|
||||
} else {
|
||||
FelicaSystem* system = state->selected_system;
|
||||
FuriString* header = furi_string_alloc_printf("%04X/", system->code);
|
||||
|
||||
FelicaArea* area = &system->root_area;
|
||||
FelicaNode* root = &system->root;
|
||||
furi_assert(root->type == FelicaNodeTypeArea);
|
||||
FelicaArea* area = root->area;
|
||||
if(FelicaAreaPath_size(state->selected_areas) > 0) {
|
||||
FelicaAreaPath_it_t it;
|
||||
for(FelicaAreaPath_it(it, state->selected_areas); !FelicaAreaPath_end_p(it);
|
||||
@@ -51,32 +51,30 @@ void nfc_scene_felica_info_select_on_enter(void* context) {
|
||||
submenu_set_header(submenu, furi_string_get_cstr(header));
|
||||
furi_string_free(header);
|
||||
|
||||
FelicaNodeList_it_t it;
|
||||
for(FelicaNodeList_it(it, area->nodes); !FelicaNodeList_end_p(it);
|
||||
FelicaNodeList_next(it)) {
|
||||
FelicaNode* node = *FelicaNodeList_ref(it);
|
||||
FuriString* node_name = furi_string_alloc();
|
||||
if(node->type == FelicaNodeTypeArea) {
|
||||
furi_string_printf(node_name, "Area %d", node->area->number);
|
||||
submenu_add_item(
|
||||
submenu,
|
||||
furi_string_get_cstr(node_name),
|
||||
i++,
|
||||
nfc_scene_felica_info_select_submenu_callback,
|
||||
nfc);
|
||||
} else {
|
||||
uint16_t service_code = node->service->number << 6;
|
||||
furi_string_printf(node_name, "Service %04X", service_code);
|
||||
submenu_add_item(
|
||||
submenu,
|
||||
furi_string_get_cstr(node_name),
|
||||
i++,
|
||||
nfc_scene_felica_info_select_submenu_callback,
|
||||
nfc);
|
||||
}
|
||||
for
|
||||
M_EACH(node, area->nodes, FelicaNodeArray_t) {
|
||||
FuriString* node_name = furi_string_alloc();
|
||||
if(node->type == FelicaNodeTypeArea) {
|
||||
furi_string_printf(node_name, "Area %d", node->area->number);
|
||||
submenu_add_item(
|
||||
submenu,
|
||||
furi_string_get_cstr(node_name),
|
||||
i++,
|
||||
nfc_scene_felica_info_select_submenu_callback,
|
||||
nfc);
|
||||
} else {
|
||||
uint16_t service_code = node->service->number << 6;
|
||||
furi_string_printf(node_name, "Service %04X", service_code);
|
||||
submenu_add_item(
|
||||
submenu,
|
||||
furi_string_get_cstr(node_name),
|
||||
i++,
|
||||
nfc_scene_felica_info_select_submenu_callback,
|
||||
nfc);
|
||||
}
|
||||
|
||||
furi_string_free(node_name);
|
||||
}
|
||||
furi_string_free(node_name);
|
||||
}
|
||||
}
|
||||
|
||||
state->selected_service = NULL;
|
||||
@@ -102,7 +100,7 @@ bool nfc_scene_felica_info_select_on_event(void* context, SceneManagerEvent even
|
||||
|
||||
index -= 1;
|
||||
if(state->selected_system == NULL) {
|
||||
state->selected_system = *FelicaSystemList_get(data->systems, index);
|
||||
state->selected_system = FelicaSystemArray_get(data->systems, index);
|
||||
if(state->selected_system->code == LITE_SYSTEM_CODE) {
|
||||
scene_manager_next_scene(nfc->scene_manager, NfcSceneFelicaServiceData);
|
||||
} else {
|
||||
@@ -111,12 +109,15 @@ bool nfc_scene_felica_info_select_on_event(void* context, SceneManagerEvent even
|
||||
consumed = true;
|
||||
} else {
|
||||
FelicaNode* selected_node = NULL;
|
||||
|
||||
FelicaNode* root = &(state->selected_system->root);
|
||||
furi_assert(root->type == FelicaNodeTypeArea);
|
||||
|
||||
if(FelicaAreaPath_size(state->selected_areas) == 0) {
|
||||
selected_node =
|
||||
*FelicaNodeList_get(state->selected_system->root_area.nodes, index);
|
||||
selected_node = FelicaNodeArray_get(root->area->nodes, index);
|
||||
} else {
|
||||
FelicaArea* current_area = *FelicaAreaPath_back(state->selected_areas);
|
||||
selected_node = *FelicaNodeList_get(current_area->nodes, index);
|
||||
selected_node = FelicaNodeArray_get(current_area->nodes, index);
|
||||
}
|
||||
|
||||
if(selected_node->type == FelicaNodeTypeArea) {
|
||||
|
||||
@@ -29,21 +29,19 @@ void nfc_scene_felica_read_success_on_enter(void* context) {
|
||||
} else {
|
||||
temp_str = furi_string_alloc_printf("\e#%s", nfc_felica_type(felica_data->type));
|
||||
|
||||
FelicaSystemList_it_t it;
|
||||
for(FelicaSystemList_it(it, felica_data->systems); !FelicaSystemList_end_p(it);
|
||||
FelicaSystemList_next(it)) {
|
||||
FelicaSystem* current_system = *FelicaSystemList_ref(it);
|
||||
furi_string_cat_printf(
|
||||
temp_str, "\nSystem %04X (#%d):", current_system->code, current_system->number);
|
||||
furi_string_cat_printf(temp_str, "\nIDm:\n ");
|
||||
for(size_t i = 0; i < 8; i++) {
|
||||
furi_string_cat_printf(temp_str, "%02X", current_system->idm[i]);
|
||||
for
|
||||
M_EACH(current_system, felica_data->systems, FelicaSystemArray_t) {
|
||||
furi_string_cat_printf(
|
||||
temp_str, "\nSystem %04X (#%d):", current_system->code, current_system->number);
|
||||
furi_string_cat_printf(temp_str, "\nIDm:\n ");
|
||||
for(size_t i = 0; i < 8; i++) {
|
||||
furi_string_cat_printf(temp_str, "%02X", current_system->idm[i]);
|
||||
}
|
||||
furi_string_cat_printf(temp_str, "\nPMm:\n ");
|
||||
for(size_t i = 0; i < 8; i++) {
|
||||
furi_string_cat_printf(temp_str, "%02X", current_system->pmm[i]);
|
||||
}
|
||||
}
|
||||
furi_string_cat_printf(temp_str, "\nPMm:\n ");
|
||||
for(size_t i = 0; i < 8; i++) {
|
||||
furi_string_cat_printf(temp_str, "%02X", current_system->pmm[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
widget_add_text_scroll_element(widget, 0, 0, 128, 52, furi_string_get_cstr(temp_str));
|
||||
|
||||
@@ -66,35 +66,35 @@ void nfc_scene_nfc_data_info_on_enter(void* context) {
|
||||
nfc_data->f_data.pmm[0],
|
||||
nfc_data->f_data.pmm[1]);
|
||||
|
||||
furi_string_cat_printf(temp_str, "Timings (1 node/blk):\n");
|
||||
furi_string_cat_printf(temp_str, "MRT (1 node/blk):\n");
|
||||
furi_string_cat_printf(
|
||||
temp_str,
|
||||
"- ReqSvc: %" PRIuLEAST32 "us\n",
|
||||
felica_estimate_timing_us(nfc_data->f_data.pmm[2], 1));
|
||||
felica_estimate_timing_us(nfc_data->f_data.pmm[FELICA_PMM_VARIABLE_MRT], 1));
|
||||
furi_string_cat_printf(
|
||||
temp_str,
|
||||
"- Fixed: %" PRIuLEAST32 "us\n",
|
||||
felica_estimate_timing_us(nfc_data->f_data.pmm[3], 0));
|
||||
felica_estimate_timing_us(nfc_data->f_data.pmm[FELICA_PMM_FIXED_MRT], 0));
|
||||
furi_string_cat_printf(
|
||||
temp_str,
|
||||
"- Auth1: %" PRIuLEAST32 "us\n",
|
||||
felica_estimate_timing_us(nfc_data->f_data.pmm[4], 1));
|
||||
felica_estimate_timing_us(nfc_data->f_data.pmm[FELICA_PMM_MUTUAL_AUTH_MRT], 1));
|
||||
furi_string_cat_printf(
|
||||
temp_str,
|
||||
"- Auth2: %" PRIuLEAST32 "us\n",
|
||||
felica_estimate_timing_us(nfc_data->f_data.pmm[4], 0));
|
||||
felica_estimate_timing_us(nfc_data->f_data.pmm[FELICA_PMM_MUTUAL_AUTH_MRT], 0));
|
||||
furi_string_cat_printf(
|
||||
temp_str,
|
||||
"- Read: %" PRIuLEAST32 "us\n",
|
||||
felica_estimate_timing_us(nfc_data->f_data.pmm[5], 1));
|
||||
felica_estimate_timing_us(nfc_data->f_data.pmm[FELICA_PMM_READ_MRT], 1));
|
||||
furi_string_cat_printf(
|
||||
temp_str,
|
||||
"- Write: %" PRIuLEAST32 "us\n",
|
||||
felica_estimate_timing_us(nfc_data->f_data.pmm[6], 1));
|
||||
felica_estimate_timing_us(nfc_data->f_data.pmm[FELICA_PMM_WRITE_MRT], 1));
|
||||
furi_string_cat_printf(
|
||||
temp_str,
|
||||
"- Other: %" PRIuLEAST32 "us\n\n",
|
||||
felica_estimate_timing_us(nfc_data->f_data.pmm[7], 0));
|
||||
felica_estimate_timing_us(nfc_data->f_data.pmm[FELICA_PMM_OTHER_MRT], 0));
|
||||
|
||||
furi_string_cat_printf(temp_str, "IDm:");
|
||||
for(size_t i = 0; i < nfc_data->uid_len; i++) {
|
||||
|
||||
@@ -8,6 +8,7 @@ enum SubmenuIndex {
|
||||
SubmenuIndexReadEMV,
|
||||
SubmenuIndexReadNFCA,
|
||||
SubmenuIndexReadFelica,
|
||||
SubmenuIndexReadNFCF,
|
||||
};
|
||||
|
||||
void nfc_scene_read_card_type_submenu_callback(void* context, uint32_t index) {
|
||||
@@ -56,6 +57,12 @@ void nfc_scene_read_card_type_on_enter(void* context) {
|
||||
SubmenuIndexReadFelica,
|
||||
nfc_scene_read_card_type_submenu_callback,
|
||||
nfc);
|
||||
submenu_add_item(
|
||||
submenu,
|
||||
"Read NFC-F data",
|
||||
SubmenuIndexReadNFCF,
|
||||
nfc_scene_read_card_type_submenu_callback,
|
||||
nfc);
|
||||
uint32_t state = scene_manager_get_scene_state(nfc->scene_manager, NfcSceneReadCardType);
|
||||
submenu_set_selected_item(submenu, state);
|
||||
|
||||
@@ -97,6 +104,11 @@ bool nfc_scene_read_card_type_on_event(void* context, SceneManagerEvent event) {
|
||||
scene_manager_next_scene(nfc->scene_manager, NfcSceneRead);
|
||||
consumed = true;
|
||||
}
|
||||
if(event.event == SubmenuIndexReadNFCF) {
|
||||
nfc->dev->dev_data.read_mode = NfcReadModeNFCF;
|
||||
scene_manager_next_scene(nfc->scene_manager, NfcSceneRead);
|
||||
consumed = true;
|
||||
}
|
||||
scene_manager_set_scene_state(nfc->scene_manager, NfcSceneReadCardType, event.event);
|
||||
}
|
||||
return consumed;
|
||||
|
||||
Reference in New Issue
Block a user