UNPKG

@dderevjanik/termux-api

Version:

This library allows you to interact with your Android device from Node.js using termux-api

42 lines (39 loc) 1.04 kB
import { exec } from "child_process"; export interface InfraredTransmitOptions { /** * Frequency IR carrier frequency in Hertz */ frequency: number; /** * Intervals, such as '20,50,20,30' * * **Note:** Only patterns shorter than 2 seconds will be transmitted */ pattern: number[]; } /** * Transmit an infrared pattern. * * **Note:** This API can be used only on devices that have infrared transmitter */ export async function infraredTransmit( options: InfraredTransmitOptions ): Promise<void> { return new Promise<void>((resolve, reject) => { if (options.pattern.length === 0) { return reject(`Error: Pattern to transmit is empty`); } const command = `termux-infrared-transmit -f ${ options.frequency } "${options.pattern.join(",")}"`; exec(command, (error, stdout, stderr) => { if (error) { return reject(`Error: ${error.message}`); } if (stderr) { return reject(`Error: ${stderr}`); } return resolve(); }); }); }