@potatosalad775/eqcaps-device-bridge 0.2.0
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.
- package/LICENSE +21 -0
- package/NOTICE.md +54 -0
- package/README.md +112 -0
- package/dist/analysis.d.ts +34 -0
- package/dist/analysis.d.ts.map +1 -0
- package/dist/analysis.js +92 -0
- package/dist/analysis.js.map +1 -0
- package/dist/biquad.d.ts +9 -0
- package/dist/biquad.d.ts.map +1 -0
- package/dist/biquad.js +50 -0
- package/dist/biquad.js.map +1 -0
- package/dist/browser/index.d.ts +14 -0
- package/dist/browser/index.d.ts.map +1 -0
- package/dist/browser/index.js +12 -0
- package/dist/browser/index.js.map +1 -0
- package/dist/browser/stream.d.ts +15 -0
- package/dist/browser/stream.d.ts.map +1 -0
- package/dist/browser/stream.js +51 -0
- package/dist/browser/stream.js.map +1 -0
- package/dist/browser/web-apis.d.ts +136 -0
- package/dist/browser/web-apis.d.ts.map +1 -0
- package/dist/browser/web-apis.js +13 -0
- package/dist/browser/web-apis.js.map +1 -0
- package/dist/browser/webbluetooth.d.ts +30 -0
- package/dist/browser/webbluetooth.d.ts.map +1 -0
- package/dist/browser/webbluetooth.js +80 -0
- package/dist/browser/webbluetooth.js.map +1 -0
- package/dist/browser/webhid.d.ts +33 -0
- package/dist/browser/webhid.d.ts.map +1 -0
- package/dist/browser/webhid.js +90 -0
- package/dist/browser/webhid.js.map +1 -0
- package/dist/browser/webserial.d.ts +34 -0
- package/dist/browser/webserial.d.ts.map +1 -0
- package/dist/browser/webserial.js +133 -0
- package/dist/browser/webserial.js.map +1 -0
- package/dist/bytes.d.ts +40 -0
- package/dist/bytes.d.ts.map +1 -0
- package/dist/bytes.js +74 -0
- package/dist/bytes.js.map +1 -0
- package/dist/chooser.d.ts +40 -0
- package/dist/chooser.d.ts.map +1 -0
- package/dist/chooser.js +49 -0
- package/dist/chooser.js.map +1 -0
- package/dist/device.d.ts +51 -0
- package/dist/device.d.ts.map +1 -0
- package/dist/device.js +94 -0
- package/dist/device.js.map +1 -0
- package/dist/errors.d.ts +24 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +12 -0
- package/dist/errors.js.map +1 -0
- package/dist/handler.d.ts +161 -0
- package/dist/handler.d.ts.map +1 -0
- package/dist/handler.js +3 -0
- package/dist/handler.js.map +1 -0
- package/dist/handlers/airoha.d.ts +12 -0
- package/dist/handlers/airoha.d.ts.map +1 -0
- package/dist/handlers/airoha.js +135 -0
- package/dist/handlers/airoha.js.map +1 -0
- package/dist/handlers/conexant-usb-hid.d.ts +4 -0
- package/dist/handlers/conexant-usb-hid.d.ts.map +1 -0
- package/dist/handlers/conexant-usb-hid.js +103 -0
- package/dist/handlers/conexant-usb-hid.js.map +1 -0
- package/dist/handlers/edifier-serial.d.ts +6 -0
- package/dist/handlers/edifier-serial.d.ts.map +1 -0
- package/dist/handlers/edifier-serial.js +111 -0
- package/dist/handlers/edifier-serial.js.map +1 -0
- package/dist/handlers/fiio-f110.d.ts +7 -0
- package/dist/handlers/fiio-f110.d.ts.map +1 -0
- package/dist/handlers/fiio-f110.js +101 -0
- package/dist/handlers/fiio-f110.js.map +1 -0
- package/dist/handlers/fiio-usb-hid.d.ts +39 -0
- package/dist/handlers/fiio-usb-hid.d.ts.map +1 -0
- package/dist/handlers/fiio-usb-hid.js +143 -0
- package/dist/handlers/fiio-usb-hid.js.map +1 -0
- package/dist/handlers/fiio-usb-serial.d.ts +9 -0
- package/dist/handlers/fiio-usb-serial.d.ts.map +1 -0
- package/dist/handlers/fiio-usb-serial.js +122 -0
- package/dist/handlers/fiio-usb-serial.js.map +1 -0
- package/dist/handlers/fosi-audio-usb-hid.d.ts +19 -0
- package/dist/handlers/fosi-audio-usb-hid.d.ts.map +1 -0
- package/dist/handlers/fosi-audio-usb-hid.js +165 -0
- package/dist/handlers/fosi-audio-usb-hid.js.map +1 -0
- package/dist/handlers/index.d.ts +25 -0
- package/dist/handlers/index.d.ts.map +1 -0
- package/dist/handlers/index.js +36 -0
- package/dist/handlers/index.js.map +1 -0
- package/dist/handlers/jds-labs-usb-serial.d.ts +5 -0
- package/dist/handlers/jds-labs-usb-serial.d.ts.map +1 -0
- package/dist/handlers/jds-labs-usb-serial.js +156 -0
- package/dist/handlers/jds-labs-usb-serial.js.map +1 -0
- package/dist/handlers/ktmicro-usb-hid.d.ts +20 -0
- package/dist/handlers/ktmicro-usb-hid.d.ts.map +1 -0
- package/dist/handlers/ktmicro-usb-hid.js +144 -0
- package/dist/handlers/ktmicro-usb-hid.js.map +1 -0
- package/dist/handlers/moondrop-edge-serial.d.ts +8 -0
- package/dist/handlers/moondrop-edge-serial.d.ts.map +1 -0
- package/dist/handlers/moondrop-edge-serial.js +100 -0
- package/dist/handlers/moondrop-edge-serial.js.map +1 -0
- package/dist/handlers/moondrop-old-fashioned-hid.d.ts +4 -0
- package/dist/handlers/moondrop-old-fashioned-hid.d.ts.map +1 -0
- package/dist/handlers/moondrop-old-fashioned-hid.js +102 -0
- package/dist/handlers/moondrop-old-fashioned-hid.js.map +1 -0
- package/dist/handlers/moondrop-usb-hid.d.ts +8 -0
- package/dist/handlers/moondrop-usb-hid.d.ts.map +1 -0
- package/dist/handlers/moondrop-usb-hid.js +134 -0
- package/dist/handlers/moondrop-usb-hid.js.map +1 -0
- package/dist/handlers/nothing-usb-serial.d.ts +19 -0
- package/dist/handlers/nothing-usb-serial.d.ts.map +1 -0
- package/dist/handlers/nothing-usb-serial.js +141 -0
- package/dist/handlers/nothing-usb-serial.js.map +1 -0
- package/dist/handlers/qudelix-usb-hid.d.ts +16 -0
- package/dist/handlers/qudelix-usb-hid.d.ts.map +1 -0
- package/dist/handlers/qudelix-usb-hid.js +127 -0
- package/dist/handlers/qudelix-usb-hid.js.map +1 -0
- package/dist/handlers/tanchjim-rita-serial.d.ts +5 -0
- package/dist/handlers/tanchjim-rita-serial.d.ts.map +1 -0
- package/dist/handlers/tanchjim-rita-serial.js +89 -0
- package/dist/handlers/tanchjim-rita-serial.js.map +1 -0
- package/dist/handlers/walkplay-hid.d.ts +12 -0
- package/dist/handlers/walkplay-hid.d.ts.map +1 -0
- package/dist/handlers/walkplay-hid.js +150 -0
- package/dist/handlers/walkplay-hid.js.map +1 -0
- package/dist/identity.d.ts +20 -0
- package/dist/identity.d.ts.map +1 -0
- package/dist/identity.js +30 -0
- package/dist/identity.js.map +1 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +12 -0
- package/dist/index.js.map +1 -0
- package/dist/io.d.ts +50 -0
- package/dist/io.d.ts.map +1 -0
- package/dist/io.js +119 -0
- package/dist/io.js.map +1 -0
- package/dist/platform.d.ts +9 -0
- package/dist/platform.d.ts.map +1 -0
- package/dist/platform.js +59 -0
- package/dist/platform.js.map +1 -0
- package/dist/protocols.d.ts +52 -0
- package/dist/protocols.d.ts.map +1 -0
- package/dist/protocols.js +204 -0
- package/dist/protocols.js.map +1 -0
- package/dist/transport.d.ts +59 -0
- package/dist/transport.d.ts.map +1 -0
- package/dist/transport.js +12 -0
- package/dist/transport.js.map +1 -0
- package/package.json +38 -0
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A database entry, as the client's index lists it: a profile id, how to recognize the device and
|
|
3
|
+
* how to drive it.
|
|
4
|
+
*/
|
|
5
|
+
export interface ChooserEntry {
|
|
6
|
+
id: string;
|
|
7
|
+
protocol?: unknown;
|
|
8
|
+
match?: {
|
|
9
|
+
usb?: readonly {
|
|
10
|
+
vendorId: string | readonly string[];
|
|
11
|
+
}[];
|
|
12
|
+
bluetooth?: readonly {
|
|
13
|
+
name?: string | readonly string[];
|
|
14
|
+
namePrefix?: string | readonly string[];
|
|
15
|
+
}[];
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
/** What to offer in a browser's device chooser. */
|
|
19
|
+
export interface ChooserFilters {
|
|
20
|
+
hidVendorIds: number[];
|
|
21
|
+
/** USB serial ports. */
|
|
22
|
+
serialVendorIds: number[];
|
|
23
|
+
/** Bluetooth serial (RFCOMM) service classes. */
|
|
24
|
+
sppServiceClasses: string[];
|
|
25
|
+
/** BLE advertised names. Empty: offer every device. */
|
|
26
|
+
bleNames: ({
|
|
27
|
+
name: string;
|
|
28
|
+
} | {
|
|
29
|
+
namePrefix: string;
|
|
30
|
+
})[];
|
|
31
|
+
/** Every GATT service a handler uses (Web Bluetooth's `optionalServices`). */
|
|
32
|
+
gattServices: string[];
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Chooser filters for the devices in `entries` that have a protocol, plus the HID vendors
|
|
36
|
+
* `guessProtocol` knows. The bridge holds no device identities (D33): pass the database's
|
|
37
|
+
* entries (`(await client.loadIndex())?.profiles`) to offer the devices it knows.
|
|
38
|
+
*/
|
|
39
|
+
export declare function chooserFilters(entries?: Iterable<ChooserEntry>): ChooserFilters;
|
|
40
|
+
//# sourceMappingURL=chooser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chooser.d.ts","sourceRoot":"","sources":["../src/chooser.ts"],"names":[],"mappings":"AAKA;;;GAGG;AACH,MAAM,WAAW,YAAY;IAC5B,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,KAAK,CAAC,EAAE;QACP,GAAG,CAAC,EAAE,SAAS;YAAE,QAAQ,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,CAAA;SAAE,EAAE,CAAC;QAC1D,SAAS,CAAC,EAAE,SAAS;YACpB,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,CAAC;YAClC,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,CAAC;SACxC,EAAE,CAAC;KACJ,CAAC;CACF;AAED,mDAAmD;AACnD,MAAM,WAAW,cAAc;IAC9B,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,wBAAwB;IACxB,eAAe,EAAE,MAAM,EAAE,CAAC;IAC1B,iDAAiD;IACjD,iBAAiB,EAAE,MAAM,EAAE,CAAC;IAC5B,uDAAuD;IACvD,QAAQ,EAAE,CAAC;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG;QAAE,UAAU,EAAE,MAAM,CAAA;KAAE,CAAC,EAAE,CAAC;IACxD,8EAA8E;IAC9E,YAAY,EAAE,MAAM,EAAE,CAAC;CACvB;AAQD;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,OAAO,GAAE,QAAQ,CAAC,YAAY,CAAM,GAAG,cAAc,CAiCnF"}
|
package/dist/chooser.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { transportsOf } from "./device.js";
|
|
2
|
+
import { HANDLERS } from "./handlers/index.js";
|
|
3
|
+
import { KNOWN_HID_VENDORS, protocolOf } from "./protocols.js";
|
|
4
|
+
const handlers = Object.values(HANDLERS);
|
|
5
|
+
const unique = (list) => [...new Set(list)];
|
|
6
|
+
/** A match field's values: one, or a list of which any matches (SPEC §3). */
|
|
7
|
+
const values = (v) => v === undefined ? [] : Array.isArray(v) ? v : [v];
|
|
8
|
+
/**
|
|
9
|
+
* Chooser filters for the devices in `entries` that have a protocol, plus the HID vendors
|
|
10
|
+
* `guessProtocol` knows. The bridge holds no device identities (D33): pass the database's
|
|
11
|
+
* entries (`(await client.loadIndex())?.profiles`) to offer the devices it knows.
|
|
12
|
+
*/
|
|
13
|
+
export function chooserFilters(entries = []) {
|
|
14
|
+
const hid = [...KNOWN_HID_VENDORS];
|
|
15
|
+
const serial = [];
|
|
16
|
+
const ble = new Map();
|
|
17
|
+
for (const entry of entries) {
|
|
18
|
+
const protocol = protocolOf(entry);
|
|
19
|
+
if (!protocol)
|
|
20
|
+
continue;
|
|
21
|
+
const kinds = transportsOf(HANDLERS[protocol.handler]);
|
|
22
|
+
for (const { vendorId } of entry.match?.usb ?? []) {
|
|
23
|
+
for (const v of values(vendorId)) {
|
|
24
|
+
const id = parseInt(v, 16);
|
|
25
|
+
if (kinds.includes('hid'))
|
|
26
|
+
hid.push(id);
|
|
27
|
+
if (kinds.includes('serial'))
|
|
28
|
+
serial.push(id);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
if (!kinds.includes('ble'))
|
|
32
|
+
continue;
|
|
33
|
+
for (const b of entry.match?.bluetooth ?? []) {
|
|
34
|
+
const filters = b.name !== undefined
|
|
35
|
+
? values(b.name).map((name) => ({ name }))
|
|
36
|
+
: values(b.namePrefix).map((namePrefix) => ({ namePrefix }));
|
|
37
|
+
for (const f of filters)
|
|
38
|
+
ble.set(JSON.stringify(f), f);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return {
|
|
42
|
+
hidVendorIds: unique(hid),
|
|
43
|
+
serialVendorIds: unique(serial),
|
|
44
|
+
sppServiceClasses: unique(handlers.flatMap((h) => (h.sppServiceClass ? [h.sppServiceClass] : []))),
|
|
45
|
+
bleNames: [...ble.values()],
|
|
46
|
+
gattServices: unique(handlers.flatMap((h) => (h.gatt ? [h.gatt.service] : [])))
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=chooser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chooser.js","sourceRoot":"","sources":["../src/chooser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AA+B/D,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAiB,CAAC;AACzD,MAAM,MAAM,GAAG,CAAI,IAAS,EAAE,EAAE,CAAC,CAAC,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC;AACpD,6EAA6E;AAC7E,MAAM,MAAM,GAAG,CAAI,CAA+B,EAAgB,EAAE,CACnE,CAAC,KAAK,SAA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,KAAK,SAAS;gBACnB,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC;gBAC1C,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC;YAC/D,KAAK,MAAM,CAAC,IAAI,OAAO;gBAAE,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QACxD,CAAC;IACF,CAAC;IACD,OAAO;QACN,YAAY,EAAE,MAAM,CAAC,GAAG,CAAC;QACzB,eAAe,EAAE,MAAM,CAAC,MAAM,CAAC;QAC/B,iBAAiB,EAAE,MAAM,CACxB,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CACvE;QACD,QAAQ,EAAE,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC;QAC3B,YAAY,EAAE,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;KAC/E,CAAC;AACH,CAAC"}
|
package/dist/device.d.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { FilterType } from '@potatosalad775/eqcaps-core';
|
|
2
|
+
import type { AnyHandler, HandlerCapabilities, PullRequest, PullResult, PushRequest, PushResult, Slot, WireGrid } from './handler.ts';
|
|
3
|
+
import { type DeviceIdentity } from './identity.ts';
|
|
4
|
+
import type { Protocol } from './protocols.ts';
|
|
5
|
+
import type { Transport } from './transport.ts';
|
|
6
|
+
export interface OpenOptions {
|
|
7
|
+
/**
|
|
8
|
+
* The device's eqcaps profile, or just its `bandCount`. It supplies the band count a pull needs
|
|
9
|
+
* when the protocol can't tell. Nothing else in it is used: the bridge never fits or clamps.
|
|
10
|
+
*/
|
|
11
|
+
profile?: {
|
|
12
|
+
bandCount?: number | null;
|
|
13
|
+
};
|
|
14
|
+
/** Replaces the waits between writes (tests pass one that returns at once). */
|
|
15
|
+
sleep?: (ms: number) => Promise<void>;
|
|
16
|
+
/** Receives diagnostic messages. */
|
|
17
|
+
log?: (message: string) => void;
|
|
18
|
+
}
|
|
19
|
+
export interface DeviceCapabilities extends HandlerCapabilities {
|
|
20
|
+
/** Filter types the protocol has wire codes for. */
|
|
21
|
+
types: readonly FilterType[];
|
|
22
|
+
/** What the write frames can carry. A profile domain outside it can't be written. */
|
|
23
|
+
wire: WireGrid;
|
|
24
|
+
/** The protocol's preset slots. */
|
|
25
|
+
slots: readonly Slot[];
|
|
26
|
+
/** The device drops the connection after a push that saves; reconnect afterwards. */
|
|
27
|
+
disconnectOnSave: boolean;
|
|
28
|
+
/** The protocol for this device is unconfirmed. */
|
|
29
|
+
experimental: boolean;
|
|
30
|
+
}
|
|
31
|
+
/** A connected device: a transport driven by a protocol. */
|
|
32
|
+
export interface BridgeDevice {
|
|
33
|
+
readonly transport: Transport;
|
|
34
|
+
readonly protocol: Protocol;
|
|
35
|
+
readonly identity: DeviceIdentity;
|
|
36
|
+
readonly capabilities: DeviceCapabilities;
|
|
37
|
+
pull(request?: PullRequest): Promise<PullResult>;
|
|
38
|
+
push(request: PushRequest): Promise<PushResult>;
|
|
39
|
+
/** The active preset slot; null when EQ is off or the protocol can't say. */
|
|
40
|
+
currentSlot(): Promise<number | null>;
|
|
41
|
+
setEnabled(enabled: boolean, slot?: number): Promise<void>;
|
|
42
|
+
close(): Promise<void>;
|
|
43
|
+
}
|
|
44
|
+
/** The transport kinds a handler runs over. */
|
|
45
|
+
export declare const transportsOf: (h: AnyHandler) => readonly Transport["kind"][];
|
|
46
|
+
/**
|
|
47
|
+
* Drives `transport` with `protocol`: `protocolOf(profile)` (or `protocolForMatches`) for a device
|
|
48
|
+
* the database knows, `guessProtocol(vendorId)` otherwise. Operations run one at a time.
|
|
49
|
+
*/
|
|
50
|
+
export declare function openDevice(transport: Transport, protocol: Protocol, options?: OpenOptions): BridgeDevice;
|
|
51
|
+
//# sourceMappingURL=device.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"device.d.ts","sourceRoot":"","sources":["../src/device.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAE9D,OAAO,KAAK,EACX,UAAU,EACV,mBAAmB,EAEnB,WAAW,EACX,UAAU,EACV,WAAW,EACX,UAAU,EACV,IAAI,EACJ,QAAQ,EACR,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAc,KAAK,cAAc,EAAE,MAAM,eAAe,CAAC;AAEhE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEhD,MAAM,WAAW,WAAW;IAC3B;;;OAGG;IACH,OAAO,CAAC,EAAE;QAAE,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,CAAC;IACxC,+EAA+E;IAC/E,KAAK,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACtC,oCAAoC;IACpC,GAAG,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;CAChC;AAED,MAAM,WAAW,kBAAmB,SAAQ,mBAAmB;IAC9D,oDAAoD;IACpD,KAAK,EAAE,SAAS,UAAU,EAAE,CAAC;IAC7B,qFAAqF;IACrF,IAAI,EAAE,QAAQ,CAAC;IACf,mCAAmC;IACnC,KAAK,EAAE,SAAS,IAAI,EAAE,CAAC;IACvB,qFAAqF;IACrF,gBAAgB,EAAE,OAAO,CAAC;IAC1B,mDAAmD;IACnD,YAAY,EAAE,OAAO,CAAC;CACtB;AAED,4DAA4D;AAC5D,MAAM,WAAW,YAAY;IAC5B,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC;IAC9B,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC5B,QAAQ,CAAC,QAAQ,EAAE,cAAc,CAAC;IAClC,QAAQ,CAAC,YAAY,EAAE,kBAAkB,CAAC;IAC1C,IAAI,CAAC,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;IACjD,IAAI,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;IAChD,6EAA6E;IAC7E,WAAW,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IACtC,UAAU,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3D,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACvB;AAED,+CAA+C;AAC/C,eAAO,MAAM,YAAY,GAAI,GAAG,UAAU,KAAG,SAAS,SAAS,CAAC,MAAM,CAAC,EAGtB,CAAC;AAElD;;;GAGG;AACH,wBAAgB,UAAU,CACzB,SAAS,EAAE,SAAS,EACpB,QAAQ,EAAE,QAAQ,EAClB,OAAO,GAAE,WAAgB,GACvB,YAAY,CAgGd"}
|
package/dist/device.js
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { BridgeError } from "./errors.js";
|
|
2
|
+
import { HANDLERS } from "./handlers/index.js";
|
|
3
|
+
import { identityOf } from "./identity.js";
|
|
4
|
+
import { realSleep } from "./platform.js";
|
|
5
|
+
/** The transport kinds a handler runs over. */
|
|
6
|
+
export const transportsOf = (h) => typeof h.transport === 'string'
|
|
7
|
+
? [h.transport]
|
|
8
|
+
: h.transport;
|
|
9
|
+
/**
|
|
10
|
+
* Drives `transport` with `protocol`: `protocolOf(profile)` (or `protocolForMatches`) for a device
|
|
11
|
+
* the database knows, `guessProtocol(vendorId)` otherwise. Operations run one at a time.
|
|
12
|
+
*/
|
|
13
|
+
export function openDevice(transport, protocol, options = {}) {
|
|
14
|
+
const handler = HANDLERS[protocol.handler];
|
|
15
|
+
if (!transportsOf(handler).includes(transport.kind)) {
|
|
16
|
+
throw new BridgeError('invalid-request', `${handler.id} doesn't run over a ${transport.kind} transport`);
|
|
17
|
+
}
|
|
18
|
+
const handlerOptions = protocol.options ?? {};
|
|
19
|
+
const bypass = protocol.presets?.find((p) => p.bypass)?.id;
|
|
20
|
+
const ctx = {
|
|
21
|
+
transport,
|
|
22
|
+
options: handlerOptions,
|
|
23
|
+
...(bypass !== undefined ? { bypass } : {}),
|
|
24
|
+
sleep: options.sleep ?? realSleep,
|
|
25
|
+
log: options.log ?? (() => { })
|
|
26
|
+
};
|
|
27
|
+
const capabilities = {
|
|
28
|
+
...handler.capabilities(transport, handlerOptions),
|
|
29
|
+
types: handler.codec.types,
|
|
30
|
+
wire: handler.codec.wire(handlerOptions),
|
|
31
|
+
slots: protocol.presets ?? [],
|
|
32
|
+
disconnectOnSave: protocol.disconnectOnSave ?? false,
|
|
33
|
+
experimental: protocol.experimental ?? false
|
|
34
|
+
};
|
|
35
|
+
// One operation at a time: two pulls interleaving on one input stream corrupt each other.
|
|
36
|
+
let queue = Promise.resolve();
|
|
37
|
+
const serial = (op) => {
|
|
38
|
+
const run = queue.then(op, op);
|
|
39
|
+
queue = run.catch(() => { });
|
|
40
|
+
return run;
|
|
41
|
+
};
|
|
42
|
+
return {
|
|
43
|
+
transport,
|
|
44
|
+
protocol,
|
|
45
|
+
identity: identityOf(transport),
|
|
46
|
+
capabilities,
|
|
47
|
+
pull(request = {}) {
|
|
48
|
+
return serial(async () => {
|
|
49
|
+
if (!capabilities.canRead) {
|
|
50
|
+
throw new BridgeError('unsupported', `${handler.id} can't read from this device`);
|
|
51
|
+
}
|
|
52
|
+
const r = {};
|
|
53
|
+
if (request.slot !== undefined) {
|
|
54
|
+
if (!capabilities.readsSlot) {
|
|
55
|
+
throw new BridgeError('invalid-request', `${handler.id} reads only the current preset, not a chosen slot`);
|
|
56
|
+
}
|
|
57
|
+
r.slot = request.slot;
|
|
58
|
+
}
|
|
59
|
+
if (capabilities.needsBandCount) {
|
|
60
|
+
const bands = request.bands ?? options.profile?.bandCount ?? undefined;
|
|
61
|
+
if (typeof bands !== 'number' || !Number.isInteger(bands) || bands < 0) {
|
|
62
|
+
throw new BridgeError('invalid-request', `${handler.id} needs a band count: pass \`bands\`, or open the device with its profile`);
|
|
63
|
+
}
|
|
64
|
+
r.bands = bands;
|
|
65
|
+
}
|
|
66
|
+
return handler.pull(ctx, r);
|
|
67
|
+
});
|
|
68
|
+
},
|
|
69
|
+
push(request) {
|
|
70
|
+
return serial(async () => {
|
|
71
|
+
if (!capabilities.canWrite) {
|
|
72
|
+
throw new BridgeError('unsupported', `${handler.id} can't write to this device`);
|
|
73
|
+
}
|
|
74
|
+
const result = await handler.push(ctx, request);
|
|
75
|
+
return { reconnect: result.reconnect || capabilities.disconnectOnSave };
|
|
76
|
+
});
|
|
77
|
+
},
|
|
78
|
+
currentSlot() {
|
|
79
|
+
return serial(async () => (handler.currentSlot ? handler.currentSlot(ctx) : null));
|
|
80
|
+
},
|
|
81
|
+
setEnabled(enabled, slot) {
|
|
82
|
+
return serial(async () => {
|
|
83
|
+
if (!handler.setEnabled) {
|
|
84
|
+
throw new BridgeError('unsupported', `${handler.id} has no EQ switch`);
|
|
85
|
+
}
|
|
86
|
+
await handler.setEnabled(ctx, enabled, slot);
|
|
87
|
+
});
|
|
88
|
+
},
|
|
89
|
+
close() {
|
|
90
|
+
return serial(() => transport.close());
|
|
91
|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C,CAAC,CAAC;QACJ,CAAC;QAED,WAAW;YACV,OAAO,MAAM,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,OAAO,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;QACpF,CAAC;QAED,UAAU,CAAC,OAAO,EAAE,IAAI;YACvB,OAAO,MAAM,CAAC,KAAK,IAAI,EAAE;gBACxB,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC;oBACzB,MAAM,IAAI,WAAW,CAAC,aAAa,EAAE,GAAG,OAAO,CAAC,EAAE,mBAAmB,CAAC,CAAC;gBACxE,CAAC;gBACD,MAAM,OAAO,CAAC,UAAU,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;YAC9C,CAAC,CAAC,CAAC;QACJ,CAAC;QAED,KAAK;YACJ,OAAO,MAAM,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC,CAAC;QACxC,CAAC;KACD,CAAC;AACH,CAAC"}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Why a bridge operation failed. Every error the bridge throws on purpose is a `BridgeError` with
|
|
3
|
+
* one of these codes, so a UI can explain it.
|
|
4
|
+
*
|
|
5
|
+
* - `unsupported-type`: the handler has no wire code for the filter type.
|
|
6
|
+
* - `unrepresentable`: a value doesn't fit the wire field (out of its integer range, or missing
|
|
7
|
+
* from a lookup table). Codecs round onto their grid but never clamp a value into range.
|
|
8
|
+
* - `unsupported`: the handler or transport can't do this at all (pull on a write-only device).
|
|
9
|
+
* - `timeout`: the device didn't answer in time.
|
|
10
|
+
* - `bad-response`: the device answered with something the handler can't parse.
|
|
11
|
+
* - `rejected`: the device answered and said no.
|
|
12
|
+
* - `transport`: the transport failed (disconnected, closed, permission lost).
|
|
13
|
+
* - `invalid-request`: the caller asked for something the protocol can't express (a slot it
|
|
14
|
+
* doesn't have, a band count it can't read).
|
|
15
|
+
*/
|
|
16
|
+
export type BridgeErrorCode = 'unsupported-type' | 'unrepresentable' | 'unsupported' | 'timeout' | 'bad-response' | 'rejected' | 'transport' | 'invalid-request';
|
|
17
|
+
export declare class BridgeError extends Error {
|
|
18
|
+
readonly code: BridgeErrorCode;
|
|
19
|
+
constructor(code: BridgeErrorCode, message: string, options?: {
|
|
20
|
+
cause?: unknown;
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
export declare function isBridgeError(error: unknown, code?: BridgeErrorCode): error is BridgeError;
|
|
24
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,MAAM,MAAM,eAAe,GACxB,kBAAkB,GAClB,iBAAiB,GACjB,aAAa,GACb,SAAS,GACT,cAAc,GACd,UAAU,GACV,WAAW,GACX,iBAAiB,CAAC;AAErB,qBAAa,WAAY,SAAQ,KAAK;IACrC,QAAQ,CAAC,IAAI,EAAE,eAAe,CAAC;gBAEnB,IAAI,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE;CAKjF;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,eAAe,GAAG,KAAK,IAAI,WAAW,CAE1F"}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export class BridgeError extends Error {
|
|
2
|
+
code;
|
|
3
|
+
constructor(code, message, options) {
|
|
4
|
+
super(message, options);
|
|
5
|
+
this.name = 'BridgeError';
|
|
6
|
+
this.code = code;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
export function isBridgeError(error, code) {
|
|
10
|
+
return error instanceof BridgeError && (code === undefined || error.code === code);
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAyBA,MAAM,OAAO,WAAY,SAAQ,KAAK;IAC5B,IAAI,CAAkB;IAE/B,YAAY,IAAqB,EAAE,OAAe,EAAE,OAA6B;QAChF,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACxB,IAAI,CAAC,IAAI,GAAG,aAAa,CAAC;QAC1B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IAClB,CAAC;CACD;AAED,MAAM,UAAU,aAAa,CAAC,KAAc,EAAE,IAAsB;IACnE,OAAO,KAAK,YAAY,WAAW,IAAI,CAAC,IAAI,KAAK,SAAS,IAAI,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC;AACpF,CAAC"}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import type { Filter, FilterType } from '@potatosalad775/eqcaps-core';
|
|
2
|
+
import type { HidTransport, StreamTransport, Transport } from './transport.ts';
|
|
3
|
+
/** An EQ preset slot (memory) on the device. Unrelated to the profile's filter slots. */
|
|
4
|
+
export interface Slot {
|
|
5
|
+
id: number;
|
|
6
|
+
name: string;
|
|
7
|
+
/** Selecting this slot turns the EQ off (`setEnabled(false)` selects it). */
|
|
8
|
+
bypass?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export interface PullRequest {
|
|
11
|
+
/**
|
|
12
|
+
* Preset slot to read. Default: the current one. Refused where the protocol can't read a
|
|
13
|
+
* chosen slot (`readsSlot`), rather than answered with the current one.
|
|
14
|
+
*/
|
|
15
|
+
slot?: number;
|
|
16
|
+
/** Bands to read, where the protocol can't tell. Default: the profile's `bandCount`. */
|
|
17
|
+
bands?: number;
|
|
18
|
+
}
|
|
19
|
+
/** What the device holds, in canonical units: written values (D29, D39). */
|
|
20
|
+
export interface PullResult {
|
|
21
|
+
/** One entry per band in band order; null for a band the device reports as off or unset. */
|
|
22
|
+
filters: (Filter | null)[];
|
|
23
|
+
/** The device's preamp in dB, when the protocol reads one. */
|
|
24
|
+
preamp?: number;
|
|
25
|
+
/** The slot that was read, when known. */
|
|
26
|
+
slot?: number;
|
|
27
|
+
}
|
|
28
|
+
export interface PushRequest {
|
|
29
|
+
/**
|
|
30
|
+
* Written values, one per band, in band order: normally core's `fit` followed by `complete`.
|
|
31
|
+
* The bridge sends them as given. It does no clamping, type conversion or padding of its own;
|
|
32
|
+
* a value the wire can't carry is a `BridgeError` (D33).
|
|
33
|
+
*/
|
|
34
|
+
filters: readonly Filter[];
|
|
35
|
+
/**
|
|
36
|
+
* Preamp in dB. Left out, the preamp isn't written; where the protocol sends it with the bands
|
|
37
|
+
* (Nothing), 0 dB is sent. Given to a protocol that can't write it (`writesPreamp`), the push
|
|
38
|
+
* is refused rather than sent without it.
|
|
39
|
+
*/
|
|
40
|
+
preamp?: number;
|
|
41
|
+
/** Preset slot to write to. Refused, like `preamp`, where the write names none (`writesSlot`). */
|
|
42
|
+
slot?: number;
|
|
43
|
+
}
|
|
44
|
+
export interface PushResult {
|
|
45
|
+
/** The device drops the connection after saving; reconnect before the next operation. */
|
|
46
|
+
reconnect: boolean;
|
|
47
|
+
}
|
|
48
|
+
/** The range and resolution a wire field can carry, in canonical units. */
|
|
49
|
+
export interface WireField {
|
|
50
|
+
min: number;
|
|
51
|
+
max: number;
|
|
52
|
+
/** Wire resolution; missing for floating-point fields. */
|
|
53
|
+
step?: number;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* What a protocol's write frames can carry. It bounds every profile of the devices the protocol
|
|
57
|
+
* drives: a profile domain outside it is a value no write can send.
|
|
58
|
+
*/
|
|
59
|
+
export interface WireGrid {
|
|
60
|
+
freq: WireField | {
|
|
61
|
+
values: readonly number[];
|
|
62
|
+
};
|
|
63
|
+
/** Missing when the protocol has no Q field. */
|
|
64
|
+
q?: WireField;
|
|
65
|
+
gain: WireField;
|
|
66
|
+
/** Missing when the write carries no preamp. */
|
|
67
|
+
preamp?: WireField;
|
|
68
|
+
}
|
|
69
|
+
/** A HID report: output (or feature, if marked) report `reportId` carrying `data`. */
|
|
70
|
+
export interface HidFrame {
|
|
71
|
+
reportId: number;
|
|
72
|
+
feature?: true;
|
|
73
|
+
data: Uint8Array;
|
|
74
|
+
}
|
|
75
|
+
/** What a set of write frames says. */
|
|
76
|
+
export interface WriteState {
|
|
77
|
+
filters: (Filter | null)[];
|
|
78
|
+
preamp?: number;
|
|
79
|
+
slot?: number;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* The pure half of a protocol: write requests to frames and back, with no I/O. The inspector
|
|
83
|
+
* analyses a codec offline (what does the wire round a value to, what does it refuse?), and tests
|
|
84
|
+
* check `decode(encode(x))` against the wire grid.
|
|
85
|
+
*/
|
|
86
|
+
export interface Codec<O, F> {
|
|
87
|
+
/** Filter types the protocol has wire codes for. */
|
|
88
|
+
readonly types: readonly FilterType[];
|
|
89
|
+
wire(options: O): WireGrid;
|
|
90
|
+
/** The frames that write `request`, in order. Throws `BridgeError` for what the wire can't carry. */
|
|
91
|
+
encode(request: PushRequest, options: O): F[];
|
|
92
|
+
/** What frames from `encode` write. */
|
|
93
|
+
decode(frames: readonly F[], options: O): WriteState;
|
|
94
|
+
}
|
|
95
|
+
/** What a handler can do, given its options and transport. */
|
|
96
|
+
export interface HandlerCapabilities {
|
|
97
|
+
canRead: boolean;
|
|
98
|
+
canWrite: boolean;
|
|
99
|
+
/** Pull returns the preamp. */
|
|
100
|
+
readsPreamp: boolean;
|
|
101
|
+
/** Pull reads the preset `slot` it is given. */
|
|
102
|
+
readsSlot: boolean;
|
|
103
|
+
/** Push writes `preamp` when given. */
|
|
104
|
+
writesPreamp: boolean;
|
|
105
|
+
/** Push writes to the preset `slot` when given. */
|
|
106
|
+
writesSlot: boolean;
|
|
107
|
+
/** The band count, when the protocol fixes it. */
|
|
108
|
+
bands?: number;
|
|
109
|
+
/**
|
|
110
|
+
* Pull needs to be told how many bands to read (`bands`, or the profile's `bandCount`): the
|
|
111
|
+
* protocol reads band by band and can't report its count.
|
|
112
|
+
*/
|
|
113
|
+
needsBandCount: boolean;
|
|
114
|
+
/** `currentSlot()` asks the device rather than returning a constant. */
|
|
115
|
+
readsCurrentSlot: boolean;
|
|
116
|
+
/** `setEnabled()` sends a command. */
|
|
117
|
+
canEnable: boolean;
|
|
118
|
+
}
|
|
119
|
+
export interface HandlerContext<T extends Transport, O> {
|
|
120
|
+
transport: T;
|
|
121
|
+
options: O;
|
|
122
|
+
/** The preset the profile marks `bypass`: selecting it turns the EQ off (SPEC §9). */
|
|
123
|
+
bypass?: number;
|
|
124
|
+
/** Waits between writes. Tests replace it to run without real delays. */
|
|
125
|
+
sleep(ms: number): Promise<void>;
|
|
126
|
+
/** Diagnostic messages; silent unless the caller passes a logger. */
|
|
127
|
+
log(message: string): void;
|
|
128
|
+
}
|
|
129
|
+
/** The I/O half of a protocol: a session over a transport, built on its codec. */
|
|
130
|
+
export interface Handler<T extends Transport, O, F> {
|
|
131
|
+
/** Stable id, used by the protocol table and in evidence reports (`fiio-usb-hid`). */
|
|
132
|
+
readonly id: string;
|
|
133
|
+
readonly transport: T['kind'] | readonly T['kind'][];
|
|
134
|
+
readonly codec: Codec<O, F>;
|
|
135
|
+
/** BLE handlers: the GATT service and characteristics the protocol uses. */
|
|
136
|
+
readonly gatt?: {
|
|
137
|
+
service: string;
|
|
138
|
+
tx: string;
|
|
139
|
+
rx: string;
|
|
140
|
+
};
|
|
141
|
+
/** Handlers that run over Bluetooth SPP: the RFCOMM service class (Web Serial needs it). */
|
|
142
|
+
readonly sppServiceClass?: string;
|
|
143
|
+
/** The protocol turns the EQ off by selecting a preset, which the profile marks `bypass`. */
|
|
144
|
+
readonly bypassPreset?: boolean;
|
|
145
|
+
capabilities(transport: T, options: O): HandlerCapabilities;
|
|
146
|
+
/** `bands` is always set when `needsBandCount` is. */
|
|
147
|
+
pull(ctx: HandlerContext<T, O>, request: {
|
|
148
|
+
slot?: number;
|
|
149
|
+
bands?: number;
|
|
150
|
+
}): Promise<PullResult>;
|
|
151
|
+
push(ctx: HandlerContext<T, O>, request: PushRequest): Promise<PushResult>;
|
|
152
|
+
currentSlot?(ctx: HandlerContext<T, O>): Promise<number | null>;
|
|
153
|
+
setEnabled?(ctx: HandlerContext<T, O>, enabled: boolean, slot?: number): Promise<void>;
|
|
154
|
+
}
|
|
155
|
+
export type HidHandler<O = object> = Handler<HidTransport, O, HidFrame>;
|
|
156
|
+
export type StreamHandler<O = object> = Handler<StreamTransport, O, Uint8Array>;
|
|
157
|
+
/** A handler of any transport and options, as the protocol table stores it. */
|
|
158
|
+
export type AnyHandler = Handler<any, any, any>;
|
|
159
|
+
/** The standard Bluetooth Serial Port Profile service class. */
|
|
160
|
+
export declare const SPP = "00001101-0000-1000-8000-00805f9b34fb";
|
|
161
|
+
//# sourceMappingURL=handler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../src/handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AACtE,OAAO,KAAK,EAAE,YAAY,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE/E,yFAAyF;AACzF,MAAM,WAAW,IAAI;IACpB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,6EAA6E;IAC7E,MAAM,CAAC,EAAE,OAAO,CAAC;CACjB;AAED,MAAM,WAAW,WAAW;IAC3B;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,wFAAwF;IACxF,KAAK,CAAC,EAAE,MAAM,CAAC;CACf;AAED,4EAA4E;AAC5E,MAAM,WAAW,UAAU;IAC1B,4FAA4F;IAC5F,OAAO,EAAE,CAAC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AAG,MAAM,IAAI,OAAO,CAAC,YAAY,EAAE,CAAC,EAAE,QAAQ,CAAC,CAAC;AACxE,MAAM,MAAM,aAAa,CAAC,CAAC,GAAG,MAAM,IAAI,OAAO,CAAC,eAAe,EAAE,CAAC,EAAE,UAAU,CAAC,CAAC;AAEhF,+EAA+E;AAE/E,MAAM,MAAM,UAAU,GAAG,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;AAEhD,gEAAgE;AAChE,eAAO,MAAM,GAAG,yCAAyC,CAAC"}
|
package/dist/handler.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handler.js","sourceRoot":"","sources":["../src/handler.ts"],"names":[],"mappings":"AAsKA,gEAAgE;AAChE,MAAM,CAAC,MAAM,GAAG,GAAG,sCAAsC,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Filter } from '@potatosalad775/eqcaps-core';
|
|
2
|
+
import { type Codec, type StreamHandler } from '../handler.ts';
|
|
3
|
+
export interface AirohaOptions {
|
|
4
|
+
/** Write in the BLE layout. The session sets it from the transport. */
|
|
5
|
+
ble?: boolean;
|
|
6
|
+
}
|
|
7
|
+
export declare const AIROHA_TYPES: import("../io.ts").TypeCodes;
|
|
8
|
+
/** Records in the read layout from byte 13 (the read answer, or a BLE write). */
|
|
9
|
+
export declare function decodeAirohaRecords(d: ArrayLike<number>, count: number): Filter[];
|
|
10
|
+
export declare const airohaCodec: Codec<AirohaOptions, Uint8Array>;
|
|
11
|
+
export declare const airoha: StreamHandler<AirohaOptions>;
|
|
12
|
+
//# sourceMappingURL=airoha.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"airoha.d.ts","sourceRoot":"","sources":["../../src/handlers/airoha.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,6BAA6B,CAAC;AAG1D,OAAO,EAAO,KAAK,KAAK,EAAE,KAAK,aAAa,EAAmB,MAAM,eAAe,CAAC;AAGrF,MAAM,WAAW,aAAa;IAC7B,uEAAuE;IACvE,GAAG,CAAC,EAAE,OAAO,CAAC;CACd;AAOD,eAAO,MAAM,YAAY,8BAAiD,CAAC;AAE3E,iFAAiF;AACjF,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,SAAS,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAUjF;AASD,eAAO,MAAM,WAAW,EAAE,KAAK,CAAC,aAAa,EAAE,UAAU,CA2CxD,CAAC;AAWF,eAAO,MAAM,MAAM,EAAE,aAAa,CAAC,aAAa,CA0C/C,CAAC"}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
// Airoha-chipset headphones (Audeze Maxwell) over Bluetooth SPP or BLE GATT, 10 bands, 4 presets
|
|
2
|
+
// (devicePEQ airohaUsbSerialHandler.js and airohaBleHandler.js, 0BSD, at 0617f38).
|
|
3
|
+
//
|
|
4
|
+
// Read preset: 05 5A 06 00 00 0A <preset> EF E8 03, answered by 193 bytes starting 05 5B BD:
|
|
5
|
+
// band count at 5, then 18-byte records from 13: 01, type, freq u32 LE ×100, gain s32 LE ×100,
|
|
6
|
+
// bandwidth u32, q u32 LE ×100. The two transports write differently:
|
|
7
|
+
// - SPP: 05 5A 4F <length u16 LE> 03 0E 00 <preset u32 LE> 06, then six sections (one per sample
|
|
8
|
+
// rate) of 00 67 00 0A 00 <rate u32 LE> and 10 records [01, type, freq, gain, q, C8 00 00 00].
|
|
9
|
+
// All fields are 32-bit (devicePEQ wrote the frequency as 16 bits, which overflows above
|
|
10
|
+
// 655.35 Hz).
|
|
11
|
+
// - BLE: 05 5A BD 00 01 0A 00 EF 01 00 00 00 00, then 10 records in the read layout. This write
|
|
12
|
+
// carries no preset number.
|
|
13
|
+
import { field, grid, I32, le16, le32, readI32le, readU32le, U32 } from "../bytes.js";
|
|
14
|
+
import { BridgeError } from "../errors.js";
|
|
15
|
+
import { SPP } from "../handler.js";
|
|
16
|
+
import { refuseUncarried, StreamReader, typeCodes } from "../io.js";
|
|
17
|
+
const BANDS = 10;
|
|
18
|
+
const ANSWER_LENGTH = 193;
|
|
19
|
+
const SAMPLE_RATES = [44100, 48000, 88200, 96000, 44100, 48000];
|
|
20
|
+
const BLE_HEADER = [0x05, 0x5a, 0xbd, 0x00, 0x01, 0x0a, 0x00, 0xef, 0x01, 0, 0, 0, 0];
|
|
21
|
+
export const AIROHA_TYPES = typeCodes('airoha', { PK: 2, LSC: 3, HSC: 4 });
|
|
22
|
+
/** Records in the read layout from byte 13 (the read answer, or a BLE write). */
|
|
23
|
+
export function decodeAirohaRecords(d, count) {
|
|
24
|
+
return Array.from({ length: Math.min(BANDS, count) }, (_, i) => {
|
|
25
|
+
const o = 13 + i * 18;
|
|
26
|
+
return {
|
|
27
|
+
type: AIROHA_TYPES.decode(d[o + 1]),
|
|
28
|
+
freq: readU32le(d, o + 2) / 100,
|
|
29
|
+
gain: readI32le(d, o + 6) / 100,
|
|
30
|
+
q: readU32le(d, o + 14) / 100
|
|
31
|
+
};
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
function checkPreset(slot) {
|
|
35
|
+
if (!Number.isInteger(slot) || slot < 0 || slot > 3) {
|
|
36
|
+
throw new BridgeError('invalid-request', `Airoha: preset ${slot}, the device has 0-3`);
|
|
37
|
+
}
|
|
38
|
+
return slot;
|
|
39
|
+
}
|
|
40
|
+
export const airohaCodec = {
|
|
41
|
+
types: AIROHA_TYPES.types,
|
|
42
|
+
wire: () => ({ freq: grid(100, U32), q: grid(100, U32), gain: grid(100, I32) }),
|
|
43
|
+
encode(request, o) {
|
|
44
|
+
refuseUncarried('airoha', request, { slot: !o.ble });
|
|
45
|
+
const { filters, slot } = request;
|
|
46
|
+
if (filters.length !== BANDS) {
|
|
47
|
+
throw new BridgeError('invalid-request', `Airoha: the write carries exactly ${BANDS} bands`);
|
|
48
|
+
}
|
|
49
|
+
const records = filters.map((f) => ({
|
|
50
|
+
type: AIROHA_TYPES.encode(f.type),
|
|
51
|
+
freq: le32(field(f.freq, 100, U32, 'freq')),
|
|
52
|
+
gain: le32(field(f.gain, 100, I32, 'gain')),
|
|
53
|
+
q: le32(field(f.q, 100, U32, 'q'))
|
|
54
|
+
}));
|
|
55
|
+
if (o.ble) {
|
|
56
|
+
const out = [...BLE_HEADER];
|
|
57
|
+
for (const r of records)
|
|
58
|
+
out.push(0x01, r.type, ...r.freq, ...r.gain, 0, 0, 0, 0, ...r.q);
|
|
59
|
+
return [Uint8Array.from(out)];
|
|
60
|
+
}
|
|
61
|
+
const body = [0x03, 0x0e, 0x00, ...le32(checkPreset(slot ?? 0)), 0x06];
|
|
62
|
+
for (const rate of SAMPLE_RATES) {
|
|
63
|
+
body.push(0x00, 0x67, 0x00, 0x0a, 0x00, ...le32(rate));
|
|
64
|
+
for (const r of records)
|
|
65
|
+
body.push(0x01, r.type, ...r.freq, ...r.gain, ...r.q, 0xc8, 0, 0, 0);
|
|
66
|
+
}
|
|
67
|
+
return [Uint8Array.from([0x05, 0x5a, 0x4f, ...le16(body.length + 2), ...body])];
|
|
68
|
+
},
|
|
69
|
+
decode(frames) {
|
|
70
|
+
const d = frames[0];
|
|
71
|
+
if (!d)
|
|
72
|
+
return { filters: [] };
|
|
73
|
+
if (d[2] === 0xbd)
|
|
74
|
+
return { filters: decodeAirohaRecords(d, BANDS) };
|
|
75
|
+
// SPP: the first sample-rate section's records, 18 bytes each after a 9-byte header.
|
|
76
|
+
const filters = Array.from({ length: BANDS }, (_, i) => {
|
|
77
|
+
const o = 13 + 9 + i * 18;
|
|
78
|
+
return {
|
|
79
|
+
type: AIROHA_TYPES.decode(d[o + 1]),
|
|
80
|
+
freq: readU32le(d, o + 2) / 100,
|
|
81
|
+
gain: readI32le(d, o + 6) / 100,
|
|
82
|
+
q: readU32le(d, o + 10) / 100
|
|
83
|
+
};
|
|
84
|
+
});
|
|
85
|
+
return { filters, slot: readU32le(d, 8) };
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
function frameAt(buf) {
|
|
89
|
+
for (let i = 0; i + 2 < buf.length; i++) {
|
|
90
|
+
if (buf[i] === 0x05 && buf[i + 1] === 0x5b && buf[i + 2] === 0xbd) {
|
|
91
|
+
return buf.length >= i + ANSWER_LENGTH ? [i, i + ANSWER_LENGTH] : null;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
export const airoha = {
|
|
97
|
+
id: 'airoha',
|
|
98
|
+
transport: ['serial', 'ble'],
|
|
99
|
+
codec: airohaCodec,
|
|
100
|
+
sppServiceClass: SPP,
|
|
101
|
+
gatt: {
|
|
102
|
+
service: '5052494d-2dab-0341-6972-6f6861424c45',
|
|
103
|
+
tx: '43484152-2dab-3241-6972-6f6861424c45',
|
|
104
|
+
rx: '43484152-2dab-3141-6972-6f6861424c45'
|
|
105
|
+
},
|
|
106
|
+
capabilities: (t, o) => ({
|
|
107
|
+
canRead: true,
|
|
108
|
+
canWrite: true,
|
|
109
|
+
readsPreamp: false,
|
|
110
|
+
readsSlot: true,
|
|
111
|
+
writesPreamp: false,
|
|
112
|
+
writesSlot: t.kind !== 'ble' && !o.ble,
|
|
113
|
+
bands: BANDS,
|
|
114
|
+
needsBandCount: false,
|
|
115
|
+
readsCurrentSlot: false,
|
|
116
|
+
canEnable: false
|
|
117
|
+
}),
|
|
118
|
+
async pull(ctx, { slot }) {
|
|
119
|
+
const preset = checkPreset(slot ?? 0);
|
|
120
|
+
const reader = new StreamReader(ctx.transport);
|
|
121
|
+
await reader.send(Uint8Array.from([0x05, 0x5a, 0x06, 0x00, 0x00, 0x0a, preset, 0xef, 0xe8, 0x03]));
|
|
122
|
+
const answer = await reader.readFrame(frameAt, 5000, 'Airoha preset');
|
|
123
|
+
return { filters: decodeAirohaRecords(answer, answer[5] ?? 0), slot: preset };
|
|
124
|
+
},
|
|
125
|
+
async push(ctx, request) {
|
|
126
|
+
const frames = airohaCodec.encode(request, {
|
|
127
|
+
...ctx.options,
|
|
128
|
+
ble: ctx.transport.kind === 'ble'
|
|
129
|
+
});
|
|
130
|
+
for (const frame of frames)
|
|
131
|
+
await ctx.transport.write(frame);
|
|
132
|
+
return { reconnect: false };
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
//# sourceMappingURL=airoha.js.map
|