FreeDATA/gui/src/js/deviceFormHelper.ts

54 lines
1.3 KiB
TypeScript
Raw Normal View History

import { getAudioDevices, getSerialDevices } from "./api";
let audioDevices = await getAudioDevices();
let serialDevices = await getSerialDevices();
//Dummy device data sent if unable to get devices from modem to prevent GUI crash
const skel = JSON.parse(`
[{
"api": "MME",
"id": "0000",
"name": "No devices received from modem",
"native_index": 0
2023-11-26 06:07:52 +00:00
}]`);
2023-12-19 01:46:19 +00:00
export function loadAudioDevices() {
getAudioDevices().then((devices) => {
audioDevices = devices;
});
}
export function loadSerialDevices() {
getSerialDevices().then((devices) => {
serialDevices = devices;
});
}
export function audioInputOptions() {
2023-11-26 06:07:52 +00:00
if (audioDevices === undefined) {
return skel;
}
return audioDevices.in;
}
export function audioOutputOptions() {
2023-11-26 06:07:52 +00:00
if (audioDevices === undefined) {
return skel;
}
2023-12-19 03:09:17 +00:00
return audioDevices.out;
}
export function serialDeviceOptions() {
2023-12-20 01:19:22 +00:00
//Return ignore option if no serialDevices
if (serialDevices === undefined)
return [{ description: "-- ignore --", port: "ignore" }];
if (serialDevices.findIndex((device) => device.port == "ignore") == -1) {
2023-12-20 01:19:22 +00:00
//Add an ignore option for rig and ptt for transceivers that don't require them
serialDevices.push({ description: "-- ignore --", port: "ignore" });
2023-12-20 01:19:22 +00:00
}
return serialDevices;
}