Skip to content

Commit

Permalink
[FL-2674] Show error popup when NFC chip is not init/disconnected (fl…
Browse files Browse the repository at this point in the history
…ipperdevices#1722)

* Show error popup when NFC chip is not init/disconnected
* Move to dialogs for the error message
* Fix a memory leak and wrap the hal check
* F7: update api_symbols.csv, add furi_hal_nfc_is_init

Co-authored-by: SG <who.just.the.doctor@gmail.com>
Co-authored-by: あく <alleteam@gmail.com>
  • Loading branch information
3 people committed Sep 19, 2022
1 parent 9e8e157 commit 1789998
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 1 deletion.
23 changes: 23 additions & 0 deletions applications/main/nfc/nfc.c
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,30 @@ void nfc_show_loading_popup(void* context, bool show) {
}
}

static bool nfc_is_hal_ready() {
if(!furi_hal_nfc_is_init()) {
// No connection to the chip, show an error screen
DialogsApp* dialogs = furi_record_open(RECORD_DIALOGS);
DialogMessage* message = dialog_message_alloc();
dialog_message_set_text(
message,
"Error!\nNFC chip failed to start\n\n\nSend a photo of this to:\nsupport@flipperzero.one",
0,
0,
AlignLeft,
AlignTop);
dialog_message_show(dialogs, message);
dialog_message_free(message);
furi_record_close(RECORD_DIALOGS);
return false;
} else {
return true;
}
}

int32_t nfc_app(void* p) {
if(!nfc_is_hal_ready()) return 0;

Nfc* nfc = nfc_alloc();
char* args = p;

Expand Down
2 changes: 2 additions & 0 deletions applications/main/nfc/nfc_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
#include <nfc/scenes/nfc_scene.h>
#include <nfc/helpers/nfc_custom_event.h>

#include <dialogs/dialogs.h>

#include "rpc/rpc_app.h"

#define NFC_TEXT_STORE_SIZE 128
Expand Down
3 changes: 2 additions & 1 deletion firmware/targets/f7/api_symbols.csv
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
entry,status,name,type,params
Version,+,1.3,,
Version,+,1.4,,
Header,+,applications/services/bt/bt_service/bt.h,,
Header,+,applications/services/cli/cli.h,,
Header,+,applications/services/cli/cli_vcp.h,,
Expand Down Expand Up @@ -1096,6 +1096,7 @@ Function,+,furi_hal_nfc_field_off,void,
Function,+,furi_hal_nfc_field_on,void,
Function,-,furi_hal_nfc_init,void,
Function,+,furi_hal_nfc_is_busy,_Bool,
Function,+,furi_hal_nfc_is_init,_Bool,
Function,+,furi_hal_nfc_listen,_Bool,"uint8_t*, uint8_t, uint8_t*, uint8_t, _Bool, uint32_t"
Function,+,furi_hal_nfc_listen_rx,_Bool,"FuriHalNfcTxRxContext*, uint32_t"
Function,+,furi_hal_nfc_listen_sleep,void,
Expand Down
4 changes: 4 additions & 0 deletions firmware/targets/f7/furi_hal/furi_hal_nfc.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ bool furi_hal_nfc_is_busy() {
return rfalNfcGetState() != RFAL_NFC_STATE_IDLE;
}

bool furi_hal_nfc_is_init() {
return rfalNfcGetState() != RFAL_NFC_STATE_NOTINIT;
}

void furi_hal_nfc_field_on() {
furi_hal_nfc_exit_sleep();
st25r3916TxRxOn();
Expand Down
6 changes: 6 additions & 0 deletions firmware/targets/furi_hal_include/furi_hal_nfc.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ void furi_hal_nfc_init();
*/
bool furi_hal_nfc_is_busy();

/** Check if nfc is initialized
*
* @return true if initialized
*/
bool furi_hal_nfc_is_init();

/** NFC field on
*/
void furi_hal_nfc_field_on();
Expand Down

0 comments on commit 1789998

Please sign in to comment.