perf(bot): lower body once and strstr instead of O(n*m) per-offset tolower

For a 140-byte channel msg with a 64-byte trigger, the old loop did
~8960 tolower() calls per inbound message; now it's 140 tolower calls
plus one strstr.

perf(buzzer): skip nRF52 STOPPED wait when PWM was not running

TASKS_STOP on a disabled PWM never fires EVENTS_STOPPED, so the wait
always timed out at 2 ms. Gating on _pwm_on removes the wait on the
first note of a melody and after pauses, where there's nothing to wait
for.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Jakub
2026-05-24 19:59:21 +02:00
parent e2d59b9a3d
commit bf724ce692
2 changed files with 21 additions and 23 deletions

View File

@@ -104,11 +104,14 @@ void genericBuzzer::_nrfStartPwm(uint16_t freq) {
_duty_buf = 0x8000U | cmp;
__DMB();
NRF_PWM2->TASKS_STOP = 1;
// Wait for STOPPED (short busy-wait, typically < 1 PWM period)
uint32_t t = millis();
while (!(NRF_PWM2->EVENTS_STOPPED) && (millis() - t) < 2) {}
NRF_PWM2->EVENTS_STOPPED = 0;
// Only wait for STOPPED if PWM was actually running — TASKS_STOP on a disabled
// PWM never fires EVENTS_STOPPED, so the wait would always time out at 2 ms.
if (_pwm_on) {
NRF_PWM2->TASKS_STOP = 1;
uint32_t t = millis();
while (!(NRF_PWM2->EVENTS_STOPPED) && (millis() - t) < 2) {}
NRF_PWM2->EVENTS_STOPPED = 0;
}
NRF_PWM2->PSEL.OUT[0] = nrf_pin;
NRF_PWM2->PSEL.OUT[1] = 0xFFFFFFFFUL;