Skip to content
This repository has been archived by the owner on Jul 28, 2024. It is now read-only.

Commit

Permalink
update apps
Browse files Browse the repository at this point in the history
  • Loading branch information
xMasterX committed Jul 13, 2023
1 parent 7ad5259 commit d67a689
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 31 deletions.
2 changes: 1 addition & 1 deletion helpers/mag_helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ void tx_deinit_rfid() {
void tx_init_rf(int hz) {
// presets and frequency will need some experimenting
furi_hal_subghz_reset();
furi_hal_subghz_load_preset(FuriHalSubGhzPresetOok650Async);
// furi_hal_subghz_load_preset(FuriHalSubGhzPresetOok650Async);
// furi_hal_subghz_load_preset(FuriHalSubGhzPresetGFSK9_99KbAsync);
// furi_hal_subghz_load_preset(FuriHalSubGhzPresetMSK99_97KbAsync);
// furi_hal_subghz_load_preset(FuriHalSubGhzPreset2FSKDev238Async);
Expand Down
67 changes: 37 additions & 30 deletions scenes/mag_scene_read.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#define TAG "MagSceneRead"

void uart_callback(UartIrqEvent event, uint8_t data, void *context) {
void uart_callback(UartIrqEvent event, uint8_t data, void* context) {
Mag* mag = context;
if(event == UartIrqEventRXNE) {
furi_stream_buffer_send(mag->uart_rx_stream, &data, 1, 0);
Expand All @@ -20,43 +20,45 @@ static int32_t uart_worker(void* context) {
mag->uart_rx_stream = furi_stream_buffer_alloc(UART_RX_BUF_SIZE, 1);
mag->uart_text_box_store_strlen = 0;

while (1) {
uint32_t events = furi_thread_flags_wait(WORKER_ALL_RX_EVENTS, FuriFlagWaitAny, FuriWaitForever);
while(1) {
uint32_t events =
furi_thread_flags_wait(WORKER_ALL_RX_EVENTS, FuriFlagWaitAny, FuriWaitForever);
// furi_check((events & FuriFlagError) == 0);

if(events & WorkerEvtStop) break;
if(events & WorkerEvtRxDone) {
FURI_LOG_D(TAG, "WorkerEvtRxDone");
// notification_message(mag->notifications, &sequence_success);
size_t len = furi_stream_buffer_receive(mag->uart_rx_stream, mag->uart_rx_buf, UART_RX_BUF_SIZE, 200);
size_t len = furi_stream_buffer_receive(
mag->uart_rx_stream, mag->uart_rx_buf, UART_RX_BUF_SIZE, 200);
FURI_LOG_D(TAG, "UART RX len: %d", len);
if (len > 0) {

if(len > 0) {
// If text box store gets too big, then truncate it
mag->uart_text_box_store_strlen += len;

if(mag->uart_text_box_store_strlen >= UART_TERMINAL_TEXT_BOX_STORE_SIZE - 1) {
furi_string_right(mag->uart_text_box_store, mag->uart_text_box_store_strlen / 2);
mag->uart_text_box_store_strlen = furi_string_size(mag->uart_text_box_store) + len;
furi_string_right(
mag->uart_text_box_store, mag->uart_text_box_store_strlen / 2);
mag->uart_text_box_store_strlen =
furi_string_size(mag->uart_text_box_store) + len;
}

// Add '\0' to the end of the string, and then add the new data
mag->uart_rx_buf[len] = '\0';
furi_string_cat_printf(mag->uart_text_box_store, "%s", mag->uart_rx_buf);

FURI_LOG_D(TAG, "UART RX buf: %*.s", len, mag->uart_rx_buf);
FURI_LOG_D(TAG, "UART RX store: %s", furi_string_get_cstr(mag->uart_text_box_store));

FURI_LOG_D(
TAG, "UART RX store: %s", furi_string_get_cstr(mag->uart_text_box_store));
}

FURI_LOG_D(TAG, "UARTEventRxData");

view_dispatcher_send_custom_event(
mag->view_dispatcher, UARTEventRxData);


view_dispatcher_send_custom_event(mag->view_dispatcher, UARTEventRxData);
}
}

furi_stream_buffer_free(mag->uart_rx_stream);

return 0;
Expand All @@ -72,7 +74,8 @@ void update_widgets(Mag* mag) {
widget_add_icon_element(mag->widget, 81, -1, &I_mag_file_10px);

// Text box
widget_add_text_scroll_element(mag->widget, 0, 10, 128, 40, furi_string_get_cstr(mag->uart_text_box_store));
widget_add_text_scroll_element(
mag->widget, 0, 10, 128, 40, furi_string_get_cstr(mag->uart_text_box_store));

// Buttons
widget_add_button_element(mag->widget, GuiButtonTypeLeft, "Clear", mag_widget_callback, mag);
Expand All @@ -84,12 +87,11 @@ void mag_scene_read_on_enter(void* context) {
FuriString* message = furi_string_alloc();
furi_string_printf(message, "Please swipe a card!\n");
mag->uart_text_box_store = message;
furi_string_free(message);

view_dispatcher_switch_to_view(mag->view_dispatcher, MagViewWidget);

update_widgets(mag);



// Initialize UART
// furi_hal_console_disable();
furi_hal_uart_deinit(FuriHalUartIdUSART1);
Expand All @@ -109,7 +111,7 @@ void mag_scene_read_on_enter(void* context) {

bool mag_scene_read_on_event(void* context, SceneManagerEvent event) {
Mag* mag = context;

bool consumed = false;

if(event.type == SceneManagerEventTypeCustom) {
Expand All @@ -132,11 +134,16 @@ bool mag_scene_read_on_event(void* context, SceneManagerEvent event) {
furi_string_reset(mag->uart_text_box_store);
if(res) {
notification_message(mag->notifications, &sequence_success);

furi_string_printf(mag->uart_text_box_store, "Track 1: %.*s\nTrack 2: %.*s\nTrack 3: %.*s",
mag_dev->dev_data.track[0].len, furi_string_get_cstr(mag_dev->dev_data.track[0].str),
mag_dev->dev_data.track[1].len, furi_string_get_cstr(mag_dev->dev_data.track[1].str),
mag_dev->dev_data.track[2].len, furi_string_get_cstr(mag_dev->dev_data.track[2].str));

furi_string_printf(
mag->uart_text_box_store,
"Track 1: %.*s\nTrack 2: %.*s\nTrack 3: %.*s",
mag_dev->dev_data.track[0].len,
furi_string_get_cstr(mag_dev->dev_data.track[0].str),
mag_dev->dev_data.track[1].len,
furi_string_get_cstr(mag_dev->dev_data.track[1].str),
mag_dev->dev_data.track[2].len,
furi_string_get_cstr(mag_dev->dev_data.track[2].str));

// Switch to saved menu scene
scene_manager_next_scene(mag->scene_manager, MagSceneSavedMenu);
Expand All @@ -160,7 +167,7 @@ void mag_scene_read_on_exit(void* context) {
// notification_message(mag->notifications, &sequence_blink_stop);
widget_reset(mag->widget);
// view_dispatcher_remove_view(mag->view_dispatcher, MagViewWidget);

// Stop UART worker
FURI_LOG_D(TAG, "Stopping UART worker");
furi_thread_flags_set(furi_thread_get_id(mag->uart_rx_thread), WorkerEvtStop);
Expand All @@ -173,6 +180,6 @@ void mag_scene_read_on_exit(void* context) {
furi_hal_uart_set_irq_cb(FuriHalUartIdUSART1, NULL, NULL);
furi_hal_uart_deinit(FuriHalUartIdUSART1);
// furi_hal_console_enable();

notification_message(mag->notifications, &sequence_blink_stop);
}
}

0 comments on commit d67a689

Please sign in to comment.