Skip to content
Draft
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
70 changes: 70 additions & 0 deletions THIRD-PARTY-LICENSES
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,76 @@ SOFTWARE.

================================================================================

joycon-webhid
https://github.com/aka256/joycon-webhid

Switch Pro Controller NFC protocol implementation in
src/lib/drivers/procon/ was informed by the joycon-webhid WebHID
implementation.

License: MIT

Copyright (c) 2021 aka

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

================================================================================

jc_toolkit
https://github.com/CTCaer/jc_toolkit

MCU and NFC command sequences in src/lib/drivers/procon/ were
cross-referenced with jc_toolkit's Joy-Con protocol implementation.

License: MIT

Copyright (c) 2017 CTCaer

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

================================================================================

Nintendo_Switch_Reverse_Engineering
https://github.com/dekuNukem/Nintendo_Switch_Reverse_Engineering

HID report structures and MCU/NFC state machine documentation in
src/lib/drivers/procon/ were referenced from dekuNukem's reverse
engineering notes. No license specified in that repository.

================================================================================

AmiiboAPI
https://github.com/N3evin/AmiiboAPI

Expand Down
64 changes: 64 additions & 0 deletions src/hooks/use-connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { HidTransport } from "@/lib/transport/hid-transport";
import { GBxCartDriver } from "@/lib/drivers/gbxcart/gbxcart-driver";
import { PowerSaveDriver } from "@/lib/drivers/powersave/powersave-driver";
import { DEVICE_FILTERS } from "@/lib/drivers/powersave/powersave-commands";
import { ProConDriver } from "@/lib/drivers/procon/procon-driver";
import { DEVICE_FILTERS as PROCON_FILTERS } from "@/lib/drivers/procon/procon-commands";
import type { DeviceDriver, DeviceInfo, Transport } from "@/lib/types";

// ─── Device probing ──────────────────────────────────────────────────────
Expand Down Expand Up @@ -273,6 +275,38 @@ export function useConnection({ log, onReady }: UseConnectionOptions) {
const info = await psDriver.initialize();
log(`Connected: ${info.deviceName}`);
finishConnect(psDriver, info, "POWERSAVE");
return;
} catch (e) {
log(`Auto-reconnect failed: ${(e as Error).message}`, "warn");
}
}

const pcDevice = devices.find((d) =>
PROCON_FILTERS.some(
(f) => f.vendorId === d.vendorId && f.productId === d.productId,
),
);
if (pcDevice && !driverRef.current) {
log("Reconnecting to Pro Controller...");
try {
const transport = new HidTransport(PROCON_FILTERS);
const identity = await transport.connectWithDevice(pcDevice);
log(`HID device opened: ${identity.name}`);

transport.on("onDisconnect", () => {
log("Device disconnected", "warn");
handleDisconnect();
});

const pcDriver = new ProConDriver(
transport,
identity.raw as HIDDevice,
);
pcDriver.on("onLog", (msg, level) => log(msg, level));

const info = await pcDriver.initialize();
log(`Connected: ${info.deviceName}`);
finishConnect(pcDriver, info, "PROCON");
} catch (e) {
log(`Auto-reconnect failed: ${(e as Error).message}`, "warn");
}
Expand Down Expand Up @@ -357,6 +391,36 @@ export function useConnection({ log, onReady }: UseConnectionOptions) {
finishConnect(psDriver, info, deviceId);
break;
}

case "PROCON": {
const transport = new HidTransport(PROCON_FILTERS);
let identity;
if (authorized) {
log("Connecting...");
identity = await transport.connectWithDevice(
authorized as HIDDevice,
);
} else {
log("Requesting HID device...");
identity = await transport.connect();
}

transport.on("onDisconnect", () => {
log("Device disconnected", "warn");
handleDisconnect();
});

const pcDriver = new ProConDriver(
transport,
identity.raw as HIDDevice,
);
pcDriver.on("onLog", (msg, level) => log(msg, level));

const pcInfo = await pcDriver.initialize();
log(`Connected: ${pcInfo.deviceName}`);
finishConnect(pcDriver, pcInfo, deviceId);
break;
}
}
} catch (e) {
const msg = (e as Error).message;
Expand Down
11 changes: 11 additions & 0 deletions src/lib/core/devices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,15 @@ export const DEVICES: Record<string, DeviceDef> = {
"Datel NFC portal. Also supports MaxLander/NaMiio clones. " +
"Protocol: github.com/malc0mn/amiigo",
},
PROCON: {
id: "PROCON",
name: "Switch Pro Controller",
vendorId: 0x057e,
productId: 0x2009,
transport: "webhid",
systems: [{ id: "amiibo", name: "Amiibo (NTAG215)" }],
notes:
"Reads Amiibo via the Pro Controller's built-in NFC reader. " +
"Also supports Joy-Con (R). Linux blocked: HID descriptor omits report 0x31.",
},
};
Loading