Skip to content

Commit

Permalink
Merge pull request #5 from jamisonderek/jamisonderek/always-rx
Browse files Browse the repository at this point in the history
Always RX except when shooting
  • Loading branch information
RocketGod-git authored Aug 25, 2024
2 parents 026c92b + 5fbc4f4 commit 59b65a9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
27 changes: 22 additions & 5 deletions infrared_controller.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const NotificationSequence sequence_hit = {
struct InfraredController {
LaserTagTeam team;
InfraredWorker* worker;
bool worker_rx_active;
InfraredSignal* signal;
NotificationApp* notification;
bool hit_received;
Expand Down Expand Up @@ -104,6 +105,11 @@ void infrared_controller_free(InfraredController* controller) {
FURI_LOG_I(TAG, "Freeing InfraredController");

if(controller) {
if(controller->worker_rx_active) {
FURI_LOG_I(TAG, "Stopping RX worker");
infrared_worker_rx_stop(controller->worker);
}

FURI_LOG_I(TAG, "Freeing InfraredWorker and InfraredSignal");
infrared_worker_free(controller->worker);
infrared_signal_free(controller->signal);
Expand Down Expand Up @@ -139,12 +145,23 @@ void infrared_controller_send(InfraredController* controller) {
(unsigned long)message.address,
(unsigned long)message.command);

if(controller->worker_rx_active) {
FURI_LOG_I(TAG, "Stopping RX worker");
infrared_worker_rx_stop(controller->worker);
controller->worker_rx_active = false;
}

FURI_LOG_I(TAG, "Setting message for infrared signal");
infrared_signal_set_message(controller->signal, &message);

FURI_LOG_I(TAG, "Starting infrared signal transmission");
infrared_signal_transmit(controller->signal);

if(!controller->worker_rx_active) {
infrared_worker_rx_start(controller->worker);
controller->worker_rx_active = true;
}

FURI_LOG_I(TAG, "Infrared signal transmission completed");
}

Expand All @@ -156,11 +173,11 @@ bool infrared_controller_receive(InfraredController* controller) {
return false;
}

infrared_worker_rx_start(controller->worker);

furi_delay_ms(250);

infrared_worker_rx_stop(controller->worker);
if(!controller->worker_rx_active) {
infrared_worker_rx_start(controller->worker);
controller->worker_rx_active = true;
furi_delay_ms(250);
}

bool hit = controller->hit_received;

Expand Down
4 changes: 4 additions & 0 deletions laser_tag_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,10 @@ static bool laser_tag_app_enter_game_state(LaserTagApp* app) {
laser_tag_view_update(app->view, app->game_state);
FURI_LOG_D(TAG, "View updated with new game state");

if(app->ir_controller) {
infrared_controller_free(app->ir_controller);
app->ir_controller = NULL;
}
app->ir_controller = infrared_controller_alloc();
if(!app->ir_controller) {
FURI_LOG_E(TAG, "Failed to allocate IR controller");
Expand Down

0 comments on commit 59b65a9

Please sign in to comment.