-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
262 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
diff --git a/package.json b/package.json | ||
index 6df2387cbfaead99f6fa36a8d6a5b11900a05bb4..3b5586d74fb8f7312c64406dda8a8ef0ced929ac 100644 | ||
--- a/package.json | ||
+++ b/package.json | ||
@@ -91,9 +91,5 @@ | ||
}, | ||
"main": "dist/Bacon.js", | ||
"module": "./dist/Bacon.mjs", | ||
- "exports": { | ||
- "import": "./dist/Bacon.mjs", | ||
- "require": "./dist/Bacon.js" | ||
- }, | ||
"types": "types/bacon.d.ts" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { API_COMMAND } from "./api"; | ||
import { process_packets, send_data } from "./packet"; | ||
|
||
export async function getDeviceInfo(dev: HIDDevice) { | ||
await send_data(dev, [API_COMMAND.GET_DEVICE_INFO], true); | ||
return process_packets(dev, true); | ||
} | ||
|
||
export async function getStageConfig(dev: HIDDevice) { | ||
await send_data(dev, [API_COMMAND.GET_CONFIG_V5], true); | ||
return process_packets(dev, true); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import * as Bacon from "baconjs"; | ||
import { Provider } from "jotai"; | ||
import { createRoot } from "react-dom/client"; | ||
|
||
import { uiState } from "./state.ts"; | ||
import { UI } from "./ui.tsx"; | ||
|
||
Bacon.fromEvent(document, "DOMContentLoaded").onValue(async () => { | ||
const rootEl = document.getElementById("root"); | ||
if (!rootEl) return; | ||
const reactRoot = createRoot(rootEl); | ||
reactRoot.render( | ||
<Provider store={uiState}> | ||
<UI /> | ||
</Provider>, | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { getDeviceInfo, getStageConfig } from "../sdk"; | ||
import { SMX_USB_PRODUCT_ID, SMX_USB_VENDOR_ID } from "../sdk/api"; | ||
import { SMXConfig } from "../sdk/commands/config"; | ||
import { SMXDeviceInfo } from "../sdk/commands/data_info"; | ||
import { devices$, nextStatusTextLine$, statusText$, uiState } from "./state"; | ||
|
||
// function formatDataForDisplay(data: DataView) { | ||
// const len = data.byteLength; | ||
|
||
// // Read raw report into groups of 8 bytes. | ||
// let str = ""; | ||
// for (let i = 0; i !== len; ++i) { | ||
// if (i !== 0 && i % 8 === 0) str += "\n"; | ||
|
||
// // biome-ignore lint/style/useTemplate: <explanation> | ||
// str += data.getUint8(i).toString(2).padStart(8, "0") + " "; | ||
// } | ||
|
||
// // Read raw report into groups of 8 bytes of hex | ||
// str += "\n\n"; | ||
// for (let i = 0; i !== len; ++i) { | ||
// if (i !== 0 && i % 8 === 0) str += "\n"; | ||
|
||
// // biome-ignore lint/style/useTemplate: <explanation> | ||
// str += data.getUint8(i).toString(16).padStart(2, "0") + " "; | ||
// } | ||
|
||
// return `report:\n${str}`; | ||
// } | ||
|
||
export async function promptSelectDevice() { | ||
const devices = await navigator.hid.requestDevice({ | ||
filters: [{ vendorId: SMX_USB_VENDOR_ID, productId: SMX_USB_PRODUCT_ID }], | ||
}); | ||
|
||
if (!devices.length || !devices[0]) { | ||
uiState.set(statusText$, "no device selected"); | ||
return; | ||
} | ||
|
||
await open_smx_device(devices[0]); | ||
} | ||
|
||
export async function open_smx_device(dev: HIDDevice) { | ||
if (!dev.opened) { | ||
await dev.open(); | ||
} | ||
// Get the device info an find the player number | ||
const packet = await getDeviceInfo(dev); | ||
const device_info = new SMXDeviceInfo(packet); | ||
uiState.set(devices$, (devices) => { | ||
return { | ||
...devices, | ||
[device_info.player]: dev, | ||
}; | ||
}); | ||
uiState.set( | ||
nextStatusTextLine$, | ||
`status: device opened: ${dev.productName}:P${device_info.player}:${device_info.serial}`, | ||
); | ||
} | ||
|
||
export async function requestConfig(dev: HIDDevice) { | ||
const response = await getStageConfig(dev); | ||
|
||
console.log("Raw Bytes: ", response); | ||
const smxconfig = new SMXConfig(response); | ||
console.log("Decoded Config:", smxconfig.config); | ||
|
||
// Right now I just want to confirm that decoding and re-encoding gives back the same data | ||
const encoded_config = smxconfig.encode(); | ||
if (encoded_config) { | ||
console.log("Encoded Config:", smxconfig.config); | ||
const buf = new Uint8Array(encoded_config.buffer); | ||
console.log("Encoded Bytes: ", buf); | ||
console.log("Same Thing:", response.slice(2, -1).toString() === buf.toString()); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { atom, createStore } from "jotai"; | ||
|
||
export const browserSupported = "hid" in navigator; | ||
|
||
/** actually holds the state of each atom */ | ||
export const uiState = createStore(); | ||
|
||
/** backing atom of all known devices */ | ||
export const devices$ = atom<Record<number, HIDDevice | undefined>>({}); | ||
|
||
/** current p1 pad, derived from devices$ above */ | ||
export const p1Dev$ = atom<HIDDevice | undefined, [HIDDevice | undefined], void>( | ||
(get) => get(devices$)[1], | ||
(_, set, dev: HIDDevice | undefined) => { | ||
set(devices$, (prev) => ({ ...prev, [1]: dev })); | ||
}, | ||
); | ||
|
||
/** current p2 pad, derived from devices$ above */ | ||
export const p2Dev$ = atom<HIDDevice | undefined, [HIDDevice | undefined], void>( | ||
(get) => get(devices$)[2], | ||
(_, set, dev: HIDDevice | undefined) => { | ||
set(devices$, (prev) => ({ ...prev, [2]: dev })); | ||
}, | ||
); | ||
|
||
export const statusText$ = atom( | ||
browserSupported | ||
? "no device connected" | ||
: "HID API not supported, use Google Chrome or MS Edge browsers for this tool", | ||
); | ||
|
||
/** write-only atom. write to this to append a line to statusText */ | ||
export const nextStatusTextLine$ = atom(null, (_, set, line: string) => set(statusText$, (prev) => prev + line)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.