From 47acf248011e41477756eab8028b8d5f8ace6e07 Mon Sep 17 00:00:00 2001 From: Nikolay Minaylov Date: Mon, 13 Jun 2022 04:08:28 +0300 Subject: [PATCH 1/2] HW LED blink integration (#1310) --- applications/ibutton/ibutton.c | 37 +++++++++++++++++-- applications/ibutton/ibutton_i.h | 6 ++- .../ibutton/scenes/ibutton_scene_emulate.c | 5 ++- .../ibutton/scenes/ibutton_scene_read.c | 5 ++- .../ibutton/scenes/ibutton_scene_write.c | 18 +++------ .../lfrfid/scene/lfrfid_app_scene_emulate.cpp | 23 +++++++++--- applications/nfc/nfc.c | 20 ++++++++++ applications/nfc/nfc_i.h | 4 ++ .../scenes/nfc_scene_emulate_apdu_sequence.c | 14 +++---- .../scenes/nfc_scene_emulate_mifare_classic.c | 4 +- .../nfc/scenes/nfc_scene_emulate_mifare_ul.c | 4 +- .../nfc/scenes/nfc_scene_emulate_uid.c | 5 ++- applications/nfc/scenes/nfc_scene_read_card.c | 5 ++- .../nfc/scenes/nfc_scene_read_emv_app.c | 4 +- .../nfc/scenes/nfc_scene_read_emv_data.c | 5 ++- .../scenes/nfc_scene_read_mifare_classic.c | 10 +++-- .../scenes/nfc_scene_read_mifare_desfire.c | 6 ++- .../nfc/scenes/nfc_scene_read_mifare_ul.c | 4 +- 18 files changed, 135 insertions(+), 44 deletions(-) diff --git a/applications/ibutton/ibutton.c b/applications/ibutton/ibutton.c index 8713919b5..ae93f9720 100644 --- a/applications/ibutton/ibutton.c +++ b/applications/ibutton/ibutton.c @@ -6,16 +6,47 @@ #include #include +static const NotificationSequence sequence_blink_start_cyan = { + &message_blink_start_10, + &message_blink_set_color_cyan, + &message_do_not_reset, + NULL, +}; + +static const NotificationSequence sequence_blink_start_magenta = { + &message_blink_start_10, + &message_blink_set_color_magenta, + &message_do_not_reset, + NULL, +}; + +static const NotificationSequence sequence_blink_set_yellow = { + &message_blink_set_color_yellow, + NULL, +}; + +static const NotificationSequence sequence_blink_set_magenta = { + &message_blink_set_color_magenta, + NULL, +}; + +static const NotificationSequence sequence_blink_stop = { + &message_blink_stop, + NULL, +}; + static const NotificationSequence* ibutton_notification_sequences[] = { &sequence_error, &sequence_success, - &sequence_blink_cyan_10, - &sequence_blink_magenta_10, - &sequence_blink_yellow_10, + &sequence_blink_start_cyan, + &sequence_blink_start_magenta, + &sequence_blink_set_yellow, + &sequence_blink_set_magenta, &sequence_set_red_255, &sequence_reset_red, &sequence_set_green_255, &sequence_reset_green, + &sequence_blink_stop, }; static void ibutton_make_app_folder(iButton* ibutton) { diff --git a/applications/ibutton/ibutton_i.h b/applications/ibutton/ibutton_i.h index e66712bee..a85dd5f6d 100644 --- a/applications/ibutton/ibutton_i.h +++ b/applications/ibutton/ibutton_i.h @@ -64,13 +64,15 @@ typedef enum { typedef enum { iButtonNotificationMessageError, iButtonNotificationMessageSuccess, - iButtonNotificationMessageRead, - iButtonNotificationMessageEmulate, + iButtonNotificationMessageReadStart, + iButtonNotificationMessageEmulateStart, iButtonNotificationMessageYellowBlink, + iButtonNotificationMessageEmulateBlink, iButtonNotificationMessageRedOn, iButtonNotificationMessageRedOff, iButtonNotificationMessageGreenOn, iButtonNotificationMessageGreenOff, + iButtonNotificationMessageBlinkStop, } iButtonNotificationMessage; bool ibutton_file_select(iButton* ibutton); diff --git a/applications/ibutton/scenes/ibutton_scene_emulate.c b/applications/ibutton/scenes/ibutton_scene_emulate.c index 590223979..9551ea90c 100644 --- a/applications/ibutton/scenes/ibutton_scene_emulate.c +++ b/applications/ibutton/scenes/ibutton_scene_emulate.c @@ -1,4 +1,5 @@ #include "../ibutton_i.h" +#include "furi/log.h" #include #include @@ -85,6 +86,8 @@ void ibutton_scene_emulate_on_enter(void* context) { ibutton_worker_emulate_start(ibutton->key_worker, key); string_clear(key_name); + + ibutton_notification_message(ibutton, iButtonNotificationMessageEmulateStart); } bool ibutton_scene_emulate_on_event(void* context, SceneManagerEvent event) { @@ -93,7 +96,6 @@ bool ibutton_scene_emulate_on_event(void* context, SceneManagerEvent event) { if(event.type == SceneManagerEventTypeTick) { consumed = true; - ibutton_notification_message(ibutton, iButtonNotificationMessageEmulate); } else if(event.type == SceneManagerEventTypeCustom) { consumed = true; if(event.event == iButtonCustomEventWorkerEmulated) { @@ -111,4 +113,5 @@ void ibutton_scene_emulate_on_exit(void* context) { popup_set_header(popup, NULL, 0, 0, AlignCenter, AlignBottom); popup_set_text(popup, NULL, 0, 0, AlignCenter, AlignTop); popup_set_icon(popup, 0, 0, NULL); + ibutton_notification_message(ibutton, iButtonNotificationMessageBlinkStop); } diff --git a/applications/ibutton/scenes/ibutton_scene_read.c b/applications/ibutton/scenes/ibutton_scene_read.c index 0cc0a8dff..c4eb15d36 100644 --- a/applications/ibutton/scenes/ibutton_scene_read.c +++ b/applications/ibutton/scenes/ibutton_scene_read.c @@ -22,6 +22,8 @@ void ibutton_scene_read_on_enter(void* context) { ibutton_worker_read_set_callback(worker, ibutton_scene_read_callback, ibutton); ibutton_worker_read_start(worker, key); + + ibutton_notification_message(ibutton, iButtonNotificationMessageReadStart); } bool ibutton_scene_read_on_event(void* context, SceneManagerEvent event) { @@ -31,7 +33,6 @@ bool ibutton_scene_read_on_event(void* context, SceneManagerEvent event) { if(event.type == SceneManagerEventTypeTick) { consumed = true; - ibutton_notification_message(ibutton, iButtonNotificationMessageRead); } else if(event.type == SceneManagerEventTypeCustom) { consumed = true; if(event.event == iButtonCustomEventWorkerRead) { @@ -69,4 +70,6 @@ void ibutton_scene_read_on_exit(void* context) { popup_set_header(popup, NULL, 0, 0, AlignCenter, AlignBottom); popup_set_text(popup, NULL, 0, 0, AlignCenter, AlignTop); popup_set_icon(popup, 0, 0, NULL); + + ibutton_notification_message(ibutton, iButtonNotificationMessageBlinkStop); } diff --git a/applications/ibutton/scenes/ibutton_scene_write.c b/applications/ibutton/scenes/ibutton_scene_write.c index 4ce19408a..195758d2c 100644 --- a/applications/ibutton/scenes/ibutton_scene_write.c +++ b/applications/ibutton/scenes/ibutton_scene_write.c @@ -80,14 +80,14 @@ void ibutton_scene_write_on_enter(void* context) { popup_set_icon(popup, 2, 10, &I_iButtonKey_49x44); - scene_manager_set_scene_state( - ibutton->scene_manager, iButtonSceneWrite, iButtonSceneWriteStateDefault); view_dispatcher_switch_to_view(ibutton->view_dispatcher, iButtonViewPopup); ibutton_worker_write_set_callback(worker, ibutton_scene_write_callback, ibutton); ibutton_worker_write_start(worker, key); string_clear(key_name); + + ibutton_notification_message(ibutton, iButtonNotificationMessageEmulateStart); } bool ibutton_scene_write_on_event(void* context, SceneManagerEvent event) { @@ -100,21 +100,13 @@ bool ibutton_scene_write_on_event(void* context, SceneManagerEvent event) { if((event.event == iButtonWorkerWriteOK) || (event.event == iButtonWorkerWriteSameKey)) { scene_manager_next_scene(scene_manager, iButtonSceneWriteSuccess); } else if(event.event == iButtonWorkerWriteNoDetect) { - scene_manager_set_scene_state( - scene_manager, iButtonSceneWrite, iButtonSceneWriteStateDefault); + ibutton_notification_message(ibutton, iButtonNotificationMessageEmulateBlink); } else if(event.event == iButtonWorkerWriteCannotWrite) { - scene_manager_set_scene_state( - scene_manager, iButtonSceneWrite, iButtonSceneWriteStateBlinkYellow); + ibutton_notification_message(ibutton, iButtonNotificationMessageYellowBlink); } } else if(event.type == SceneManagerEventTypeTick) { consumed = true; - if(scene_manager_get_scene_state(scene_manager, iButtonSceneWrite) == - iButtonSceneWriteStateBlinkYellow) { - ibutton_notification_message(ibutton, iButtonNotificationMessageYellowBlink); - } else { - ibutton_notification_message(ibutton, iButtonNotificationMessageEmulate); - } } return consumed; @@ -127,4 +119,6 @@ void ibutton_scene_write_on_exit(void* context) { popup_set_header(popup, NULL, 0, 0, AlignCenter, AlignBottom); popup_set_text(popup, NULL, 0, 0, AlignCenter, AlignTop); popup_set_icon(popup, 0, 0, NULL); + + ibutton_notification_message(ibutton, iButtonNotificationMessageBlinkStop); } diff --git a/applications/lfrfid/scene/lfrfid_app_scene_emulate.cpp b/applications/lfrfid/scene/lfrfid_app_scene_emulate.cpp index f1118a481..3df526d0c 100644 --- a/applications/lfrfid/scene/lfrfid_app_scene_emulate.cpp +++ b/applications/lfrfid/scene/lfrfid_app_scene_emulate.cpp @@ -1,6 +1,19 @@ #include "lfrfid_app_scene_emulate.h" +#include "furi/common_defines.h" #include +static const NotificationSequence sequence_blink_start_magenta = { + &message_blink_start_10, + &message_blink_set_color_magenta, + &message_do_not_reset, + NULL, +}; + +static const NotificationSequence sequence_blink_stop = { + &message_blink_stop, + NULL, +}; + void LfRfidAppSceneEmulate::on_enter(LfRfidApp* app, bool /* need_restore */) { string_init(data_string); @@ -23,15 +36,14 @@ void LfRfidAppSceneEmulate::on_enter(LfRfidApp* app, bool /* need_restore */) { app->view_controller.switch_to(); app->worker.start_emulate(); + + notification_message(app->notification, &sequence_blink_start_magenta); } bool LfRfidAppSceneEmulate::on_event(LfRfidApp* app, LfRfidApp::Event* event) { + UNUSED(app); + UNUSED(event); bool consumed = false; - - if(event->type == LfRfidApp::EventType::Tick) { - notification_message(app->notification, &sequence_blink_magenta_10); - } - return consumed; } @@ -39,4 +51,5 @@ void LfRfidAppSceneEmulate::on_exit(LfRfidApp* app) { app->view_controller.get()->clean(); app->worker.stop_emulate(); string_clear(data_string); + notification_message(app->notification, &sequence_blink_stop); } diff --git a/applications/nfc/nfc.c b/applications/nfc/nfc.c index c4eaf900b..adc3b1494 100755 --- a/applications/nfc/nfc.c +++ b/applications/nfc/nfc.c @@ -164,6 +164,26 @@ void nfc_text_store_clear(Nfc* nfc) { memset(nfc->text_store, 0, sizeof(nfc->text_store)); } +static const NotificationSequence sequence_blink_start_blue = { + &message_blink_start_10, + &message_blink_set_color_blue, + &message_do_not_reset, + NULL, +}; + +static const NotificationSequence sequence_blink_stop = { + &message_blink_stop, + NULL, +}; + +void nfc_blink_start(Nfc* nfc) { + notification_message(nfc->notifications, &sequence_blink_start_blue); +} + +void nfc_blink_stop(Nfc* nfc) { + notification_message(nfc->notifications, &sequence_blink_stop); +} + int32_t nfc_app(void* p) { Nfc* nfc = nfc_alloc(); char* args = p; diff --git a/applications/nfc/nfc_i.h b/applications/nfc/nfc_i.h index 51ea82e6c..a640d9578 100755 --- a/applications/nfc/nfc_i.h +++ b/applications/nfc/nfc_i.h @@ -76,3 +76,7 @@ int32_t nfc_task(void* p); void nfc_text_store_set(Nfc* nfc, const char* text, ...); void nfc_text_store_clear(Nfc* nfc); + +void nfc_blink_start(Nfc* nfc); + +void nfc_blink_stop(Nfc* nfc); diff --git a/applications/nfc/scenes/nfc_scene_emulate_apdu_sequence.c b/applications/nfc/scenes/nfc_scene_emulate_apdu_sequence.c index 4f9626e9b..2a6bb9449 100644 --- a/applications/nfc/scenes/nfc_scene_emulate_apdu_sequence.c +++ b/applications/nfc/scenes/nfc_scene_emulate_apdu_sequence.c @@ -1,4 +1,5 @@ #include "../nfc_i.h" +#include "furi/common_defines.h" void nfc_scene_emulate_apdu_sequence_on_enter(void* context) { Nfc* nfc = context; @@ -10,17 +11,14 @@ void nfc_scene_emulate_apdu_sequence_on_enter(void* context) { // Setup and start worker view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewPopup); nfc_worker_start(nfc->worker, NfcWorkerStateEmulateApdu, &nfc->dev->dev_data, NULL, nfc); + + nfc_blink_start(nfc); } bool nfc_scene_emulate_apdu_sequence_on_event(void* context, SceneManagerEvent event) { - Nfc* nfc = context; + UNUSED(context); + UNUSED(event); bool consumed = false; - - if(event.type == SceneManagerEventTypeTick) { - notification_message(nfc->notifications, &sequence_blink_blue_10); - consumed = true; - } - return consumed; } @@ -31,4 +29,6 @@ void nfc_scene_emulate_apdu_sequence_on_exit(void* context) { nfc_worker_stop(nfc->worker); // Clear view popup_reset(nfc->popup); + + nfc_blink_stop(nfc); } diff --git a/applications/nfc/scenes/nfc_scene_emulate_mifare_classic.c b/applications/nfc/scenes/nfc_scene_emulate_mifare_classic.c index 1286024c3..97e865454 100644 --- a/applications/nfc/scenes/nfc_scene_emulate_mifare_classic.c +++ b/applications/nfc/scenes/nfc_scene_emulate_mifare_classic.c @@ -32,6 +32,7 @@ void nfc_scene_emulate_mifare_classic_on_enter(void* context) { &nfc->dev->dev_data, nfc_emulate_mifare_classic_worker_callback, nfc); + nfc_blink_start(nfc); } bool nfc_scene_emulate_mifare_classic_on_event(void* context, SceneManagerEvent event) { @@ -39,7 +40,6 @@ bool nfc_scene_emulate_mifare_classic_on_event(void* context, SceneManagerEvent bool consumed = false; if(event.type == SceneManagerEventTypeTick) { - notification_message(nfc->notifications, &sequence_blink_blue_10); consumed = true; } else if(event.type == SceneManagerEventTypeBack) { // Stop worker @@ -61,4 +61,6 @@ void nfc_scene_emulate_mifare_classic_on_exit(void* context) { // Clear view popup_reset(nfc->popup); + + nfc_blink_stop(nfc); } diff --git a/applications/nfc/scenes/nfc_scene_emulate_mifare_ul.c b/applications/nfc/scenes/nfc_scene_emulate_mifare_ul.c index eda7637c2..f23f554e6 100755 --- a/applications/nfc/scenes/nfc_scene_emulate_mifare_ul.c +++ b/applications/nfc/scenes/nfc_scene_emulate_mifare_ul.c @@ -32,6 +32,7 @@ void nfc_scene_emulate_mifare_ul_on_enter(void* context) { &nfc->dev->dev_data, nfc_emulate_mifare_ul_worker_callback, nfc); + nfc_blink_start(nfc); } bool nfc_scene_emulate_mifare_ul_on_event(void* context, SceneManagerEvent event) { @@ -39,7 +40,6 @@ bool nfc_scene_emulate_mifare_ul_on_event(void* context, SceneManagerEvent event bool consumed = false; if(event.type == SceneManagerEventTypeTick) { - notification_message(nfc->notifications, &sequence_blink_blue_10); consumed = true; } else if(event.type == SceneManagerEventTypeBack) { // Stop worker @@ -61,4 +61,6 @@ void nfc_scene_emulate_mifare_ul_on_exit(void* context) { // Clear view popup_reset(nfc->popup); + + nfc_blink_stop(nfc); } diff --git a/applications/nfc/scenes/nfc_scene_emulate_uid.c b/applications/nfc/scenes/nfc_scene_emulate_uid.c index e67b72740..3fabf4959 100755 --- a/applications/nfc/scenes/nfc_scene_emulate_uid.c +++ b/applications/nfc/scenes/nfc_scene_emulate_uid.c @@ -80,6 +80,8 @@ void nfc_scene_emulate_uid_on_enter(void* context) { &nfc->dev->dev_data, nfc_emulate_uid_worker_callback, nfc); + + nfc_blink_start(nfc); } bool nfc_scene_emulate_uid_on_event(void* context, SceneManagerEvent event) { @@ -89,7 +91,6 @@ bool nfc_scene_emulate_uid_on_event(void* context, SceneManagerEvent event) { bool consumed = false; if(event.type == SceneManagerEventTypeTick) { - notification_message(nfc->notifications, &sequence_blink_blue_10); consumed = true; } else if(event.type == SceneManagerEventTypeCustom) { if(event.event == NfcCustomEventWorkerExit) { @@ -141,4 +142,6 @@ void nfc_scene_emulate_uid_on_exit(void* context) { widget_reset(nfc->widget); text_box_reset(nfc->text_box); string_reset(nfc->text_box_store); + + nfc_blink_stop(nfc); } diff --git a/applications/nfc/scenes/nfc_scene_read_card.c b/applications/nfc/scenes/nfc_scene_read_card.c index 645b8deb2..0cd0fc898 100755 --- a/applications/nfc/scenes/nfc_scene_read_card.c +++ b/applications/nfc/scenes/nfc_scene_read_card.c @@ -20,6 +20,8 @@ void nfc_scene_read_card_on_enter(void* context) { view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewPopup); nfc_worker_start( nfc->worker, NfcWorkerStateDetect, &nfc->dev->dev_data, nfc_read_card_worker_callback, nfc); + + nfc_blink_start(nfc); } bool nfc_scene_read_card_on_event(void* context, SceneManagerEvent event) { @@ -32,7 +34,6 @@ bool nfc_scene_read_card_on_event(void* context, SceneManagerEvent event) { consumed = true; } } else if(event.type == SceneManagerEventTypeTick) { - notification_message(nfc->notifications, &sequence_blink_blue_10); consumed = true; } return consumed; @@ -45,4 +46,6 @@ void nfc_scene_read_card_on_exit(void* context) { nfc_worker_stop(nfc->worker); // Clear view popup_reset(nfc->popup); + + nfc_blink_stop(nfc); } diff --git a/applications/nfc/scenes/nfc_scene_read_emv_app.c b/applications/nfc/scenes/nfc_scene_read_emv_app.c index 4a64622dc..5bb8ac5fe 100755 --- a/applications/nfc/scenes/nfc_scene_read_emv_app.c +++ b/applications/nfc/scenes/nfc_scene_read_emv_app.c @@ -24,6 +24,7 @@ void nfc_scene_read_emv_app_on_enter(void* context) { &nfc->dev->dev_data, nfc_read_emv_app_worker_callback, nfc); + nfc_blink_start(nfc); } bool nfc_scene_read_emv_app_on_event(void* context, SceneManagerEvent event) { @@ -38,7 +39,6 @@ bool nfc_scene_read_emv_app_on_event(void* context, SceneManagerEvent event) { consumed = true; } } else if(event.type == SceneManagerEventTypeTick) { - notification_message(nfc->notifications, &sequence_blink_blue_10); consumed = true; } @@ -53,4 +53,6 @@ void nfc_scene_read_emv_app_on_exit(void* context) { // Clear view popup_reset(nfc->popup); + + nfc_blink_stop(nfc); } diff --git a/applications/nfc/scenes/nfc_scene_read_emv_data.c b/applications/nfc/scenes/nfc_scene_read_emv_data.c index 85df41212..e1881cefb 100755 --- a/applications/nfc/scenes/nfc_scene_read_emv_data.c +++ b/applications/nfc/scenes/nfc_scene_read_emv_data.c @@ -26,6 +26,8 @@ void nfc_scene_read_emv_data_on_enter(void* context) { &nfc->dev->dev_data, nfc_read_emv_data_worker_callback, nfc); + + nfc_blink_start(nfc); } bool nfc_scene_read_emv_data_on_event(void* context, SceneManagerEvent event) { @@ -40,7 +42,6 @@ bool nfc_scene_read_emv_data_on_event(void* context, SceneManagerEvent event) { consumed = true; } } else if(event.type == SceneManagerEventTypeTick) { - notification_message(nfc->notifications, &sequence_blink_blue_10); consumed = true; } return consumed; @@ -53,4 +54,6 @@ void nfc_scene_read_emv_data_on_exit(void* context) { nfc_worker_stop(nfc->worker); // Clear view popup_reset(nfc->popup); + + nfc_blink_stop(nfc); } diff --git a/applications/nfc/scenes/nfc_scene_read_mifare_classic.c b/applications/nfc/scenes/nfc_scene_read_mifare_classic.c index c44222857..a901ecd48 100644 --- a/applications/nfc/scenes/nfc_scene_read_mifare_classic.c +++ b/applications/nfc/scenes/nfc_scene_read_mifare_classic.c @@ -33,17 +33,15 @@ void nfc_scene_read_mifare_classic_on_enter(void* context) { &nfc->dev->dev_data, nfc_read_mifare_classic_worker_callback, nfc); + + nfc_blink_start(nfc); } bool nfc_scene_read_mifare_classic_on_event(void* context, SceneManagerEvent event) { Nfc* nfc = context; bool consumed = false; - uint32_t state = scene_manager_get_scene_state(nfc->scene_manager, NfcSceneReadMifareClassic); if(event.type == SceneManagerEventTypeTick) { - if(state == NfcSceneReadMifareClassicStateInProgress) { - notification_message(nfc->notifications, &sequence_blink_blue_10); - } consumed = true; } else if(event.type == SceneManagerEventTypeCustom) { if(event.event == NfcCustomEventDictAttackDone) { @@ -70,12 +68,14 @@ bool nfc_scene_read_mifare_classic_on_event(void* context, SceneManagerEvent eve } else if(event.event == NfcWorkerEventSuccess) { scene_manager_set_scene_state( nfc->scene_manager, NfcSceneReadMifareClassic, NfcSceneReadMifareClassicStateDone); + nfc_blink_stop(nfc); notification_message(nfc->notifications, &sequence_success); dict_attack_set_result(nfc->dict_attack, true); consumed = true; } else if(event.event == NfcWorkerEventFail) { scene_manager_set_scene_state( nfc->scene_manager, NfcSceneReadMifareClassic, NfcSceneReadMifareClassicStateDone); + nfc_blink_stop(nfc); dict_attack_set_result(nfc->dict_attack, false); consumed = true; } else if(event.event == NfcWorkerEventNoDictFound) { @@ -91,4 +91,6 @@ void nfc_scene_read_mifare_classic_on_exit(void* context) { // Stop worker nfc_worker_stop(nfc->worker); dict_attack_reset(nfc->dict_attack); + + nfc_blink_stop(nfc); } diff --git a/applications/nfc/scenes/nfc_scene_read_mifare_desfire.c b/applications/nfc/scenes/nfc_scene_read_mifare_desfire.c index f14f81bad..fc99b64c8 100644 --- a/applications/nfc/scenes/nfc_scene_read_mifare_desfire.c +++ b/applications/nfc/scenes/nfc_scene_read_mifare_desfire.c @@ -24,6 +24,7 @@ void nfc_scene_read_mifare_desfire_on_enter(void* context) { &nfc->dev->dev_data, nfc_read_mifare_desfire_worker_callback, nfc); + nfc_blink_start(nfc); } bool nfc_scene_read_mifare_desfire_on_event(void* context, SceneManagerEvent event) { @@ -33,12 +34,11 @@ bool nfc_scene_read_mifare_desfire_on_event(void* context, SceneManagerEvent eve if(event.type == SceneManagerEventTypeCustom) { if(event.event == NfcCustomEventWorkerExit) { notification_message(nfc->notifications, &sequence_success); + DOLPHIN_DEED(DolphinDeedNfcReadSuccess); scene_manager_next_scene(nfc->scene_manager, NfcSceneReadMifareDesfireSuccess); consumed = true; } } else if(event.type == SceneManagerEventTypeTick) { - notification_message(nfc->notifications, &sequence_blink_blue_10); - DOLPHIN_DEED(DolphinDeedNfcReadSuccess); consumed = true; } return consumed; @@ -51,4 +51,6 @@ void nfc_scene_read_mifare_desfire_on_exit(void* context) { nfc_worker_stop(nfc->worker); // Clear view popup_reset(nfc->popup); + + nfc_blink_stop(nfc); } diff --git a/applications/nfc/scenes/nfc_scene_read_mifare_ul.c b/applications/nfc/scenes/nfc_scene_read_mifare_ul.c index 659e08fbe..444f62538 100755 --- a/applications/nfc/scenes/nfc_scene_read_mifare_ul.c +++ b/applications/nfc/scenes/nfc_scene_read_mifare_ul.c @@ -24,6 +24,7 @@ void nfc_scene_read_mifare_ul_on_enter(void* context) { &nfc->dev->dev_data, nfc_read_mifare_ul_worker_callback, nfc); + nfc_blink_start(nfc); } bool nfc_scene_read_mifare_ul_on_event(void* context, SceneManagerEvent event) { @@ -36,7 +37,6 @@ bool nfc_scene_read_mifare_ul_on_event(void* context, SceneManagerEvent event) { consumed = true; } } else if(event.type == SceneManagerEventTypeTick) { - notification_message(nfc->notifications, &sequence_blink_blue_10); consumed = true; } return consumed; @@ -49,4 +49,6 @@ void nfc_scene_read_mifare_ul_on_exit(void* context) { nfc_worker_stop(nfc->worker); // Clear view popup_reset(nfc->popup); + + nfc_blink_stop(nfc); } From cc861dd92b548fe0141dab901990cdbd88657297 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=82=E3=81=8F?= Date: Mon, 13 Jun 2022 05:40:57 +0300 Subject: [PATCH 2/2] Desktop: poweroff timer and 5 seconds delay and other improvements (#1312) * Desktop: poweroff timer and 5 seconds delay * Desktop: cleanup logic in settings application --- .../desktop_settings/desktop_settings_app.h | 3 -- .../scenes/desktop_settings_scene_favorite.c | 28 +++++++++--------- .../scenes/desktop_settings_scene_start.c | 4 +-- .../desktop/views/desktop_view_main.c | 29 +++++++++++++++++-- 4 files changed, 44 insertions(+), 20 deletions(-) diff --git a/applications/desktop/desktop_settings/desktop_settings_app.h b/applications/desktop/desktop_settings/desktop_settings_app.h index f0bff489e..93ca7b35c 100644 --- a/applications/desktop/desktop_settings/desktop_settings_app.h +++ b/applications/desktop/desktop_settings/desktop_settings_app.h @@ -38,7 +38,4 @@ typedef struct { bool pincode_buffer_filled; uint8_t menu_idx; - - bool setting_primary_favorite; - } DesktopSettingsApp; diff --git a/applications/desktop/desktop_settings/scenes/desktop_settings_scene_favorite.c b/applications/desktop/desktop_settings/scenes/desktop_settings_scene_favorite.c index ef44c411b..0ec18af7a 100644 --- a/applications/desktop/desktop_settings/scenes/desktop_settings_scene_favorite.c +++ b/applications/desktop/desktop_settings/scenes/desktop_settings_scene_favorite.c @@ -21,10 +21,13 @@ void desktop_settings_scene_favorite_on_enter(void* context) { app); } + uint32_t primary_favorite = + scene_manager_get_scene_state(app->scene_manager, DesktopSettingsAppSceneFavorite); + submenu_set_header( - app->submenu, - app->setting_primary_favorite ? "Primary favorite app:" : "Secondary favorite app:"); - if(app->setting_primary_favorite) { + app->submenu, primary_favorite ? "Primary favorite app:" : "Secondary favorite app:"); + + if(primary_favorite) { submenu_set_selected_item(app->submenu, app->settings.favorite_primary); } else { submenu_set_selected_item(app->submenu, app->settings.favorite_secondary); @@ -36,18 +39,17 @@ bool desktop_settings_scene_favorite_on_event(void* context, SceneManagerEvent e DesktopSettingsApp* app = context; bool consumed = false; + uint32_t primary_favorite = + scene_manager_get_scene_state(app->scene_manager, DesktopSettingsAppSceneFavorite); + if(event.type == SceneManagerEventTypeCustom) { - switch(event.event) { - default: - if(app->setting_primary_favorite) { - app->settings.favorite_primary = event.event; - } else { - app->settings.favorite_secondary = event.event; - } - scene_manager_previous_scene(app->scene_manager); - consumed = true; - break; + if(primary_favorite) { + app->settings.favorite_primary = event.event; + } else { + app->settings.favorite_secondary = event.event; } + scene_manager_previous_scene(app->scene_manager); + consumed = true; } return consumed; } diff --git a/applications/desktop/desktop_settings/scenes/desktop_settings_scene_start.c b/applications/desktop/desktop_settings/scenes/desktop_settings_scene_start.c index 05c08e1a5..8e649c695 100644 --- a/applications/desktop/desktop_settings/scenes/desktop_settings_scene_start.c +++ b/applications/desktop/desktop_settings/scenes/desktop_settings_scene_start.c @@ -72,12 +72,12 @@ bool desktop_settings_scene_start_on_event(void* context, SceneManagerEvent even if(event.type == SceneManagerEventTypeCustom) { switch(event.event) { case SCENE_EVENT_SELECT_FAVORITE_PRIMARY: - app->setting_primary_favorite = true; + scene_manager_set_scene_state(app->scene_manager, DesktopSettingsAppSceneFavorite, 1); scene_manager_next_scene(app->scene_manager, DesktopSettingsAppSceneFavorite); consumed = true; break; case SCENE_EVENT_SELECT_FAVORITE_SECONDARY: - app->setting_primary_favorite = false; + scene_manager_set_scene_state(app->scene_manager, DesktopSettingsAppSceneFavorite, 0); scene_manager_next_scene(app->scene_manager, DesktopSettingsAppSceneFavorite); consumed = true; break; diff --git a/applications/desktop/views/desktop_view_main.c b/applications/desktop/views/desktop_view_main.c index 4e7260b0e..ba944a9ef 100644 --- a/applications/desktop/views/desktop_view_main.c +++ b/applications/desktop/views/desktop_view_main.c @@ -13,8 +13,16 @@ struct DesktopMainView { View* view; DesktopMainViewCallback callback; void* context; + TimerHandle_t poweroff_timer; }; +#define DESKTOP_MAIN_VIEW_POWEROFF_TIMEOUT 5000 + +static void desktop_main_poweroff_timer_callback(TimerHandle_t timer) { + DesktopMainView* main_view = pvTimerGetTimerID(timer); + main_view->callback(DesktopMainEventOpenPowerOff, main_view->context); +} + void desktop_main_set_callback( DesktopMainView* main_view, DesktopMainViewCallback callback, @@ -53,8 +61,17 @@ bool desktop_main_input(InputEvent* event, void* context) { main_view->callback(DesktopMainEventOpenDebug, main_view->context); } else if(event->key == InputKeyLeft) { main_view->callback(DesktopMainEventOpenFavoriteSecondary, main_view->context); - } else if(event->key == InputKeyBack) { - main_view->callback(DesktopMainEventOpenPowerOff, main_view->context); + } + } + + if(event->key == InputKeyBack) { + if(event->type == InputTypePress) { + xTimerChangePeriod( + main_view->poweroff_timer, + pdMS_TO_TICKS(DESKTOP_MAIN_VIEW_POWEROFF_TIMEOUT), + portMAX_DELAY); + } else if(event->type == InputTypeRelease) { + xTimerStop(main_view->poweroff_timer, portMAX_DELAY); } } @@ -69,11 +86,19 @@ DesktopMainView* desktop_main_alloc() { view_set_context(main_view->view, main_view); view_set_input_callback(main_view->view, desktop_main_input); + main_view->poweroff_timer = xTimerCreate( + NULL, + pdMS_TO_TICKS(DESKTOP_MAIN_VIEW_POWEROFF_TIMEOUT), + pdFALSE, + main_view, + desktop_main_poweroff_timer_callback); + return main_view; } void desktop_main_free(DesktopMainView* main_view) { furi_assert(main_view); view_free(main_view->view); + osTimerDelete(main_view->poweroff_timer); free(main_view); }