Skip to content

Commit

Permalink
refactor: subghz post rx now happens on the queue
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashley Huxley committed Jul 9, 2024
1 parent 453e019 commit db1bae1
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
4 changes: 4 additions & 0 deletions bomber_loop.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 7 additions & 4 deletions subghz.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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
Expand All @@ -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");
}
}
}

Expand Down
1 change: 1 addition & 0 deletions subghz.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion types.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit db1bae1

Please sign in to comment.