Skip to content

Commit 7f727b9

Browse files
committed
simplify tx error checks
1 parent e4cc175 commit 7f727b9

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/connection/esb.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ void esb_set_pair(uint64_t addr)
351351

352352
void esb_pair(void)
353353
{
354-
if (tx_errors >= 100)
354+
if (get_status(SYS_STATUS_CONNECTION_ERROR))
355355
set_status(SYS_STATUS_CONNECTION_ERROR, false);
356356
tx_errors = 0;
357357
if (!paired_addr[0]) // zero, no receiver paired
@@ -490,22 +490,22 @@ static void esb_thread(void)
490490

491491
while (1)
492492
{
493-
if (!esb_paired && (!use_hid || (get_status(SYS_STATUS_USB_CONNECTED) == false && k_uptime_get() - 750 > start_time))) // only automatically enter pairing while not potentially communicating by usb
493+
if (!esb_paired && (!use_hid || (!get_status(SYS_STATUS_USB_CONNECTED) && k_uptime_get() - 750 > start_time))) // only automatically enter pairing while not potentially communicating by usb
494494
{
495495
esb_pair();
496496
esb_initialize(true);
497497
}
498498
if (tx_errors >= TX_ERROR_THRESHOLD)
499499
{
500-
if (get_status(SYS_STATUS_CONNECTION_ERROR) == false && (!use_hid || get_status(SYS_STATUS_USB_CONNECTED) == false)) // only raise error while not potentially communicating by usb
500+
if (!get_status(SYS_STATUS_CONNECTION_ERROR) && (!use_hid || !get_status(SYS_STATUS_USB_CONNECTED))) // only raise error while not potentially communicating by usb
501501
set_status(SYS_STATUS_CONNECTION_ERROR, true);
502502
if (use_shutdown && k_uptime_get() - last_tx_success > CONFIG_3_SETTINGS_READ(CONFIG_3_CONNECTION_TIMEOUT_DELAY)) // shutdown if receiver is not detected // TODO: is shutdown necessary if usb is connected at the time?
503503
{
504504
LOG_WRN("No response from receiver in %dm", CONFIG_3_SETTINGS_READ(CONFIG_3_CONNECTION_TIMEOUT_DELAY) / 60000);
505505
sys_request_system_off(false);
506506
}
507507
}
508-
else if (tx_errors == 0 && get_status(SYS_STATUS_CONNECTION_ERROR) == true)
508+
else if (tx_errors == 0 && get_status(SYS_STATUS_CONNECTION_ERROR))
509509
{
510510
set_status(SYS_STATUS_CONNECTION_ERROR, false);
511511
}

0 commit comments

Comments
 (0)