Add driver in debug UI and misc config stuff

This commit is contained in:
NGnius (Graham) 2023-01-02 21:22:53 -05:00
parent 500fde964c
commit cda1111cd3
9 changed files with 61 additions and 141 deletions

2
backend/Cargo.lock generated
View file

@ -886,6 +886,8 @@ checksum = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09"
[[package]]
name = "ryzenadj-rs"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fc77f2824d9c46759ba4907c8d3c3ca7131593a41fc389335bcdfda339a866bd"
dependencies = [
"bindgen",
]

View file

@ -21,7 +21,7 @@ simplelog = "0.12"
# limits & driver functionality
limits_core = { version = "0.1.0", path = "./limits_core" }
regex = "1"
ryzenadj-rs = { version = "0.1", path = "../../ryzenadj-rs" }
ryzenadj-rs = { version = "0.1" }
# ureq's tls feature does not like musl targets
ureq = { version = "2.5", features = ["json", "gzip", "brotli", "charset"], default-features = false, optional = true }

View file

@ -1,3 +1,5 @@
FROM ghcr.io/steamdeckhomebrew/holo-toolchain-rust:latest
RUN pacman -S --noconfirm cmake make
ENTRYPOINT [ "/backend/entrypoint.sh" ]

View file

@ -178,6 +178,35 @@ pub fn get_limits(
}
}
/// Generate get current driver name
pub fn get_provider(
sender: Sender<ApiMessage>,
) -> impl AsyncCallable {
let sender = Arc::new(Mutex::new(sender)); // Sender is not Sync; this is required for safety
let getter = move || {
let sender2 = sender.clone();
move |provider_name: String| {
let (tx, rx) = mpsc::channel();
let callback = move |name: crate::persist::DriverJson| tx.send(name).expect("get_provider callback send failed");
sender2.lock().unwrap().send(ApiMessage::GetProvider(provider_name, Box::new(callback))).expect("get_provider send failed");
rx.recv().expect("get_provider callback recv failed")
}
};
super::async_utils::AsyncIsh {
trans_setter: |mut params| {
if let Some(Primitive::String(name)) = params.pop() {
Ok(name.to_owned())
} else {
Err(format!("Invalid/missing single param in get_provider"))
}
},
set_get: getter,
trans_getter: |result| {
vec![format!("{:?}", result).into()]
}
}
}
pub fn gunter(_: super::ApiParameterType) -> super::ApiParameterType {
std::thread::spawn(|| {
log::info!("Zhu Li, do the thing!");

View file

@ -17,6 +17,7 @@ pub enum ApiMessage {
LoadMainSettings,
LoadSystemSettings,
GetLimits(Callback<super::SettingsLimits>),
GetProvider(String, Callback<crate::persist::DriverJson>),
}
pub enum BatteryMessage {
@ -221,6 +222,14 @@ impl ApiMessageHandler {
gpu: settings.gpu.limits(),
general: settings.general.limits(),
});
},
ApiMessage::GetProvider(name, cb) => {
cb(match &name as &str {
"battery" => settings.battery.provider(),
"cpu" | "cpus" => settings.cpus.provider(),
"gpu" => settings.gpu.provider(),
_ => settings.general.provider(),
})
}
}
}

View file

@ -212,6 +212,10 @@ fn main() -> Result<(), ()> {
"GENERAL_get_limits",
api::general::get_limits(api_sender.clone())
)
.register_async(
"GENERAL_get_provider",
api::general::get_provider(api_sender.clone())
)
.register("GENERAL_idk", api::general::gunter);
api_worker::spawn(loaded_settings, api_handler);

View file

@ -227,6 +227,10 @@ export async function getLimits(): Promise<SettingsLimits> {
return (await call_backend("GENERAL_get_limits", []))[0];
}
export async function getDriverProviderName(name: string): Promise<string> {
return (await call_backend("GENERAL_get_provider", [name]))[0];
}
export async function idk(): Promise<boolean> {
return (await call_backend("GENERAL_idk", []))[0];
}

View file

@ -46,6 +46,7 @@ type MinMax = {
// usdpl persistent store keys
const BACKEND_INFO = "VINFO";
const DRIVER_INFO = "GENERAL_provider";
const LIMITS_INFO = "LIMITS_all";
@ -144,6 +145,7 @@ const reload = function() {
backend.resolve(backend.getGeneralSettingsName(), (name: string) => { set_value(NAME_GEN, name) });
backend.resolve(backend.getInfo(), (info: string) => { set_value(BACKEND_INFO, info) });
backend.resolve(backend.getDriverProviderName("gpu"), (driver: string) => { set_value(DRIVER_INFO, driver) });
};
// init USDPL WASM and connection to back-end
@ -842,6 +844,13 @@ const Content: VFC<{ serverAPI: ServerAPI }> = ({}) => {
{eggCount % 10 == 9 ? "<3 <3 <3" : target_usdpl()}
</Field>
</PanelSectionRow>
<PanelSectionRow>
<Field
label="Driver"
onClick={()=> eggCount++}>
{eggCount % 10 == 9 ? "Tracy Chapman" : get_value(DRIVER_INFO)}
</Field>
</PanelSectionRow>
<PanelSectionRow>
<Field
label="USDPL"

View file

@ -1,139 +0,0 @@
import { ServerAPI } from "decky-frontend-lib";
var server: ServerAPI | undefined = undefined;
//import { useEffect } from "react";
export function resolve(promise: Promise<any>, setter: any) {
(async function () {
let data = await promise;
if (data.success) {
console.debug("Got resolved", data, "promise", promise);
setter(data.result);
} else {
console.warn("Resolve failed:", data, "promise", promise);
}
})();
}
export function execute(promise: Promise<any>) {
(async function () {
let data = await promise;
if (data.success) {
console.debug("Got executed", data, "promise", promise);
} else {
console.warn("Execute failed:", data, "promise", promise);
}
})();
}
export function setServer(s: ServerAPI) {
server = s;
}
// Python functions
export function getVersion(): Promise<any> {
return server!.callPluginMethod("get_version", {});
}
export function onViewReady(): Promise<any> {
return server!.callPluginMethod("on_ready", {});
}
export function setCPUs(value: number, smt: boolean): Promise<any> {
return server!.callPluginMethod("set_cpus", {"count":value, "smt": smt});
}
export function getCPUs(): Promise<any> {
return server!.callPluginMethod("get_cpus", {});
}
export function getSMT(): Promise<any> {
return server!.callPluginMethod("get_smt", {});
}
export function setCPUBoost(value: boolean): Promise<any> {
return server!.callPluginMethod("set_boost", {"enabled": value});
}
export function getCPUBoost(): Promise<any> {
return server!.callPluginMethod("get_boost", {});
}
export function setMaxBoost(index: number): Promise<any> {
return server!.callPluginMethod("set_max_boost", {"index": index});
}
export function getMaxBoost(): Promise<any> {
return server!.callPluginMethod("get_max_boost", {});
}
export function setGPUPower(value: number, index: number): Promise<any> {
return server!.callPluginMethod("set_gpu_power", {"value": value, "power_number": index});
}
export function getGPUPower(index: number): Promise<any> {
return server!.callPluginMethod("get_gpu_power", {"power_number": index});
}
export function setGPUPowerI(value: number, index: number): Promise<any> {
return server!.callPluginMethod("set_gpu_power_index", {"index": value, "power_number": index});
}
export function getGPUPowerI(index: number): Promise<any> {
return server!.callPluginMethod("get_gpu_power_index", {"power_number": index});
}
export function setFanTick(tick: number): Promise<any> {
return server!.callPluginMethod("set_fan_tick", {"tick": tick});
}
export function getFanTick(): Promise<any> {
return server!.callPluginMethod("get_fan_tick", {});
}
export function getFantastic(): Promise<any> {
return server!.callPluginMethod("fantastic_installed", {});
}
export function getChargeNow(): Promise<any> {
return server!.callPluginMethod("get_charge_now", {});
}
export function getChargeFull(): Promise<any> {
return server!.callPluginMethod("get_charge_full", {});
}
export function getChargeDesign(): Promise<any> {
return server!.callPluginMethod("get_charge_design", {});
}
export function setPersistent(value: boolean): Promise<any> {
return server!.callPluginMethod("set_persistent", {"enabled": value});
}
export function getPersistent(): Promise<any> {
return server!.callPluginMethod("get_persistent", {});
}
export function setPerGameProfile(value: boolean): Promise<any> {
return server!.callPluginMethod("set_per_game_profile", {"enabled": value});
}
export function getPerGameProfile(): Promise<any> {
return server!.callPluginMethod("get_per_game_profile", {});
}
export function getCurrentGame(): Promise<any> {
return server!.callPluginMethod("get_current_game", {});
}
export function onGameStart(gameId: number, data: any): Promise<any> {
const data2 = {appid: data.appid, display_name: data.display_name, gameid: gameId}; // Issue #17
return server!.callPluginMethod("on_game_start", {"game_id": gameId, "data":data2});
}
export function onGameStop(gameId: number | null): Promise<any> {
return server!.callPluginMethod("on_game_stop", {"game_id": gameId});
}