Eric Betts пре 8 месеци
родитељ
комит
d96e5564bc
3 измењених фајлова са 64 додато и 13 уклоњено
  1. 1 0
      scenes/weebo_scene_config.h
  2. 12 13
      scenes/weebo_scene_write.c
  3. 51 0
      scenes/weebo_scene_write_card_success.c

+ 1 - 0
scenes/weebo_scene_config.h

@@ -3,3 +3,4 @@ ADD_SCENE(weebo, keys_missing, KeysMissing)
 ADD_SCENE(weebo, file_select, FileSelect)
 ADD_SCENE(weebo, saved_menu, SavedMenu)
 ADD_SCENE(weebo, write, Write)
+ADD_SCENE(weebo, write_card_success, WriteCardSuccess)

+ 12 - 13
scenes/weebo_scene_write.c

@@ -70,27 +70,27 @@ NfcCommand weebo_scene_write_poller_callback(NfcGenericEvent event, void* contex
             data->iso14443_3a_data->uid[4],
             data->iso14443_3a_data->uid[5]);
 
-        for(size_t p = 0; p < 2; p++) {
-            for(size_t i = 0; i < MF_ULTRALIGHT_PAGE_SIZE; i++) {
-                weebo->figure[NFC3D_UID_OFFSET + p * MF_ULTRALIGHT_PAGE_SIZE + i] =
-                    data->page[p].data[i];
-            }
-        }
-
-        uint8_t modified[NTAG215_SIZE];
-        nfc3d_amiibo_pack(&weebo->amiiboKeys, weebo->figure, modified);
-        FURI_LOG_D(TAG, "Re-packed");
-
         /*
         MfUltralightAuth* mf_ul_auth;
         mf_ul_auth = mf_ultralight_auth_alloc();
         mf_ultralight_generate_amiibo_pass(
             mf_ul_auth, data->iso14443_3a_data->uid, data->iso14443_3a_data->uid_len);
+        mf_ultralight_auth_free(weebo->mf_ul_auth);
         */
         uint8_t PWD[4];
         weebo_scene_write_calculate_pwd(data->iso14443_3a_data->uid, PWD);
         FURI_LOG_D(TAG, "PWD: %02X%02X%02X%02X", PWD[0], PWD[1], PWD[2], PWD[3]);
 
+        for(size_t p = 0; p < 2; p++) {
+            for(size_t i = 0; i < MF_ULTRALIGHT_PAGE_SIZE; i++) {
+                weebo->figure[NFC3D_UID_OFFSET + p * MF_ULTRALIGHT_PAGE_SIZE + i] =
+                    data->page[p].data[i];
+            }
+        }
+
+        uint8_t modified[NTAG215_SIZE];
+        nfc3d_amiibo_pack(&weebo->amiiboKeys, weebo->figure, modified);
+
         MfUltralightData* newdata = mf_ultralight_alloc();
         nfc_device_copy_data(weebo->nfc_device, NfcProtocolMfUltralight, newdata);
 
@@ -130,7 +130,6 @@ NfcCommand weebo_scene_write_poller_callback(NfcGenericEvent event, void* contex
         nfc_device_set_data(weebo->nfc_device, NfcProtocolMfUltralight, newdata);
 
         mf_ultralight_free(newdata);
-        //mf_ultralight_auth_free(weebo->mf_ul_auth);
     } else if(mf_ultralight_event->type == MfUltralightPollerEventTypeRequestWriteData) {
         // NOTE: Consider saving the first 2 pages of the data (UID + BCC) and then doing all the calculations and setting up the data in this block.
         mf_ultralight_event->data->write_data =
@@ -175,7 +174,7 @@ bool weebo_scene_write_on_event(void* context, SceneManagerEvent event) {
         } else if(event.event == WeeboCustomEventWriteSuccess) {
             popup_set_text(weebo->popup, "Write success", 64, 36, AlignCenter, AlignTop);
             consumed = true;
-            // TODO: push to new scene
+            scene_manager_next_scene(weebo->scene_manager, WeeboSceneWriteCardSuccess);
         } else if(event.event == WeeboCustomEventWrongCard) {
             popup_set_text(weebo->popup, "Wrong card", 64, 36, AlignCenter, AlignTop);
             consumed = true;

+ 51 - 0
scenes/weebo_scene_write_card_success.c

@@ -0,0 +1,51 @@
+#include "../weebo_i.h"
+#include <dolphin/dolphin.h>
+
+void weebo_scene_write_card_success_widget_callback(
+    GuiButtonType result,
+    InputType type,
+    void* context) {
+    furi_assert(context);
+    Weebo* weebo = context;
+
+    if(type == InputTypeShort) {
+        view_dispatcher_send_custom_event(weebo->view_dispatcher, result);
+    }
+}
+
+void weebo_scene_write_card_success_on_enter(void* context) {
+    Weebo* weebo = context;
+    Widget* widget = weebo->widget;
+    FuriString* str = furi_string_alloc_set("Write Success!");
+
+    dolphin_deed(DolphinDeedNfcReadSuccess);
+
+    // Send notification
+    notification_message(weebo->notifications, &sequence_success);
+
+    widget_add_string_element(
+        widget, 64, 5, AlignCenter, AlignCenter, FontSecondary, furi_string_get_cstr(str));
+
+    furi_string_free(str);
+
+    view_dispatcher_switch_to_view(weebo->view_dispatcher, WeeboViewWidget);
+}
+
+bool weebo_scene_write_card_success_on_event(void* context, SceneManagerEvent event) {
+    Weebo* weebo = context;
+    bool consumed = false;
+
+    // Jump back to main menu
+    if(event.type == SceneManagerEventTypeBack) {
+        consumed = scene_manager_search_and_switch_to_previous_scene(
+            weebo->scene_manager, WeeboSceneMainMenu);
+    }
+    return consumed;
+}
+
+void weebo_scene_write_card_success_on_exit(void* context) {
+    Weebo* weebo = context;
+
+    // Clear view
+    widget_reset(weebo->widget);
+}