# Diagnostics

> Build your own controller tester with raw axes, 72-sector stick circularity, resting drift, and button bounce detection.

Source: https://gamepadly.com/sdk/guides/diagnostics

`@gamepadly/sdk/diagnostics` is the headless core of the [gamepadly.com](https://gamepadly.com) controller tester.
It measures; you draw.

```ts
import { createGamepadly } from '@gamepadly/sdk';
import { buildSectorPath, createControllerTelemetry } from '@gamepadly/sdk/diagnostics';

const hub = createGamepadly();
const telemetry = createControllerTelemetry({ source: hub.hid });

function frame(now: number) {
  const f = telemetry.update(now);

  const ring = f.diagnostics.circularity.left;
  leftRing.setAttribute('d', buildSectorPath(ring.sectors, 80, 80, 58));
  coverage.textContent = `${ring.coveragePct.toFixed(0)}% swept`;
  error.textContent = ring.avgErrorPct === null ? '—' : `${ring.avgErrorPct.toFixed(1)}% error`;

  const drift = f.diagnostics.drift.getSnapshot();
  leftDrift.textContent = drift.left.verdict; // 'waiting' | 'normal' | 'mild' | 'drift'

  bounced.textContent = f.diagnostics.bounce.getBouncedButtons().join(', ');
  tested.textContent = `${f.diagnostics.tested.size} buttons tested`;

  requestAnimationFrame(frame);
}
requestAnimationFrame(frame);
```

## What each measurement means

| Measurement | How it works |
| :--- | :--- |
| **Circularity** | The stick's travel is split into 72 sectors. Rotating the stick fills each with its peak radius. `avgErrorPct` is the mean distance from a perfect circle, and `coveragePct` how much of the circle was swept. |
| **Drift** | When the stick rests, the tracker records the peak offset from center and the jitter. Verdicts go from `'waiting'` (not settled yet) to `'normal'`, `'mild'`, or `'drift'`. Thresholds are configurable with the `drift` option. |
| **Bounce** | A release followed by a re-press within a few milliseconds is contact bounce from a worn switch. Tune with the `bounce` option. |
| **Tested** | The set of buttons pressed at least once, for "press every button" checklists. |

Axes in `f.input` are raw, with no deadzone, so the numbers reflect the hardware.

## Several controllers

The telemetry switches to whichever controller receives deliberate input and keeps separate measurements for
each one. `f.slots` lists them and `f.activeSlotId` is the one being shown. Call `telemetry.selectSlot(id, now)`
to pick one manually and `telemetry.resetActive()` to clear its measurements. Pass `brandFilter: 'sony'` to build
a brand-specific tester.

See the [diagnostics example](https://gamepadly.com/sdk/examples#controller-diagnostics) for a complete page.
