Created
December 18, 2024 13:28
-
-
Save cambiata/eb4ca6aadc130a52117b6faa67f32146 to your computer and use it in GitHub Desktop.
BlackmagickSpeedEditorDeno.ts - A Deno-fied version of https://github.com/Haavard15/SpeedEditorHID
This file contains hidden or 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
{ | |
"nodeModulesDir": "auto", | |
"tasks": { | |
"dev": "deno run --watch main.ts" | |
}, | |
"imports": { | |
"@std/assert": "jsr:@std/assert@1", | |
"node-hid": "npm:node-hid@^3.1.2" | |
} | |
} |
This file contains hidden or 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
deno --allow-read --allow-ffi main.ts |
This file contains hidden or 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
import HID from 'node-hid'; | |
import { Buffer } from "node:buffer"; | |
const device = new HID.HID(7899, 55822); | |
function hexToBinary(hexArray: string[]) { | |
const binaryArray: number[] = [] | |
hexArray.forEach(hexNumber => { | |
binaryArray.push(parseInt(hexNumber, 16)) | |
}) | |
return binaryArray | |
} | |
console.log("Feature Report 1:", device.getFeatureReport(1, 8)) | |
console.log("Feature Report 8:", device.getFeatureReport(8, 33)) | |
device.write(Buffer.from([3, 2, 0, 0, 0, 0, 255])) | |
device.write(Buffer.from([4, 1])) | |
device.write(Buffer.from([2, 32, 0, 0, 0])) | |
device.sendFeatureReport(Buffer.from([6, 0, 0, 0, 0, 0, 0, 0, 0, 0])) | |
console.log("Feature Report 6:", device.getFeatureReport(6, 10)) | |
device.write(Buffer.from([3, 2, 0, 0, 0, 0, 255])) | |
device.write(Buffer.from([4, 1])) | |
device.write(Buffer.from([2, 32])) | |
device.sendFeatureReport(Buffer.from(hexToBinary(["06", "01", "B0", "DD", "AF", "58", "39", "E1", "89", "86"]))) | |
device.sendFeatureReport(Buffer.from(hexToBinary(["06", "03", "68", "06", "57", "9D", "01", "76", "4C", "1D"]))) | |
device.sendFeatureReport(Buffer.from(hexToBinary(["06", "00", "00", "00", "00", "00", "00", "00", "00", "00"]))) | |
device.sendFeatureReport(Buffer.from(hexToBinary(["06", "01", "C9", "86", "49", "19", "1A", "36", "03", "C5"]))) | |
device.sendFeatureReport(Buffer.from(hexToBinary(["06", "03", "C0", "A3", "15", "4D", "F7", "DE", "DE", "76"]))) | |
const buttons = [ | |
"Smart Insert", | |
"Append", | |
"Ripple", | |
"Close Up", | |
"Place On Top", | |
"Source", | |
"In", | |
"Out", | |
"Trim In", | |
"Trim Out", | |
"Roll", | |
"Slip Source", | |
"Slip Destination", | |
"Transistion Duration", | |
"Cut", | |
"Dissolve", | |
"Smooth Cut", | |
"Smooth Cut", | |
] | |
const otherButtons: { [key: number]: string } = { | |
49: "Escape", | |
31: "Sync Bin", | |
44: "Audio Level", | |
45: "Full View", | |
34: "Transistion", | |
47: "Split", | |
46: "Snap", | |
43: "Ripple Delete", | |
51: "Camera 1", | |
52: "Camera 2", | |
53: "Camera 3", | |
54: "Camera 4", | |
55: "Camera 5", | |
56: "Camera 6", | |
57: "Camera 7", | |
58: "Camera 8", | |
59: "Camera 9", | |
48: "Live", | |
37: "Video Only", | |
38: "Audio Only", | |
60: "Play / Pause", | |
26: "Source", | |
27: "Timeline", | |
} | |
Object.keys(otherButtons).forEach((buttonNumber: string) => { | |
const nr = parseInt(buttonNumber); | |
buttons[`${(nr - 1)}`] = otherButtons[nr]; | |
}); | |
buttons.forEach((button, i) => { | |
console.log(i, button) | |
}); | |
let previousButtons: number[] = [] | |
device.on("error", function (err) { | |
console.log('error', err) | |
}); | |
device.on("data", function (data) { | |
const dataArray = [...data]; | |
switch (dataArray[0]) { | |
case 3: { // Wheel | |
const direction = dataArray[4]; | |
const speed = dataArray[3]; | |
switch (direction) { | |
case 0: { | |
console.log('wheel forwards', speed); | |
break; | |
} | |
case 255: { | |
console.log('wheel backwards', 255 - speed) | |
break; | |
} | |
} | |
break; | |
} | |
case 4: { // Button | |
const buttonsPressed: number[] = [] | |
if (dataArray[1] != 0) buttonsPressed.push(dataArray[1]); | |
if (dataArray[3] != 0) buttonsPressed.push(dataArray[3]); | |
if (dataArray[5] != 0) buttonsPressed.push(dataArray[5]); | |
if (dataArray[7] != 0) buttonsPressed.push(dataArray[7]); | |
if (dataArray[9] != 0) buttonsPressed.push(dataArray[9]); | |
if (dataArray[11] != 0) buttonsPressed.push(dataArray[11]); | |
console.log(buttonsPressed) | |
buttonsPressed.forEach(button => { | |
if (previousButtons.indexOf(button) == -1) { | |
console.log("Key Down:", buttons[button - 1]) | |
switch (buttons[button - 1]) { | |
case "Cut": { | |
device.close(); // Close the device | |
break; | |
} | |
} | |
} | |
}); | |
// console.log(previousButtons) | |
previousButtons.forEach(button => { | |
if (buttonsPressed.indexOf(button) == -1) { | |
console.log("Key Up:", buttons[button - 1]) | |
// if (buttons[button - 1] == "Cut") { | |
// console.log("cut Key Up"); | |
// } | |
} | |
}); | |
previousButtons = buttonsPressed; | |
break; | |
} | |
default: | |
} | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment