mirror of
https://github.com/DJ2LS/FreeDATA
synced 2024-05-14 08:04:33 +00:00
54 lines
1.3 KiB
TypeScript
54 lines
1.3 KiB
TypeScript
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
|
|
}]`);
|
|
|
|
export function loadAudioDevices() {
|
|
getAudioDevices().then((devices) => {
|
|
audioDevices = devices;
|
|
});
|
|
}
|
|
|
|
export function loadSerialDevices() {
|
|
getSerialDevices().then((devices) => {
|
|
serialDevices = devices;
|
|
});
|
|
}
|
|
|
|
export function audioInputOptions() {
|
|
if (audioDevices === undefined) {
|
|
return skel;
|
|
}
|
|
return audioDevices.in;
|
|
}
|
|
|
|
export function audioOutputOptions() {
|
|
if (audioDevices === undefined) {
|
|
return skel;
|
|
}
|
|
|
|
return audioDevices.out;
|
|
}
|
|
|
|
export function serialDeviceOptions() {
|
|
//Return ignore option if no serialDevices
|
|
if (serialDevices === undefined)
|
|
return [{ description: "-- ignore --", port: "ignore" }];
|
|
|
|
if (serialDevices.findIndex((device) => device.port == "ignore") == -1) {
|
|
//Add an ignore option for rig and ptt for transceivers that don't require them
|
|
serialDevices.push({ description: "-- ignore --", port: "ignore" });
|
|
}
|
|
|
|
return serialDevices;
|
|
}
|