Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "speedometer",
"version": "0.0.82",
"version": "0.0.83",
"description": "Minimal PWA speedometer that displays GPS speed. Includes TypeScript script to render PNG icons from SVG using sharp.",
"license": "MIT",
"private": true,
Expand Down
11 changes: 10 additions & 1 deletion src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ let lastSpeedMs: number | null = null; // last known native speed (m/s), if any
let lastUpdateTimestamp = 0;
let wakeLock: WakeLockSentinel | null = null;
let firstSpeedTimestamp: number | null = null;
let speedSampleCount = 0;

const GPS_WARMUP_MS = 1000;
const MIN_SAMPLES_TO_SKIP_WARMUP = 5;

export const PLACEHOLDER = "———";

Expand Down Expand Up @@ -261,9 +263,15 @@ function handlePosition(pos: GeolocationPosition): void {
if (typeof speed === "number" && Number.isFinite(speed) && speed >= 0) {
if (firstSpeedTimestamp === null) {
firstSpeedTimestamp = pos.timestamp;
speedSampleCount = 0;
}

if (pos.timestamp - firstSpeedTimestamp >= GPS_WARMUP_MS) {
speedSampleCount++;

if (
pos.timestamp - firstSpeedTimestamp >= GPS_WARMUP_MS ||
speedSampleCount >= MIN_SAMPLES_TO_SKIP_WARMUP
) {
lastSpeedMs = speed;
renderSpeed(speed);
lastUpdateTimestamp = pos.timestamp;
Expand Down Expand Up @@ -363,6 +371,7 @@ export function resetState(): void {
lastUpdateTimestamp = 0;
wakeLock = null;
firstSpeedTimestamp = null;
speedSampleCount = 0;
}

export function init(): void {
Expand Down