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 "esp_log.h"
#include "esp_timer.h"
#include "esp_sleep.h"
#include "driver/gpio.h"
#include "driver/rtc_io.h"
#define TAG "main"
#define TRIGGER_PIN GPIO_NUM_12
@ -82,6 +84,9 @@ void handleTrigger(void *)
void app_main()
{
rtc_gpio_pullup_en(TRIGGER_PIN);
esp_sleep_enable_ext0_wakeup(TRIGGER_PIN, 0);
ESP_LOGI("main", "Starting BLE work!");
NimBLEDevice::init("Speed buzzer");
@ -124,11 +129,14 @@ void app_main()
for (;;)
{
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->notify();
// ESP_LOGI(TAG, "Characteristic written!");
}
else if (bleServer->getConnectedCount() == 0)
{
esp_deep_sleep_start();
}
}
}

View file

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

View file

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