Compare commits
4 commits
Author | SHA1 | Date | |
---|---|---|---|
82518c0b6b | |||
7230eaca2b | |||
48fe73611d | |||
bc4a087614 |
8 changed files with 50 additions and 9 deletions
|
@ -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, ¤tTime, portMAX_DELAY) == pdTRUE)
|
||||
if (xQueueReceive(triggerQueue, ¤tTime, 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
17
package-lock.json
generated
17
package-lock.json
generated
|
@ -8,12 +8,14 @@
|
|||
"name": "bluetooth-buzzer",
|
||||
"version": "0.0.1",
|
||||
"dependencies": {
|
||||
"nosleep.js": "^0.12.0",
|
||||
"ua-parser-js": "^1.0.37"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@sveltejs/adapter-auto": "^2.0.0",
|
||||
"@sveltejs/adapter-static": "^2.0.3",
|
||||
"@sveltejs/kit": "^1.27.4",
|
||||
"@types/nosleep.js": "^0.10.0",
|
||||
"@types/ua-parser-js": "^0.7.39",
|
||||
"@types/web-bluetooth": "^0.0.20",
|
||||
"@typescript-eslint/eslint-plugin": "^6.0.0",
|
||||
|
@ -766,6 +768,16 @@
|
|||
"integrity": "sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/@types/nosleep.js": {
|
||||
"version": "0.10.0",
|
||||
"resolved": "https://registry.npmjs.org/@types/nosleep.js/-/nosleep.js-0.10.0.tgz",
|
||||
"integrity": "sha512-eFRD95pEYIPo7YZnRbasEJAwSzBOxkT9++vZ7ykoDDuxvBauSuEGKZsijLm2BzohGt5wIj8gSiI+9vwjKfmNgA==",
|
||||
"deprecated": "This is a stub types definition. nosleep.js provides its own type definitions, so you do not need this installed.",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"nosleep.js": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/pug": {
|
||||
"version": "2.0.10",
|
||||
"resolved": "https://registry.npmjs.org/@types/pug/-/pug-2.0.10.tgz",
|
||||
|
@ -2592,6 +2604,11 @@
|
|||
"node": ">=0.10.0"
|
||||
}
|
||||
},
|
||||
"node_modules/nosleep.js": {
|
||||
"version": "0.12.0",
|
||||
"resolved": "https://registry.npmjs.org/nosleep.js/-/nosleep.js-0.12.0.tgz",
|
||||
"integrity": "sha512-9d1HbpKLh3sdWlhXMhU6MMH+wQzKkrgfRkYV0EBdvt99YJfj0ilCJrWRDYG2130Tm4GXbEoTCx5b34JSaP+HhA=="
|
||||
},
|
||||
"node_modules/object-assign": {
|
||||
"version": "4.1.1",
|
||||
"resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz",
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
"@sveltejs/adapter-auto": "^2.0.0",
|
||||
"@sveltejs/adapter-static": "^2.0.3",
|
||||
"@sveltejs/kit": "^1.27.4",
|
||||
"@types/nosleep.js": "^0.10.0",
|
||||
"@types/ua-parser-js": "^0.7.39",
|
||||
"@types/web-bluetooth": "^0.0.20",
|
||||
"@typescript-eslint/eslint-plugin": "^6.0.0",
|
||||
|
@ -38,6 +39,7 @@
|
|||
},
|
||||
"type": "module",
|
||||
"dependencies": {
|
||||
"nosleep.js": "^0.12.0",
|
||||
"ua-parser-js": "^1.0.37"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<!doctype html>
|
||||
<html lang="en">
|
||||
<html lang="en" class="dark">
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
|
|
|
@ -4,8 +4,10 @@
|
|||
import { bluetoothState } from '../stores';
|
||||
import { UAParser } from 'ua-parser-js';
|
||||
import Timer from './Timer.svelte';
|
||||
import NoSleep from 'nosleep.js';
|
||||
|
||||
const uap = new UAParser();
|
||||
const noSleep = new NoSleep();
|
||||
let timer: Timer;
|
||||
|
||||
let state: 'idle' | 'wait' | 'ready' | 'running' = 'idle';
|
||||
|
@ -15,12 +17,23 @@
|
|||
};
|
||||
|
||||
const start = async () => {
|
||||
if (!noSleep.isEnabled) {
|
||||
noSleep.enable();
|
||||
}
|
||||
|
||||
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';
|
||||
};
|
||||
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
||||
|
|
1
static/.domains
Normal file
1
static/.domains
Normal file
|
@ -0,0 +1 @@
|
|||
bluetooth-buzzer.dorian.im
|
|
@ -59,7 +59,7 @@ const config = {
|
|||
],
|
||||
|
||||
plugins: [require('flowbite/plugin')],
|
||||
darkMode: 'media'
|
||||
darkMode: 'class'
|
||||
};
|
||||
|
||||
module.exports = config;
|
Loading…
Reference in a new issue