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 { return new Promise((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(); }); }); }