Fix: properly wait for audio
All checks were successful
/ build (push) Successful in 3m40s

This commit is contained in:
Dorian Zedler 2024-01-20 11:16:01 +01:00
parent bc4a087614
commit 48fe73611d
Signed by: dorian
GPG key ID: 989DE36109AFA354
3 changed files with 22 additions and 7 deletions

View file

@ -10,7 +10,9 @@
#include "freertos/queue.h" #include "freertos/queue.h"
#include "esp_log.h" #include "esp_log.h"
#include "esp_timer.h" #include "esp_timer.h"
#include "esp_sleep.h"
#include "driver/gpio.h" #include "driver/gpio.h"
#include "driver/rtc_io.h"
#define TAG "main" #define TAG "main"
#define TRIGGER_PIN GPIO_NUM_12 #define TRIGGER_PIN GPIO_NUM_12
@ -82,6 +84,9 @@ void handleTrigger(void *)
void app_main() void app_main()
{ {
rtc_gpio_pullup_en(TRIGGER_PIN);
esp_sleep_enable_ext0_wakeup(TRIGGER_PIN, 0);
ESP_LOGI("main", "Starting BLE work!"); ESP_LOGI("main", "Starting BLE work!");
NimBLEDevice::init("Speed buzzer"); NimBLEDevice::init("Speed buzzer");
@ -124,11 +129,14 @@ void app_main()
for (;;) for (;;)
{ {
uint64_t currentTime; uint64_t currentTime;
if (xQueueReceive(triggerQueue, &currentTime, portMAX_DELAY) == pdTRUE) if (xQueueReceive(triggerQueue, &currentTime, 5 * 60 * 1000 / portTICK_PERIOD_MS) == pdTRUE)
{ {
bleLastTriggerTimeCharacteristic->setValue(currentTime); bleLastTriggerTimeCharacteristic->setValue(currentTime);
bleLastTriggerTimeCharacteristic->notify(); bleLastTriggerTimeCharacteristic->notify();
// ESP_LOGI(TAG, "Characteristic written!"); }
else if (bleServer->getConnectedCount() == 0)
{
esp_deep_sleep_start();
} }
} }
} }

View file

@ -18,9 +18,16 @@
state = 'wait'; state = 'wait';
await delay(3000); await delay(3000);
state = 'ready'; state = 'ready';
await new Audio('/sound/ok-ready-go.mp3').play(); const audio = new Audio('/sound/ok-ready-go.mp3');
await delay(2600); const audioDone = new Promise<void>((resolve) => {
timer.start(); audio.onended = () => {
resolve();
};
});
await audio.play();
await audioDone;
timer.start(200n);
state = 'running'; state = 'running';
}; };

View file

@ -3,8 +3,8 @@
import { buzzerState } from '../stores'; import { buzzerState } from '../stores';
import { Button } from 'flowbite-svelte'; import { Button } from 'flowbite-svelte';
export const start = () => { export const start = (offset: bigint = 0n) => {
timerStartedAt = BigInt(Math.floor(performance.now())); timerStartedAt = BigInt(Math.floor(performance.now())) - offset;
timerStoppedAt = undefined; timerStoppedAt = undefined;
}; };