Przeglądaj źródła

simple working read sequence complete.

frux-c 2 lat temu
rodzic
commit
cd4014e736
7 zmienionych plików z 115 dodań i 55 usunięć
  1. 2 1
      application.fam
  2. 9 19
      scenes/uhf_scene_read_tag.c
  3. 67 17
      scenes/uhf_scene_read_tag_success.c
  4. 1 2
      uhf_app.c
  5. 19 4
      uhf_data.c
  6. 4 1
      uhf_data.h
  7. 13 11
      uhf_worker.c

+ 2 - 1
application.fam

@@ -18,5 +18,6 @@ App(
     #         name="loclass",
     #     ),
     # ],
-    # fap_icon_assets="icons",
+    fap_icon_assets="icons",
+    fap_icon_assets_symbol="uhf_rfid",
 )

+ 9 - 19
scenes/uhf_scene_read_tag.c

@@ -2,9 +2,13 @@
 #include <dolphin/dolphin.h>
 
 void uhf_read_tag_worker_callback(UHFWorkerEvent event, void* ctx) {
-    UNUSED(event);
     UHFApp* uhf_app = ctx;
-    view_dispatcher_send_custom_event(uhf_app->view_dispatcher, UHFCustomEventWorkerExit);
+    if(event == UHFWorkerEventSuccess) {
+        view_dispatcher_send_custom_event(uhf_app->view_dispatcher, UHFCustomEventWorkerExit);
+    }
+    // } else if(event == UHFWorkerEventAborted) {
+    //     scene_manager_search_and_switch_to_previous_scene(uhf_app->scene_manager, UHFSceneStart);
+    // }
 }
 
 void uhf_scene_read_tag_on_enter(void* ctx) {
@@ -22,31 +26,17 @@ void uhf_scene_read_tag_on_enter(void* ctx) {
     uhf_worker_start(uhf_app->worker, UHFWorkerStateDetect, uhf_read_tag_worker_callback, uhf_app);
 
     uhf_blink_start(uhf_app);
-
-    // furi_delay_ms(2000);
-    // view_dispatcher_send_custom_event(uhf_app->view_dispatcher, UHFCustomEventWorkerExit);
 }
 
 bool uhf_scene_read_tag_on_event(void* ctx, SceneManagerEvent event) {
+    // UNUSED(ctx);
     UHFApp* uhf_app = ctx;
     bool consumed = false;
-    uint8_t cmd[] = {0xBB, 0x00, 0x22, 0x00, 0x00, 0x22, 0x7E};
-    // while(uhf_worker->state != UHFWorkerStateStop || !first_data->data_full) {
-    FURI_LOG_E("uhf_scene_read_tag_on_event", "sending single polling command");
-    furi_hal_uart_tx(FuriHalUartIdUSART1, cmd, 7);
-    if(uhf_app->worker->data->data->data_full) {
+    if(event.event == UHFCustomEventWorkerExit) {
+        FURI_LOG_E("uhf_scene_read_tag_on_event", "event was registered");
         scene_manager_next_scene(uhf_app->scene_manager, UHFSceneReadTagSuccess);
         consumed = true;
     }
-    // FURI_LOG_E("33", "uhf_scene_read_tag_on_event was called! event.event: %lu", event.event);
-    if(event.type == SceneManagerEventTypeCustom) {
-        // FURI_LOG_E("36", "SceneManagerEventTypeCustom");
-        if(event.event == UHFCustomEventWorkerExit) {
-            uhf_app->worker->state = UHFWorkerStateStop;
-            // scene_manager_next_scene(uhf_app->scene_manager, UHFSceneReadTagSuccess);
-            consumed = true;
-        }
-    }
     return consumed;
 }
 

+ 67 - 17
scenes/uhf_scene_read_tag_success.c

@@ -5,18 +5,71 @@ void uhf_read_tag_success_worker_callback(UHFWorkerEvent event, void* ctx) {
     UNUSED(ctx);
 }
 
+void uhf_scene_read_card_success_widget_callback(GuiButtonType result, InputType type, void* ctx) {
+    furi_assert(ctx);
+    UHFApp* uhf_app = ctx;
+
+    if(type == InputTypeShort) {
+        view_dispatcher_send_custom_event(uhf_app->view_dispatcher, result);
+    }
+}
+
 void uhf_scene_read_tag_success_on_enter(void* ctx) {
     // UNUSED(ctx);
     UHFApp* uhf_app = ctx;
 
+    const uint8_t* read_data = uhf_app->worker->data->data->data;
+
+    widget_add_string_element(
+        uhf_app->widget, 32, 5, AlignLeft, AlignCenter, FontPrimary, "Read Success");
+
+    widget_add_string_element(uhf_app->widget, 3, 18, AlignLeft, AlignCenter, FontPrimary, "PC :");
+
+    widget_add_string_element(
+        uhf_app->widget, 66, 18, AlignLeft, AlignCenter, FontPrimary, "CRC :");
+
+    widget_add_string_element(
+        uhf_app->widget, 3, 32, AlignLeft, AlignCenter, FontPrimary, "EPC :");
+
     widget_add_string_element(
         uhf_app->widget,
-        20,
-        20,
+        26,
+        19,
+        AlignLeft,
         AlignCenter,
+        FontKeyboard,
+        convertToHexString(read_data + 6, 2));
+
+    widget_add_string_element(
+        uhf_app->widget,
+        96,
+        19,
+        AlignLeft,
         AlignCenter,
-        FontPrimary,
-        convertToHexString(uhf_app->worker->data->data->data, uhf_app->worker->data->data->length));
+        FontKeyboard,
+        convertToHexString(read_data + 20, 2));
+
+    widget_add_string_multiline_element(
+        uhf_app->widget,
+        34,
+        29,
+        AlignLeft,
+        AlignTop,
+        FontKeyboard,
+        convertToHexString(read_data + 8, 12));
+
+    widget_add_button_element(
+        uhf_app->widget,
+        GuiButtonTypeRight,
+        "More",
+        uhf_scene_read_card_success_widget_callback,
+        uhf_app);
+    widget_add_button_element(
+        uhf_app->widget,
+        GuiButtonTypeLeft,
+        "Exit",
+        uhf_scene_read_card_success_widget_callback,
+        uhf_app);
 
     view_dispatcher_switch_to_view(uhf_app->view_dispatcher, UHFViewWidget);
 }
@@ -24,24 +77,21 @@ void uhf_scene_read_tag_success_on_enter(void* ctx) {
 bool uhf_scene_read_tag_success_on_event(void* ctx, SceneManagerEvent event) {
     UHFApp* uhf_app = ctx;
     bool consumed = false;
-    // FURI_LOG_E("33", "uhf_scene_read_tag_on_event was called! event.event: %d", event.type);
-    // FURI_LOG_E("33", "uhf_scene_read_tag_on_event was called! event.event: %lu", event.event);
     if(event.event == SceneManagerEventTypeBack) {
         // FURI_LOG_E("36", "Back button was pressed");
         uhf_app->worker->state = UHFWorkerStateStop;
     }
     if(event.type == SceneManagerEventTypeCustom) {
-        // FURI_LOG_E("36", "SceneManagerEventTypeCustom");
-        if(event.event == UHFCustomEventWorkerExit) {
-            // FURI_LOG_E("38", "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;
+        // if 'exit' is pressed go back to home screen
+        if(event.event == GuiButtonTypeLeft) {
+            consumed = scene_manager_search_and_switch_to_previous_scene(
+                uhf_app->scene_manager, UHFSceneStart);
+        } else if(event.event == GuiButtonTypeRight) {
+            // scene_manager_next_scene(picopass->scene_manager, PicopassSceneCardMenu);
+            // consumed = true;
+        } else if(event.event == GuiButtonTypeCenter) {
+            // consumed = scene_manager_search_and_switch_to_another_scene(
+            //     picopass->scene_manager, PicopassSceneStart);
         }
     }
     return consumed;

+ 1 - 2
uhf_app.c

@@ -184,8 +184,7 @@ void uhf_show_loading_popup(void* ctx, bool show) {
 int32_t uhf_app_main(void* ctx) {
     UNUSED(ctx);
     UHFApp* uhf_app = uhf_alloc();
-    view_dispatcher_attach_to_gui(
-        uhf_app->view_dispatcher, uhf_app->gui, ViewDispatcherTypeFullscreen);
+
     scene_manager_next_scene(uhf_app->scene_manager, UHFSceneStart);
     view_dispatcher_run(uhf_app->view_dispatcher);
 

+ 19 - 4
uhf_data.c

@@ -5,20 +5,35 @@
 UHFData* uhf_data_alloc() {
     UHFData* uhf_data = (UHFData*)malloc(sizeof(UHFData));
     uhf_data->length = 0;
-    uhf_data->data_full = false;
+    uhf_data->start = false;
+    uhf_data->end = false;
     uhf_data->next = NULL;
     return uhf_data;
 }
 
 int uhf_data_append(UHFData* uhf_data, uint8_t data) {
-    if(uhf_data->length >= MAX_DATA_SIZE || uhf_data->data_full) return 0;
-    uhf_data->data[uhf_data->length++] = data;
+    if(data == 0xBB) {
+        uhf_data->start = true;
+    }
+    if(!uhf_data->start) return 0;
+    if(uhf_data->end) return 0;
+    if(uhf_data->length >= MAX_DATA_SIZE) return 0;
     if(data == 0x7E) {
-        uhf_data->data_full = true;
+        uhf_data->end = true;
     }
+    uhf_data->data[uhf_data->length++] = data;
     return 1;
 }
 
+void uhf_data_reset(UHFData* uhf_data) {
+    for(size_t i = 0; i < uhf_data->length; i++) {
+        uhf_data->data[i] = 0x00;
+    }
+    uhf_data->start = false;
+    uhf_data->end = false;
+    uhf_data->length = 0;
+}
+
 void uhf_data_free(UHFData* uhf_data) {
     if(uhf_data != NULL) {
         while(uhf_data != NULL) {

+ 4 - 1
uhf_data.h

@@ -1,4 +1,5 @@
 #pragma once
+
 #include <stdint.h>
 #include <stdlib.h>
 
@@ -7,7 +8,8 @@
 typedef struct UHFData {
     uint8_t data[MAX_DATA_SIZE];
     size_t length;
-    bool data_full;
+    bool start;
+    bool end;
     struct UHFData* next;
 } UHFData;
 
@@ -19,6 +21,7 @@ typedef struct UHFResponseData {
 
 UHFData* uhf_data_alloc();
 int uhf_data_append(UHFData* uhf_data, uint8_t data);
+void uhf_data_reset(UHFData* uhf_data);
 void uhf_data_free(UHFData* uhf_data);
 
 UHFResponseData* uhf_response_data_alloc();

+ 13 - 11
uhf_worker.c

@@ -1,5 +1,5 @@
 #include "uhf_worker.h"
-// #include "uhf_cmd.h"
+#include "uhf_cmd.h"
 
 void single_poll_rx_callback(UartIrqEvent event, uint8_t data, void* ctx) {
     UNUSED(event);
@@ -9,21 +9,23 @@ void single_poll_rx_callback(UartIrqEvent event, uint8_t data, void* ctx) {
 }
 
 UHFWorkerEvent read_single_card(UHFWorker* uhf_worker) {
-    // UNUSED(uhf_worker);
-    // furi_hal_uart_set_br(FuriHalUartIdUSART1, DEFAULT_BAUD_RATE);
-    furi_hal_uart_set_br(FuriHalUartIdUSART1, 115200);
-    furi_hal_uart_set_irq_cb(FuriHalUartIdUSART1, single_poll_rx_callback, uhf_worker->data);
-    // UHFData* first_data = uhf_worker->data->data;
-
-    // furi_delay_ms(1000);
-    // FURI_LOG_E("read_single_card", "waiting on read");
-    // }
+    UHFResponseData* uhf_response_data = uhf_worker->data;
+    furi_hal_uart_set_br(FuriHalUartIdUSART1, DEFAULT_BAUD_RATE);
+    furi_hal_uart_set_irq_cb(FuriHalUartIdUSART1, single_poll_rx_callback, uhf_response_data);
+    UHFData* uhf_data = uhf_response_data->data;
+    uhf_data_reset(uhf_data);
+    while(!uhf_data->end) {
+        furi_hal_uart_tx(FuriHalUartIdUSART1, CMD_SINGLE_POLLING.cmd, CMD_SINGLE_POLLING.length);
+        furi_delay_ms(100);
+        if(uhf_worker->state == UHFWorkerStateStop) {
+            return UHFWorkerEventAborted;
+        }
+    }
     return UHFWorkerEventSuccess;
 }
 
 int32_t uhf_worker_task(void* ctx) {
     UHFWorker* uhf_worker = ctx;
-    // // FURI_LOG_E("uhf_worker", "worker callback has been called");
     if(uhf_worker->state == UHFWorkerStateDetect) {
         UHFWorkerEvent event = read_single_card(uhf_worker);
         uhf_worker->callback(event, uhf_worker->ctx);