This commit is contained in:
parent
bc4a087614
commit
48fe73611d
3 changed files with 22 additions and 7 deletions
|
@ -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, ¤tTime, portMAX_DELAY) == pdTRUE)
|
if (xQueueReceive(triggerQueue, ¤tTime, 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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -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;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue