@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.
Files changed (148) hide show
  1. package/LICENSE +21 -0
  2. package/NOTICE.md +54 -0
  3. package/README.md +112 -0
  4. package/dist/analysis.d.ts +34 -0
  5. package/dist/analysis.d.ts.map +1 -0
  6. package/dist/analysis.js +92 -0
  7. package/dist/analysis.js.map +1 -0
  8. package/dist/biquad.d.ts +9 -0
  9. package/dist/biquad.d.ts.map +1 -0
  10. package/dist/biquad.js +50 -0
  11. package/dist/biquad.js.map +1 -0
  12. package/dist/browser/index.d.ts +14 -0
  13. package/dist/browser/index.d.ts.map +1 -0
  14. package/dist/browser/index.js +12 -0
  15. package/dist/browser/index.js.map +1 -0
  16. package/dist/browser/stream.d.ts +15 -0
  17. package/dist/browser/stream.d.ts.map +1 -0
  18. package/dist/browser/stream.js +51 -0
  19. package/dist/browser/stream.js.map +1 -0
  20. package/dist/browser/web-apis.d.ts +136 -0
  21. package/dist/browser/web-apis.d.ts.map +1 -0
  22. package/dist/browser/web-apis.js +13 -0
  23. package/dist/browser/web-apis.js.map +1 -0
  24. package/dist/browser/webbluetooth.d.ts +30 -0
  25. package/dist/browser/webbluetooth.d.ts.map +1 -0
  26. package/dist/browser/webbluetooth.js +80 -0
  27. package/dist/browser/webbluetooth.js.map +1 -0
  28. package/dist/browser/webhid.d.ts +33 -0
  29. package/dist/browser/webhid.d.ts.map +1 -0
  30. package/dist/browser/webhid.js +90 -0
  31. package/dist/browser/webhid.js.map +1 -0
  32. package/dist/browser/webserial.d.ts +34 -0
  33. package/dist/browser/webserial.d.ts.map +1 -0
  34. package/dist/browser/webserial.js +133 -0
  35. package/dist/browser/webserial.js.map +1 -0
  36. package/dist/bytes.d.ts +40 -0
  37. package/dist/bytes.d.ts.map +1 -0
  38. package/dist/bytes.js +74 -0
  39. package/dist/bytes.js.map +1 -0
  40. package/dist/chooser.d.ts +40 -0
  41. package/dist/chooser.d.ts.map +1 -0
  42. package/dist/chooser.js +49 -0
  43. package/dist/chooser.js.map +1 -0
  44. package/dist/device.d.ts +51 -0
  45. package/dist/device.d.ts.map +1 -0
  46. package/dist/device.js +94 -0
  47. package/dist/device.js.map +1 -0
  48. package/dist/errors.d.ts +24 -0
  49. package/dist/errors.d.ts.map +1 -0
  50. package/dist/errors.js +12 -0
  51. package/dist/errors.js.map +1 -0
  52. package/dist/handler.d.ts +161 -0
  53. package/dist/handler.d.ts.map +1 -0
  54. package/dist/handler.js +3 -0
  55. package/dist/handler.js.map +1 -0
  56. package/dist/handlers/airoha.d.ts +12 -0
  57. package/dist/handlers/airoha.d.ts.map +1 -0
  58. package/dist/handlers/airoha.js +135 -0
  59. package/dist/handlers/airoha.js.map +1 -0
  60. package/dist/handlers/conexant-usb-hid.d.ts +4 -0
  61. package/dist/handlers/conexant-usb-hid.d.ts.map +1 -0
  62. package/dist/handlers/conexant-usb-hid.js +103 -0
  63. package/dist/handlers/conexant-usb-hid.js.map +1 -0
  64. package/dist/handlers/edifier-serial.d.ts +6 -0
  65. package/dist/handlers/edifier-serial.d.ts.map +1 -0
  66. package/dist/handlers/edifier-serial.js +111 -0
  67. package/dist/handlers/edifier-serial.js.map +1 -0
  68. package/dist/handlers/fiio-f110.d.ts +7 -0
  69. package/dist/handlers/fiio-f110.d.ts.map +1 -0
  70. package/dist/handlers/fiio-f110.js +101 -0
  71. package/dist/handlers/fiio-f110.js.map +1 -0
  72. package/dist/handlers/fiio-usb-hid.d.ts +39 -0
  73. package/dist/handlers/fiio-usb-hid.d.ts.map +1 -0
  74. package/dist/handlers/fiio-usb-hid.js +143 -0
  75. package/dist/handlers/fiio-usb-hid.js.map +1 -0
  76. package/dist/handlers/fiio-usb-serial.d.ts +9 -0
  77. package/dist/handlers/fiio-usb-serial.d.ts.map +1 -0
  78. package/dist/handlers/fiio-usb-serial.js +122 -0
  79. package/dist/handlers/fiio-usb-serial.js.map +1 -0
  80. package/dist/handlers/fosi-audio-usb-hid.d.ts +19 -0
  81. package/dist/handlers/fosi-audio-usb-hid.d.ts.map +1 -0
  82. package/dist/handlers/fosi-audio-usb-hid.js +165 -0
  83. package/dist/handlers/fosi-audio-usb-hid.js.map +1 -0
  84. package/dist/handlers/index.d.ts +25 -0
  85. package/dist/handlers/index.d.ts.map +1 -0
  86. package/dist/handlers/index.js +36 -0
  87. package/dist/handlers/index.js.map +1 -0
  88. package/dist/handlers/jds-labs-usb-serial.d.ts +5 -0
  89. package/dist/handlers/jds-labs-usb-serial.d.ts.map +1 -0
  90. package/dist/handlers/jds-labs-usb-serial.js +156 -0
  91. package/dist/handlers/jds-labs-usb-serial.js.map +1 -0
  92. package/dist/handlers/ktmicro-usb-hid.d.ts +20 -0
  93. package/dist/handlers/ktmicro-usb-hid.d.ts.map +1 -0
  94. package/dist/handlers/ktmicro-usb-hid.js +144 -0
  95. package/dist/handlers/ktmicro-usb-hid.js.map +1 -0
  96. package/dist/handlers/moondrop-edge-serial.d.ts +8 -0
  97. package/dist/handlers/moondrop-edge-serial.d.ts.map +1 -0
  98. package/dist/handlers/moondrop-edge-serial.js +100 -0
  99. package/dist/handlers/moondrop-edge-serial.js.map +1 -0
  100. package/dist/handlers/moondrop-old-fashioned-hid.d.ts +4 -0
  101. package/dist/handlers/moondrop-old-fashioned-hid.d.ts.map +1 -0
  102. package/dist/handlers/moondrop-old-fashioned-hid.js +102 -0
  103. package/dist/handlers/moondrop-old-fashioned-hid.js.map +1 -0
  104. package/dist/handlers/moondrop-usb-hid.d.ts +8 -0
  105. package/dist/handlers/moondrop-usb-hid.d.ts.map +1 -0
  106. package/dist/handlers/moondrop-usb-hid.js +134 -0
  107. package/dist/handlers/moondrop-usb-hid.js.map +1 -0
  108. package/dist/handlers/nothing-usb-serial.d.ts +19 -0
  109. package/dist/handlers/nothing-usb-serial.d.ts.map +1 -0
  110. package/dist/handlers/nothing-usb-serial.js +141 -0
  111. package/dist/handlers/nothing-usb-serial.js.map +1 -0
  112. package/dist/handlers/qudelix-usb-hid.d.ts +16 -0
  113. package/dist/handlers/qudelix-usb-hid.d.ts.map +1 -0
  114. package/dist/handlers/qudelix-usb-hid.js +127 -0
  115. package/dist/handlers/qudelix-usb-hid.js.map +1 -0
  116. package/dist/handlers/tanchjim-rita-serial.d.ts +5 -0
  117. package/dist/handlers/tanchjim-rita-serial.d.ts.map +1 -0
  118. package/dist/handlers/tanchjim-rita-serial.js +89 -0
  119. package/dist/handlers/tanchjim-rita-serial.js.map +1 -0
  120. package/dist/handlers/walkplay-hid.d.ts +12 -0
  121. package/dist/handlers/walkplay-hid.d.ts.map +1 -0
  122. package/dist/handlers/walkplay-hid.js +150 -0
  123. package/dist/handlers/walkplay-hid.js.map +1 -0
  124. package/dist/identity.d.ts +20 -0
  125. package/dist/identity.d.ts.map +1 -0
  126. package/dist/identity.js +30 -0
  127. package/dist/identity.js.map +1 -0
  128. package/dist/index.d.ts +18 -0
  129. package/dist/index.d.ts.map +1 -0
  130. package/dist/index.js +12 -0
  131. package/dist/index.js.map +1 -0
  132. package/dist/io.d.ts +50 -0
  133. package/dist/io.d.ts.map +1 -0
  134. package/dist/io.js +119 -0
  135. package/dist/io.js.map +1 -0
  136. package/dist/platform.d.ts +9 -0
  137. package/dist/platform.d.ts.map +1 -0
  138. package/dist/platform.js +59 -0
  139. package/dist/platform.js.map +1 -0
  140. package/dist/protocols.d.ts +52 -0
  141. package/dist/protocols.d.ts.map +1 -0
  142. package/dist/protocols.js +204 -0
  143. package/dist/protocols.js.map +1 -0
  144. package/dist/transport.d.ts +59 -0
  145. package/dist/transport.d.ts.map +1 -0
  146. package/dist/transport.js +12 -0
  147. package/dist/transport.js.map +1 -0
  148. package/package.json +38 -0
@@ -0,0 +1,30 @@
1
+ export const usbHex = (id) => `0x${id.toString(16).padStart(4, '0')}`;
2
+ export function identityOf(transport) {
3
+ switch (transport.kind) {
4
+ case 'hid':
5
+ return {
6
+ usb: {
7
+ vendorId: usbHex(transport.vendorId),
8
+ productId: usbHex(transport.productId),
9
+ productName: transport.productName
10
+ }
11
+ };
12
+ case 'serial': {
13
+ const s = transport.serial ?? {};
14
+ if (s.usbVendorId !== undefined) {
15
+ return {
16
+ usb: {
17
+ vendorId: usbHex(s.usbVendorId),
18
+ ...(s.usbProductId !== undefined ? { productId: usbHex(s.usbProductId) } : {})
19
+ }
20
+ };
21
+ }
22
+ return s.bluetoothServiceClassId
23
+ ? { bluetooth: { serviceUuids: [s.bluetoothServiceClassId.toLowerCase()] } }
24
+ : {};
25
+ }
26
+ case 'ble':
27
+ return transport.bleName === undefined ? {} : { bluetooth: { name: transport.bleName } };
28
+ }
29
+ }
30
+ //# sourceMappingURL=identity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"identity.js","sourceRoot":"","sources":["../src/identity.ts"],"names":[],"mappings":"AAYA,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,EAAU,EAAE,EAAE,CAAC,KAAK,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC;AAE9E,MAAM,UAAU,UAAU,CAAC,SAAoB;IAC9C,QAAQ,SAAS,CAAC,IAAI,EAAE,CAAC;QACxB,KAAK,KAAK;YACT,OAAO;gBACN,GAAG,EAAE;oBACJ,QAAQ,EAAE,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC;oBACpC,SAAS,EAAE,MAAM,CAAC,SAAS,CAAC,SAAS,CAAC;oBACtC,WAAW,EAAE,SAAS,CAAC,WAAW;iBAClC;aACD,CAAC;QACH,KAAK,QAAQ,CAAC,CAAC,CAAC;YACf,MAAM,CAAC,GAAG,SAAS,CAAC,MAAM,IAAI,EAAE,CAAC;YACjC,IAAI,CAAC,CAAC,WAAW,KAAK,SAAS,EAAE,CAAC;gBACjC,OAAO;oBACN,GAAG,EAAE;wBACJ,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAC,WAAW,CAAC;wBAC/B,GAAG,CAAC,CAAC,CAAC,YAAY,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;qBAC9E;iBACD,CAAC;YACH,CAAC;YACD,OAAO,CAAC,CAAC,uBAAuB;gBAC/B,CAAC,CAAC,EAAE,SAAS,EAAE,EAAE,YAAY,EAAE,CAAC,CAAC,CAAC,uBAAuB,CAAC,WAAW,EAAE,CAAC,EAAE,EAAE;gBAC5E,CAAC,CAAC,EAAE,CAAC;QACP,CAAC;QACD,KAAK,KAAK;YACT,OAAO,SAAS,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,EAAE,IAAI,EAAE,SAAS,CAAC,OAAO,EAAE,EAAE,CAAC;IAC3F,CAAC;AACF,CAAC"}
@@ -0,0 +1,18 @@
1
+ export { BridgeError, isBridgeError } from './errors.ts';
2
+ export type { BridgeErrorCode } from './errors.ts';
3
+ export type { HidCollectionInfo, HidReportInfo, HidTransport, SerialPortIdentity, StreamTransport, Transport, TransportKind } from './transport.ts';
4
+ export type { AnyHandler, Codec, Handler, HandlerCapabilities, HandlerContext, PullRequest, PullResult, PushRequest, PushResult, HidFrame, HidHandler, Slot, StreamHandler, WireField, WireGrid, WriteState } from './handler.ts';
5
+ export { SPP } from './handler.ts';
6
+ export { HANDLERS } from './handlers/index.ts';
7
+ export type { HandlerId, HandlerOptions } from './handlers/index.ts';
8
+ export { guessProtocol, KNOWN_HID_VENDORS, protocolForMatches, protocolOf, protocolProblem } from './protocols.ts';
9
+ export type { Protocol } from './protocols.ts';
10
+ export { chooserFilters } from './chooser.ts';
11
+ export type { ChooserEntry, ChooserFilters } from './chooser.ts';
12
+ export { identityOf, usbHex } from './identity.ts';
13
+ export type { DeviceIdentity } from './identity.ts';
14
+ export { analyzeCodec, handlerCodeUrl, MAX_ANALYSED_BANDS } from './analysis.ts';
15
+ export type { CodecAnalysis } from './analysis.ts';
16
+ export { openDevice, transportsOf } from './device.ts';
17
+ export type { BridgeDevice, DeviceCapabilities, OpenOptions } from './device.ts';
18
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACzD,YAAY,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACnD,YAAY,EACX,iBAAiB,EACjB,aAAa,EACb,YAAY,EACZ,kBAAkB,EAClB,eAAe,EACf,SAAS,EACT,aAAa,EACb,MAAM,gBAAgB,CAAC;AACxB,YAAY,EACX,UAAU,EACV,KAAK,EACL,OAAO,EACP,mBAAmB,EACnB,cAAc,EACd,WAAW,EACX,UAAU,EACV,WAAW,EACX,UAAU,EACV,QAAQ,EACR,UAAU,EACV,IAAI,EACJ,aAAa,EACb,SAAS,EACT,QAAQ,EACR,UAAU,EACV,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AACnC,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,YAAY,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrE,OAAO,EACN,aAAa,EACb,iBAAiB,EACjB,kBAAkB,EAClB,UAAU,EACV,eAAe,EACf,MAAM,gBAAgB,CAAC;AACxB,YAAY,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,YAAY,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AACjE,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACnD,YAAY,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACjF,YAAY,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AACvD,YAAY,EAAE,YAAY,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,12 @@
1
+ // @potatosalad775/eqcaps-device-bridge: reads and writes parametric EQ on audio hardware.
2
+ // Platform-free: handlers talk to the transport interfaces below. Browser transports (WebHID,
3
+ // Web Serial, Web Bluetooth) are in the `./browser` entry point.
4
+ export { BridgeError, isBridgeError } from "./errors.js";
5
+ export { SPP } from "./handler.js";
6
+ export { HANDLERS } from "./handlers/index.js";
7
+ export { guessProtocol, KNOWN_HID_VENDORS, protocolForMatches, protocolOf, protocolProblem } from "./protocols.js";
8
+ export { chooserFilters } from "./chooser.js";
9
+ export { identityOf, usbHex } from "./identity.js";
10
+ export { analyzeCodec, handlerCodeUrl, MAX_ANALYSED_BANDS } from "./analysis.js";
11
+ export { openDevice, transportsOf } from "./device.js";
12
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,0FAA0F;AAC1F,8FAA8F;AAC9F,iEAAiE;AAEjE,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AA6BzD,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AACnC,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAE/C,OAAO,EACN,aAAa,EACb,iBAAiB,EACjB,kBAAkB,EAClB,UAAU,EACV,eAAe,EACf,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAE9C,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAEnD,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAEjF,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC"}
package/dist/io.d.ts ADDED
@@ -0,0 +1,50 @@
1
+ import type { FilterType } from '@potatosalad775/eqcaps-core';
2
+ import type { HidFrame, PushRequest } from './handler.ts';
3
+ import type { HidTransport, StreamTransport } from './transport.ts';
4
+ /**
5
+ * Waits for the first input report that `match` accepts. Subscribe before sending the request,
6
+ * so a fast answer can't be missed.
7
+ */
8
+ export declare function waitForInput(transport: HidTransport, match: (data: Uint8Array, reportId: number) => boolean, timeoutMs: number, what: string): Promise<Uint8Array>;
9
+ /** Sends an output report and waits for the matching input report. */
10
+ export declare function hidRequest(transport: HidTransport, reportId: number, data: Uint8Array | number[], match: (data: Uint8Array, reportId: number) => boolean, timeoutMs: number, what: string): Promise<Uint8Array>;
11
+ /**
12
+ * Reads a byte stream into a buffer until `frame` finds a complete frame in it. `frame` returns
13
+ * the frame's [start, end) or null while incomplete. Bytes after the frame stay in the buffer for
14
+ * the next call.
15
+ */
16
+ export declare class StreamReader {
17
+ private buffer;
18
+ private readonly transport;
19
+ constructor(transport: StreamTransport);
20
+ readFrame(frame: (buffer: readonly number[]) => [number, number] | null, timeoutMs: number, what: string, now?: () => number): Promise<Uint8Array>;
21
+ /**
22
+ * Writes a request after dropping every byte received so far, buffered here or still queued in
23
+ * the transport: a late answer to an earlier request can't be taken for this one's.
24
+ */
25
+ send(data: Uint8Array): Promise<void>;
26
+ }
27
+ /**
28
+ * Filter type ↔ wire code table of one protocol. A numeric code without a known meaning decodes
29
+ * as the extension type `x-wire-<code>`, and that type encodes back to the same code, so a pull
30
+ * never hides what the device holds (D33).
31
+ */
32
+ export interface TypeCodes {
33
+ types: FilterType[];
34
+ encode(type: FilterType): number;
35
+ decode(code: number): FilterType;
36
+ }
37
+ export declare function typeCodes(handler: string, table: Partial<Record<FilterType, number>>, aliases?: [number, FilterType][]): TypeCodes;
38
+ /**
39
+ * Refuses the request fields a protocol's write doesn't carry. Dropped silently, a preamp or slot
40
+ * would look applied (D33).
41
+ */
42
+ export declare function refuseUncarried(handler: string, request: PushRequest, carries: {
43
+ preamp?: boolean;
44
+ slot?: boolean;
45
+ }): void;
46
+ /** Round to a fixed number of decimals, for values decoded from scaled integers. */
47
+ export declare function decimals(value: number, places: number): number;
48
+ export declare const hidFrame: (reportId: number, data: ArrayLike<number>, feature?: boolean) => HidFrame;
49
+ export declare function sendFrame(transport: HidTransport, frame: HidFrame): Promise<void>;
50
+ //# sourceMappingURL=io.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"io.d.ts","sourceRoot":"","sources":["../src/io.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAG9D,OAAO,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC1D,OAAO,KAAK,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAEpE;;;GAGG;AACH,wBAAgB,YAAY,CAC3B,SAAS,EAAE,YAAY,EACvB,KAAK,EAAE,CAAC,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,KAAK,OAAO,EACtD,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,MAAM,GACV,OAAO,CAAC,UAAU,CAAC,CAarB;AAED,sEAAsE;AACtE,wBAAsB,UAAU,CAC/B,SAAS,EAAE,YAAY,EACvB,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,UAAU,GAAG,MAAM,EAAE,EAC3B,KAAK,EAAE,CAAC,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,KAAK,OAAO,EACtD,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,MAAM,GACV,OAAO,CAAC,UAAU,CAAC,CAMrB;AAED;;;;GAIG;AACH,qBAAa,YAAY;IACxB,OAAO,CA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CAAC,IAAI,CAAC,CAIjF"}
package/dist/io.js ADDED
@@ -0,0 +1,119 @@
1
+ // Request/response helpers shared by handlers.
2
+ import { BridgeError } from "./errors.js";
3
+ import { after } from "./platform.js";
4
+ /**
5
+ * Waits for the first input report that `match` accepts. Subscribe before sending the request,
6
+ * so a fast answer can't be missed.
7
+ */
8
+ export function waitForInput(transport, match, timeoutMs, what) {
9
+ return new Promise((resolve, reject) => {
10
+ const cancel = after(timeoutMs, () => {
11
+ unsubscribe();
12
+ reject(new BridgeError('timeout', `No answer to ${what} within ${timeoutMs} ms`));
13
+ });
14
+ const unsubscribe = transport.onInputReport((reportId, data) => {
15
+ if (!match(data, reportId))
16
+ return;
17
+ cancel();
18
+ unsubscribe();
19
+ resolve(data);
20
+ });
21
+ });
22
+ }
23
+ /** Sends an output report and waits for the matching input report. */
24
+ export async function hidRequest(transport, reportId, data, match, timeoutMs, what) {
25
+ const answer = waitForInput(transport, match, timeoutMs, what);
26
+ // Keeps a send failure from leaving the wait's rejection unhandled.
27
+ answer.catch(() => { });
28
+ await transport.sendReport(reportId, Uint8Array.from(data));
29
+ return answer;
30
+ }
31
+ /**
32
+ * Reads a byte stream into a buffer until `frame` finds a complete frame in it. `frame` returns
33
+ * the frame's [start, end) or null while incomplete. Bytes after the frame stay in the buffer for
34
+ * the next call.
35
+ */
36
+ export class StreamReader {
37
+ buffer = [];
38
+ transport;
39
+ constructor(transport) {
40
+ this.transport = transport;
41
+ }
42
+ async readFrame(frame, timeoutMs, what, now = Date.now) {
43
+ const deadline = now() + timeoutMs;
44
+ for (;;) {
45
+ const found = frame(this.buffer);
46
+ if (found) {
47
+ const [start, end] = found;
48
+ const bytes = Uint8Array.from(this.buffer.slice(start, end));
49
+ this.buffer = this.buffer.slice(end);
50
+ return bytes;
51
+ }
52
+ const remaining = deadline - now();
53
+ if (remaining <= 0)
54
+ break;
55
+ const chunk = await this.transport.read(remaining);
56
+ if (!chunk)
57
+ break;
58
+ for (const b of chunk)
59
+ this.buffer.push(b);
60
+ }
61
+ throw new BridgeError('timeout', `No complete answer to ${what} within ${timeoutMs} ms`);
62
+ }
63
+ /**
64
+ * Writes a request after dropping every byte received so far, buffered here or still queued in
65
+ * the transport: a late answer to an earlier request can't be taken for this one's.
66
+ */
67
+ async send(data) {
68
+ this.buffer = [];
69
+ // Bounded, so a device that never stops sending can't stall the request.
70
+ for (let i = 0; i < 64 && (await this.transport.read(0)); i++)
71
+ ;
72
+ await this.transport.write(data);
73
+ }
74
+ }
75
+ const WIRE = /^x-wire-(\d+)$/;
76
+ export function typeCodes(handler, table, aliases = []) {
77
+ const entries = Object.entries(table);
78
+ return {
79
+ types: entries.map(([t]) => t),
80
+ encode(type) {
81
+ const code = table[type] ?? (WIRE.test(type) ? Number(WIRE.exec(type)[1]) : undefined);
82
+ if (code === undefined) {
83
+ throw new BridgeError('unsupported-type', `${handler} has no wire code for type ${type}`);
84
+ }
85
+ return code;
86
+ },
87
+ decode(code) {
88
+ return (entries.find(([, c]) => c === code)?.[0] ??
89
+ aliases.find(([c]) => c === code)?.[1] ??
90
+ `x-wire-${code}`);
91
+ }
92
+ };
93
+ }
94
+ /**
95
+ * Refuses the request fields a protocol's write doesn't carry. Dropped silently, a preamp or slot
96
+ * would look applied (D33).
97
+ */
98
+ export function refuseUncarried(handler, request, carries) {
99
+ if (request.preamp !== undefined && !carries.preamp) {
100
+ throw new BridgeError('invalid-request', `${handler}: the write carries no preamp`);
101
+ }
102
+ if (request.slot !== undefined && !carries.slot) {
103
+ throw new BridgeError('invalid-request', `${handler}: the write names no preset slot`);
104
+ }
105
+ }
106
+ /** Round to a fixed number of decimals, for values decoded from scaled integers. */
107
+ export function decimals(value, places) {
108
+ const f = 10 ** places;
109
+ return Math.round(value * f) / f;
110
+ }
111
+ export const hidFrame = (reportId, data, feature = false) => feature
112
+ ? { reportId, feature: true, data: Uint8Array.from(data) }
113
+ : { reportId, data: Uint8Array.from(data) };
114
+ export function sendFrame(transport, frame) {
115
+ return frame.feature
116
+ ? transport.sendFeatureReport(frame.reportId, frame.data)
117
+ : transport.sendReport(frame.reportId, frame.data);
118
+ }
119
+ //# sourceMappingURL=io.js.map
package/dist/io.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"io.js","sourceRoot":"","sources":["../src/io.ts"],"names":[],"mappings":"AAAA,+CAA+C;AAG/C,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAItC;;;GAGG;AACH,MAAM,UAAU,YAAY,CAC3B,SAAuB,EACvB,KAAsD,EACtD,SAAiB,EACjB,IAAY;IAEZ,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACtC,MAAM,MAAM,GAAG,KAAK,CAAC,SAAS,EAAE,GAAG,EAAE;YACpC,WAAW,EAAE,CAAC;YACd,MAAM,CAAC,IAAI,WAAW,CAAC,SAAS,EAAE,gBAAgB,IAAI,WAAW,SAAS,KAAK,CAAC,CAAC,CAAC;QACnF,CAAC,CAAC,CAAC;QACH,MAAM,WAAW,GAAG,SAAS,CAAC,aAAa,CAAC,CAAC,QAAQ,EAAE,IAAI,EAAE,EAAE;YAC9D,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,QAAQ,CAAC;gBAAE,OAAO;YACnC,MAAM,EAAE,CAAC;YACT,WAAW,EAAE,CAAC;YACd,OAAO,CAAC,IAAI,CAAC,CAAC;QACf,CAAC,CAAC,CAAC;IACJ,CAAC,CAAC,CAAC;AACJ,CAAC;AAED,sEAAsE;AACtE,MAAM,CAAC,KAAK,UAAU,UAAU,CAC/B,SAAuB,EACvB,QAAgB,EAChB,IAA2B,EAC3B,KAAsD,EACtD,SAAiB,EACjB,IAAY;IAEZ,MAAM,MAAM,GAAG,YAAY,CAAC,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE,IAAI,CAAC,CAAC;IAC/D,oEAAoE;IACpE,MAAM,CAAC,KAAK,CAAC,G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;AAE9C,MAAM,UAAU,SAAS,CAAC,SAAuB,EAAE,KAAe;IACjE,OAAO,KAAK,CAAC,OAAO;QACnB,CAAC,CAAC,SAAS,CAAC,iBAAiB,CAAC,KAAK,CAAC,QAAQ,EAAE,KAAK,CAAC,IAAI,CAAC;QACzD,CAAC,CAAC,SAAS,CAAC,UAAU,CAAC,KAAK,CAAC,QAAQ,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;AACrD,CAAC"}
@@ -0,0 +1,9 @@
1
+ /** Resolves after `ms` milliseconds. */
2
+ export declare function realSleep(ms: number): Promise<void>;
3
+ /** Runs `fn` after `ms`; returns a cancel function. */
4
+ export declare function after(ms: number, fn: () => void): () => void;
5
+ /** UTF-8 encoding without TextEncoder, which ES2023 doesn't declare. */
6
+ export declare function utf8Encode(text: string): Uint8Array;
7
+ /** UTF-8 decoding; malformed sequences become U+FFFD. */
8
+ export declare function utf8Decode(bytes: Uint8Array): string;
9
+ //# sourceMappingURL=platform.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"platform.d.ts","sourceRoot":"","sources":["../src/platform.ts"],"names":[],"mappings":"AAUA,wCAAwC;AACxC,wBAAgB,SAAS,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAEnD;AAED,uDAAuD;AACvD,wBAAgB,KAAK,CAAC,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI,CAG5D;AAED,wEAAwE;AACxE,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,CAWnD;AAED,yDAAyD;AACzD,wBAAgB,UAAU,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CA0BpD"}
@@ -0,0 +1,59 @@
1
+ // The few platform facilities handlers need, read from globalThis with only the types used, so
2
+ // the package has no DOM or Node types (same approach as the client, D32).
3
+ const timers = globalThis;
4
+ /** Resolves after `ms` milliseconds. */
5
+ export function realSleep(ms) {
6
+ return new Promise((resolve) => timers.setTimeout(resolve, ms));
7
+ }
8
+ /** Runs `fn` after `ms`; returns a cancel function. */
9
+ export function after(ms, fn) {
10
+ const handle = timers.setTimeout(fn, ms);
11
+ return () => timers.clearTimeout(handle);
12
+ }
13
+ /** UTF-8 encoding without TextEncoder, which ES2023 doesn't declare. */
14
+ export function utf8Encode(text) {
15
+ const out = [];
16
+ for (const ch of text) {
17
+ const c = ch.codePointAt(0);
18
+ if (c < 0x80)
19
+ out.push(c);
20
+ else if (c < 0x800)
21
+ out.push(0xc0 | (c >> 6), 0x80 | (c & 63));
22
+ else if (c < 0x10000)
23
+ out.push(0xe0 | (c >> 12), 0x80 | ((c >> 6) & 63), 0x80 | (c & 63));
24
+ else
25
+ out.push(0xf0 | (c >> 18), 0x80 | ((c >> 12) & 63), 0x80 | ((c >> 6) & 63), 0x80 | (c & 63));
26
+ }
27
+ return new Uint8Array(out);
28
+ }
29
+ /** UTF-8 decoding; malformed sequences become U+FFFD. */
30
+ export function utf8Decode(bytes) {
31
+ let out = '';
32
+ for (let i = 0; i < bytes.length;) {
33
+ const b = bytes[i];
34
+ const n = b < 0x80 ? 0 : b >= 0xf8 ? -1 : b >= 0xf0 ? 3 : b >= 0xe0 ? 2 : b >= 0xc0 ? 1 : -1;
35
+ if (n <= 0) {
36
+ out += n === 0 ? String.fromCharCode(b) : '�';
37
+ i++;
38
+ continue;
39
+ }
40
+ let c = b & (0x3f >> n);
41
+ let ok = true;
42
+ for (let k = 1; k <= n; k++) {
43
+ const cont = bytes[i + k];
44
+ if (cont === undefined || (cont & 0xc0) !== 0x80)
45
+ ok = false;
46
+ else
47
+ c = (c << 6) | (cont & 63);
48
+ }
49
+ if (!ok) {
50
+ out += '�';
51
+ i++;
52
+ continue;
53
+ }
54
+ out += String.fromCodePoint(c);
55
+ i += n + 1;
56
+ }
57
+ return out;
58
+ }
59
+ //# sourceMappingURL=platform.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"platform.js","sourceRoot":"","sources":["../src/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CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;YAC7B,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;YAC1B,IAAI,IAAI,KAAK,SAAS,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,KAAK,IAAI;gBAAE,EAAE,GAAG,KAAK,CAAC;;gBACxD,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,IAAI,GAAG,EAAE,CAAC,CAAC;QACjC,CAAC;QACD,IAAI,CAAC,EAAE,EAAE,CAAC;YACT,GAAG,IAAI,GAAG,CAAC;YACX,CAAC,EAAE,CAAC;YACJ,SAAS;QACV,CAAC;QACD,GAAG,IAAI,MAAM,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;QAC/B,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACZ,CAAC;IACD,OAAO,GAAG,CAAC;AACZ,CAAC"}
@@ -0,0 +1,52 @@
1
+ import type { Slot } from './handler.ts';
2
+ import { type HandlerId, type HandlerOptions } from './handlers/index.ts';
3
+ interface ProtocolBase {
4
+ /** EQ preset slots the device offers; the one marked `bypass` turns the EQ off. */
5
+ presets?: readonly Slot[];
6
+ /** The device drops the connection after a push that saves. */
7
+ disconnectOnSave?: boolean;
8
+ /** The protocol for this device is unconfirmed. */
9
+ experimental?: boolean;
10
+ /** Serial ports: the baud rate. Default 115200 over USB, 9600 over Bluetooth. */
11
+ baudRate?: number;
12
+ }
13
+ /** How to drive one device: a handler and its settings. */
14
+ export type Protocol = {
15
+ [K in HandlerId]: ProtocolBase & {
16
+ handler: K;
17
+ options?: HandlerOptions<K>;
18
+ };
19
+ }[HandlerId];
20
+ /**
21
+ * Why this bridge can't drive a profile's `protocol`, or undefined when it can: a handler it
22
+ * doesn't have (data newer than the bridge), or settings that handler doesn't take.
23
+ */
24
+ export declare function protocolProblem(raw: unknown): string | undefined;
25
+ /**
26
+ * How to drive the device a profile (or its index entry) describes: its `protocol`, checked
27
+ * against this bridge's handlers. Undefined when it has none, or one this bridge can't drive.
28
+ */
29
+ export declare function protocolOf(profile: {
30
+ protocol?: unknown;
31
+ } | null | undefined): Protocol | undefined;
32
+ /**
33
+ * How to drive a device, from the profiles it matches, most specific first: the client's
34
+ * `matchDevice` matches (or the profiles or index entries themselves, in that order). Gives the
35
+ * protocol of the first one that has one this bridge can drive, and which profile that was.
36
+ */
37
+ export declare function protocolForMatches(matches: Iterable<{
38
+ id: string;
39
+ protocol?: unknown;
40
+ entry?: {
41
+ protocol?: unknown;
42
+ };
43
+ }>): {
44
+ profileId: string;
45
+ protocol: Protocol;
46
+ } | undefined;
47
+ /** USB vendor ids the vendor guesses cover: a default filter for a browser's HID chooser. */
48
+ export declare const KNOWN_HID_VENDORS: readonly number[];
49
+ /** The protocol a HID device's vendor usually speaks, marked experimental; undefined if none. */
50
+ export declare function guessProtocol(vendorId: number): Protocol | undefined;
51
+ export {};
52
+ //# sourceMappingURL=protocols.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protocols.d.ts","sourceRoot":"","sources":["../src/protocols.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAY,KAAK,SAAS,EAAE,KAAK,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAEpF,UAAU,YAAY;IACrB,mFAAmF;IACnF,OAAO,CAAC,EAAE,SAAS,IAAI,EAAE,CAAC;IAC1B,+DAA+D;IAC/D,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,mDAAmD;IACnD,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,iFAAiF;IACjF,QAAQ,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,2DAA2D;AAC3D,MAAM,MAAM,QAAQ,GAAG;KACrB,CAAC,IAAI,SAAS,GAAG,YAAY,GAAG;QAAE,OAAO,EAAE,CAAC,CAAC;QAAC,OAAO,CAAC,EAAE,cAAc,CAAC,CAAC,CAAC,CAAA;KAAE;CAC5E,CAAC,SAAS,CAAC,CAAC;AA8Hb;;;GAGG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAOhE;AAED;;;GAGG;AACH,wBAAgB,UAAU,CACzB,OAAO,EAAE;IAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAE,GAAG,IAAI,GAAG,SAAS,GAChD,QAAQ,GAAG,SAAS,CAOtB;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CACjC,OAAO,EAAE,QAAQ,CAAC;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;IAAC,KAAK,CAAC,EAAE;QAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;KAAE,CAAA;CAAE,CAAC,GACnF;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,QAAQ,CAAA;CAAE,GAAG,SAAS,CAMvD;AAgDD,6FAA6F;AAC7F,eAAO,MAAM,iBAAiB,EAAE,SAAS,MAAM,EAA4C,CAAC;AAE5F,iGAAiG;AACjG,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,QAAQ,GAAG,SAAS,CAGpE"}
@@ -0,0 +1,204 @@
1
+ // How to drive a device (D33, D42). A profile's `protocol` names the handler and the settings that
2
+ // differ between the devices it drives: options, preset slots, transport details. The database
3
+ // holds them, so a device on a known protocol needs a profile and no bridge release; this module
4
+ // checks what the data says against the handlers this bridge has. The wire formats themselves are
5
+ // in the handlers (invariant 2).
6
+ import { HANDLERS } from "./handlers/index.js";
7
+ const fail = (why) => {
8
+ throw new Error(why);
9
+ };
10
+ /** A byte, written as a number or a hex string (`"0x3f"`, like the profiles' USB ids). */
11
+ const byte = (v) => {
12
+ const n = typeof v === 'string' && /^0x[0-9a-f]{1,2}$/.test(v) ? parseInt(v, 16) : v;
13
+ return typeof n === 'number' && Number.isInteger(n) && n >= 0 && n <= 0xff
14
+ ? n
15
+ : fail(`${JSON.stringify(v)} is not a byte`);
16
+ };
17
+ /** Any finite number. */
18
+ const number = (v) => typeof v === 'number' && Number.isFinite(v) ? v : fail(`${JSON.stringify(v)} is not a number`);
19
+ const isObject = (v) => typeof v === 'object' && v !== null && !Array.isArray(v);
20
+ /** KT Micro's per-band register pairs. */
21
+ const registers = (v) => Array.isArray(v) && v.length > 0
22
+ ? v.map((r) => {
23
+ if (!isObject(r) || Object.keys(r).some((k) => k !== 'freq' && k !== 'q')) {
24
+ fail(`${JSON.stringify(r)} is not a register pair`);
25
+ }
26
+ const { freq, q } = r;
27
+ return { freq: byte(freq), q: byte(q) };
28
+ })
29
+ : fail('not a list of register pairs');
30
+ /**
31
+ * The options a profile may set, per handler. Options a handler derives itself (Qudelix's report
32
+ * from the descriptor, Airoha's layout from the transport) aren't data and are left out.
33
+ */
34
+ const OPTIONS = {
35
+ 'fiio-usb-hid': { reportId: byte, saveCommand: byte },
36
+ 'walkplay-hid': { defaultSlot: byte },
37
+ 'moondrop-usb-hid': {},
38
+ 'moondrop-old-fashioned-hid': {},
39
+ 'conexant-usb-hid': {},
40
+ 'ktmicro-usb-hid': {
41
+ baseRegister: byte,
42
+ bandRegisters: registers,
43
+ customSlot: byte
44
+ },
45
+ 'fosi-audio-usb-hid': { reportId: byte, bandwidth: number, defaultSlot: byte },
46
+ 'qudelix-usb-hid': {},
47
+ 'jds-labs-usb-serial': {},
48
+ 'nothing-usb-serial': { customSlot: byte },
49
+ 'fiio-usb-serial': { saveCommand: byte },
50
+ 'fiio-f110': {},
51
+ 'tanchjim-rita-serial': {},
52
+ 'moondrop-edge-serial': {},
53
+ 'edifier-serial': {},
54
+ airoha: {}
55
+ };
56
+ function read(raw) {
57
+ if (!isObject(raw))
58
+ fail('not an object');
59
+ const { handler, options, presets, disconnectOnSave, experimental, baudRate } = raw;
60
+ if (typeof handler !== 'string' || !Object.hasOwn(HANDLERS, handler)) {
61
+ fail(`this bridge has no handler "${String(handler)}"`);
62
+ }
63
+ const id = handler;
64
+ const out = { handler: id };
65
+ if (options !== undefined) {
66
+ if (!isObject(options))
67
+ fail('options: not an object');
68
+ const known = OPTIONS[id];
69
+ const parsed = {};
70
+ for (const [k, v] of Object.entries(options)) {
71
+ if (k.startsWith('x-'))
72
+ continue;
73
+ const option = Object.hasOwn(known, k) ? known[k] : undefined;
74
+ if (!option)
75
+ fail(`options: ${id} has no option "${k}"`);
76
+ try {
77
+ parsed[k] = option(v);
78
+ }
79
+ catch (e) {
80
+ fail(`options.${k}: ${e.message}`);
81
+ }
82
+ }
83
+ if (Object.keys(parsed).length)
84
+ out.options = parsed;
85
+ }
86
+ if (presets !== undefined) {
87
+ const ids = new Set();
88
+ let bypassed = false;
89
+ out.presets = (Array.isArray(presets) ? presets : fail('presets: not a list')).map((p) => {
90
+ const { id: slot, name, bypass } = isObject(p) ? p : fail('presets: not an object');
91
+ if (typeof slot !== 'number' || !Number.isInteger(slot) || slot < 0) {
92
+ fail(`presets: id ${JSON.stringify(slot)}`);
93
+ }
94
+ if (typeof name !== 'string' || !name)
95
+ fail(`presets: name of ${String(slot)}`);
96
+ if (ids.has(slot))
97
+ fail(`presets: id ${String(slot)} twice`);
98
+ ids.add(slot);
99
+ if (bypass === undefined || bypass === false)
100
+ return { id: slot, name };
101
+ if (bypass !== true)
102
+ fail(`presets: bypass of ${String(slot)} is not a boolean`);
103
+ if (bypassed)
104
+ fail('presets: more than one bypass preset');
105
+ if (!HANDLERS[id].bypassPreset)
106
+ fail(`presets: ${id} turns the EQ off without a preset`);
107
+ bypassed = true;
108
+ return { id: slot, name, bypass: true };
109
+ });
110
+ }
111
+ for (const [k, v] of [
112
+ ['disconnectOnSave', disconnectOnSave],
113
+ ['experimental', experimental]
114
+ ]) {
115
+ if (v !== undefined)
116
+ out[k] = typeof v === 'boolean' ? v : fail(`${k}: not a boolean`);
117
+ }
118
+ if (baudRate !== undefined) {
119
+ out.baudRate =
120
+ typeof baudRate === 'number' && Number.isInteger(baudRate) && baudRate > 0
121
+ ? baudRate
122
+ : fail('baudRate: not a positive integer');
123
+ }
124
+ return out;
125
+ }
126
+ /**
127
+ * Why this bridge can't drive a profile's `protocol`, or undefined when it can: a handler it
128
+ * doesn't have (data newer than the bridge), or settings that handler doesn't take.
129
+ */
130
+ export function protocolProblem(raw) {
131
+ try {
132
+ read(raw);
133
+ return undefined;
134
+ }
135
+ catch (e) {
136
+ return e.message;
137
+ }
138
+ }
139
+ /**
140
+ * How to drive the device a profile (or its index entry) describes: its `protocol`, checked
141
+ * against this bridge's handlers. Undefined when it has none, or one this bridge can't drive.
142
+ */
143
+ export function protocolOf(profile) {
144
+ if (profile?.protocol === undefined)
145
+ return undefined;
146
+ try {
147
+ return read(profile.protocol);
148
+ }
149
+ catch {
150
+ return undefined;
151
+ }
152
+ }
153
+ /**
154
+ * How to drive a device, from the profiles it matches, most specific first: the client's
155
+ * `matchDevice` matches (or the profiles or index entries themselves, in that order). Gives the
156
+ * protocol of the first one that has one this bridge can drive, and which profile that was.
157
+ */
158
+ export function protocolForMatches(matches) {
159
+ for (const match of matches) {
160
+ const protocol = protocolOf(match.entry ?? match);
161
+ if (protocol)
162
+ return { profileId: match.id, protocol };
163
+ }
164
+ return undefined;
165
+ }
166
+ // --- Devices without a profile --------------------------------------------------------------------
167
+ const presets = (...list) => list.map(([id, name]) => ({ id, name }));
168
+ const users = (first, count) => presets(...Array.from({ length: count }, (_, i) => [first + i, `USER${i + 1}`]));
169
+ /**
170
+ * Vendors whose devices mostly speak one protocol. For a device the database doesn't know, this
171
+ * is a guess: the protocol is marked experimental, and without a profile a pull needs `bands`.
172
+ */
173
+ const HID_VENDORS = [
174
+ {
175
+ vendorIds: [0x2972, 0x0a12],
176
+ protocol: {
177
+ handler: 'fiio-usb-hid',
178
+ presets: [
179
+ ...presets([0, 'Jazz'], [1, 'Pop'], [2, 'Rock'], [3, 'Dance'], [4, 'R&B'], [5, 'Classic'], [6, 'Hip-hop'], [7, 'Monitor']),
180
+ ...users(160, 10)
181
+ ]
182
+ }
183
+ },
184
+ {
185
+ vendorIds: [
186
+ 0x0104, 0x011b, 0x011d, 0x0661, 0x0663, 0x0666, 0x0762, 0x0909, 0x0d8c, 0x2fc6, 0x3302,
187
+ 0x34be, 0x35d8, 0x36a7, 0x373b, 0x60c1, 0x60e1, 0xb445, 0xb44d
188
+ ],
189
+ protocol: { handler: 'walkplay-hid', presets: presets([101, 'Custom']) }
190
+ },
191
+ {
192
+ vendorIds: [0x31b2],
193
+ protocol: { handler: 'ktmicro-usb-hid', presets: presets([3, 'Custom']) }
194
+ },
195
+ { vendorIds: [0x152a], protocol: { handler: 'fosi-audio-usb-hid' } }
196
+ ];
197
+ /** USB vendor ids the vendor guesses cover: a default filter for a browser's HID chooser. */
198
+ export const KNOWN_HID_VENDORS = HID_VENDORS.flatMap((v) => v.vendorIds);
199
+ /** The protocol a HID device's vendor usually speaks, marked experimental; undefined if none. */
200
+ export function guessProtocol(vendorId) {
201
+ const v = HID_VENDORS.find((x) => x.vendorIds.includes(vendorId));
202
+ return v && { ...v.protocol, experimental: true };
203
+ }
204
+ //# sourceMappingURL=protocols.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protocols.js","sourceRoot":"","sources":["../src/protocols.ts"],"names":[],"mappings":"AAAA,mGAAmG;AACnG,+FAA+F;AAC/F,iGAAiG;AACjG,kGAAkG;AAClG,iCAAiC;AAGjC,OAAO,EAAE,QAAQ,EAAuC,MAAM,qBAAqB,CAAC;AAuBpF,MAAM,IAAI,GAAG,CAAC,GAAW,EAAS,EAAE;IACnC,MAAM,IAAI,KAAK,CAAC,GAAG,CAAC,CAAC;AACtB,CAAC,CAAC;AAEF,0FAA0F;AAC1F,MAAM,IAAI,GAAS,CAAC,CAAC,EAAE,EAAE;IACxB,MAAM,CAAC,GAAG,OAAO,CAAC,KAAK,QAAQ,IAAI,mBAAmB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,EA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