Skip to content

Commit

Permalink
Always RX except when shooting
Browse files Browse the repository at this point in the history
  • Loading branch information
jamisonderek committed Aug 25, 2024
1 parent fb3160c commit 6a56928
Showing 1 changed file with 22 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

0 comments on commit 6a56928

Please sign in to comment.