@gamepadly/sdk 0.2.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (134) hide show
  1. package/README.md +163 -8
  2. package/dist/audio/index.d.ts +10 -0
  3. package/dist/audio/index.d.ts.map +1 -0
  4. package/dist/audio/index.js +15 -0
  5. package/dist/audio/index.js.map +7 -0
  6. package/dist/audio/routing.d.ts +40 -0
  7. package/dist/audio/routing.d.ts.map +1 -0
  8. package/dist/audio/routing.js +26 -0
  9. package/dist/audio/routing.js.map +7 -0
  10. package/dist/audio/sampleBank.d.ts +29 -0
  11. package/dist/audio/sampleBank.d.ts.map +1 -0
  12. package/dist/audio/sampleBank.js +354 -0
  13. package/dist/audio/sampleBank.js.map +7 -0
  14. package/dist/bridge/index.js +5 -93
  15. package/dist/bridge/index.js.map +3 -3
  16. package/dist/bridge/profiles.js +89 -0
  17. package/dist/bridge/profiles.js.map +7 -0
  18. package/dist/browser.d.ts +6 -2
  19. package/dist/browser.d.ts.map +1 -1
  20. package/dist/browser.js +2577 -53
  21. package/dist/browser.js.map +4 -4
  22. package/dist/browser.min.js +1 -1
  23. package/dist/diagnostics/circularity.d.ts +26 -0
  24. package/dist/diagnostics/circularity.d.ts.map +1 -0
  25. package/dist/diagnostics/circularity.js +56 -0
  26. package/dist/diagnostics/circularity.js.map +7 -0
  27. package/dist/diagnostics/index.d.ts +15 -0
  28. package/dist/diagnostics/index.d.ts.map +1 -0
  29. package/dist/diagnostics/index.js +31 -0
  30. package/dist/diagnostics/index.js.map +7 -0
  31. package/dist/diagnostics/stick.d.ts +73 -0
  32. package/dist/diagnostics/stick.d.ts.map +1 -0
  33. package/dist/diagnostics/stick.js +134 -0
  34. package/dist/diagnostics/stick.js.map +7 -0
  35. package/dist/diagnostics/telemetry.d.ts +65 -0
  36. package/dist/diagnostics/telemetry.d.ts.map +1 -0
  37. package/dist/diagnostics/telemetry.js +98 -0
  38. package/dist/diagnostics/telemetry.js.map +7 -0
  39. package/dist/game/host.d.ts +40 -0
  40. package/dist/game/host.d.ts.map +1 -0
  41. package/dist/game/host.js +214 -0
  42. package/dist/game/host.js.map +7 -0
  43. package/dist/game/index.d.ts +12 -0
  44. package/dist/game/index.d.ts.map +1 -0
  45. package/dist/game/index.js +27 -0
  46. package/dist/game/index.js.map +7 -0
  47. package/dist/game/mock.d.ts +35 -0
  48. package/dist/game/mock.d.ts.map +1 -0
  49. package/dist/game/mock.js +221 -0
  50. package/dist/game/mock.js.map +7 -0
  51. package/dist/game/seats.d.ts +27 -0
  52. package/dist/game/seats.d.ts.map +1 -0
  53. package/dist/game/seats.js +66 -0
  54. package/dist/game/seats.js.map +7 -0
  55. package/dist/game/types.d.ts +90 -0
  56. package/dist/game/types.d.ts.map +1 -0
  57. package/dist/game/types.js +7 -0
  58. package/dist/game/types.js.map +7 -0
  59. package/dist/haptics/presets.js +133 -0
  60. package/dist/haptics/presets.js.map +7 -0
  61. package/dist/haptics/router.d.ts +16 -0
  62. package/dist/haptics/router.d.ts.map +1 -1
  63. package/dist/haptics/router.js +146 -0
  64. package/dist/haptics/router.js.map +7 -0
  65. package/dist/haptics/samples.d.ts +68 -0
  66. package/dist/haptics/samples.d.ts.map +1 -0
  67. package/dist/haptics/samples.js +124 -0
  68. package/dist/haptics/samples.js.map +7 -0
  69. package/dist/haptics/triggerWrites.d.ts +41 -0
  70. package/dist/haptics/triggerWrites.d.ts.map +1 -0
  71. package/dist/haptics/triggerWrites.js +127 -0
  72. package/dist/haptics/triggerWrites.js.map +7 -0
  73. package/dist/hid/index.d.ts +7 -1
  74. package/dist/hid/index.d.ts.map +1 -1
  75. package/dist/{chunks/chunk-75I5NTQZ.js → hid/index.js} +35 -157
  76. package/dist/hid/index.js.map +7 -0
  77. package/dist/hub.d.ts +33 -2
  78. package/dist/hub.d.ts.map +1 -1
  79. package/dist/hub.js +474 -0
  80. package/dist/hub.js.map +7 -0
  81. package/dist/index.d.ts +12 -2
  82. package/dist/index.d.ts.map +1 -1
  83. package/dist/index.js +45 -793
  84. package/dist/index.js.map +4 -4
  85. package/dist/input/actions.js +244 -0
  86. package/dist/input/actions.js.map +7 -0
  87. package/dist/input/motion.d.ts +70 -0
  88. package/dist/input/motion.d.ts.map +1 -0
  89. package/dist/input/motion.js +175 -0
  90. package/dist/input/motion.js.map +7 -0
  91. package/dist/input/slotSwitcher.d.ts +31 -0
  92. package/dist/input/slotSwitcher.d.ts.map +1 -0
  93. package/dist/input/slotSwitcher.js +118 -0
  94. package/dist/input/slotSwitcher.js.map +7 -0
  95. package/dist/input/touchpad.d.ts +92 -0
  96. package/dist/input/touchpad.d.ts.map +1 -0
  97. package/dist/input/touchpad.js +268 -0
  98. package/dist/input/touchpad.js.map +7 -0
  99. package/dist/lifecycle.d.ts +37 -0
  100. package/dist/lifecycle.d.ts.map +1 -0
  101. package/dist/lifecycle.js +55 -0
  102. package/dist/lifecycle.js.map +7 -0
  103. package/dist/link/connect.d.ts +67 -0
  104. package/dist/link/connect.d.ts.map +1 -0
  105. package/dist/link/connect.js +123 -0
  106. package/dist/link/connect.js.map +7 -0
  107. package/dist/link/engine.d.ts +7 -1
  108. package/dist/link/engine.d.ts.map +1 -1
  109. package/dist/link/engine.js +985 -0
  110. package/dist/link/engine.js.map +7 -0
  111. package/dist/link/index.d.ts +15 -4
  112. package/dist/link/index.d.ts.map +1 -1
  113. package/dist/link/index.js +29 -958
  114. package/dist/link/index.js.map +4 -4
  115. package/dist/loop/index.js +0 -1
  116. package/dist/loop/index.js.map +1 -1
  117. package/dist/mic/blow.d.ts +72 -0
  118. package/dist/mic/blow.d.ts.map +1 -0
  119. package/dist/mic/blow.js +152 -0
  120. package/dist/mic/blow.js.map +7 -0
  121. package/dist/mic/index.d.ts +9 -0
  122. package/dist/mic/index.d.ts.map +1 -0
  123. package/dist/mic/index.js +23 -0
  124. package/dist/mic/index.js.map +7 -0
  125. package/dist/mic/input.d.ts +37 -0
  126. package/dist/mic/input.d.ts.map +1 -0
  127. package/dist/mic/input.js +109 -0
  128. package/dist/mic/input.js.map +7 -0
  129. package/dist/mic/level.d.ts +33 -0
  130. package/dist/mic/level.d.ts.map +1 -0
  131. package/dist/mic/level.js +61 -0
  132. package/dist/mic/level.js.map +7 -0
  133. package/package.json +17 -1
  134. package/dist/chunks/chunk-75I5NTQZ.js.map +0 -7
@@ -0,0 +1,56 @@
1
+ const CIRCULARITY_SECTORS = 72;
2
+ const SECTORS = CIRCULARITY_SECTORS;
3
+ const CIRCULARITY_MIN_RIM_MAGNITUDE = 0.72;
4
+ const CIRCULARITY_MIN_SECTORS = 12;
5
+ function createCircularity() {
6
+ return {
7
+ sectors: new Float32Array(SECTORS),
8
+ coveragePct: 0,
9
+ avgErrorPct: null,
10
+ maxMag: 0
11
+ };
12
+ }
13
+ function updateCircularity(c, x, y) {
14
+ const mag = Math.hypot(x, y);
15
+ if (mag > c.maxMag) c.maxMag = mag;
16
+ if (mag < CIRCULARITY_MIN_RIM_MAGNITUDE) return;
17
+ let ang = Math.atan2(y, x);
18
+ if (ang < 0) ang += Math.PI * 2;
19
+ const idx = Math.min(SECTORS - 1, Math.floor(ang / (Math.PI * 2) * SECTORS));
20
+ if (mag > c.sectors[idx]) {
21
+ c.sectors[idx] = mag;
22
+ let filled = 0;
23
+ let errSum = 0;
24
+ for (let i = 0; i < SECTORS; i++) {
25
+ if (c.sectors[i] > 0) {
26
+ filled++;
27
+ errSum += Math.abs(c.sectors[i] - 1);
28
+ }
29
+ }
30
+ c.coveragePct = Math.round(filled / SECTORS * 100);
31
+ c.avgErrorPct = filled >= CIRCULARITY_MIN_SECTORS ? Number((errSum / filled * 100).toFixed(1)) : null;
32
+ }
33
+ }
34
+ function buildSectorPath(sectors, cx, cy, radius) {
35
+ const pts = [];
36
+ for (let i = 0; i < SECTORS; i++) {
37
+ const r = sectors[i];
38
+ if (r <= 0) continue;
39
+ const ang = (i + 0.5) / SECTORS * Math.PI * 2;
40
+ const clampedR = Math.min(1.22, r);
41
+ const px = cx + Math.cos(ang) * radius * clampedR;
42
+ const py = cy + Math.sin(ang) * radius * clampedR;
43
+ pts.push(`${pts.length === 0 ? "M" : "L"}${px.toFixed(1)},${py.toFixed(1)}`);
44
+ }
45
+ if (pts.length >= 24) pts.push("Z");
46
+ return pts.join(" ");
47
+ }
48
+ export {
49
+ CIRCULARITY_MIN_RIM_MAGNITUDE,
50
+ CIRCULARITY_MIN_SECTORS,
51
+ CIRCULARITY_SECTORS,
52
+ buildSectorPath,
53
+ createCircularity,
54
+ updateCircularity
55
+ };
56
+ //# sourceMappingURL=circularity.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/diagnostics/circularity.ts"],
4
+ "sourcesContent": ["/**\n * True 360\u00B0 stick circularity measurement: the stick's outer travel is binned into 72 five-degree\n * sectors and the reported error is the mean radial deviation from the unit circle across every\n * sampled sector, never a single peak value. Feed it raw (0% deadzone) axes.\n */\n/** 5-degree angular sectors for true 360-degree circularity measurement. */\nexport const CIRCULARITY_SECTORS = 72;\nconst SECTORS = CIRCULARITY_SECTORS;\n/** Samples below this radius are ignored (the stick is not at its outer rim). */\nexport const CIRCULARITY_MIN_RIM_MAGNITUDE = 0.72;\n/** Minimum filled sectors before `avgErrorPct` is reported. */\nexport const CIRCULARITY_MIN_SECTORS = 12;\n\nexport interface CircularityStats {\n /** Peak radius seen per sector (`0` = not yet swept). */\n sectors: Float32Array;\n /** Share of the 72 sectors swept so far (0..100). */\n coveragePct: number;\n /** Mean |r - 1| over swept sectors in percent, `null` until enough sectors are swept. */\n avgErrorPct: number | null;\n /** Largest radius seen anywhere (including inside the rim band). */\n maxMag: number;\n}\n\nexport function createCircularity(): CircularityStats {\n return {\n sectors: new Float32Array(SECTORS),\n coveragePct: 0,\n avgErrorPct: null,\n maxMag: 0,\n };\n}\n\nexport function updateCircularity(c: CircularityStats, x: number, y: number): void {\n const mag = Math.hypot(x, y);\n if (mag > c.maxMag) c.maxMag = mag;\n if (mag < CIRCULARITY_MIN_RIM_MAGNITUDE) return;\n let ang = Math.atan2(y, x);\n if (ang < 0) ang += Math.PI * 2;\n const idx = Math.min(SECTORS - 1, Math.floor((ang / (Math.PI * 2)) * SECTORS));\n if (mag > c.sectors[idx]) {\n c.sectors[idx] = mag;\n let filled = 0;\n let errSum = 0;\n for (let i = 0; i < SECTORS; i++) {\n if (c.sectors[i] > 0) {\n filled++;\n errSum += Math.abs(c.sectors[i] - 1.0);\n }\n }\n c.coveragePct = Math.round((filled / SECTORS) * 100);\n c.avgErrorPct = filled >= CIRCULARITY_MIN_SECTORS ? Number(((errSum / filled) * 100).toFixed(1)) : null;\n }\n}\n\n/** SVG path (`M\u2026L\u2026Z`) of the swept rim, centred on `(cx, cy)` with unit circle = `radius`. */\nexport function buildSectorPath(sectors: Float32Array, cx: number, cy: number, radius: number): string {\n const pts: string[] = [];\n for (let i = 0; i < SECTORS; i++) {\n const r = sectors[i];\n if (r <= 0) continue;\n const ang = ((i + 0.5) / SECTORS) * Math.PI * 2;\n const clampedR = Math.min(1.22, r);\n const px = cx + Math.cos(ang) * radius * clampedR;\n const py = cy + Math.sin(ang) * radius * clampedR;\n pts.push(`${pts.length === 0 ? 'M' : 'L'}${px.toFixed(1)},${py.toFixed(1)}`);\n }\n if (pts.length >= 24) pts.push('Z');\n return pts.join(' ');\n}\n"],
5
+ "mappings": "AAMO,MAAM,sBAAsB;AACnC,MAAM,UAAU;AAET,MAAM,gCAAgC;AAEtC,MAAM,0BAA0B;AAahC,SAAS,oBAAsC;AACpD,SAAO;AAAA,IACL,SAAS,IAAI,aAAa,OAAO;AAAA,IACjC,aAAa;AAAA,IACb,aAAa;AAAA,IACb,QAAQ;AAAA,EACV;AACF;AAEO,SAAS,kBAAkB,GAAqB,GAAW,GAAiB;AACjF,QAAM,MAAM,KAAK,MAAM,GAAG,CAAC;AAC3B,MAAI,MAAM,EAAE,OAAQ,GAAE,SAAS;AAC/B,MAAI,MAAM,8BAA+B;AACzC,MAAI,MAAM,KAAK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k/diagnostics — Building blocks for a browser controller tester.
3
+ *
4
+ * - `createCircularity` / `updateCircularity` / `buildSectorPath`: 72-sector 360° circularity error.
5
+ * - `StickDriftTracker` / `classifyRestVerdict`: resting drift & jitter with a settle window.
6
+ * - `ButtonBounceTracker`: micro-switch double-click (contact bounce) detection.
7
+ * - `createControllerTelemetry`: per-controller memory of all of the above + intentional-input
8
+ * auto-switching, driven by one `update(now)` call per frame.
9
+ *
10
+ * Everything works on raw (0% deadzone) input and has no UI or framework dependency.
11
+ */
12
+ export { CIRCULARITY_MIN_RIM_MAGNITUDE, CIRCULARITY_MIN_SECTORS, CIRCULARITY_SECTORS, buildSectorPath, createCircularity, updateCircularity, type CircularityStats, } from './circularity.js';
13
+ export { ButtonBounceTracker, DEFAULT_DRIFT_THRESHOLDS, StickDriftTracker, classifyRestVerdict, type ButtonBounceTrackerOptions, type DriftThresholds, type StickDriftTrackerOptions, type StickDriftVerdict, type StickRestMetrics, } from './stick.js';
14
+ export { createControllerTelemetry, type ControllerTelemetry, type ControllerTelemetryOptions, type SlotDiagnostics, type TelemetryFrame, type TelemetrySource, } from './telemetry.js';
15
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/diagnostics/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EACL,6BAA6B,EAC7B,uBAAuB,EACvB,mBAAmB,EACnB,eAAe,EACf,iBAAiB,EACjB,iBAAiB,EACjB,KAAK,gBAAgB,GACtB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EACL,mBAAmB,EACnB,wBAAwB,EACxB,iBAAiB,EACjB,mBAAmB,EACnB,KAAK,0BAA0B,EAC/B,KAAK,eAAe,EACpB,KAAK,wBAAwB,EAC7B,KAAK,iBAAiB,EACtB,KAAK,gBAAgB,GACtB,MAAM,YAAY,CAAC;AAEpB,OAAO,EACL,yBAAyB,EACzB,KAAK,mBAAmB,EACxB,KAAK,0BAA0B,EAC/B,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,KAAK,eAAe,GACrB,MAAM,gBAAgB,CAAC"}
@@ -0,0 +1,31 @@
1
+ import {
2
+ CIRCULARITY_MIN_RIM_MAGNITUDE,
3
+ CIRCULARITY_MIN_SECTORS,
4
+ CIRCULARITY_SECTORS,
5
+ buildSectorPath,
6
+ createCircularity,
7
+ updateCircularity
8
+ } from "./circularity.js";
9
+ import {
10
+ ButtonBounceTracker,
11
+ DEFAULT_DRIFT_THRESHOLDS,
12
+ StickDriftTracker,
13
+ classifyRestVerdict
14
+ } from "./stick.js";
15
+ import {
16
+ createControllerTelemetry
17
+ } from "./telemetry.js";
18
+ export {
19
+ ButtonBounceTracker,
20
+ CIRCULARITY_MIN_RIM_MAGNITUDE,
21
+ CIRCULARITY_MIN_SECTORS,
22
+ CIRCULARITY_SECTORS,
23
+ DEFAULT_DRIFT_THRESHOLDS,
24
+ StickDriftTracker,
25
+ buildSectorPath,
26
+ classifyRestVerdict,
27
+ createCircularity,
28
+ createControllerTelemetry,
29
+ updateCircularity
30
+ };
31
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/diagnostics/index.ts"],
4
+ "sourcesContent": ["/**\n * @gamepadly/sdk/diagnostics \u2014 Building blocks for a browser controller tester.\n *\n * - `createCircularity` / `updateCircularity` / `buildSectorPath`: 72-sector 360\u00B0 circularity error.\n * - `StickDriftTracker` / `classifyRestVerdict`: resting drift & jitter with a settle window.\n * - `ButtonBounceTracker`: micro-switch double-click (contact bounce) detection.\n * - `createControllerTelemetry`: per-controller memory of all of the above + intentional-input\n * auto-switching, driven by one `update(now)` call per frame.\n *\n * Everything works on raw (0% deadzone) input and has no UI or framework dependency.\n */\nexport {\n CIRCULARITY_MIN_RIM_MAGNITUDE,\n CIRCULARITY_MIN_SECTORS,\n CIRCULARITY_SECTORS,\n buildSectorPath,\n createCircularity,\n updateCircularity,\n type CircularityStats,\n} from './circularity.js';\n\nexport {\n ButtonBounceTracker,\n DEFAULT_DRIFT_THRESHOLDS,\n StickDriftTracker,\n classifyRestVerdict,\n type ButtonBounceTrackerOptions,\n type DriftThresholds,\n type StickDriftTrackerOptions,\n type StickDriftVerdict,\n type StickRestMetrics,\n} from './stick.js';\n\nexport {\n createControllerTelemetry,\n type ControllerTelemetry,\n type ControllerTelemetryOptions,\n type SlotDiagnostics,\n type TelemetryFrame,\n type TelemetrySource,\n} from './telemetry.js';\n"],
5
+ "mappings": "AAWA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AAEP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAMK;AAEP;AAAA,EACE;AAAA,OAMK;",
6
+ "names": []
7
+ }
@@ -0,0 +1,73 @@
1
+ import type { ButtonName } from '../hid/index.js';
2
+ /**
3
+ * Resting stick drift & micro-switch bounce diagnostics on raw (0% deadzone) input.
4
+ */
5
+ export interface DriftThresholds {
6
+ /** Peak resting offset (0..1) at or above which the stick is `'mild'`. Default `0.03`. */
7
+ mildOffset: number;
8
+ /** Peak resting offset (0..1) at or above which the stick is `'drift'`. Default `0.08`. */
9
+ driftOffset: number;
10
+ /** Peak-to-peak resting jitter at or above which the stick is `'mild'`. Default `0.015`. */
11
+ mildJitter: number;
12
+ /** Peak-to-peak resting jitter at or above which the stick is `'drift'`. Default `0.03`. */
13
+ driftJitter: number;
14
+ }
15
+ export declare const DEFAULT_DRIFT_THRESHOLDS: Readonly<DriftThresholds>;
16
+ export interface StickDriftTrackerOptions {
17
+ /** Radius below which the stick counts as "at rest". Default `0.22`. */
18
+ restMaxMagnitude?: number;
19
+ /** Time the stick must stay at rest before sampling (filters spring rebound). Default `350` ms. */
20
+ settleMs?: number;
21
+ /** Verdict thresholds (partial overrides merge with `DEFAULT_DRIFT_THRESHOLDS`). */
22
+ thresholds?: Partial<DriftThresholds>;
23
+ }
24
+ export interface ButtonBounceTrackerOptions {
25
+ /** Max release→re-press gap that counts as contact bounce. Default `55` ms. */
26
+ releaseMaxMs?: number;
27
+ /** Max press→press interval that counts as contact bounce. Default `90` ms. */
28
+ pressIntervalMaxMs?: number;
29
+ }
30
+ export type StickDriftVerdict = 'waiting' | 'normal' | 'mild' | 'drift';
31
+ export interface StickRestMetrics {
32
+ settled: boolean;
33
+ /** Peak resting radial offset (0..1) captured after the stick settles inside the rest band. */
34
+ peakOffset: number;
35
+ /** Peak-to-peak axis jitter observed during a continuous settled rest window. */
36
+ peakJitter: number;
37
+ verdict: StickDriftVerdict;
38
+ }
39
+ export declare function classifyRestVerdict(settled: boolean, peakOffset: number, peakJitter: number, thresholds?: DriftThresholds): StickDriftVerdict;
40
+ /**
41
+ * Tracks resting 0%-deadzone peak offset and axis jitter for both thumbsticks while filtering out
42
+ * intentional thumb pushes and spring-rebound transients via a 350 ms settle window.
43
+ */
44
+ export declare class StickDriftTracker {
45
+ private left;
46
+ private right;
47
+ private readonly restMaxMag;
48
+ private readonly settleMs;
49
+ private readonly thresholds;
50
+ constructor(options?: StickDriftTrackerOptions);
51
+ private updateAxis;
52
+ update(lx: number, ly: number, rx: number, ry: number, now: number): void;
53
+ private snapshotAxis;
54
+ getSnapshot(): {
55
+ left: StickRestMetrics;
56
+ right: StickRestMetrics;
57
+ };
58
+ reset(): void;
59
+ }
60
+ /**
61
+ * Detects faulty micro-switch contact bounce (double-click within 55ms release / 90ms press interval).
62
+ */
63
+ export declare class ButtonBounceTracker {
64
+ private states;
65
+ private counts;
66
+ private readonly releaseMaxMs;
67
+ private readonly pressIntervalMaxMs;
68
+ constructor(options?: ButtonBounceTrackerOptions);
69
+ update(buttons: Record<ButtonName, boolean>, now: number): void;
70
+ getBouncedButtons(): ButtonName[];
71
+ reset(): void;
72
+ }
73
+ //# sourceMappingURL=stick.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stick.d.ts","sourceRoot":"","sources":["../../src/di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ClD,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;IACpC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAClC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAkB;gBAEjC,OAAO,GAAE,wBAA6B;IAMlD,OAAO,CAAC,UAAU;IAmCX,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,IAAI;IAKhF,OAAO,CAAC,YAAY;IAWb,WAAW,IAAI;QAAE,IAAI,EAAE,gBAAgB,CAAC;QAAC,KAAK,EAAE,gBAAgB,CAAA;KAAE;IAOlE,KAAK,IAAI,IAAI;CAIrB;AAQD;;GAEG;AACH,qBAAa,mBAAmB;IAC9B,OAAO,CAAC,MAAM,CAAuC;IACrD,OAAO,CAAC,MAAM,CAAiC;IAC/C,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAS;IACtC,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAS;gBAEhC,OAAO,GAAE,0BAA+B;IAK7C,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,UAAU,EAAE,OAAO,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,IAAI;IA0B/D,iBAAiB,IAAI,UAAU,EAAE;IAIjC,KAAK,IAAI,IAAI;CAIrB"}
@@ -0,0 +1,134 @@
1
+ const DEFAULT_DRIFT_THRESHOLDS = Object.freeze({
2
+ mildOffset: 0.03,
3
+ driftOffset: 0.08,
4
+ mildJitter: 0.015,
5
+ driftJitter: 0.03
6
+ });
7
+ function createRestState() {
8
+ return {
9
+ inRestSince: null,
10
+ sessionActive: false,
11
+ sessionMinX: 0,
12
+ sessionMaxX: 0,
13
+ sessionMinY: 0,
14
+ sessionMaxY: 0,
15
+ settled: false,
16
+ peakOffset: 0,
17
+ peakJitter: 0
18
+ };
19
+ }
20
+ function classifyRestVerdict(settled, peakOffset, peakJitter, thresholds = DEFAULT_DRIFT_THRESHOLDS) {
21
+ if (!settled) return "waiting";
22
+ if (peakOffset >= thresholds.driftOffset || peakJitter >= thresholds.driftJitter) return "drift";
23
+ if (peakOffset >= thresholds.mildOffset || peakJitter >= thresholds.mildJitter) return "mild";
24
+ return "normal";
25
+ }
26
+ class StickDriftTracker {
27
+ left = createRestState();
28
+ right = createRestState();
29
+ restMaxMag;
30
+ settleMs;
31
+ thresholds;
32
+ constructor(options = {}) {
33
+ this.restMaxMag = options.restMaxMagnitude ?? 0.22;
34
+ this.settleMs = options.settleMs ?? 350;
35
+ this.thresholds = { ...DEFAULT_DRIFT_THRESHOLDS, ...options.thresholds };
36
+ }
37
+ updateAxis(state, x, y, now) {
38
+ const mag = Math.hypot(x, y);
39
+ if (mag >= this.restMaxMag) {
40
+ state.inRestSince = null;
41
+ state.sessionActive = false;
42
+ return;
43
+ }
44
+ if (state.inRestSince === null) {
45
+ state.inRestSince = now;
46
+ state.sessionActive = false;
47
+ return;
48
+ }
49
+ if (now - state.inRestSince < this.settleMs) return;
50
+ if (!state.sessionActive) {
51
+ state.sessionActive = true;
52
+ state.sessionMinX = x;
53
+ state.sessionMaxX = x;
54
+ state.sessionMinY = y;
55
+ state.sessionMaxY = y;
56
+ } else {
57
+ if (x < state.sessionMinX) state.sessionMinX = x;
58
+ if (x > state.sessionMaxX) state.sessionMaxX = x;
59
+ if (y < state.sessionMinY) state.sessionMinY = y;
60
+ if (y > state.sessionMaxY) state.sessionMaxY = y;
61
+ }
62
+ state.settled = true;
63
+ if (mag > state.peakOffset) state.peakOffset = mag;
64
+ const jitter = Math.max(state.sessionMaxX - state.sessionMinX, state.sessionMaxY - state.sessionMinY);
65
+ if (jitter > state.peakJitter) state.peakJitter = jitter;
66
+ }
67
+ update(lx, ly, rx, ry, now) {
68
+ this.updateAxis(this.left, lx, ly, now);
69
+ this.updateAxis(this.right, rx, ry, now);
70
+ }
71
+ snapshotAxis(state) {
72
+ const peakOffset = Number(state.peakOffset.toFixed(4));
73
+ const peakJitter = Number(state.peakJitter.toFixed(4));
74
+ return {
75
+ settled: state.settled,
76
+ peakOffset,
77
+ peakJitter,
78
+ verdict: classifyRestVerdict(state.settled, peakOffset, peakJitter, this.thresholds)
79
+ };
80
+ }
81
+ getSnapshot() {
82
+ return {
83
+ left: this.snapshotAxis(this.left),
84
+ right: this.snapshotAxis(this.right)
85
+ };
86
+ }
87
+ reset() {
88
+ this.left = createRestState();
89
+ this.right = createRestState();
90
+ }
91
+ }
92
+ class ButtonBounceTracker {
93
+ states = /* @__PURE__ */ new Map();
94
+ counts = /* @__PURE__ */ new Map();
95
+ releaseMaxMs;
96
+ pressIntervalMaxMs;
97
+ constructor(options = {}) {
98
+ this.releaseMaxMs = options.releaseMaxMs ?? 55;
99
+ this.pressIntervalMaxMs = options.pressIntervalMaxMs ?? 90;
100
+ }
101
+ update(buttons, now) {
102
+ for (const [key, pressed] of Object.entries(buttons)) {
103
+ let timing = this.states.get(key);
104
+ if (!timing) {
105
+ timing = { pressed, lastPressAt: pressed ? now : 0, lastReleaseAt: 0 };
106
+ this.states.set(key, timing);
107
+ continue;
108
+ }
109
+ if (pressed && !timing.pressed) {
110
+ if (timing.lastReleaseAt > 0 && timing.lastPressAt > 0 && now - timing.lastReleaseAt <= this.releaseMaxMs && now - timing.lastPressAt <= this.pressIntervalMaxMs) {
111
+ this.counts.set(key, (this.counts.get(key) ?? 0) + 1);
112
+ }
113
+ timing.lastPressAt = now;
114
+ } else if (!pressed && timing.pressed) {
115
+ timing.lastReleaseAt = now;
116
+ }
117
+ timing.pressed = pressed;
118
+ }
119
+ }
120
+ getBouncedButtons() {
121
+ return Array.from(this.counts.keys());
122
+ }
123
+ reset() {
124
+ this.states.clear();
125
+ this.counts.clear();
126
+ }
127
+ }
128
+ export {
129
+ ButtonBounceTracker,
130
+ DEFAULT_DRIFT_THRESHOLDS,
131
+ StickDriftTracker,
132
+ classifyRestVerdict
133
+ };
134
+ //# sourceMappingURL=stick.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/diagnostics/stick.ts"],
4
+ "sourcesContent": ["import type { ButtonName } from '../hid/index.js';\n\n/**\n * Resting stick drift & micro-switch bounce diagnostics on raw (0% deadzone) input.\n */\n\nexport interface DriftThresholds {\n /** Peak resting offset (0..1) at or above which the stick is `'mild'`. Default `0.03`. */\n mildOffset: number;\n /** Peak resting offset (0..1) at or above which the stick is `'drift'`. Default `0.08`. */\n driftOffset: number;\n /** Peak-to-peak resting jitter at or above which the stick is `'mild'`. Default `0.015`. */\n mildJitter: number;\n /** Peak-to-peak resting jitter at or above which the stick is `'drift'`. Default `0.03`. */\n driftJitter: number;\n}\n\nexport const DEFAULT_DRIFT_THRESHOLDS: Readonly<DriftThresholds> = Object.freeze({\n mildOffset: 0.03,\n driftOffset: 0.08,\n mildJitter: 0.015,\n driftJitter: 0.03,\n});\n\nexport interface StickDriftTrackerOptions {\n /** Radius below which the stick counts as \"at rest\". Default `0.22`. */\n restMaxMagnitude?: number;\n /** Time the stick must stay at rest before sampling (filters spring rebound). Default `350` ms. */\n settleMs?: number;\n /** Verdict thresholds (partial overrides merge with `DEFAULT_DRIFT_THRESHOLDS`). */\n thresholds?: Partial<DriftThresholds>;\n}\n\nexport interface ButtonBounceTrackerOptions {\n /** Max release\u2192re-press gap that counts as contact bounce. Default `55` ms. */\n releaseMaxMs?: number;\n /** Max press\u2192press interval that counts as contact bounce. Default `90` ms. */\n pressIntervalMaxMs?: number;\n}\n\nexport type StickDriftVerdict = 'waiting' | 'normal' | 'mild' | 'drift';\n\nexport interface StickRestMetrics {\n settled: boolean;\n /** Peak resting radial offset (0..1) captured after the stick settles inside the rest band. */\n peakOffset: number;\n /** Peak-to-peak axis jitter observed during a continuous settled rest window. */\n peakJitter: number;\n verdict: StickDriftVerdict;\n}\n\ninterface StickRestState {\n inRestSince: number | null;\n sessionActive: boolean;\n sessionMinX: number;\n sessionMaxX: number;\n sessionMinY: number;\n sessionMaxY: number;\n settled: boolean;\n peakOffset: number;\n peakJitter: number;\n}\n\nfunction createRestState(): StickRestState {\n return {\n inRestSince: null,\n sessionActive: false,\n sessionMinX: 0,\n sessionMaxX: 0,\n sessionMinY: 0,\n sessionMaxY: 0,\n settled: false,\n peakOffset: 0,\n peakJitter: 0,\n };\n}\n\nexport function classifyRestVerdict(\n settled: boolean,\n peakOffset: number,\n peakJitter: number,\n thresholds: DriftThresholds = DEFAULT_DRIFT_THRESHOLDS\n): StickDriftVerdict {\n if (!settled) return 'waiting';\n if (peakOffset >= thresholds.driftOffset || peakJitter >= thresholds.driftJitter) return 'drift';\n if (peakOffset >= thresholds.mildOffset || peakJitter >= thresholds.mildJitter) return 'mild';\n return 'normal';\n}\n\n/**\n * Tracks resting 0%-deadzone peak offset and axis jitter for both thumbsticks while filtering out\n * intentional thumb pushes and spring-rebound transients via a 350 ms settle window.\n */\nexport class StickDriftTracker {\n private left: StickRestState = createRestState();\n private right: StickRestState = createRestState();\n private readonly restMaxMag: number;\n private readonly settleMs: number;\n private readonly thresholds: DriftThresholds;\n\n constructor(options: StickDriftTrackerOptions = {}) {\n this.restMaxMag = options.restMaxMagnitude ?? 0.22;\n this.settleMs = options.settleMs ?? 350;\n this.thresholds = { ...DEFAULT_DRIFT_THRESHOLDS, ...options.thresholds };\n }\n\n private updateAxis(state: StickRestState, x: number, y: number, now: number): void {\n const mag = Math.hypot(x, y);\n if (mag >= this.restMaxMag) {\n state.inRestSince = null;\n state.sessionActive = false;\n return;\n }\n\n if (state.inRestSince === null) {\n state.inRestSince = now;\n state.sessionActive = false;\n return;\n }\n\n if (now - state.inRestSince < this.settleMs) return;\n\n if (!state.sessionActive) {\n state.sessionActive = true;\n state.sessionMinX = x;\n state.sessionMaxX = x;\n state.sessionMinY = y;\n state.sessionMaxY = y;\n } else {\n if (x < state.sessionMinX) state.sessionMinX = x;\n if (x > state.sessionMaxX) state.sessionMaxX = x;\n if (y < state.sessionMinY) state.sessionMinY = y;\n if (y > state.sessionMaxY) state.sessionMaxY = y;\n }\n\n state.settled = true;\n if (mag > state.peakOffset) state.peakOffset = mag;\n const jitter = Math.max(state.sessionMaxX - state.sessionMinX, state.sessionMaxY - state.sessionMinY);\n if (jitter > state.peakJitter) state.peakJitter = jitter;\n }\n\n public update(lx: number, ly: number, rx: number, ry: number, now: number): void {\n this.updateAxis(this.left, lx, ly, now);\n this.updateAxis(this.right, rx, ry, now);\n }\n\n private snapshotAxis(state: StickRestState): StickRestMetrics {\n const peakOffset = Number(state.peakOffset.toFixed(4));\n const peakJitter = Number(state.peakJitter.toFixed(4));\n return {\n settled: state.settled,\n peakOffset,\n peakJitter,\n verdict: classifyRestVerdict(state.settled, peakOffset, peakJitter, this.thresholds),\n };\n }\n\n public getSnapshot(): { left: StickRestMetrics; right: StickRestMetrics } {\n return {\n left: this.snapshotAxis(this.left),\n right: this.snapshotAxis(this.right),\n };\n }\n\n public reset(): void {\n this.left = createRestState();\n this.right = createRestState();\n }\n}\n\ninterface ButtonTiming {\n pressed: boolean;\n lastPressAt: number;\n lastReleaseAt: number;\n}\n\n/**\n * Detects faulty micro-switch contact bounce (double-click within 55ms release / 90ms press interval).\n */\nexport class ButtonBounceTracker {\n private states = new Map<ButtonName, ButtonTiming>();\n private counts = new Map<ButtonName, number>();\n private readonly releaseMaxMs: number;\n private readonly pressIntervalMaxMs: number;\n\n constructor(options: ButtonBounceTrackerOptions = {}) {\n this.releaseMaxMs = options.releaseMaxMs ?? 55;\n this.pressIntervalMaxMs = options.pressIntervalMaxMs ?? 90;\n }\n\n public update(buttons: Record<ButtonName, boolean>, now: number): void {\n for (const [key, pressed] of Object.entries(buttons) as Array<[ButtonName, boolean]>) {\n let timing = this.states.get(key);\n if (!timing) {\n timing = { pressed, lastPressAt: pressed ? now : 0, lastReleaseAt: 0 };\n this.states.set(key, timing);\n continue;\n }\n\n if (pressed && !timing.pressed) {\n if (\n timing.lastReleaseAt > 0 &&\n timing.lastPressAt > 0 &&\n now - timing.lastReleaseAt <= this.releaseMaxMs &&\n now - timing.lastPressAt <= this.pressIntervalMaxMs\n ) {\n this.counts.set(key, (this.counts.get(key) ?? 0) + 1);\n }\n timing.lastPressAt = now;\n } else if (!pressed && timing.pressed) {\n timing.lastReleaseAt = now;\n }\n timing.pressed = pressed;\n }\n }\n\n public getBouncedButtons(): ButtonName[] {\n return Array.from(this.counts.keys());\n }\n\n public reset(): void {\n this.states.clear();\n this.counts.clear();\n }\n}\n"],
5
+ "mappings": "AAiBO,MAAM,2BAAsD,OAAO,OAAO;AAAA,EAC/E,YAAY;AAAA,EACZ,aAAa;AAAA,EACb,YAAY;AAAA,EACZ,aAAa;AACf,CAAC;AAyCD,SAAS,kBAAkC;AACzC,SAAO;AAAA,IACL,aAAa;AAAA,IACb,eAAe;AAAA,IACf,aAAa;AAAA,IACb,aAAa;AAAA,IACb,aAAa;AAAA,IACb,aAAa;AAAA,IACb,SAAS;AAAA,IACT,YAAY;AAAA,IACZ,YAAY;AAAA,EACd;AACF;AAEO,SAAS,oBACd,SACA,YACA,YACA,aAA8B,0BACX;AACnB,MAAI,CAAC,QAAS,QAAO;AACrB,MAAI,cAAc,WAAW,eAAe,cAAc,WAAW,YAAa,QAAO;AACzF,MAAI,cAAc,WAAW,cAAc,cAAc,WAAW,WAAY,QAAO;AACvF,SAAO;AACT;AAMO,MAAM,kBAAkB;AAAA,EACrB,OAAuB,gBAAgB;AAAA,EACvC,QAAwB,gBAAgB;AAAA,EAC/B;AAAA,EACA;AAAA,EACA;AAAA,EAEjB,YAAY,UAAoC,CAAC,GAAG;AAClD,SAAK,aAAa,QAAQ,oBAAoB;AAC9C,SAAK,WAAW,QAAQ,YAAY;AACpC,SAAK,aAAa,EAAE,GAAG,0BAA0B,GAAG,QAAQ,WAAW;AAAA,EACzE;AAAA,EAEQ,WAAW,OAAuB,GAAW,GAAW,KAAmB;AACjF,UAAM,MAAM,KAAK,MAAM,GAAG,CAAC;AAC3B,QAAI,OAAO,KAAK,YAAY;AAC1B,YAAM,cAA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core: per-controller 360° circularity, resting drift,
3
+ * micro-switch bounce and tested-button memory, plus intentional-input auto-switching between
4
+ * connected controllers. Call `update(now)` once per animation frame and render the frame however
5
+ * you like (React, Vue, Canvas, plain DOM).
6
+ */
7
+ import { type ButtonName, type ControllerBrand, type ControllerSlotInfo, type UnifiedInputState } from '../hid/index.js';
8
+ import { type CircularityStats } from './circularity.js';
9
+ import { ButtonBounceTracker, StickDriftTracker, type ButtonBounceTrackerOptions, type StickDriftTrackerOptions } from './stick.js';
10
+ /** The subset of `DualSenseControllerManager` the telemetry reads (any compatible source works). */
11
+ export interface TelemetrySource {
12
+ getConnectedControllers(): ControllerSlotInfo[];
13
+ getActiveSlotId(): string | null;
14
+ getInputState(slotId?: string): UnifiedInputState;
15
+ setActiveSlot(slotId: string): boolean;
16
+ }
17
+ export interface ControllerTelemetryOptions {
18
+ source: TelemetrySource;
19
+ /** Only bind controllers of this brand (brand-dedicated tester pages). Others go to `otherSlots`. */
20
+ brandFilter?: ControllerBrand;
21
+ /**
22
+ * Called to change the active controller (auto-switch, brand scoping, `selectSlot`).
23
+ * Defaults to `source.setActiveSlot`; pass your own to keep host UI state in sync.
24
+ */
25
+ setActiveSlot?: (slotId: string) => void;
26
+ drift?: StickDriftTrackerOptions;
27
+ bounce?: ButtonBounceTrackerOptions;
28
+ }
29
+ export interface SlotDiagnostics {
30
+ circularity: {
31
+ left: CircularityStats;
32
+ right: CircularityStats;
33
+ };
34
+ drift: StickDriftTracker;
35
+ bounce: ButtonBounceTracker;
36
+ tested: Set<ButtonName>;
37
+ }
38
+ export interface TelemetryFrame {
39
+ now: number;
40
+ /** Controllers bound to this tester (all, or only `brandFilter` matches). */
41
+ slots: ControllerSlotInfo[];
42
+ /** Connected controllers excluded by `brandFilter`. */
43
+ otherSlots: ControllerSlotInfo[];
44
+ activeSlotId: string | null;
45
+ /** Key of the per-controller memory used this frame (`activeSlotId` or a placeholder). */
46
+ slotKey: string;
47
+ /** Raw input of the active controller (empty state when none is bound). */
48
+ input: UnifiedInputState;
49
+ /** True when any bound controller received intentional input this frame. */
50
+ triggered: boolean;
51
+ /** Live per-controller measurements (mutated in place by later frames). */
52
+ diagnostics: SlotDiagnostics;
53
+ }
54
+ export interface ControllerTelemetry {
55
+ /** Samples all controllers once; call every animation frame with `performance.now()`. */
56
+ update(now: number): TelemetryFrame;
57
+ /** Manually selects a controller and pauses auto-switching briefly so it isn't undone. */
58
+ selectSlot(slotId: string, now: number): void;
59
+ /** Clears circularity, drift, bounce and tested-button memory for the current controller. */
60
+ resetActive(): void;
61
+ /** Returns (creating if needed) the stored measurements for a controller key. */
62
+ getDiagnostics(slotKey: string): SlotDiagnostics;
63
+ }
64
+ export declare function createControllerTelemetry(options: ControllerTelemetryOptions): ControllerTelemetry;
65
+ //# sourceMappingURL=telemetry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"telemetry.d.ts","sourceRoot":"","sources":["../../src/diagnostics/telemetry.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAEL,KAAK,UAAU,EACf,KAAK,eAAe,EACpB,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EACvB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAwC,KAAK,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAC/F,OAAO,EACL,mBAAmB,EACnB,iBAAiB,EACjB,KAAK,0BAA0B,EAC/B,KAAK,wBAAwB,EAC9B,MAAM,YAAY,CAAC;AAEpB,oGAAoG;AACpG,MAAM,WAAW,eAAe;IAC9B,uBAAuB,IAAI,kBAAkB,EAAE,CAAC;IAChD,eAAe,IAAI,MAAM,GAAG,IAAI,CAAC;IACjC,aAAa,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,iBAAiB,CAAC;IAClD,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC;CACxC;AAED,MAAM,WAAW,0BAA0B;IACzC,MAAM,EAAE,eAAe,CAAC;IACxB,qGAAqG;IACrG,WAAW,C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{
2
+ createEmptyInput
3
+ } from "../hid/index.js";
4
+ import { SlotAutoSwitcher } from "../input/slotSwitcher.js";
5
+ import { createCircularity, updateCircularity } from "./circularity.js";
6
+ import {
7
+ ButtonBounceTracker,
8
+ StickDriftTracker
9
+ } from "./stick.js";
10
+ function createControllerTelemetry(options) {
11
+ const { source, brandFilter } = options;
12
+ const setActive = options.setActiveSlot ?? ((id) => void source.setActiveSlot(id));
13
+ const switcher = new SlotAutoSwitcher();
14
+ const memory = /* @__PURE__ */ new Map();
15
+ let latestSamples = [];
16
+ let activeKey = brandFilter ? `__none_${brandFilter}__` : "__none__";
17
+ const createDiagnostics = () => ({
18
+ circularity: { left: createCircularity(), right: createCircularity() },
19
+ drift: new StickDriftTracker(options.drift),
20
+ bounce: new ButtonBounceTracker(options.bounce),
21
+ tested: /* @__PURE__ */ new Set()
22
+ });
23
+ const getDiagnostics = (key) => {
24
+ let d = memory.get(key);
25
+ if (!d) {
26
+ d = createDiagnostics();
27
+ memory.set(key, d);
28
+ }
29
+ return d;
30
+ };
31
+ return {
32
+ update(now) {
33
+ const allSlots = source.getConnectedControllers();
34
+ const slots = brandFilter ? allSlots.filter((s) => s.identity.brand === brandFilter) : allSlots;
35
+ const otherSlots = brandFilter ? allSlots.filter((s) => s.identity.brand !== brandFilter) : [];
36
+ const globalActiveId = source.getActiveSlotId();
37
+ let activeSlotId = globalActiveId;
38
+ if (brandFilter) {
39
+ if (slots.length === 0) {
40
+ activeSlotId = null;
41
+ } else if (!globalActiveId || !slots.some((s) => s.id === globalActiveId)) {
42
+ activeSlotId = slots[0].id;
43
+ setActive(activeSlotId);
44
+ }
45
+ }
46
+ let triggered = false;
47
+ if (slots.length > 0) {
48
+ latestSamples = slots.map((slot) => {
49
+ const s = source.getInputState(slot.id);
50
+ return {
51
+ id: slot.id,
52
+ lastActivityAt: slot.lastActivityAt,
53
+ lx: s.lx,
54
+ ly: s.ly,
55
+ rx: s.rx,
56
+ ry: s.ry,
57
+ l2: s.l2,
58
+ r2: s.r2
59
+ };
60
+ });
61
+ const { switchTo, triggeredSlotId } = switcher.evaluate(latestSamples, activeSlotId, now);
62
+ if (switchTo && switchTo !== activeSlotId) {
63
+ activeSlotId = switchTo;
64
+ setActive(switchTo);
65
+ }
66
+ triggered = triggeredSlotId !== null;
67
+ } else {
68
+ latestSamples = [];
69
+ }
70
+ const slotKey = activeSlotId ?? (brandFilter ? `__none_${brandFilter}__` : "__none__");
71
+ activeKey = slotKey;
72
+ const diagnostics = getDiagnostics(slotKey);
73
+ const input = activeSlotId ? source.getInputState(activeSlotId) : brandFilter ? createEmptyInput() : source.getInputState();
74
+ if (input.connected) {
75
+ updateCircularity(diagnostics.circularity.left, input.lx, input.ly);
76
+ updateCircularity(diagnostics.circularity.right, input.rx, input.ry);
77
+ diagnostics.drift.update(input.lx, input.ly, input.rx, input.ry, now);
78
+ diagnostics.bounce.update(input.buttons, now);
79
+ for (const [btn, pressed] of Object.entries(input.buttons)) {
80
+ if (pressed) diagnostics.tested.add(btn);
81
+ }
82
+ }
83
+ return { now, slots, otherSlots, activeSlotId, slotKey, input, triggered, diagnostics };
84
+ },
85
+ selectSlot(slotId, now) {
86
+ switcher.notifyManualSelect(latestSamples, now);
87
+ setActive(slotId);
88
+ },
89
+ resetActive() {
90
+ memory.set(activeKey, createDiagnostics());
91
+ },
92
+ getDiagnostics
93
+ };
94
+ }
95
+ export {
96
+ createControllerTelemetry
97
+ };
98
+ //# sourceMappingURL=telemetry.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/diagnostics/telemetry.ts"],
4
+ "sourcesContent": ["/**\n * Framework-agnostic controller tester core: per-controller 360\u00B0 circularity, resting drift,\n * micro-switch bounce and tested-button memory, plus intentional-input auto-switching between\n * connected controllers. Call `update(now)` once per animation frame and render the frame however\n * you like (React, Vue, Canvas, plain DOM).\n */\nimport {\n createEmptyInput,\n type ButtonName,\n type ControllerBrand,\n type ControllerSlotInfo,\n type UnifiedInputState,\n} from '../hid/index.js';\nimport { SlotAutoSwitcher, type SlotMotionSample } from '../input/slotSwitcher.js';\nimport { createCircularity, updateCircularity, type CircularityStats } from './circularity.js';\nimport {\n ButtonBounceTracker,\n StickDriftTracker,\n type ButtonBounceTrackerOptions,\n type StickDriftTrackerOptions,\n} from './stick.js';\n\n/** The subset of `DualSenseControllerManager` the telemetry reads (any compatible source works). */\nexport interface TelemetrySource {\n getConnectedControllers(): ControllerSlotInfo[];\n getActiveSlotId(): string | null;\n getInputState(slotId?: string): UnifiedInputState;\n setActiveSlot(slotId: string): boolean;\n}\n\nexport interface ControllerTelemetryOptions {\n source: TelemetrySource;\n /** Only bind controllers of this brand (brand-dedicated tester pages). Others go to `otherSlots`. */\n brandFilter?: ControllerBrand;\n /**\n * Called to change the active controller (auto-switch, brand scoping, `selectSlot`).\n * Defaults to `source.setActiveSlot`; pass your own to keep host UI state in sync.\n */\n setActiveSlot?: (slotId: string) => void;\n drift?: StickDriftTrackerOptions;\n bounce?: ButtonBounceTrackerOptions;\n}\n\nexport interface SlotDiagnostics {\n circularity: { left: CircularityStats; right: CircularityStats };\n drift: StickDriftTracker;\n bounce: ButtonBounceTracker;\n tested: Set<ButtonName>;\n}\n\nexport interface TelemetryFrame {\n now: number;\n /** Controllers bound to this tester (all, or only `brandFilter` matches). */\n slots: ControllerSlotInfo[];\n /** Connected controllers excluded by `brandFilter`. */\n otherSlots: ControllerSlotInfo[];\n activeSlotId: string | null;\n /** Key of the per-controller memory used this frame (`activeSlotId` or a placeholder). */\n slotKey: string;\n /** Raw input of the active controller (empty state when none is bound). */\n input: UnifiedInputState;\n /** True when any bound controller received intentional input this frame. */\n triggered: boolean;\n /** Live per-controller measurements (mutated in place by later frames). */\n diagnostics: SlotDiagnostics;\n}\n\nexport interface ControllerTelemetry {\n /** Samples all controllers once; call every animation frame with `performance.now()`. */\n update(now: number): TelemetryFrame;\n /** Manually selects a controller and pauses auto-switching briefly so it isn't undone. */\n selectSlot(slotId: string, now: number): void;\n /** Clears circularity, drift, bounce and tested-button memory for the current controller. */\n resetActive(): void;\n /** Returns (creating if needed) the stored measurements for a controller key. */\n getDiagnostics(slotKey: string): SlotDiagnostics;\n}\n\nexport function createControllerTelemetry(options: ControllerTelemetryOptions): ControllerTelemetry {\n const { source, brandFilter } = options;\n const setActive = options.setActiveSlot ?? ((id: string) => void source.setActiveSlot(id));\n const switcher = new SlotAutoSwitcher();\n const memory = new Map<string, SlotDiagnostics>();\n let latestSamples: SlotMotionSample[] = [];\n let activeKey = brandFilter ? `__none_${brandFilter}__` : '__none__';\n\n const createDiagnostics = (): SlotDiagnostics => ({\n circularity: { left: createCircularity(), right: createCircularity() },\n drift: new StickDriftTracker(options.drift),\n bounce: new ButtonBounceTracker(options.bounce),\n tested: new Set<ButtonName>(),\n });\n\n const getDiagnostics = (key: string): SlotDiagnostics => {\n let d = memory.get(key);\n if (!d) {\n d = createDiagnostics();\n memory.set(key, d);\n }\n return d;\n };\n\n return {\n update(now) {\n const allSlots = source.getConnectedControllers();\n const slots = brandFilter ? allSlots.filter((s) => s.identity.brand === brandFilter) : allSlots;\n const otherSlots = brandFilter ? allSlots.filter((s) => s.identity.brand !== brandFilter) : [];\n\n const globalActiveId = source.getActiveSlotId();\n let activeSlotId: string | null = globalActiveId;\n if (brandFilter) {\n if (slots.length === 0) {\n activeSlotId = null;\n } else if (!globalActiveId || !slots.some((s) => s.id === globalActiveId)) {\n activeSlotId = slots[0].id;\n setActive(activeSlotId);\n }\n }\n\n let triggered = false;\n if (slots.length > 0) {\n latestSamples = slots.map((slot) => {\n const s = source.getInputState(slot.id);\n return {\n id: slot.id,\n lastActivityAt: slot.lastActivityAt,\n lx: s.lx,\n ly: s.ly,\n rx: s.rx,\n ry: s.ry,\n l2: s.l2,\n r2: s.r2,\n };\n });\n const { switchTo, triggeredSlotId } = switcher.evaluate(latestSamples, activeSlotId, now);\n if (switchTo && switchTo !== activeSlotId) {\n activeSlotId = switchTo;\n setActive(switchTo);\n }\n triggered = triggeredSlotId !== null;\n } else {\n latestSamples = [];\n }\n\n const slotKey = activeSlotId ?? (brandFilter ? `__none_${brandFilter}__` : '__none__');\n activeKey = slotKey;\n const diagnostics = getDiagnostics(slotKey);\n\n const input = activeSlotId\n ? source.getInputState(activeSlotId)\n : brandFilter\n ? createEmptyInput()\n : source.getInputState();\n\n if (input.connected) {\n updateCircularity(diagnostics.circularity.left, input.lx, input.ly);\n updateCircularity(diagnostics.circularity.right, input.rx, input.ry);\n diagnostics.drift.update(input.lx, input.ly, input.rx, input.ry, now);\n diagnostics.bounce.update(input.buttons, now);\n for (const [btn, pressed] of Object.entries(input.buttons) as Array<[ButtonName, boolean]>) {\n if (pressed) diagnostics.tested.add(btn);\n }\n }\n\n return { now, slots, otherSlots, activeSlotId, slotKey, input, triggered, diagnostics };\n },\n\n selectSlot(slotId, now) {\n switcher.notifyManualSelect(latestSamples, now);\n setActive(slotId);\n },\n\n resetActive() {\n memory.set(activeKey, createDiagnostics());\n },\n\n getDiagnostics,\n };\n}\n"],
5
+ "mappings": "AAMA;AAAA,EACE;AAAA,OAKK;AACP,SAAS,wBAA+C;AACxD,SAAS,mBAAmB,yBAAgD;AAC5E;AAAA,EACE;AAAA,EACA;AAAA,OAGK;AA0DA,SAAS,0BAA0B,SAA0D;AAClG,QAAM,EAAE,QAAQ,YAAY,IAAI;AAChC,QAAM,YAAY,QAAQ,kBAAkB,CAAC,OAAe,KAAK,OAAO,cAAc,EAAE;AACxF,QAAM,WAAW,IAAI,iBAAiB;AACtC,QAAM,SAAS,oBAAI,IAA6B;AAChD,MAAI,gBAAoC,CAAC;AACzC,MAAI,YAAY,cAAc,UAAU,WAAW,OAAO;AAE1D,QAAM,oBAAoB,OAAwB;AAAA,IAChD,aAAa,EAAE,MAAM,kBAAkB,GAAG,OAAO,kBAAkB,EAAE;AAAA,IACrE,OAAO,IAAI,kBAAkB,QAAQ,KAAK;AAAA,IAC1C,QAAQ,IAAI,oBAAoB,QAAQ,MAAM;AAAA,IAC9C,QA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oB;AAAA,MAClC,OAAO;AACL,wBAAgB,CAAC;AAAA,MACnB;AAEA,YAAM,UAAU,iBAAiB,cAAc,UAAU,WAAW,OAAO;AAC3E,kBAAY;AACZ,YAAM,cAAc,eAAe,OAAO;AAE1C,YAAM,QAAQ,eACV,OAAO,cAAc,YAAY,IACjC,cACE,iBAAiB,IACjB,OAAO,cAAc;AAE3B,UAAI,MAAM,WAAW;AACnB,0BAAkB,YAAY,YAAY,MAAM,MAAM,IAAI,MAAM,EAAE;AAClE,0BAAkB,YAAY,YAAY,OAAO,MAAM,IAAI,MAAM,EAAE;AACnE,oBAAY,MAAM,OAAO,MAAM,IAAI,MAAM,IAAI,MAAM,IAAI,MAAM,IAAI,GAAG;AACpE,oBAAY,OAAO,OAAO,MAAM,SAAS,GAAG;AAC5C,mBAAW,CAAC,KAAK,OAAO,KAAK,OAAO,QAAQ,MAAM,OAAO,GAAmC;AAC1F,cAAI,QAAS,aAAY,OAAO,IAAI,GAAG;AAAA,QACzC;AAAA,MACF;AAEA,aAAO,EAAE,KAAK,OAAO,YAAY,cAAc,SAAS,OAAO,WAAW,YAAY;AAAA,IACxF;AAAA,IAEA,WAAW,QAAQ,KAAK;AACtB,eAAS,mBAAmB,eAAe,GAAG;AAC9C,gBAAU,MAAM;AAAA,IAClB;AAAA,IAEA,cAAc;AACZ,aAAO,IAAI,WAAW,kBAAkB,CAAC;AAAA,IAC3C;AAAA,IAEA;AAAA,EACF;AACF;",
6
+ "names": []
7
+ }
@@ -0,0 +1,40 @@
1
+ import { type GamepadlyHub, type GamepadlyHubOptions } from '../hub.js';
2
+ import type { GameSDK, GameStorage } from './types.js';
3
+ export interface GameHostOptions<TLocale extends string = string> {
4
+ gameId: string;
5
+ locale: TLocale;
6
+ /**
7
+ * Options for the game-scoped hub. Pass a shared `hid` (and `audio` / `samples`) from your app and
8
+ * set `autoHotplug: false` / `autoEmergencyReset: false` if the app already manages those.
9
+ */
10
+ hub?: GamepadlyHubOptions;
11
+ /**
12
+ * Optional live multiplayer seat map (`[slotIdForP1, slotIdForP2, ...]`). When provided,
13
+ * `sdk.players.get(seatIndex)` follows `seats[seatIndex]` (an idle handle while it is `null`).
14
+ */
15
+ getPlayerSeats?: () => ReadonlyArray<string | null>;
16
+ /** Best-score storage. Defaults to `localStorage` under `${storageKeyPrefix}${gameId}`. */
17
+ storage?: GameStorage;
18
+ /** Key prefix for the default `localStorage` storage. Default `'gamepadly:best:'`. */
19
+ storageKeyPrefix?: string;
20
+ /**
21
+ * Hide the manager's synthesized keyboard-fallback state from games (default `true`), so each
22
+ * game's own `createActions()` keyboard bindings stay the single source of keyboard input.
23
+ */
24
+ isolateKeyboardFallback?: boolean;
25
+ /** Mark the SDK as a static preview render (`sdk.showcase`). */
26
+ showcase?: boolean;
27
+ }
28
+ export interface GameHost<TLocale extends string = string> {
29
+ readonly sdk: GameSDK<TLocale>;
30
+ /** The game-scoped hub (for host UI such as connect buttons; games only see `sdk`). */
31
+ readonly hub: GamepadlyHub;
32
+ /** Re-notifies `onCapabilitiesChange` subscribers after seat assignments change. */
33
+ notifyPlayerSeatsChanged(): void;
34
+ /** Stops mic sensors, haptics, triggers and samples started by the game, then frees listeners. */
35
+ dispose(): void;
36
+ }
37
+ /** `localStorage`-backed best score that silently degrades when storage is unavailable. */
38
+ export declare function createLocalBestScoreStorage(key: string): GameStorage;
39
+ export declare function createGameHost<TLocale extends string = string>(opts: GameHostOptions<TLocale>): GameHost<TLocale>;
40
+ //# sourceMappingURL=host.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"host.d.ts","sourceRoot":"","sources":["../../src/game/host.ts"],"names":[],"mappings":"AAaA,OAAO,EAIL,KAAK,YAAY,EACjB,KAAK,mBAAmB,EAEzB,MAAM,WAAW,CAAC;AAEnB,OAAO,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEvD,MAAM,WAAW,eAAe,CAAC,OAAO,SAAS,MAAM,GAAG,MAAM;IAC9D,MAAM,EA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