Просмотр исходного кода

Info & delete scenes

Saved cards can now display stored values, and be deleted
Zachary Weiss 3 лет назад
Родитель
Сommit
3e646d93b4

BIN
icons/DolphinMafia_115x62.png


+ 32 - 4
scenes/mag_scene_delete_confirm.c

@@ -1,20 +1,48 @@
 #include "../mag_i.h"
+#include "../mag_device.h"
+#include <toolbox/path.h>
 
 void mag_scene_delete_confirm_on_enter(void* context) {
     Mag* mag = context;
-    UNUSED(mag);
+    Widget* widget = mag->widget;
+    MagDevice* mag_dev = mag->mag_dev;
+
+    FuriString* tmp_str;
+    tmp_str = furi_string_alloc();
+
+    furi_string_printf(tmp_str, "\e#Delete %s?\e#", mag_dev->dev_name);
+
+    widget_add_text_box_element(
+        widget, 0, 0, 128, 27, AlignCenter, AlignCenter, furi_string_get_cstr(tmp_str), true);
+    widget_add_button_element(widget, GuiButtonTypeLeft, "Cancel", mag_widget_callback, mag);
+    widget_add_button_element(widget, GuiButtonTypeRight, "Delete", mag_widget_callback, mag);
+
+    view_dispatcher_switch_to_view(mag->view_dispatcher, MagViewWidget);
+
+    furi_string_free(tmp_str);
 }
 
 bool mag_scene_delete_confirm_on_event(void* context, SceneManagerEvent event) {
     Mag* mag = context;
-    UNUSED(mag);
-    UNUSED(event);
+    SceneManager* scene_manager = mag->scene_manager;
     bool consumed = false;
 
+    if(event.type == SceneManagerEventTypeCustom) {
+        if(event.event == GuiButtonTypeRight) {
+            consumed = true;
+            if(mag_device_delete(mag->mag_dev, true)) {
+                scene_manager_next_scene(scene_manager, MagSceneDeleteSuccess);
+            }
+        } else if(event.event == GuiButtonTypeLeft) {
+            consumed = true;
+            scene_manager_previous_scene(scene_manager);
+        }
+    }
+
     return consumed;
 }
 
 void mag_scene_delete_confirm_on_exit(void* context) {
     Mag* mag = context;
-    UNUSED(mag);
+    widget_reset(mag->widget);
 }

+ 23 - 4
scenes/mag_scene_delete_success.c

@@ -2,19 +2,38 @@
 
 void mag_scene_delete_success_on_enter(void* context) {
     Mag* mag = context;
-    UNUSED(mag);
+    Popup* popup = mag->popup;
+
+    popup_set_icon(popup, 0, 2, &I_DolphinMafia_115x62);
+    popup_set_header(popup, "Deleted", 83, 19, AlignLeft, AlignBottom);
+
+    popup_set_callback(popup, mag_popup_timeout_callback);
+    popup_set_context(popup, mag);
+    popup_set_timeout(popup, 1500);
+    popup_enable_timeout(popup);
+
+    view_dispatcher_switch_to_view(mag->view_dispatcher, MagViewPopup);
 }
 
 bool mag_scene_delete_success_on_event(void* context, SceneManagerEvent event) {
     Mag* mag = context;
-    UNUSED(mag);
-    UNUSED(event);
     bool consumed = false;
 
+    if(event.type == SceneManagerEventTypeCustom) {
+        if(event.event == MagEventPopupClosed) {
+            consumed = true;
+
+            scene_manager_search_and_switch_to_previous_scene(
+                mag->scene_manager, MagSceneFileSelect);
+        }
+    }
+
     return consumed;
 }
 
 void mag_scene_delete_success_on_exit(void* context) {
     Mag* mag = context;
-    UNUSED(mag);
+    Popup* popup = mag->popup;
+
+    popup_reset(popup);
 }

+ 29 - 29
scenes/mag_scene_emulate_test.c

@@ -1,18 +1,18 @@
 #include "../mag_i.h"
 
 #define PIN_A 0
-#define PIN_B 1      // currently unused
+#define PIN_B 1 // currently unused
 #define CLOCK_US 240 // typically set between 200-500us
-#define TEST_STR "%B123456781234567^LASTNAME/FIRST^YYMMSSSDDDDDDDDDDDDDDDDDDDDDDDDD?;1234567812?"
+#define TEST_STR "%%B123456781234567^LASTNAME/FIRST^YYMMSSSDDDDDDDDDDDDDDDDDDDDDDDDD?;1234567812?"
 #define TEST_TRACK 0
 // TODO: better way of setting temp test str,
 //       text wrapping on screen? (Will be relevant for any loaded data too)
 
 uint8_t magspoof_bit_dir = 0;
-const char *test_str = TEST_STR;
+const char* test_str = TEST_STR;
 
 void gpio_item_set_rfid_pin(uint8_t index, bool level) {
-    if (index == 0) {
+    if(index == 0) {
         furi_hal_gpio_write(&gpio_rfid_carrier_out, level);
         // A7 GPIO pin for debugging purposes
         // furi_hal_gpio_write(&gpio_ext_pa7, level);
@@ -31,8 +31,8 @@ static void play_bit(uint8_t send_bit) {
     // NFC tests
     //(magspoof_bit_dir) ? st25r3916TxRxOn() : st25r3916TxRxOff();
     //(magspoof_bit_dir) ? furi_hal_nfc_field_on() : furi_hal_nfc_field_off();
-    
-    if (send_bit) {
+
+    if(send_bit) {
         magspoof_bit_dir ^= 1;
         gpio_item_set_rfid_pin(PIN_A, magspoof_bit_dir);
         gpio_item_set_rfid_pin(PIN_B, !magspoof_bit_dir);
@@ -43,29 +43,29 @@ static void play_bit(uint8_t send_bit) {
     furi_delay_us(CLOCK_US);
 }
 
-static void mag_spoof(FuriString *track_str, uint8_t track) {
+static void mag_spoof(FuriString* track_str, uint8_t track) {
     furi_hal_power_enable_otg();
 
     size_t from;
     size_t to;
 
     // TODO ';' in first track case
-    if (track == 0) {
+    if(track == 0) {
         from = furi_string_search_char(track_str, '%');
         to = furi_string_search_char(track_str, '?', from);
-    } else if (track == 1) {
+    } else if(track == 1) {
         from = furi_string_search_char(track_str, ';');
         to = furi_string_search_char(track_str, '?', from);
     } else {
         from = 0;
         to = furi_string_size(track_str);
     }
-    if (from >= to) {
+    if(from >= to) {
         return;
     }
     furi_string_mid(track_str, from, to - from + 1);
 
-    const char *data = furi_string_get_cstr(track_str);
+    const char* data = furi_string_get_cstr(track_str);
 
     printf("%s", data);
 
@@ -105,15 +105,15 @@ static void mag_spoof(FuriString *track_str, uint8_t track) {
     magspoof_bit_dir = 0;
 
     // First put out a bunch of leading zeros.
-    for (uint8_t i = 0; i < 25; i++) {
+    for(uint8_t i = 0; i < 25; i++) {
         play_bit(0);
     }
 
-    for (uint8_t i = 0; data[i] != '\0'; i++) {
+    for(uint8_t i = 0; data[i] != '\0'; i++) {
         crc = 1;
         tmp = data[i] - sublen[track];
 
-        for (uint8_t j = 0; j < bitlen[track] - 1; j++) {
+        for(uint8_t j = 0; j < bitlen[track] - 1; j++) {
             crc ^= tmp & 1;
             lrc ^= (tmp & 1) << j;
             play_bit(tmp & 1);
@@ -125,7 +125,7 @@ static void mag_spoof(FuriString *track_str, uint8_t track) {
     // finish calculating and send last "byte" (LRC)
     tmp = lrc;
     crc = 1;
-    for (uint8_t j = 0; j < bitlen[track] - 1; j++) {
+    for(uint8_t j = 0; j < bitlen[track] - 1; j++) {
         crc ^= tmp & 1;
         play_bit(tmp & 1);
         tmp >>= 1;
@@ -133,7 +133,7 @@ static void mag_spoof(FuriString *track_str, uint8_t track) {
     play_bit(crc);
 
     // finish with 0's
-    for (uint8_t i = 0; i < 5 * 5; i++) {
+    for(uint8_t i = 0; i < 5 * 5; i++) {
         play_bit(0);
     }
 
@@ -153,9 +153,9 @@ static void mag_spoof(FuriString *track_str, uint8_t track) {
     furi_hal_power_disable_otg();
 }
 
-void mag_scene_emulate_test_on_enter(void *context) {
-    Mag *mag = context;
-    Widget *widget = mag->widget;
+void mag_scene_emulate_test_on_enter(void* context) {
+    Mag* mag = context;
+    Widget* widget = mag->widget;
 
     //FuriString *tmp_string;
     //tmp_string = furi_string_alloc();
@@ -172,26 +172,26 @@ void mag_scene_emulate_test_on_enter(void *context) {
     //furi_string_free(tmp_string);
 }
 
-bool mag_scene_emulate_test_on_event(void *context, SceneManagerEvent event) {
-    Mag *mag = context;
-    SceneManager *scene_manager = mag->scene_manager;
+bool mag_scene_emulate_test_on_event(void* context, SceneManagerEvent event) {
+    Mag* mag = context;
+    SceneManager* scene_manager = mag->scene_manager;
     bool consumed = false;
 
-    if (event.type == SceneManagerEventTypeCustom) {
-        if (event.event == GuiButtonTypeRight) {
+    if(event.type == SceneManagerEventTypeCustom) {
+        if(event.event == GuiButtonTypeRight) {
             consumed = true;
 
             // Hardcoding a test string for the time being, while we debug/improve LF RFID TX
-            FuriString *v = furi_string_alloc();
+            FuriString* v = furi_string_alloc();
             furi_string_set_str(v, test_str);
 
             // blink led while spoofing
-            notification_message(mag->notifications, &sequence_blink_start_blue);
+            notification_message(mag->notifications, &sequence_blink_start_cyan);
             mag_spoof(v, TEST_TRACK);
             notification_message(mag->notifications, &sequence_blink_stop);
 
             furi_string_free(v);
-        } else if (event.event == GuiButtonTypeLeft) {
+        } else if(event.event == GuiButtonTypeLeft) {
             consumed = true;
 
             scene_manager_previous_scene(scene_manager);
@@ -201,7 +201,7 @@ bool mag_scene_emulate_test_on_event(void *context, SceneManagerEvent event) {
     return consumed;
 }
 
-void mag_scene_emulate_test_on_exit(void *context) {
-    Mag *mag = context;
+void mag_scene_emulate_test_on_exit(void* context) {
+    Mag* mag = context;
     widget_reset(mag->widget);
 }

+ 9 - 8
scenes/mag_scene_saved_info.c

@@ -4,18 +4,19 @@ void mag_scene_saved_info_on_enter(void* context) {
     Mag* mag = context;
     Widget* widget = mag->widget;
 
-    widget_add_string_element(
-        widget,
-        64,
-        12,
-        AlignCenter,
-        AlignCenter,
-        FontSecondary,
-        furi_string_get_cstr(mag->mag_dev->dev_data));
+    FuriString* tmp_str;
+    tmp_str = furi_string_alloc();
+
+    furi_string_printf(tmp_str, "%s\r\n", mag->mag_dev->dev_name);
+    furi_string_cat_printf(tmp_str, furi_string_get_cstr(mag->mag_dev->dev_data));
+
+    widget_add_string_multiline_element(
+        widget, 0, 1, AlignLeft, AlignTop, FontSecondary, furi_string_get_cstr(tmp_str));
 
     widget_add_button_element(widget, GuiButtonTypeLeft, "Back", mag_widget_callback, mag);
 
     view_dispatcher_switch_to_view(mag->view_dispatcher, MagViewWidget);
+    furi_string_free(tmp_str);
 }
 
 bool mag_scene_saved_info_on_event(void* context, SceneManagerEvent event) {

+ 1 - 1
scenes/mag_scene_saved_menu.c

@@ -47,7 +47,7 @@ bool mag_scene_saved_menu_on_event(void* context, SceneManagerEvent event) {
             scene_manager_next_scene(mag->scene_manager, MagSceneUnderConstruction);
             consumed = true;
         } else if(event.event == SubmenuIndexDelete) {
-            scene_manager_next_scene(mag->scene_manager, MagSceneUnderConstruction);
+            scene_manager_next_scene(mag->scene_manager, MagSceneDeleteConfirm);
             consumed = true;
         } else if(event.event == SubmenuIndexInfo) {
             scene_manager_next_scene(mag->scene_manager, MagSceneSavedInfo);