2022-03-23 13:45:37 +00:00
|
|
|
#include "../nfc_i.h"
|
|
|
|
#include <dolphin/dolphin.h>
|
|
|
|
|
2022-08-17 15:08:13 +00:00
|
|
|
void nfc_scene_mf_desfire_read_success_widget_callback(
|
|
|
|
GuiButtonType result,
|
|
|
|
InputType type,
|
|
|
|
void* context) {
|
2022-04-19 15:23:58 +00:00
|
|
|
Nfc* nfc = context;
|
2022-03-23 13:45:37 +00:00
|
|
|
|
2022-08-17 15:08:13 +00:00
|
|
|
if(type == InputTypeShort) {
|
|
|
|
view_dispatcher_send_custom_event(nfc->view_dispatcher, result);
|
|
|
|
}
|
2022-03-23 13:45:37 +00:00
|
|
|
}
|
|
|
|
|
2022-07-26 15:30:49 +00:00
|
|
|
void nfc_scene_mf_desfire_read_success_on_enter(void* context) {
|
2022-04-19 15:23:58 +00:00
|
|
|
Nfc* nfc = context;
|
2022-03-23 13:45:37 +00:00
|
|
|
|
2022-08-17 15:08:13 +00:00
|
|
|
FuriHalNfcDevData* nfc_data = &nfc->dev->dev_data.nfc_data;
|
2022-03-23 13:45:37 +00:00
|
|
|
MifareDesfireData* data = &nfc->dev->dev_data.mf_df_data;
|
2022-08-17 15:08:13 +00:00
|
|
|
Widget* widget = nfc->widget;
|
|
|
|
|
|
|
|
// Prepare string for data display
|
|
|
|
string_t temp_str;
|
|
|
|
string_init_printf(temp_str, "\e#MIFARE DESfire\n");
|
|
|
|
string_cat_printf(temp_str, "UID:");
|
|
|
|
for(size_t i = 0; i < nfc_data->uid_len; i++) {
|
|
|
|
string_cat_printf(temp_str, " %02X", nfc_data->uid[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t bytes_total = 1 << (data->version.sw_storage >> 1);
|
|
|
|
uint32_t bytes_free = data->free_memory ? data->free_memory->bytes : 0;
|
|
|
|
string_cat_printf(temp_str, "\n%d", bytes_total);
|
|
|
|
if(data->version.sw_storage & 1) {
|
|
|
|
string_push_back(temp_str, '+');
|
|
|
|
}
|
|
|
|
string_cat_printf(temp_str, " bytes, %d bytes free\n", bytes_free);
|
2022-03-23 13:45:37 +00:00
|
|
|
|
|
|
|
uint16_t n_apps = 0;
|
|
|
|
uint16_t n_files = 0;
|
|
|
|
for(MifareDesfireApplication* app = data->app_head; app; app = app->next) {
|
|
|
|
n_apps++;
|
|
|
|
for(MifareDesfireFile* file = app->file_head; file; file = file->next) {
|
|
|
|
n_files++;
|
|
|
|
}
|
|
|
|
}
|
2022-08-17 15:08:13 +00:00
|
|
|
string_cat_printf(temp_str, "%d Application", n_apps);
|
|
|
|
if(n_apps != 1) {
|
|
|
|
string_push_back(temp_str, 's');
|
|
|
|
}
|
|
|
|
string_cat_printf(temp_str, ", %d file", n_files);
|
|
|
|
if(n_files != 1) {
|
|
|
|
string_push_back(temp_str, 's');
|
|
|
|
}
|
2022-03-23 13:45:37 +00:00
|
|
|
|
2022-08-17 15:08:13 +00:00
|
|
|
// Add text scroll element
|
|
|
|
widget_add_text_scroll_element(widget, 0, 0, 128, 52, string_get_cstr(temp_str));
|
|
|
|
string_clear(temp_str);
|
2022-03-23 13:45:37 +00:00
|
|
|
|
2022-08-17 15:08:13 +00:00
|
|
|
// Add button elements
|
|
|
|
widget_add_button_element(
|
|
|
|
widget, GuiButtonTypeLeft, "Retry", nfc_scene_mf_desfire_read_success_widget_callback, nfc);
|
|
|
|
widget_add_button_element(
|
|
|
|
widget, GuiButtonTypeRight, "More", nfc_scene_mf_desfire_read_success_widget_callback, nfc);
|
|
|
|
|
|
|
|
view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewWidget);
|
2022-03-23 13:45:37 +00:00
|
|
|
}
|
|
|
|
|
2022-07-26 15:30:49 +00:00
|
|
|
bool nfc_scene_mf_desfire_read_success_on_event(void* context, SceneManagerEvent event) {
|
2022-03-23 13:45:37 +00:00
|
|
|
Nfc* nfc = context;
|
2022-04-19 15:23:58 +00:00
|
|
|
bool consumed = false;
|
2022-03-23 13:45:37 +00:00
|
|
|
|
|
|
|
if(event.type == SceneManagerEventTypeCustom) {
|
2022-08-17 15:08:13 +00:00
|
|
|
if(event.event == GuiButtonTypeLeft) {
|
2022-07-26 15:30:49 +00:00
|
|
|
scene_manager_next_scene(nfc->scene_manager, NfcSceneRetryConfirm);
|
2022-03-23 13:45:37 +00:00
|
|
|
consumed = true;
|
2022-08-17 15:08:13 +00:00
|
|
|
} else if(event.event == GuiButtonTypeRight) {
|
2022-07-26 15:30:49 +00:00
|
|
|
scene_manager_next_scene(nfc->scene_manager, NfcSceneMfDesfireMenu);
|
2022-03-23 13:45:37 +00:00
|
|
|
consumed = true;
|
|
|
|
}
|
|
|
|
} else if(event.type == SceneManagerEventTypeBack) {
|
2022-08-17 15:08:13 +00:00
|
|
|
scene_manager_next_scene(nfc->scene_manager, NfcSceneExitConfirm);
|
|
|
|
consumed = true;
|
2022-03-23 13:45:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return consumed;
|
|
|
|
}
|
|
|
|
|
2022-07-26 15:30:49 +00:00
|
|
|
void nfc_scene_mf_desfire_read_success_on_exit(void* context) {
|
2022-04-19 15:23:58 +00:00
|
|
|
Nfc* nfc = context;
|
2022-03-23 13:45:37 +00:00
|
|
|
|
|
|
|
// Clean dialog
|
2022-08-17 15:08:13 +00:00
|
|
|
widget_reset(nfc->widget);
|
2022-03-23 13:45:37 +00:00
|
|
|
}
|