From 4b08b4b24cc49978162b7fbca5d1e95dc518fa87 Mon Sep 17 00:00:00 2001 From: Rob Pilling Date: Sat, 21 Sep 2024 12:51:49 +0100 Subject: [PATCH] typescript: add exstats --- typescript/types/exstats.d.ts | 75 +++++++++++++++++++++++++++++++++++ typescript/types/modules.d.ts | 1 + 2 files changed, 76 insertions(+) create mode 100644 typescript/types/exstats.d.ts diff --git a/typescript/types/exstats.d.ts b/typescript/types/exstats.d.ts new file mode 100644 index 000000000..7c68b6d59 --- /dev/null +++ b/typescript/types/exstats.d.ts @@ -0,0 +1,75 @@ +declare module ExStats { + type StatsId = "time" | "dist" | "step" | "bpm" | "maxbpm" | "pacea" | "pacec" | "speed" | "caden" | "altg" | "altb"; + + function getList(): { name: string, id: StatsId }[]; + + function getStats( + ids: Ids[], + options?: Options + ): StatsInst; + + type Options = { + paceLength?: number, + notify?: Notify, + }; + + type Notify = { + [key in Ids & ("dist" | "step" | "time")]?: { + // optional when passed in ^ + increment?: number, + next?: number, + } + }; + + type StatsInst = { + stats: Stats, + state: State, + start(): void, + stop(): void, + resume(): void, + }; + + type State = { + notify: Notify, + + active: boolean, + duration: number, + startTime: number, + lastTime: number, + + BPM: number, + BPMage: number, + maxBPM: number, + + alt: number | undefined, + alti: number, + + avrSpeed: number, + curSpeed: number, + distance: number, + + startSteps: number, + lastSteps: number, + stepHistory: Uint8Array, + stepsPerMin: number, + + thisGPS: GPSFix | {}, + lastGPS: GPSFix | {}, + }; + + type Stats = { + [key in Ids]: Stat + }; + + type Stat = { + title: string, + getValue(): number, + getString(): string, + id: StatsId, + + on(what: "changed", cb: (stat: Stat) => void): void; + + // emitted by dist|step|time + on(what: "notify", cb: (stat: Stat) => void): void; + }; +} diff --git a/typescript/types/modules.d.ts b/typescript/types/modules.d.ts index e8aa15ac1..1227250c3 100644 --- a/typescript/types/modules.d.ts +++ b/typescript/types/modules.d.ts @@ -6,3 +6,4 @@ declare function require(moduleName: "ClockFace"): typeof ClockFace_.ClockFace; declare function require(moduleName: "clock_info"): typeof ClockInfo; declare function require(moduleName: "Layout"): typeof Layout.Layout; declare function require(moduleName: "power_usage"): PowerUsageModule; +declare function require(moduleName: "exstats"): typeof ExStats;