Skip to content

Commit

Permalink
Direct file load testing, minor UART refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
zacharyweiss committed Apr 26, 2024
1 parent facc698 commit 011a9b9
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 13 deletions.
2 changes: 1 addition & 1 deletion helpers/mag_helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ void play_halfbit(bool value, MagSetting* setting) {

if(last_value == 2 || value != (bool)last_value) {
//furi_hal_nfc_ll_txrx_on();
//furi_delay_us(64);
furi_delay_us(64);
//furi_hal_nfc_ll_txrx_off();
}
break;
Expand Down
33 changes: 22 additions & 11 deletions mag.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "mag_i.h"
#include <expansion/expansion.h>

#define TAG "Mag"

Expand Down Expand Up @@ -42,6 +41,7 @@ static Mag* mag_alloc() {

mag->file_name = furi_string_alloc();
mag->file_path = furi_string_alloc_set(MAG_APP_FOLDER);
mag->args = furi_string_alloc();

mag->view_dispatcher = view_dispatcher_alloc();
mag->scene_manager = scene_manager_alloc(&mag_scene_handlers, mag);
Expand Down Expand Up @@ -94,6 +94,10 @@ static Mag* mag_alloc() {
view_dispatcher_add_view(
mag->view_dispatcher, MagViewTextInput, text_input_get_view(mag->text_input));

// Disable expansion protocol to avoid interference with UART Handle
mag->expansion = furi_record_open(RECORD_EXPANSION);
expansion_disable(mag->expansion);

return mag;
}

Expand All @@ -108,6 +112,7 @@ static void mag_free(Mag* mag) {

furi_string_free(mag->file_name);
furi_string_free(mag->file_path);
furi_string_free(mag->args);

// Mag device
mag_device_free(mag->mag_dev);
Expand Down Expand Up @@ -159,6 +164,10 @@ static void mag_free(Mag* mag) {
furi_record_close(RECORD_NOTIFICATION);
mag->notifications = NULL;

// Return previous state of expansion
expansion_enable(mag->expansion);
furi_record_close(RECORD_EXPANSION);

furi_record_close(RECORD_STORAGE);
furi_record_close(RECORD_DIALOGS);

Expand All @@ -167,14 +176,14 @@ static void mag_free(Mag* mag) {

// entry point for app
int32_t mag_app(void* p) {
UNUSED(p);

// Disable expansion protocol to avoid interference with UART Handle
Expansion* expansion = furi_record_open(RECORD_EXPANSION);
expansion_disable(expansion);
const char* args = p;

Mag* mag = mag_alloc();

if(args && strlen(args)) {
furi_string_set(mag->args, args);
}

mag_make_app_folder(mag);

// Enable 5v power, multiple attempts to avoid issues with power chip protection false triggering
Expand All @@ -186,7 +195,13 @@ int32_t mag_app(void* p) {
}

view_dispatcher_attach_to_gui(mag->view_dispatcher, mag->gui, ViewDispatcherTypeFullscreen);
scene_manager_next_scene(mag->scene_manager, MagSceneStart);

if(furi_string_empty(mag->args)) {
scene_manager_next_scene(mag->scene_manager, MagSceneStart);
} else {
mag_device_load_data(mag->mag_dev, mag->args, true);
scene_manager_next_scene(mag->scene_manager, MagSceneEmulate);
}

view_dispatcher_run(mag->view_dispatcher);

Expand All @@ -197,10 +212,6 @@ int32_t mag_app(void* p) {

mag_free(mag);

// Return previous state of expansion
expansion_enable(expansion);
furi_record_close(RECORD_EXPANSION);

return 0;
}

Expand Down
3 changes: 3 additions & 0 deletions mag_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <furi/core/log.h>
#include <furi_hal_gpio.h>
#include <furi_hal_resources.h>
#include <expansion/expansion.h>

#include <gui/gui.h>
#include <gui/view.h>
Expand Down Expand Up @@ -73,6 +74,7 @@ typedef struct {
char text_store[MAG_TEXT_STORE_SIZE + 1];
FuriString* file_path;
FuriString* file_name;
FuriString* args;

MagSetting* setting;

Expand All @@ -86,6 +88,7 @@ typedef struct {
VariableItemList* variable_item_list;

// UART
Expansion* expansion;
FuriThread* uart_rx_thread;
FuriStreamBuffer* uart_rx_stream;
uint8_t uart_rx_buf[UART_RX_BUF_SIZE + 1];
Expand Down
1 change: 0 additions & 1 deletion scenes/mag_scene_file_select.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

void mag_scene_file_select_on_enter(void* context) {
Mag* mag = context;
//UNUSED(mag);
mag_device_set_loading_callback(mag->mag_dev, mag_show_loading_popup, mag);
if(mag_file_select(mag->mag_dev)) {
scene_manager_next_scene(mag->scene_manager, MagSceneSavedMenu);
Expand Down

0 comments on commit 011a9b9

Please sign in to comment.