From db1bae15b65cf88030240b4a29ec8d9d594583ea Mon Sep 17 00:00:00 2001 From: Ashley Huxley Date: Tue, 9 Jul 2024 17:37:35 +0100 Subject: [PATCH] refactor: subghz post rx now happens on the queue --- bomber_loop.c | 4 ++++ subghz.c | 11 +++++++---- subghz.h | 1 + types.h | 3 ++- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/bomber_loop.c b/bomber_loop.c index f30a3120dfa..4279a451e20 100644 --- a/bomber_loop.c +++ b/bomber_loop.c @@ -207,6 +207,10 @@ void bomber_main_loop(BomberAppState* state) { case BomberEventType_Tick: updated = bomber_game_tick(state); break; + case BomberEventType_SubGhz: + bomber_game_post_rx(state, event.subGhzIncomingSize); + updated = true; + break; default: FURI_LOG_E(TAG, "Unknown event received from queue."); break; diff --git a/subghz.c b/subghz.c index fbef123bd55..1a3799aa0aa 100644 --- a/subghz.c +++ b/subghz.c @@ -63,7 +63,7 @@ void tx_death(BomberAppState* state) { // Handle the buffer once data receive has completed // state: Pointer to the application state // rx_size: Number of bytes of data received -static void post_rx(BomberAppState* state, size_t rx_size) { +void bomber_game_post_rx(BomberAppState* state, size_t rx_size) { furi_assert(state); furi_assert(rx_size); @@ -112,8 +112,6 @@ static void post_rx(BomberAppState* state, size_t rx_size) { } break; } - - view_port_update(state->view_port); } // Handle incoming subghz data @@ -132,7 +130,12 @@ void subghz_check_incoming(BomberAppState* state) { size_t rx_size = subghz_tx_rx_worker_read(state->subghz_worker, state->rx_buffer, RX_TX_BUFFER_SIZE); - post_rx(state, rx_size); + + BomberEvent event = {.type = BomberEventType_SubGhz, .subGhzIncomingSize = rx_size }; + + if(furi_message_queue_put(state->queue, &event, FuriWaitForever) != FuriStatusOk) { + FURI_LOG_W(TAG, "Failed to put timer event in message queue"); + } } } diff --git a/subghz.h b/subghz.h index 5b3f1dbe49b..2e7f2bdaa3d 100644 --- a/subghz.h +++ b/subghz.h @@ -10,5 +10,6 @@ void tx_bomb_placement(BomberAppState* state, uint8_t x, uint8_t y); void tx_death(BomberAppState* state); void subghz_check_incoming(BomberAppState* state); void have_read_cb(void* context); +void bomber_game_post_rx(BomberAppState* state, size_t rx_size); #endif \ No newline at end of file diff --git a/types.h b/types.h index df358431916..425224680ba 100644 --- a/types.h +++ b/types.h @@ -97,12 +97,13 @@ typedef enum { typedef enum { BomberEventType_Input, BomberEventType_Tick, + BomberEventType_SubGhz } BomberEventType; typedef struct { BomberEventType type; - //InfraredMessage* ir_message; InputEvent input; + size_t subGhzIncomingSize; } BomberEvent; typedef enum { WhoDied_None, WhoDied_Fox, WhoDied_Wolf } WhoDied;