now-cet-key-press-module
Advanced tools
Comparing version 1.1.0 to 1.2.0
74
index.ts
@@ -1,24 +0,66 @@ | ||
import { COMMAND } from "@sky-uk-cat/now-cet-service-sdk"; | ||
import { CAPABILITY, COMMAND } from "@sky-uk-cat/now-cet-service-sdk"; | ||
import { | ||
ERROR_CODES, | ||
ServiceError, | ||
} from "@sky-uk-cat/now-cet-service-sdk/errors"; | ||
import { CommandResponse } from "@sky-uk-cat/now-cet-service-sdk/types"; | ||
import { execSync } from "child_process"; | ||
import { COMMAND_TO_HEX_CODE } from "./utils/mappings"; | ||
export function sendHIDCommand(command: COMMAND): void { | ||
let hexCode = getHexCodeByCommand(command); | ||
const hidReport = new Uint8Array(8); | ||
hidReport[0] = 0; | ||
hidReport[2] = hexCode; | ||
execSync(`echo -ne "${hidReport}" > /dev/hidg0`); | ||
setTimeout( | ||
() => execSync(`echo -ne "\x00\x00\x00\x00\x00\x00\x00\x00" > /dev/hidg0`), | ||
1000 | ||
); | ||
export function sendHIDCommand( | ||
command: COMMAND, | ||
longPress?: boolean | ||
): CommandResponse { | ||
if (!command) { | ||
throw new ServiceError({ | ||
statusCode: 400, | ||
code: ERROR_CODES.MISSING_PARAMS, | ||
message: "Bad Request: Missing command in request body", | ||
}); | ||
} | ||
const hexCode = getHexCodeByCommand(command); | ||
if (!hexCode) { | ||
throw new ServiceError({ | ||
statusCode: 400, | ||
code: ERROR_CODES.COMMANDS_NOT_FOUND, | ||
message: "Bad Request: No HID mapping found for command", | ||
}); | ||
} | ||
try { | ||
executeHIDCommand(hexCode); | ||
if (longPress) { | ||
setTimeout(() => executeHIDCommand("00000000"), 1000); | ||
} else { | ||
executeHIDCommand("00000000"); | ||
} | ||
return { | ||
command, | ||
capability: CAPABILITY.HID, | ||
message: "Successfully sent HID command", | ||
}; | ||
} catch (error) { | ||
throw new ServiceError({ | ||
statusCode: 500, | ||
code: ERROR_CODES.EXECUTION_ERROR, | ||
message: "Execution Error: Failed to send HID command", | ||
}); | ||
} | ||
} | ||
function getKeyByValue(object: { [K in COMMAND]?: number }, value: string) { | ||
return Object.keys(object).find((key) => object[key] === value); | ||
function executeHIDCommand(hexCode: string): void { | ||
execSync( | ||
`echo -ne "\\x00\\x00\\x${hexCode}\\x00\\x00\\x00\\x00\\x00" > /dev/hidg0`, | ||
{ | ||
shell: "/bin/bash", | ||
} | ||
); | ||
} | ||
function getHexCodeByCommand(command: COMMAND) { | ||
const key = getKeyByValue(COMMAND_TO_HEX_CODE, command); | ||
return key ? COMMAND_TO_HEX_CODE[key] : undefined; | ||
function getHexCodeByCommand(command: COMMAND): string | undefined { | ||
return COMMAND_TO_HEX_CODE[command]; | ||
} |
{ | ||
"name": "now-cet-key-press-module", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -1,98 +0,99 @@ | ||
import { COMMAND } from "@sky-uk-cat/now-cet-service-sdk"; | ||
import { HexStringCommandMapping } from "./types"; | ||
export const COMMAND_TO_HEX_CODE: { [K in COMMAND]?: number } = { | ||
UP: 0x52, | ||
DOWN: 0x51, | ||
LEFT: 0x50, | ||
RIGHT: 0x4f, | ||
BACK: 0x29, | ||
ENTER: 0x28, | ||
EXIT: 0x75, | ||
HOME: 0x4a, | ||
MENU: 0xe3, | ||
BACKSPACE: 0x2a, | ||
MEDIA_PLAY_PAUSE: 0xe8, | ||
MEDIA_PLAY: 0xe8, | ||
MEDIA_PAUSE: 0x48, | ||
MEDIA_STOP: 0x48, | ||
CHANNEL_UP: 0x4b, | ||
CHANNEL_DOWN: 0x4e, | ||
SUBTITLES: 0x77, | ||
VOLUME_UP: 0x3e, | ||
VOLUME_DOWN: 0x3f, | ||
VOLUME_MUTE: 0xe8, | ||
KEY_0: 0x27, | ||
KEY_1: 0x1e, | ||
KEY_2: 0x1f, | ||
KEY_3: 0x20, | ||
KEY_4: 0x21, | ||
KEY_5: 0x22, | ||
KEY_6: 0x23, | ||
KEY_7: 0x24, | ||
KEY_8: 0x25, | ||
KEY_9: 0x26, | ||
KEY_a: 0x04, | ||
KEY_b: 0x05, | ||
KEY_c: 0x06, | ||
KEY_d: 0x07, | ||
KEY_e: 0x08, | ||
KEY_f: 0x09, | ||
KEY_g: 0x0a, | ||
KEY_h: 0x0b, | ||
KEY_i: 0x0c, | ||
KEY_j: 0x0d, | ||
KEY_k: 0x0e, | ||
KEY_l: 0x0f, | ||
KEY_m: 0x10, | ||
KEY_n: 0x11, | ||
KEY_o: 0x12, | ||
KEY_p: 0x13, | ||
KEY_q: 0x14, | ||
KEY_r: 0x15, | ||
KEY_s: 0x16, | ||
KEY_t: 0x17, | ||
KEY_u: 0x18, | ||
KEY_v: 0x19, | ||
KEY_w: 0x1a, | ||
KEY_x: 0x1b, | ||
KEY_y: 0x1c, | ||
KEY_z: 0x1d, | ||
KEY_A: 0x04, | ||
KEY_B: 0x05, | ||
KEY_C: 0x06, | ||
KEY_D: 0x07, | ||
KEY_E: 0x08, | ||
KEY_F: 0x09, | ||
KEY_G: 0x0a, | ||
KEY_H: 0x0b, | ||
KEY_I: 0x0c, | ||
KEY_J: 0x0d, | ||
KEY_K: 0x0e, | ||
KEY_L: 0x0f, | ||
KEY_M: 0x10, | ||
KEY_N: 0x11, | ||
KEY_O: 0x12, | ||
KEY_P: 0x13, | ||
KEY_Q: 0x14, | ||
KEY_R: 0x15, | ||
KEY_S: 0x16, | ||
KEY_T: 0x17, | ||
KEY_U: 0x18, | ||
KEY_V: 0x19, | ||
KEY_W: 0x1a, | ||
KEY_X: 0x1b, | ||
KEY_Y: 0x1c, | ||
KEY_Z: 0x1d, | ||
KEY_F1: 0x3a, | ||
KEY_F2: 0x3b, | ||
KEY_F3: 0x3c, | ||
KEY_F4: 0x3d, | ||
KEY_F5: 0x3e, | ||
KEY_F6: 0x3f, | ||
KEY_F7: 0x40, | ||
KEY_F8: 0x41, | ||
KEY_F9: 0x42, | ||
KEY_F10: 0x43, | ||
KEY_F11: 0x44, | ||
KEY_F12: 0x45, | ||
export const COMMAND_TO_HEX_CODE: HexStringCommandMapping = { | ||
UP: "52", | ||
DOWN: "51", | ||
LEFT: "50", | ||
RIGHT: "4f", | ||
BACK: "29", | ||
ENTER: "28", | ||
EXIT: "75", | ||
HOME: "4a", | ||
MENU: "e3", | ||
BACKSPACE: "2a", | ||
MEDIA_PLAY_PAUSE: "e8", | ||
MEDIA_PLAY: "e8", | ||
MEDIA_PAUSE: "48", | ||
MEDIA_STOP: "48", | ||
CHANNEL_UP: "4b", | ||
CHANNEL_DOWN: "4e", | ||
SUBTITLES: "77", | ||
VOLUME_UP: "3e", | ||
VOLUME_DOWN: "3f", | ||
VOLUME_MUTE: "e8", | ||
KEY_0: "27", | ||
KEY_1: "1e", | ||
KEY_2: "1f", | ||
KEY_3: "20", | ||
KEY_4: "21", | ||
KEY_5: "22", | ||
KEY_6: "23", | ||
KEY_7: "24", | ||
KEY_8: "25", | ||
KEY_9: "26", | ||
KEY_a: "04", | ||
KEY_b: "05", | ||
KEY_c: "06", | ||
KEY_d: "07", | ||
KEY_e: "08", | ||
KEY_f: "09", | ||
KEY_g: "0a", | ||
KEY_h: "0b", | ||
KEY_i: "0c", | ||
KEY_j: "0d", | ||
KEY_k: "0e", | ||
KEY_l: "0f", | ||
KEY_m: "10", | ||
KEY_n: "11", | ||
KEY_o: "12", | ||
KEY_p: "13", | ||
KEY_q: "14", | ||
KEY_r: "15", | ||
KEY_s: "16", | ||
KEY_t: "17", | ||
KEY_u: "18", | ||
KEY_v: "19", | ||
KEY_w: "1a", | ||
KEY_x: "1b", | ||
KEY_y: "1c", | ||
KEY_z: "1d", | ||
KEY_A: "04", | ||
KEY_B: "05", | ||
KEY_C: "06", | ||
KEY_D: "07", | ||
KEY_E: "08", | ||
KEY_F: "09", | ||
KEY_G: "0a", | ||
KEY_H: "0b", | ||
KEY_I: "0c", | ||
KEY_J: "0d", | ||
KEY_K: "0e", | ||
KEY_L: "0f", | ||
KEY_M: "10", | ||
KEY_N: "11", | ||
KEY_O: "12", | ||
KEY_P: "13", | ||
KEY_Q: "14", | ||
KEY_R: "15", | ||
KEY_S: "16", | ||
KEY_T: "17", | ||
KEY_U: "18", | ||
KEY_V: "19", | ||
KEY_W: "1a", | ||
KEY_X: "1b", | ||
KEY_Y: "1c", | ||
KEY_Z: "1d", | ||
KEY_F1: "3a", | ||
KEY_F2: "3b", | ||
KEY_F3: "3c", | ||
KEY_F4: "3d", | ||
KEY_F5: "3e", | ||
KEY_F6: "3f", | ||
KEY_F7: "40", | ||
KEY_F8: "41", | ||
KEY_F9: "42", | ||
KEY_F10: "43", | ||
KEY_F11: "44", | ||
KEY_F12: "45", | ||
}; |
@@ -1,5 +0,3 @@ | ||
export interface ServiceError extends Error { | ||
code: string; | ||
statusCode: number; | ||
} | ||
import { COMMAND } from "@sky-uk-cat/now-cet-service-sdk"; | ||
export type HexStringCommandMapping = { [K in COMMAND]?: string }; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3714
157
1