import {init_usdpl, target, init_embedded, call_backend} from "usdpl-front"; const USDPL_PORT: number = 44443; // Utility export function resolve(promise: Promise, 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); console.log("USDPL started for framework: " + target()); //setReady(true); } // API // Battery export async function getBatteryCurrent(): Promise { return (await call_backend("BATTERY_current_now", []))[0]; } export async function getBatteryChargeRate(): Promise { return (await call_backend("BATTERY_get_charge_rate", []))[0]; } export async function setBatteryChargeRate(val: number): Promise { return (await call_backend("BATTERY_set_charge_rate", [val]))[0]; } export async function unsetBatteryChargeRate(): Promise { return await call_backend("BATTERY_unset_charge_rate", []); } // CPU export async function getCpuCount(): Promise { return (await call_backend("CPU_count", []))[0]; } export async function setCpuOnline(index: number, online: boolean): Promise { return (await call_backend("CPU_set_online", [index, online]))[0]; } export async function getCpusOnline(): Promise { return (await call_backend("CPU_get_onlines", [])); // -> online status for all CPUs } export async function setCpuClockLimits(index: number, min: number, max: number): Promise { return (await call_backend("CPU_set_clock_limits", [index, min, max])); // -> [min, max] } export async function getCpuClockLimits(index: number): Promise { return (await call_backend("CPU_get_clock_limits", [index])); // -> [min, max] } export async function unsetCpuClockLimits(index: number): Promise { return (await call_backend("CPU_unset_clock_limits", [index])); } export async function setCpuGovernor(index: number, val: string): Promise { return (await call_backend("CPU_set_governor", [index, val]))[0]; } export async function getCpusGovernor(): Promise { return (await call_backend("CPU_get_governors", [])); // -> governors for all CPUs } // GPU export async function setGpuPpt(fast: number, slow: number): Promise { return (await call_backend("GPU_set_ppt", [fast, slow])); // -> [fastPPT, slowPPT] } export async function getGpuPpt(): Promise { return (await call_backend("GPU_get_ppt", [])); // -> [fastPPT, slowPPT] } export async function unsetGpuPpt(): Promise { return (await call_backend("GPU_unset_ppt", [])); } export async function setGpuClockLimits(min: number, max: number): Promise { return (await call_backend("GPU_set_clock_limits", [min, max])); // -> [min, max] } export async function getGpuClockLimits(): Promise { return (await call_backend("GPU_get_clock_limits", [])); // -> [min, max] } export async function unsetGpuClockLimits(): Promise { return (await call_backend("GPU_unset_clock_limits", [])); } export async function setGpuSlowMemory(val: boolean): Promise { return (await call_backend("GPU_set_slow_memory", [min, max]))[0]; } export async function getGpuSlowMemory(): Promise { return (await call_backend("GPU_get_slow_memory", []))[0]; }