Skip to content
Merged
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
22 changes: 22 additions & 0 deletions proto/cormoran/kscan_diagnostics/kscan_diagnostics.proto
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,27 @@ message ResetStats {}

message Ok {}

// Relay a query to the split peripheral half/halves. `payload` is an encoded
// Request that the peripheral runs against its own topology/stats tables; the
// result comes back asynchronously as a PeripheralEvent notification, not in
// this call's Response (which is just an Ok, or Error if this build is not a
// split central). The query is broadcast to all connected peripherals and each
// replies with its `source` stamped; the client correlates by (source, req_id).
message QueryPeripheral {
uint32 req_id = 1;
bytes payload = 2;
}

// Firmware-initiated notification carrying one peripheral's reply to a
// QueryPeripheral. `source` is the peripheral index (1-based; central is 0),
// `req_id` echoes the triggering QueryPeripheral, and `payload` is an encoded
// Response produced by that peripheral's query dispatch.
message PeripheralEvent {
uint32 source = 1;
uint32 req_id = 2;
bytes payload = 3;
}

message Request {
oneof request_type {
GetInfo get_info = 1;
Expand All @@ -135,6 +156,7 @@ message Request {
GetPositionMap get_position_map = 5;
GetStats get_stats = 6;
ResetStats reset_stats = 7;
QueryPeripheral query_peripheral = 8;
}
}

Expand Down
58 changes: 58 additions & 0 deletions src/components/troubleshooting/KscanDiagnosticsSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ export function KscanDiagnosticsSection({
isLoadingTopology,
topologyError,
loadTopology,
peripheralTopologies,
isLoadingPeripheralTopologies,
peripheralTopologyErrors,
peripheralDiscoveryError,
loadPeripheralTopologies,
} = kscan;
const [showResetConfirm, setShowResetConfirm] = useState(false);
const [hasRequestedTopology, setHasRequestedTopology] = useState(false);
Expand All @@ -81,6 +86,7 @@ export function KscanDiagnosticsSection({
if (hasRequestedTopology) return;
setHasRequestedTopology(true);
void loadTopology();
void loadPeripheralTopologies();
void officialLayouts.load();
};

Expand Down Expand Up @@ -211,6 +217,58 @@ export function KscanDiagnosticsSection({
</div>
)}

{/* Peripheral halves */}
{isLoadingPeripheralTopologies && peripheralTopologies.size === 0 && (
<LoadingIndicator
variant="inline"
className="mb-4"
label={t("Loading peripheral wiring…")}
/>
)}
{peripheralDiscoveryError && (
<SectionError message={t(peripheralDiscoveryError)} />
)}
{[...peripheralTopologyErrors.entries()].map(([src, msg]) => (
<SectionError
key={src}
message={t("Peripheral {{src}}: {{msg}}", { src, msg })}
/>
))}
{[...peripheralTopologies.entries()].map(([src, periph]) => {
const peripheralActiveLayout =
periph.layouts.find(
(l) => l.layoutIndex === periph.selectedLayout,
) ??
periph.layouts[0] ??
null;
const peripheralWiring = peripheralActiveLayout
? buildWiringMap(periph, peripheralActiveLayout)
: new Map();
return (
<div key={src} className="mb-4">
<p className="text-xs font-medium uppercase tracking-wide text-[var(--color-text-muted)] mb-2">
{t("Peripheral {{src}}", { src })}
{peripheralActiveLayout && (
<span className="ml-2 normal-case font-normal">
— {peripheralActiveLayout.displayName}
</span>
)}
</p>
{physicalLayout && peripheralActiveLayout ? (
<KscanKeyboardView
layout={physicalLayout}
wiring={peripheralWiring}
statsByPosition={new Map()}
/>
) : (
<p className="text-xs text-[var(--color-text-muted)]">
{t("Wiring info received — no matching physical layout.")}
</p>
)}
</div>
);
})}

{/* Driver info + suspect-key stats table, collapsed by default */}
<details className="mt-2">
<summary className="cursor-pointer text-xs font-medium uppercase tracking-wide text-[var(--color-text-muted)]">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ function baseKscan(
isLoadingTopology: false,
topologyError: null,
loadTopology: jest.fn(),
peripheralTopologies: new Map(),
isLoadingPeripheralTopologies: false,
peripheralTopologyErrors: new Map(),
peripheralDiscoveryError: null,
loadPeripheralTopologies: jest.fn(),
...overrides,
};
}
Expand Down Expand Up @@ -130,16 +135,22 @@ describe("KscanDiagnosticsSection", () => {
expect(loadTopology).not.toHaveBeenCalled();
});

it("calls loadTopology and the official layouts loader on first expand", async () => {
it("calls loadTopology, loadPeripheralTopologies, and the official layouts loader on first expand", async () => {
const loadTopology = jest.fn();
const loadPeripheralTopologies = jest.fn();
const load = jest.fn();
mockOfficialLayoutsReturn({ load });

render(<KscanDiagnosticsSection kscan={baseKscan({ loadTopology })} />);
render(
<KscanDiagnosticsSection
kscan={baseKscan({ loadTopology, loadPeripheralTopologies })}
/>,
);

fireEvent.click(screen.getByRole("button", { name: "Key Switches" }));

await waitFor(() => expect(loadTopology).toHaveBeenCalledTimes(1));
expect(loadPeripheralTopologies).toHaveBeenCalledTimes(1);
expect(load).toHaveBeenCalledTimes(1);
});

Expand Down
Loading
Loading