typescript: add exstats

pull/3565/head
Rob Pilling 2024-09-21 12:51:49 +01:00
parent d447b5c2e6
commit 4b08b4b24c
2 changed files with 76 additions and 0 deletions

75
typescript/types/exstats.d.ts vendored Normal file
View File

@ -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 extends StatsId>(
ids: Ids[],
options?: Options<Ids>
): StatsInst<Ids>;
type Options<Ids> = {
paceLength?: number,
notify?: Notify<Ids>,
};
type Notify<Ids> = {
[key in Ids & ("dist" | "step" | "time")]?: {
// optional when passed in ^
increment?: number,
next?: number,
}
};
type StatsInst<Ids extends StatsId> = {
stats: Stats<Ids>,
state: State<Ids>,
start(): void,
stop(): void,
resume(): void,
};
type State<Ids> = {
notify: Notify<Ids>,
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<Ids extends StatsId> = {
[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;
};
}

View File

@ -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;