diff --git a/.husky/pre-commit b/.husky/pre-commit old mode 100755 new mode 100644 diff --git a/src/dicta_sonicMic_3_device.ts b/src/dicta_sonicMic_3_device.ts new file mode 100644 index 0000000..61e26c0 --- /dev/null +++ b/src/dicta_sonicMic_3_device.ts @@ -0,0 +1,47 @@ +import {ButtonEvent, DeviceType, DictationDeviceBase, ImplementationType} from './dictation_device_base'; + +const BUTTON_MAPPINGS = new Map([ + [ButtonEvent.REWIND, 1 << 0], + // returns "3" in reality, see getInputBitmask + [ButtonEvent.FORWARD, 1 << 1], + [ButtonEvent.PLAY, 1 << 2], + [ButtonEvent.RECORD, 1 << 8], + [ButtonEvent.INSTR, 1 << 9], + [ButtonEvent.TAB_BACKWARD, 1 << 10], + [ButtonEvent.F2_B, 1 << 11], + [ButtonEvent.TAB_FORWARD, 1 << 12], + [ButtonEvent.F3_C, 1 << 13], + [ButtonEvent.F1_A, 1 << 15], + [ButtonEvent.TRANSCRIBE, 1 << 16], + [ButtonEvent.INS_OVR, 1 << 17], + [ButtonEvent.ENTER_SELECT, 1 << 22], +]); + +export class SonicMic3Device extends DictationDeviceBase { + readonly implType = ImplementationType.SONICMIC_3; + + static create(hidDevice: HIDDevice) { + return new SonicMic3Device(hidDevice); + } + + getDeviceType(): DeviceType { + return DeviceType.SONICMIC_3; + } + + protected getButtonMappings(): Map { + return BUTTON_MAPPINGS; + } + + protected getInputBitmask(data: DataView): number { + const raw = data.getUint32(4, false); + // FORWARD returns value "3", which is "11" in binary. + // This makes it incompatible for single-bit bitmasking + // So we return 2 (10) instead & map this in BUTTON_MAPPINGS + if (raw === 3) return 1 << 1; + return raw; + } + + protected getThisAsDictationDevice(): SonicMic3Device { + return this; + } +} diff --git a/src/dictation_device.ts b/src/dictation_device.ts index cfdc22f..006bf1d 100644 --- a/src/dictation_device.ts +++ b/src/dictation_device.ts @@ -15,10 +15,11 @@ * limitations under the License. */ +import {SonicMic3Device} from './dicta_sonicMic_3_device'; import {FootControlDevice} from './foot_control_device'; import {PowerMic3Device} from './powermic_3_device'; import {SpeechMikeGamepadDevice} from './speechmike_gamepad_device'; import {SpeechMikeHidDevice} from './speechmike_hid_device'; export type DictationDevice =|SpeechMikeHidDevice|SpeechMikeGamepadDevice| - PowerMic3Device|FootControlDevice; + PowerMic3Device|FootControlDevice|SonicMic3Device; diff --git a/src/dictation_device_base.ts b/src/dictation_device_base.ts index 11e75a6..87f8e92 100644 --- a/src/dictation_device_base.ts +++ b/src/dictation_device_base.ts @@ -22,6 +22,7 @@ export enum ImplementationType { SPEECHMIKE_GAMEPAD = 1, FOOT_CONTROL = 2, POWERMIC_3 = 3, + SONICMIC_3 = 4, } export enum DeviceType { @@ -49,6 +50,7 @@ export enum DeviceType { POWERMIC_3 = 4097, POWERMIC_4 = 100, SPEECHMIKE_AMBIENT_PSM5000 = 5000, + SONICMIC_3 = 7000, } export enum ButtonEvent { diff --git a/src/dictation_device_manager.ts b/src/dictation_device_manager.ts index f10bed9..57259b3 100644 --- a/src/dictation_device_manager.ts +++ b/src/dictation_device_manager.ts @@ -15,6 +15,7 @@ * limitations under the License. */ +import {SonicMic3Device} from './dicta_sonicMic_3_device'; import {DictationDevice} from './dictation_device'; import {ButtonEventListener, ImplementationType} from './dictation_device_base'; import {FootControlDevice} from './foot_control_device'; @@ -70,6 +71,11 @@ const DEVICE_FILTERS: Readonly< Object.freeze( {vendorId: 0x0554, productId: 0x1001, usagePage: 1, usage: 0}), ]), + [ImplementationType.SONICMIC_3]: Object.freeze([ + // SonicMic III + Object.freeze( + {vendorId: 0x15D8, productId: 0x002A, usagePage: 65280, usage: 1}), + ]), }); export class DictationDeviceManager { @@ -214,6 +220,8 @@ export class DictationDeviceManager { return SpeechMikeGamepadDevice.create(hidDevice); case ImplementationType.FOOT_CONTROL: return FootControlDevice.create(hidDevice); + case ImplementationType.SONICMIC_3: + return SonicMic3Device.create(hidDevice); default: checkExhaustive(implType); } diff --git a/src/index.ts b/src/index.ts index 10ded03..a6dcb13 100644 --- a/src/index.ts +++ b/src/index.ts @@ -21,3 +21,4 @@ export * from './foot_control_device'; export * from './powermic_3_device'; export * from './speechmike_gamepad_device'; export * from './speechmike_hid_device'; +export * from './dicta_sonicMic_3_device';