2022-09-01 01:18:15 +01:00
|
|
|
import {init_usdpl, target_usdpl, init_embedded, call_backend} from "usdpl-front";
|
2022-08-23 22:50:46 +01:00
|
|
|
|
|
|
|
const USDPL_PORT: number = 44443;
|
|
|
|
|
|
|
|
// Utility
|
|
|
|
|
|
|
|
export function resolve(promise: Promise<any>, setter: any) {
|
|
|
|
(async function () {
|
|
|
|
let data = await promise;
|
|
|
|
if (data != null) {
|
|
|
|
console.debug("Got resolved", data);
|
|
|
|
setter(data);
|
|
|
|
} else {
|
|
|
|
console.warn("Resolve failed:", data);
|
|
|
|
}
|
|
|
|
})();
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function initBackend() {
|
|
|
|
// init usdpl
|
|
|
|
await init_embedded();
|
|
|
|
init_usdpl(USDPL_PORT);
|
2022-09-01 01:18:15 +01:00
|
|
|
console.log("USDPL started for framework: " + target_usdpl());
|
2022-08-23 22:50:46 +01:00
|
|
|
//setReady(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
// API
|
|
|
|
|
2022-09-01 01:18:15 +01:00
|
|
|
export async function getInfo(): Promise<string> {
|
|
|
|
return (await call_backend("V_INFO", []))[0];
|
|
|
|
}
|
|
|
|
|
2022-08-23 22:50:46 +01:00
|
|
|
// Battery
|
|
|
|
|
|
|
|
export async function getBatteryCurrent(): Promise<number> {
|
|
|
|
return (await call_backend("BATTERY_current_now", []))[0];
|
|
|
|
}
|
|
|
|
|
2022-09-05 22:02:02 +01:00
|
|
|
export async function getBatteryChargeNow(): Promise<number> {
|
|
|
|
return (await call_backend("BATTERY_charge_now", []))[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function getBatteryChargeFull(): Promise<number> {
|
|
|
|
return (await call_backend("BATTERY_charge_full", []))[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function getBatteryChargeDesign(): Promise<number> {
|
|
|
|
return (await call_backend("BATTERY_charge_design", []))[0];
|
|
|
|
}
|
|
|
|
|
2022-08-23 22:50:46 +01:00
|
|
|
export async function getBatteryChargeRate(): Promise<number> {
|
|
|
|
return (await call_backend("BATTERY_get_charge_rate", []))[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function setBatteryChargeRate(val: number): Promise<number> {
|
|
|
|
return (await call_backend("BATTERY_set_charge_rate", [val]))[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function unsetBatteryChargeRate(): Promise<any[]> {
|
|
|
|
return await call_backend("BATTERY_unset_charge_rate", []);
|
|
|
|
}
|
|
|
|
|
|
|
|
// CPU
|
|
|
|
|
2022-11-13 04:17:13 +00:00
|
|
|
export async function setCpuSmt(status: boolean): Promise<number> {
|
|
|
|
return (await call_backend("CPU_set_smt", [status]))[0];
|
|
|
|
}
|
|
|
|
|
2022-08-23 22:50:46 +01:00
|
|
|
export async function getCpuCount(): Promise<number> {
|
|
|
|
return (await call_backend("CPU_count", []))[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function setCpuOnline(index: number, online: boolean): Promise<boolean> {
|
|
|
|
return (await call_backend("CPU_set_online", [index, online]))[0];
|
|
|
|
}
|
|
|
|
|
2022-09-06 02:36:01 +01:00
|
|
|
export async function setCpuOnlines(onlines: boolean[]): Promise<boolean[]> {
|
|
|
|
return await call_backend("CPU_set_onlines", onlines);
|
|
|
|
}
|
|
|
|
|
2022-08-23 22:50:46 +01:00
|
|
|
export async function getCpusOnline(): Promise<boolean[]> {
|
|
|
|
return (await call_backend("CPU_get_onlines", [])); // -> online status for all CPUs
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function setCpuClockLimits(index: number, min: number, max: number): Promise<number[]> {
|
|
|
|
return (await call_backend("CPU_set_clock_limits", [index, min, max])); // -> [min, max]
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function getCpuClockLimits(index: number): Promise<number[]> {
|
|
|
|
return (await call_backend("CPU_get_clock_limits", [index])); // -> [min, max]
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function unsetCpuClockLimits(index: number): Promise<any[]> {
|
|
|
|
return (await call_backend("CPU_unset_clock_limits", [index]));
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function setCpuGovernor(index: number, val: string): Promise<string> {
|
|
|
|
return (await call_backend("CPU_set_governor", [index, val]))[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function getCpusGovernor(): Promise<string[]> {
|
|
|
|
return (await call_backend("CPU_get_governors", [])); // -> governors for all CPUs
|
|
|
|
}
|
|
|
|
|
|
|
|
// GPU
|
|
|
|
|
|
|
|
export async function setGpuPpt(fast: number, slow: number): Promise<number[]> {
|
|
|
|
return (await call_backend("GPU_set_ppt", [fast, slow])); // -> [fastPPT, slowPPT]
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function getGpuPpt(): Promise<number[]> {
|
|
|
|
return (await call_backend("GPU_get_ppt", [])); // -> [fastPPT, slowPPT]
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function unsetGpuPpt(): Promise<any[]> {
|
|
|
|
return (await call_backend("GPU_unset_ppt", []));
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function setGpuClockLimits(min: number, max: number): Promise<number[]> {
|
|
|
|
return (await call_backend("GPU_set_clock_limits", [min, max])); // -> [min, max]
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function getGpuClockLimits(): Promise<number[]> {
|
|
|
|
return (await call_backend("GPU_get_clock_limits", [])); // -> [min, max]
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function unsetGpuClockLimits(): Promise<any[]> {
|
|
|
|
return (await call_backend("GPU_unset_clock_limits", []));
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function setGpuSlowMemory(val: boolean): Promise<boolean> {
|
2022-08-26 22:00:43 +01:00
|
|
|
return (await call_backend("GPU_set_slow_memory", [val]))[0];
|
2022-08-23 22:50:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function getGpuSlowMemory(): Promise<boolean> {
|
|
|
|
return (await call_backend("GPU_get_slow_memory", []))[0];
|
|
|
|
}
|
2022-08-26 22:00:43 +01:00
|
|
|
|
|
|
|
// general
|
|
|
|
|
|
|
|
export async function setGeneralPersistent(val: boolean): Promise<boolean> {
|
|
|
|
return (await call_backend("GENERAL_set_persistent", [val]))[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function getGeneralPersistent(): Promise<boolean> {
|
|
|
|
return (await call_backend("GENERAL_get_persistent", []))[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function loadGeneralSettings(path: string, name: string): Promise<boolean> {
|
|
|
|
return (await call_backend("GENERAL_load_settings", [path, name]))[0];
|
|
|
|
}
|
|
|
|
|
2022-09-01 01:18:15 +01:00
|
|
|
export async function loadGeneralDefaultSettings(): Promise<boolean> {
|
|
|
|
return (await call_backend("GENERAL_load_default_settings", []))[0];
|
|
|
|
}
|
|
|
|
|
2022-11-13 04:17:13 +00:00
|
|
|
export async function loadGeneralSystemSettings(): Promise<boolean> {
|
|
|
|
return (await call_backend("GENERAL_load_system_settings", []))[0];
|
|
|
|
}
|
|
|
|
|
2022-09-01 01:18:15 +01:00
|
|
|
export async function getGeneralSettingsName(): Promise<boolean> {
|
2022-08-26 22:00:43 +01:00
|
|
|
return (await call_backend("GENERAL_get_name", []))[0];
|
|
|
|
}
|
2022-09-01 01:18:15 +01:00
|
|
|
|
|
|
|
export async function waitForComplete(): Promise<boolean> {
|
|
|
|
return (await call_backend("GENERAL_wait_for_unlocks", []))[0];
|
|
|
|
}
|