Kaynağa Gözat

partially working ui, with a BusFault error on app exit

frux-c 2 yıl önce
ebeveyn
işleme
4026ea0a9b

BIN
icons/DolphinMafia_115x62.png


BIN
icons/DolphinNice_96x59.png


BIN
icons/Nfc_10px.png


BIN
icons/RFIDDolphinReceive_97x61.png


BIN
icons/RFIDDolphinSend_97x61.png


+ 1 - 1
scenes/uhf_scene_config.h

@@ -1,5 +1,5 @@
 ADD_SCENE(uhf, start, Start)
 ADD_SCENE(uhf, start, Start)
-// ADD_SCENE(uhf, read_card, ReadCard)
+ADD_SCENE(uhf, read_tag, ReadTag)
 // ADD_SCENE(uhf, read_card_success, ReadCardSuccess)
 // ADD_SCENE(uhf, read_card_success, ReadCardSuccess)
 // ADD_SCENE(uhf, card_menu, CardMenu)
 // ADD_SCENE(uhf, card_menu, CardMenu)
 // ADD_SCENE(uhf, save_name, SaveName)
 // ADD_SCENE(uhf, save_name, SaveName)

+ 54 - 0
scenes/uhf_scene_read_tag.c

@@ -0,0 +1,54 @@
+#include "../uhf_app_i.h"
+#include <dolphin/dolphin.h>
+
+void uhf_read_tag_worker_callback(UHFWorkerEvent event, void* ctx) {
+    FURI_LOG_E("read_callback", "%d", event);
+    UHFApp* uhf_app = ctx;
+    view_dispatcher_send_custom_event(uhf_app->view_dispatcher, UHFCustomEventWorkerExit);
+}
+
+void uhf_scene_read_tag_on_enter(void* ctx) {
+    UHFApp* uhf_app = ctx;
+    dolphin_deed(DolphinDeedNfcRead);
+
+    // Setup view
+    Popup* popup = uhf_app->popup;
+    popup_set_header(popup, "Detecting\n[UHF] RFID\nTag", 68, 30, AlignLeft, AlignTop);
+    popup_set_icon(popup, 0, 3, &I_RFIDDolphinReceive_97x61);
+
+    // Start worker
+    view_dispatcher_switch_to_view(uhf_app->view_dispatcher, UHFViewPopup);
+    uhf_worker_start(uhf_app->worker, UHFWorkerStateDetect, uhf_read_tag_worker_callback, uhf_app);
+
+    uhf_blink_start(uhf_app);
+}
+
+bool uhf_scene_read_tag_on_event(void* ctx, SceneManagerEvent event) {
+    UHFApp* uhf_app = ctx;
+    bool consumed = false;
+
+    if(event.type == SceneManagerEventTypeCustom) {
+        if(event.event == UHFCustomEventWorkerExit) {
+            // if(memcmp(uhf_app->dev->dev_data.pacs.key, uhf_factory_debit_key, PICOPASS_BLOCK_LEN) ==
+            //    0) {
+            //     scene_manager_next_scene(uhf_app->scene_manager, PicopassSceneReadFactorySuccess);
+            // } else {
+            //     scene_manager_next_scene(uhf_app->scene_manager, PicopassSceneReadCardSuccess);
+            // }
+            scene_manager_next_scene(uhf_app->scene_manager, UHFSceneStart);
+            consumed = true;
+        }
+    }
+    return consumed;
+}
+
+void uhf_scene_read_tag_on_exit(void* ctx) {
+    UHFApp* uhf_app = ctx;
+
+    // Stop worker
+    uhf_worker_stop(uhf_app->worker);
+    // Clear view
+    popup_reset(uhf_app->popup);
+
+    uhf_blink_stop(uhf_app);
+}

+ 14 - 14
scenes/uhf_scene_start.c

@@ -2,12 +2,12 @@
 
 
 enum SubmenuIndex { SubmenuIndexRead, SubmenuIndexSaved, SubmenuIndexSettings };
 enum SubmenuIndex { SubmenuIndexRead, SubmenuIndexSaved, SubmenuIndexSettings };
 
 
-void uhf_scene_start_submenu_callback(void* context, uint32_t index) {
-    UHFApp* uhf_app = context;
+void uhf_scene_start_submenu_callback(void* ctx, uint32_t index) {
+    UHFApp* uhf_app = ctx;
     view_dispatcher_send_custom_event(uhf_app->view_dispatcher, index);
     view_dispatcher_send_custom_event(uhf_app->view_dispatcher, index);
 }
 }
-void uhf_scene_start_on_enter(void* context) {
-    UHFApp* uhf_app = context;
+void uhf_scene_start_on_enter(void* ctx) {
+    UHFApp* uhf_app = ctx;
 
 
     Submenu* submenu = uhf_app->submenu;
     Submenu* submenu = uhf_app->submenu;
     submenu_add_item(
     submenu_add_item(
@@ -22,18 +22,18 @@ void uhf_scene_start_on_enter(void* context) {
     view_dispatcher_switch_to_view(uhf_app->view_dispatcher, UHFViewMenu);
     view_dispatcher_switch_to_view(uhf_app->view_dispatcher, UHFViewMenu);
 }
 }
 
 
-bool uhf_scene_start_on_event(void* context, SceneManagerEvent event) {
-    UNUSED(context);
-    // UHFApp* uhf_app = context;
+bool uhf_scene_start_on_event(void* ctx, SceneManagerEvent event) {
+    UHFApp* uhf_app = ctx;
     bool consumed = false;
     bool consumed = false;
 
 
     if(event.type == SceneManagerEventTypeCustom) {
     if(event.type == SceneManagerEventTypeCustom) {
         FURI_LOG_E("EVENT", "%lu", event.event);
         FURI_LOG_E("EVENT", "%lu", event.event);
-        // if(event.event == SubmenuIndexRead) {
-        //     scene_manager_set_scene_state(uhf_app->scene_manager, UHFSceneStart, SubmenuIndexRead);
-        //     scene_manager_next_scene(uhf_app->scene_manager, UHFSceneReadCard);
-        //     consumed = true;
-        // } else if(event.event == SubmenuIndexSaved) {
+        if(event.event == SubmenuIndexRead) {
+            scene_manager_set_scene_state(uhf_app->scene_manager, UHFSceneStart, SubmenuIndexRead);
+            scene_manager_next_scene(uhf_app->scene_manager, UHFSceneReadTag);
+            consumed = true;
+        }
+        //else if(event.event == SubmenuIndexSaved) {
         // Explicitly save state so that the correct item is
         // Explicitly save state so that the correct item is
         // reselected if the user cancels loading a file.
         // reselected if the user cancels loading a file.
         // scene_manager_set_scene_state(
         // scene_manager_set_scene_state(
@@ -51,7 +51,7 @@ bool uhf_scene_start_on_event(void* context, SceneManagerEvent event) {
     return consumed;
     return consumed;
 }
 }
 
 
-void uhf_scene_start_on_exit(void* context) {
-    UHFApp* uhf_app = context;
+void uhf_scene_start_on_exit(void* ctx) {
+    UHFApp* uhf_app = ctx;
     submenu_reset(uhf_app->submenu);
     submenu_reset(uhf_app->submenu);
 }
 }

+ 60 - 13
uhf_app.c

@@ -1,24 +1,24 @@
 #include "uhf_app_i.h"
 #include "uhf_app_i.h"
 
 
-bool uhf_custom_event_callback(void* context, uint32_t event) {
-    furi_assert(context);
-    UHFApp* uhf_app = context;
+bool uhf_custom_event_callback(void* ctx, uint32_t event) {
+    furi_assert(ctx);
+    UHFApp* uhf_app = ctx;
     return scene_manager_handle_custom_event(uhf_app->scene_manager, event);
     return scene_manager_handle_custom_event(uhf_app->scene_manager, event);
 }
 }
 
 
-bool uhf_back_event_callback(void* context) {
-    furi_assert(context);
-    UHFApp* uhf_app = context;
+bool uhf_back_event_callback(void* ctx) {
+    furi_assert(ctx);
+    UHFApp* uhf_app = ctx;
     return scene_manager_handle_back_event(uhf_app->scene_manager);
     return scene_manager_handle_back_event(uhf_app->scene_manager);
 }
 }
 
 
-void uhf_tick_event_callback(void* context) {
-    furi_assert(context);
-    UHFApp* uhf_app = context;
+void uhf_tick_event_callback(void* ctx) {
+    furi_assert(ctx);
+    UHFApp* uhf_app = ctx;
     scene_manager_handle_tick_event(uhf_app->scene_manager);
     scene_manager_handle_tick_event(uhf_app->scene_manager);
 }
 }
 
 
-UHFApp* uhf_app_alloc() {
+UHFApp* uhf_alloc() {
     UHFApp* uhf_app = (UHFApp*)malloc(sizeof(UHFApp));
     UHFApp* uhf_app = (UHFApp*)malloc(sizeof(UHFApp));
     uhf_app->worker = (UHFWorker*)uhf_worker_alloc();
     uhf_app->worker = (UHFWorker*)uhf_worker_alloc();
     uhf_app->view_dispatcher = view_dispatcher_alloc();
     uhf_app->view_dispatcher = view_dispatcher_alloc();
@@ -67,7 +67,7 @@ UHFApp* uhf_app_alloc() {
     return uhf_app;
     return uhf_app;
 }
 }
 
 
-void uhf_app_free(UHFApp* uhf_app) {
+void uhf_free(UHFApp* uhf_app) {
     furi_assert(uhf_app);
     furi_assert(uhf_app);
 
 
     // Submenu
     // Submenu
@@ -111,14 +111,61 @@ void uhf_app_free(UHFApp* uhf_app) {
     free(uhf_app);
     free(uhf_app);
 }
 }
 
 
+// void uhf_text_store_set(UHFApp* uhf_app, const char* text, ...) {
+//     va_list args;
+//     va_start(args, text);
+
+//     vsnprintf(uhf_app->text_store, sizeof(uhf_app->text_store), text, args);
+
+//     va_end(args);
+// }
+
+// void uhf_text_store_clear(UHFApp* uhf_app) {
+//     memset(uhf_app->text_store, 0, sizeof(uhf_app->text_store));
+// }
+//  ==================
+static const NotificationSequence uhf_sequence_blink_start_cyan = {
+    &message_blink_start_10,
+    &message_blink_set_color_cyan,
+    &message_do_not_reset,
+    NULL,
+};
+
+static const NotificationSequence uhf_sequence_blink_stop = {
+    &message_blink_stop,
+    NULL,
+};
+
+void uhf_blink_start(UHFApp* uhf_app) {
+    notification_message(uhf_app->notifications, &uhf_sequence_blink_start_cyan);
+}
+
+void uhf_blink_stop(UHFApp* uhf_app) {
+    notification_message(uhf_app->notifications, &uhf_sequence_blink_stop);
+}
+
+void uhf_show_loading_popup(void* ctx, bool show) {
+    UHFApp* uhf_app = ctx;
+    TaskHandle_t timer_task = xTaskGetHandle(configTIMER_SERVICE_TASK_NAME);
+
+    if(show) {
+        // Raise timer priority so that animations can play
+        vTaskPrioritySet(timer_task, configMAX_PRIORITIES - 1);
+        view_dispatcher_switch_to_view(uhf_app->view_dispatcher, UHFViewLoading);
+    } else {
+        // Restore default timer priority
+        vTaskPrioritySet(timer_task, configTIMER_TASK_PRIORITY);
+    }
+}
+
 int32_t uhf_app_main(void* ctx) {
 int32_t uhf_app_main(void* ctx) {
     UNUSED(ctx);
     UNUSED(ctx);
-    UHFApp* uhf_app = uhf_app_alloc();
+    UHFApp* uhf_app = uhf_alloc();
     view_dispatcher_attach_to_gui(
     view_dispatcher_attach_to_gui(
         uhf_app->view_dispatcher, uhf_app->gui, ViewDispatcherTypeFullscreen);
         uhf_app->view_dispatcher, uhf_app->gui, ViewDispatcherTypeFullscreen);
     scene_manager_next_scene(uhf_app->scene_manager, UHFSceneStart);
     scene_manager_next_scene(uhf_app->scene_manager, UHFSceneStart);
     view_dispatcher_run(uhf_app->view_dispatcher);
     view_dispatcher_run(uhf_app->view_dispatcher);
 
 
-    uhf_app_free(uhf_app);
+    uhf_free(uhf_app);
     return 0;
     return 0;
 }
 }

+ 1 - 2
uhf_app_i.h

@@ -21,7 +21,7 @@
 
 
 #include <storage/storage.h>
 #include <storage/storage.h>
 #include <lib/toolbox/path.h>
 #include <lib/toolbox/path.h>
-// #include <uhf_icons.h>
+#include <uhf_rfid_icons.h>
 
 
 #define UHF_TEXT_STORE_SIZE 128
 #define UHF_TEXT_STORE_SIZE 128
 
 
@@ -33,7 +33,6 @@ enum UHFCustomEvent {
     UHFCustomEventWorkerExit,
     UHFCustomEventWorkerExit,
     UHFCustomEventByteInputDone,
     UHFCustomEventByteInputDone,
     UHFCustomEventTextInputDone,
     UHFCustomEventTextInputDone,
-    UHFCustomEventDictAttackSkip,
 };
 };
 
 
 typedef enum {
 typedef enum {

+ 9 - 0
uhf_cmd.c

@@ -0,0 +1,9 @@
+// #include "uhf_cmd.h"
+// #include "uhf_app_i.h"
+
+// char* uhf_get_dev_info(UHFApp* uhf_app) {
+// }
+
+// uint8_t* uhf_single_poll(UHFApp* uhf_app){
+
+// }

+ 102 - 0
uhf_cmd.h

@@ -0,0 +1,102 @@
+#pragma once
+#include <stdint.h>
+#include <stdlib.h>
+
+typedef struct UHF_RFID_CMD {
+    uint8_t* cmd;
+    size_t length;
+}UHF_RFID_CMD;
+
+typedef enum{
+    COMMAND_FRAME = 0x00,
+    RESPONSE_FRAME,
+    NOTIFICATION_FRAME
+}UHFFrameType;
+
+typedef enum{
+    CHINA_900MHZ = 1,
+    CHINA_800MHZ = 4,
+    US = 2,
+    EU = 3,
+    KOREA = 6
+}UHFWorkArea;
+
+#define FRAME_START 0xBB
+#define FRAME_END 0x7E
+#define ERROR 0x15
+
+const UHF_RFID_CMD CMD_HARDWARE_VERSION = {.cmd = (uint8_t[]){0xBB, 0x00, 0x03, 0x00, 0x01, 0x00, 0x04, 0x7E}, .length = 8};
+
+const UHF_RFID_CMD CMD_SOFTWARE_VERSION = {.cmd = (uint8_t[]){0xBB, 0x00, 0x03, 0x00, 0x01, 0x01, 0x05, 0x7E}, .length = 8};
+
+const UHF_RFID_CMD CMD_MANUFACTURERS = {.cmd = (uint8_t[]){0xBB, 0x00, 0x03, 0x00, 0x01, 0x02, 0x06, 0x7E}, .length = 8};
+
+const UHF_RFID_CMD CMD_SINGLE_POLLING = {.cmd = (uint8_t[]){0xBB, 0x00, 0x22, 0x00, 0x00, 0x22, 0x7E}, .length = 7};
+
+const UHF_RFID_CMD CMD_MULTIPLE_POLLING = {.cmd = (uint8_t[]){0xBB, 0x00, 0x27, 0x00, 0x03, 0x22, 0x27, 0x10, 0x83, 0x7E}, .length = 10};
+
+const UHF_RFID_CMD CMD_STOP_MULTIPLE_POLLING = {.cmd = (uint8_t[]){0xBB, 0x00, 0x28, 0x00, 0x00, 0x28, 0x7E}, .length = 7};
+
+const UHF_RFID_CMD CMD_SET_SELECT_PARAMETER = {.cmd = (uint8_t[]){0xBB, 0x00, 0x0C, 0x00, 0x13, 0x01, 0x00, 0x00, 0x00, 0x20, 0x60, 0x00, 0x30, 0x75, 0x1F, 0xEB, 0x70, 0x5C, 0x59, 0x04, 0xE3, 0xD5, 0x0D, 0x70, 0xAD, 0x7E }, .length = 27};
+
+const UHF_RFID_CMD CMD_GET_SELECT_PARAMETER = {.cmd = (uint8_t[]){0xBB, 0x00, 0x0B, 0x00, 0x00, 0x0B, 0x7E}, .length = 7};
+
+const UHF_RFID_CMD CMD_SET_SELECT_MODE = {.cmd = (uint8_t[]){0xBB, 0x00, 0x12, 0x00, 0x01, 0x01, 0x14, 0x7E}, .length = 8};
+
+const UHF_RFID_CMD CMD_READ_LABEL_DATA_STORAGE = {.cmd = (uint8_t[]){0xBB, 0x00, 0x39, 0x00, 0x09, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x08, 0x4D, 0x7E}, .length = 17};
+
+const UHF_RFID_CMD CMD_WRITE_LABEL_DATA_STORAGE = {.cmd = (uint8_t[]){0xBB, 0x00, 0x49, 0x00, 0x11, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x04, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x71, 0x7E}, .length = 24};
+
+const UHF_RFID_CMD CMD_LOCK_LABEL_DATA_STORAGE = {.cmd = (uint8_t[]){0xBB, 0x00, 0x82, 0x00, 0x07, 0x00, 0x00, 0xFF, 0xFF, 0x02, 0x00, 0x80, 0x09, 0x7E}, .length = 13};
+
+const UHF_RFID_CMD CMD_INACTIVATE_KILL_TAG = {.cmd = (uint8_t[]){0xBB, 0x00, 0x65, 0x00, 0x04, 0x00, 0x00, 0xFF, 0xFF, 0x67, 0x7E}, .length = 11};
+
+const UHF_RFID_CMD CMD_SET_COMMUNICATION_BAUD_RATE = {.cmd = (uint8_t[]){0xBB, 0x00, 0x11, 0x00, 0x02, 0x00, 0xC0, 0xD3, 0x7E}, .length = 9};
+
+const UHF_RFID_CMD CMD_GET_QUERY_PARAMETERS = {.cmd = (uint8_t[]){0xBB, 0x00, 0x0D, 0x00, 0x00, 0x0D, 0x7E}, .length = 7};
+
+const UHF_RFID_CMD CMD_SET_QUERY_PARAMETER = {.cmd = (uint8_t[]){0xBB, 0x00, 0x0E, 0x00, 0x02, 0x10, 0x20, 0x40, 0x7E}, .length = 9};
+
+const UHF_RFID_CMD CMD_SETUP_WORK_AREA = {.cmd = (uint8_t[]){0xBB, 0x00, 0x07, 0x00, 0x01, 0x01, 0x09, 0x7E}, .length = 8};
+
+const UHF_RFID_CMD CMD_ACQUIRE_WORK_LOCATIONS = {.cmd = (uint8_t[]){0xBB, 0x00, 0x08, 0x00, 0x00, 0x08, 0x7E}, .length = 7};
+
+const UHF_RFID_CMD CMD_SETUP_WORKING_CHANNEL = {.cmd = (uint8_t[]){0xBB, 0x00, 0xAB, 0x00, 0x01, 0x01, 0xAC, 0x7E}, .length = 8};
+
+const UHF_RFID_CMD CMD_GET_WORKING_CHANNEL = {.cmd = (uint8_t[]){0xBB, 0x00, 0xAA, 0x00, 0x00, 0xAA, 0x7E}, .length = 7};
+
+const UHF_RFID_CMD CMD_SET_AUTO_FREQUENCY_HOPPING = {.cmd = (uint8_t[]){0xBB, 0x00, 0xAD, 0x00, 0x01, 0xFF, 0xAD, 0x7E}, .length = 8};
+
+const UHF_RFID_CMD CMD_INSERT_WORKING_CHANNEL = {.cmd = (uint8_t[]){0xBB, 0x00, 0xA9, 0x00, 0x06, 0x05, 0x01, 0x02,0x03, 0x04, 0x05, 0xC3, 0x7E}, .length = 13};
+
+const UHF_RFID_CMD CMD_ACQUIRE_TRANSMITTING_POWER = {.cmd = (uint8_t[]){0xBB, 0x00, 0xB7, 0x00, 0x00, 0xB7, 0x7E}, .length = 7};
+
+const UHF_RFID_CMD CMD_SET_TRANSMITTING_POWER = {.cmd = (uint8_t[]){0xBB, 0x00, 0xB6, 0x00, 0x02, 0x07, 0xD0, 0x8F, 0x7E}, .length = 9};
+
+const UHF_RFID_CMD CMD_SET_CONTINUOUS_CARRIER = {.cmd = (uint8_t[]){0xBB, 0x00, 0xB0, 0x00, 0x01, 0xFF, 0xB0, 0x7E}, .length = 8};
+
+const UHF_RFID_CMD CMD_GET_DEMODULATOR_PARAMETERS = {.cmd = (uint8_t[]){0xBB, 0x00, 0xF1, 0x00, 0x00, 0xF1, 0x7E}, .length = 7};
+
+const UHF_RFID_CMD CMD_SET_DEMODULATOR_PARAMETERS = {.cmd = (uint8_t[]){0xBB, 0x00, 0xF0, 0x00, 0x04, 0x03, 0x06, 0x01, 0xB0, 0xAE, 0x7E}, .length = 11};
+
+const UHF_RFID_CMD CMD_TEST_RF_INPUT_BLOCK_SIGNAL = {.cmd = (uint8_t[]){0xBB, 0x00, 0xF2, 0x00, 0x00, 0xF2, 0x7E}, .length = 7};
+
+const UHF_RFID_CMD CMD_TEST_RSSI_SIGNAL = {.cmd = (uint8_t[]){0xBB, 0x00, 0xF3, 0x00, 0x00, 0xF3, 0x7E}, .length = 7};
+
+const UHF_RFID_CMD CMD_MODULE_HIBERNATION = {.cmd = (uint8_t[]){0xBB, 0x00, 0x17, 0x00, 0x00, 0x17, 0x7E}, .length = 7};
+
+const UHF_RFID_CMD CMD_IDLE_HIBERNATION_TIME = {.cmd = (uint8_t[]){0xBB, 0x00, 0x1D, 0x00, 0x01, 0x02, 0x20, 0x7E}, .length = 8};
+
+const UHF_RFID_CMD CMD_IDLE_MODE = {.cmd = (uint8_t[]){0xBB, 0x00, 0x04, 0x00, 0x03, 0x01, 0x01, 0x03, 0x0C, 0x7E}, .length = 10};
+
+const UHF_RFID_CMD CMD_NXP_READPROTECT = {.cmd = (uint8_t[]){0xBB, 0x00, 0xE1, 0x00, 0x05, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0xE4, 0x7E}, .length = 12};
+
+const UHF_RFID_CMD CMD_NXP_CHANGE_EAS = {.cmd = (uint8_t[]){0xBB, 0x00, 0xE3, 0x00, 0x05, 0x00, 0x00, 0xFF, 0xFF, 0x01, 0xE7, 0x7E}, .length = 12};
+
+const UHF_RFID_CMD CMD_NXP_EAS_ALARM = {.cmd = (uint8_t[]){0xBB, 0x00, 0xE4, 0x00, 0x00, 0xE4, 0x7E}, .length = 7};
+
+const UHF_RFID_CMD CMD_NXP_CONFIG_WORD = {.cmd = (uint8_t[]){0xBB, 0x00, 0xE0, 0x00, 0x06, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0xE4, 0x7E}, .length = 13};
+
+const UHF_RFID_CMD CMD_IMPINJ_MONZA4_QT = {.cmd = (uint8_t[]){0xBB, 0x00, 0xE5, 0x00, 0x08, 0x00, 0x00, 0xFF, 0xFF, 0x01, 0x01, 0x40, 0x00, 0x2D, 0x7E}, .length = 15};
+
+const UHF_RFID_CMD CMD_BLOCK_PERMALOCK = {.cmd = (uint8_t[]){0xBB, 0x00, 0xD3, 0x00, 0x0B, 0x00, 0x00, 0xFF,0xFF, 0x01, 0x03, 0x00, 0x00, 0x01, 0x07, 0x00, 0xE8, 0x7E}, .length = 18};

+ 6 - 5
uhf_data.c

@@ -1,5 +1,5 @@
 #include "uhf_data.h"
 #include "uhf_data.h"
-
+#include <furi.h>
 UHFData* uhf_data_alloc() {
 UHFData* uhf_data_alloc() {
     UHFData* uhf_data = (UHFData*)malloc(sizeof(UHFData));
     UHFData* uhf_data = (UHFData*)malloc(sizeof(UHFData));
     uhf_data->length = 0;
     uhf_data->length = 0;
@@ -14,12 +14,13 @@ int uhf_data_append(UHFData* uhf_data, uint8_t data) {
 }
 }
 
 
 void uhf_data_free(UHFData* uhf_data) {
 void uhf_data_free(UHFData* uhf_data) {
-    free(uhf_data->data);
-    if(uhf_data->next != NULL) {
+    if(uhf_data != NULL) {
+        FURI_LOG_E("LL", "Freeing linked list");
+        free(uhf_data->data);
         uhf_data_free((UHFData*)uhf_data->next);
         uhf_data_free((UHFData*)uhf_data->next);
+        free(uhf_data->next);
+        free(uhf_data);
     }
     }
-    free(uhf_data->next);
-    free(uhf_data);
 }
 }
 
 
 UHFResponseData* uhf_response_data_alloc() {
 UHFResponseData* uhf_response_data_alloc() {

+ 0 - 364
uhf_main.c

@@ -1,364 +0,0 @@
-#include <furi.h>
-#include <furi_hal.h>
-#include <gui/gui.h>
-#include <gui/view_dispatcher.h>
-#include <gui/scene_manager.h>
-#include <gui/modules/widget.h>
-#include <gui/modules/submenu.h>
-#include <gui/modules/text_input.h>
-#include <lib/toolbox/stream/file_stream.h>
-#include "cmd.h"
-#include <stdlib.h>
-
-#define UHF_APPS_DATA_FOLDER EXT_PATH("apps_data")
-#define UHF_LOG_FOLDER       \
-    UHF_APPS_DATA_FOLDER "/" \
-                         "uhf"
-#define UHF_LOG_FILE_NAME "log.txt"
-#define UHF_LOG_PATH UHF_LOG_FOLDER "/" UHF_LOG_FILE_NAME
-#define SCENE_COUNT 2
-
-bool logged = false;
-// volatile int array_ptr = 0;
-// uint8_t array_log[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
-//                        0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
-
-char* convertToHexString(const uint8_t* array, size_t length) {
-    if(array == NULL || length == 0) {
-        return NULL;
-    }
-
-    // Each byte takes 3 characters in the hex representation (2 characters + space), plus 1 for the null terminator
-    size_t hexLength = (length * 3) + 1;
-
-    char* hexArray = (char*)malloc(hexLength * sizeof(char));
-    if(hexArray == NULL) {
-        return NULL;
-    }
-
-    size_t index = 0;
-    for(size_t i = 0; i < length; i++) {
-        index += snprintf(&hexArray[index], hexLength - index, "%02x ", array[i]);
-    }
-
-    hexArray[hexLength - 1] = '\0';
-
-    return hexArray;
-}
-
-void store_message(char* message) {
-    Storage* storage = furi_record_open(RECORD_STORAGE);
-    if(!storage_dir_exists(storage, UHF_APPS_DATA_FOLDER)) {
-        storage_simply_mkdir(storage, UHF_APPS_DATA_FOLDER);
-    }
-
-    if(!storage_dir_exists(storage, UHF_LOG_FOLDER)) {
-        storage_simply_mkdir(storage, UHF_LOG_FOLDER);
-    }
-
-    File* file = storage_file_alloc(storage);
-    if(storage_file_open(file, UHF_LOG_PATH, FSAM_WRITE, FSOM_OPEN_APPEND)) {
-        if(!logged) {
-            storage_file_seek(file, 0, true);
-            storage_file_truncate(file);
-            logged = true;
-        }
-        storage_file_write(file, message, strlen(message));
-        storage_file_write(file, "\n", 1);
-        storage_file_close(file);
-        storage_file_free(file);
-    }
-    furi_record_close(RECORD_STORAGE);
-}
-
-typedef enum { STARTED, RUNNING, STOPPED } UHFRFIDWorkerState;
-typedef enum { SEND_READ_CMD, SEND_WRITE_CMD } UHFRFIDWorkerCMD;
-
-// typedef void (*UHFRFIDWorkerCallback)();
-typedef struct UHFReturnData {
-    uint8_t* data;
-    size_t length;
-} UHFReturnData;
-
-UHFReturnData* uhf_return_data_alloc() {
-    UHFReturnData* uhf_data = (UHFReturnData*)malloc(sizeof(UHFReturnData));
-    uhf_data->data = (uint8_t*)malloc(24 * sizeof(uint8_t));
-    uhf_data->length = 0;
-    return uhf_data;
-}
-
-void uhf_return_data_free(UHFReturnData* uhf_data) {
-    free(uhf_data->data);
-}
-
-typedef struct UHFRFIDWorker {
-    FuriThread* thread;
-    UHFReturnData* uhf_data;
-    // UHFRFIDWorkerCMD cmd;
-    // Storage* storage;
-    // UHFRFIDWorkerCallback callback;
-
-} UHFRFIDWorker;
-
-typedef enum { MainMenuRead, MainMenuSaved } MainMenuSceneIndex;
-typedef enum { MainMenuReadEvent, MainMenuSavedEvent } MainMenuEvent;
-
-void uhf_rfid_worker_enable_field() {
-}
-
-void uhf_rfid_worker_disable_field() {
-}
-
-// uint8_t* uhf_rfid_read() {
-//     return 0;
-// }
-
-void rx_callback(UartIrqEvent event, uint8_t data, void* ctx) {
-    UNUSED(event);
-    UHFReturnData* uhf_data = ctx;
-    uhf_data->data[uhf_data->length++] = data;
-    // UNUSED(ctx);
-    // UNUSED(data);
-    // array_log[array_ptr++] = data;
-}
-
-int32_t uhf_rfid_worker_task(void* ctx) {
-    UHFRFIDWorker* worker = ctx;
-    // UHFRFIDWorker* worker = ctx;
-    // uhf_rfid_worker_enable_field();
-    // array_ptr = 0;
-    furi_hal_console_disable();
-    furi_hal_uart_set_br(FuriHalUartIdUSART1, 115200);
-    furi_hal_uart_set_irq_cb(FuriHalUartIdUSART1, rx_callback, worker->uhf_data);
-    // ArrayList* data_list = worker->context;
-    // int prev_size = data_list->size;
-    // switch(worker->cmd) {
-    // case SEND_READ_CMD:
-    //     // furi_hal_console_enable();
-    //     // FURI_LOG_E("TAG", "SENDING DATA");
-    //     // FURI_LOG_E(
-    //     //     "TAG",
-    //     //     "%02x%02x%02x%02x%02x%02x%02x",
-    //     //     CMD_SINGLE_POLLING.cmd[0],
-    //     //     CMD_SINGLE_POLLING.cmd[1],
-    //     //     CMD_SINGLE_POLLING.cmd[2],
-    //     //     CMD_SINGLE_POLLING.cmd[3],
-    //     //     CMD_SINGLE_POLLING.cmd[4],
-    //     //     CMD_SINGLE_POLLING.cmd[5],
-    //     //     CMD_SINGLE_POLLING.cmd[6]);
-    //     // furi_hal_console_disable();
-    //     break;
-    // default:
-    //     break;
-    // }
-    furi_hal_uart_tx(FuriHalUartIdUSART1, CMD_SINGLE_POLLING.cmd, CMD_SINGLE_POLLING.length);
-    // while(prev_size == 0 || !(prev_size != data_list->size)) {
-    //     furi_delay_ms(50);
-    // }
-    // furi_hal_console_enable();
-    // FURI_LOG_E("TAG", "DATA READ %s", array_list_to_string(data_list));
-    // furi_delay_ms(2000);
-    return 0;
-}
-UHFRFIDWorker* uhf_rfid_worker_alloc() {
-    UHFRFIDWorker* uhf_rfid_worker = malloc(sizeof(UHFRFIDWorker));
-    uhf_rfid_worker->thread =
-        furi_thread_alloc_ex("UHFRFIDWorker", 8 * 1024, uhf_rfid_worker_task, uhf_rfid_worker);
-    // uhf_rfid_worker->cmd = SEND_READ_CMD;
-    uhf_rfid_worker->uhf_data = uhf_return_data_alloc();
-    return uhf_rfid_worker;
-}
-
-void uhf_rfid_worker_free(UHFRFIDWorker* uhf_rfid_worker) {
-    furi_assert(uhf_rfid_worker);
-    furi_thread_free(uhf_rfid_worker->thread);
-    // ArrayList* data_list = uhf_rfid_worker->context;
-    // array_list_free(data_list);
-
-    // furi_record_close(RECORD_STORAGE);
-
-    free(uhf_rfid_worker);
-}
-
-// void uhf_rfid_worker_change_state(UHFRFIDWorker* worker, UHFRFIDWorkerState state) {
-//     worker->state = state;
-// }
-void uhf_rfid_worker_start(UHFRFIDWorker* uhf_rfid_worker, UHFRFIDWorkerState state, void* ctx) {
-    UNUSED(state);
-    UNUSED(ctx);
-    // uhf_rfid_worker_change_state(uhf_rfid_worker, state);
-    furi_thread_start(uhf_rfid_worker->thread);
-}
-
-void uhf_rfid_worker_stop(UHFRFIDWorker* uhf_rfid_worker) {
-    furi_assert(uhf_rfid_worker);
-    furi_assert(uhf_rfid_worker->thread);
-
-    if(furi_thread_get_state(uhf_rfid_worker->thread) != FuriThreadStateStopped) {
-        // uhf_rfid_worker_change_state(uhf_rfid_worker, STOPPED);
-        furi_thread_join(uhf_rfid_worker->thread);
-    }
-}
-
-typedef enum { MainMenuScene, WaitingReadScene, ReadSuccessScene } UHF_RFID_Scene;
-
-typedef enum { SubmenuView, WidgetView, TextInputView } UHF_RFID_Scene_View;
-
-typedef struct UHFRFIDApp {
-    SceneManager* scene_manager;
-    ViewDispatcher* view_dispatcher;
-    Submenu* submenu;
-    Widget* widget;
-    TextInput* text_input;
-} UHFRFIDApp;
-
-void scenes_menu_callback(void* ctx, uint32_t index) {
-    UHFRFIDApp* app = ctx;
-    switch(index) {
-    case MainMenuRead:
-        scene_manager_handle_custom_event(app->scene_manager, MainMenuReadEvent);
-        break;
-    case MainMenuSaved:
-        // not implemented yet
-        furi_hal_console_enable();
-        FURI_LOG_E("TAG", "Saved was pressed");
-        furi_hal_console_disable();
-        break;
-    }
-}
-
-void scene_main_menu_on_enter(void* ctx) {
-    UHFRFIDApp* app = ctx;
-    submenu_reset(app->submenu);
-    submenu_set_header(app->submenu, "[UHF]RFID App");
-    submenu_add_item(app->submenu, "Read", MainMenuRead, scenes_menu_callback, app);
-    submenu_add_item(app->submenu, "Saved", MainMenuSaved, scenes_menu_callback, app);
-    view_dispatcher_switch_to_view(app->view_dispatcher, SubmenuView);
-}
-
-bool scene_main_menu_on_event(void* ctx, SceneManagerEvent event) {
-    UHFRFIDApp* app = ctx;
-    bool consumed = false;
-    switch(event.type) {
-    case SceneManagerEventTypeCustom:
-        switch(event.event) {
-        case MainMenuReadEvent:
-            scene_manager_next_scene(app->scene_manager, WaitingReadScene);
-            consumed = true;
-            break;
-        case MainMenuSavedEvent:
-            // TODO : not implemented yet
-            break;
-        }
-    default:
-        break;
-    }
-    return consumed;
-}
-
-void scene_main_menu_on_exit(void* ctx) {
-    UHFRFIDApp* app = ctx;
-    submenu_reset(app->submenu);
-}
-
-void scene_read_on_enter(void* ctx) {
-    UHFRFIDApp* app = ctx;
-    widget_reset(app->widget);
-    UHFRFIDWorker* worker = uhf_rfid_worker_alloc();
-    UHFReturnData* uhf_data = worker->uhf_data;
-    uhf_rfid_worker_start(worker, RUNNING, NULL);
-    furi_delay_ms(1000);
-    // UNUSED(uhf_data);
-    char* values = convertToHexString(uhf_data->data, uhf_data->length);
-    // UNUSED(values);
-    if(values != NULL) {
-        store_message(values);
-        widget_add_string_element(
-            app->widget, 25, 15, AlignCenter, AlignCenter, FontPrimary, values);
-    } else {
-        store_message("No data found");
-        widget_add_string_element(
-            app->widget, 25, 15, AlignCenter, AlignCenter, FontPrimary, "No data found");
-    }
-    // furi_hal_console_enable();
-    // FURI_LOG_E("TAG", "data %s", values);
-
-    view_dispatcher_switch_to_view(app->view_dispatcher, WidgetView);
-    // furi_delay_ms(2000);
-    uhf_rfid_worker_stop(worker);
-    uhf_return_data_free(worker->uhf_data);
-    uhf_rfid_worker_free(worker);
-}
-
-bool scene_read_on_event(void* ctx, SceneManagerEvent event) {
-    UNUSED(ctx);
-    UNUSED(event);
-    return false; // event not handled.
-}
-
-void scene_read_on_exit(void* ctx) {
-    UNUSED(ctx);
-}
-
-bool scene_custom_callback(void* ctx, uint32_t custom_event) {
-    furi_assert(ctx);
-    UHFRFIDApp* app = ctx;
-    return scene_manager_handle_custom_event(app->scene_manager, custom_event);
-};
-
-bool scene_back_event_callback(void* ctx) {
-    furi_assert(ctx);
-    UHFRFIDApp* app = ctx;
-    return scene_manager_handle_back_event(app->scene_manager);
-}
-
-void (*const scene_on_enter_handlers[])(void*) = {scene_main_menu_on_enter, scene_read_on_enter};
-bool (*const scene_on_event_handlers[])(void*, SceneManagerEvent) = {
-    scene_main_menu_on_event,
-    scene_read_on_event};
-void (*const scene_on_exit_handlers[])(void*) = {scene_main_menu_on_exit, scene_read_on_exit};
-
-const SceneManagerHandlers scene_manager_handlers = {
-    .on_enter_handlers = scene_on_enter_handlers,
-    .on_event_handlers = scene_on_event_handlers,
-    .on_exit_handlers = scene_on_exit_handlers,
-    .scene_num = SCENE_COUNT};
-
-UHFRFIDApp* uhf_rfid_app_alloc() {
-    UHFRFIDApp* app = malloc(sizeof(UHFRFIDApp));
-    app->scene_manager = scene_manager_alloc(&scene_manager_handlers, app);
-    app->view_dispatcher = view_dispatcher_alloc();
-    view_dispatcher_enable_queue(app->view_dispatcher);
-    view_dispatcher_set_event_callback_context(app->view_dispatcher, app);
-    view_dispatcher_set_custom_event_callback(app->view_dispatcher, scene_custom_callback);
-    view_dispatcher_set_navigation_event_callback(app->view_dispatcher, scene_back_event_callback);
-    app->submenu = submenu_alloc();
-    view_dispatcher_add_view(app->view_dispatcher, SubmenuView, submenu_get_view(app->submenu));
-    app->widget = widget_alloc();
-    view_dispatcher_add_view(app->view_dispatcher, WidgetView, widget_get_view(app->widget));
-    return app;
-}
-
-void uhf_rfid_app_free(UHFRFIDApp* app) {
-    furi_assert(app);
-    view_dispatcher_remove_view(app->view_dispatcher, SubmenuView);
-    view_dispatcher_remove_view(app->view_dispatcher, WidgetView);
-    scene_manager_free(app->scene_manager);
-    view_dispatcher_free(app->view_dispatcher);
-    submenu_free(app->submenu);
-    widget_free(app->widget);
-    free(app);
-}
-
-int32_t uhf_rfid_app2(void* p) {
-    UNUSED(p);
-    UHFRFIDApp* app = uhf_rfid_app_alloc();
-
-    Gui* gui = furi_record_open(RECORD_GUI);
-    view_dispatcher_attach_to_gui(app->view_dispatcher, gui, ViewDispatcherTypeFullscreen);
-    scene_manager_next_scene(app->scene_manager, MainMenuScene);
-    view_dispatcher_run(app->view_dispatcher);
-
-    uhf_rfid_app_free(app);
-    return 0;
-}

+ 3 - 1
uhf_worker.c

@@ -1,8 +1,10 @@
-#include "uhf_data.h"
+
 #include "uhf_worker.h"
 #include "uhf_worker.h"
+#include "uhf_data.h"
 
 
 int32_t uhf_worker_task(void* ctx) {
 int32_t uhf_worker_task(void* ctx) {
     UNUSED(ctx);
     UNUSED(ctx);
+    FURI_LOG_E("uhf_worker", "worker callback has been called");
     return 0;
     return 0;
 }
 }