Upgrade frontend to experimental USDPL next

This commit is contained in:
NGnius (Graham) 2023-06-04 16:31:29 -04:00
parent c88402e580
commit 3d744f31aa
8 changed files with 375 additions and 325 deletions

View file

@ -99,7 +99,7 @@ message VersionStr {
}
message RpmMessage {
uint64 rpm = 1;
uint32 rpm = 1;
}
message TemperatureMessage {
@ -132,5 +132,5 @@ message CurveMessageY {
}
message IndexMessage {
uint64 index = 1;
uint32 index = 1;
}

View file

@ -73,7 +73,7 @@ impl IFan for FanService {
) -> Result<RpmMessage, Box<dyn std::error::Error>> {
if let Some(rpm) = crate::sys::read_fan() {
log::debug!("get_fan_rpm() success: {}", rpm);
Ok(RpmMessage { rpm })
Ok(RpmMessage { rpm: rpm as u32 })
} else {
Err("Failed to read fan speed".into())
}

View file

@ -1,6 +1,6 @@
{
"name": "Fantastic",
"version": "0.4.0",
"version": "0.5.0",
"description": "A template to quickly create decky plugins from scratch, based on TypeScript and webpack",
"scripts": {
"build": "shx rm -rf dist && rollup -c",
@ -32,17 +32,17 @@
"@rollup/plugin-replace": "^4.0.0",
"@rollup/plugin-typescript": "^8.5.0",
"@types/react": "16.14.0",
"@types/webpack": "^5.28.0",
"@types/webpack": "^5.28.1",
"rollup": "^2.79.1",
"rollup-plugin-import-assets": "^1.1.1",
"shx": "^0.3.4",
"tslib": "^2.5.0",
"tslib": "^2.5.3",
"typescript": "^4.9.5"
},
"dependencies": {
"decky-frontend-lib": "~3.19.1",
"react-icons": "^4.7.1",
"fantastic-wasm": "file:src/rust/pkg"
"decky-frontend-lib": "~3.21.1",
"fantastic-wasm": "file:src/rust/pkg",
"react-icons": "^4.9.0"
},
"pnpm": {
"peerDependencyRules": {

File diff suppressed because it is too large Load diff

View file

@ -1,7 +1,11 @@
import {init_usdpl, target_usdpl, init_embedded, call_backend} from "usdpl-front";
//import {init_usdpl, target_usdpl, init_embedded, call_backend} from "usdpl-front";
import { Fan, init_embedded, target_usdpl } from "fantastic-wasm";
const USDPL_PORT: number = 44444;
var FAN_CLIENT: Fan | undefined = undefined;
// Utility
export function resolve(promise: Promise<any>, setter: any) {
@ -26,7 +30,7 @@ export function execute(promise: Promise<any[]>) {
export async function initBackend() {
// init usdpl
await init_embedded();
init_usdpl(USDPL_PORT);
FAN_CLIENT = new Fan(USDPL_PORT);
console.log("FANTASTIC: USDPL started for framework: " + target_usdpl());
//setReady(true);
}
@ -34,45 +38,66 @@ export async function initBackend() {
// Back-end functions
export async function setEnabled(value: boolean): Promise<boolean> {
return (await call_backend("set_enable", [value]))[0];
return (await FAN_CLIENT!.set_enable(value))?? value;
//return (await call_backend("set_enable", [value]))[0];
}
export async function getEnabled(): Promise<boolean> {
return (await call_backend("get_enable", []))[0];
return (await FAN_CLIENT!.get_enable(true)) ?? false;
}
export async function setInterpolate(value: boolean): Promise<boolean> {
return (await call_backend("set_interpolate", [value]))[0];
return (await FAN_CLIENT!.set_interpolate(value)) ?? value;
//return (await call_backend("set_interpolate", [value]))[0];
}
export async function getInterpolate(): Promise<boolean> {
return (await call_backend("get_interpolate", []))[0];
return (await FAN_CLIENT!.get_interpolate(true)) ?? false;
//return (await call_backend("get_interpolate", []))[0];
}
export async function getVersion(): Promise<string> {
return (await call_backend("version", []))[0];
return (await FAN_CLIENT!.version_str(true)) ?? "version";
//return (await call_backend("version", []))[0];
}
export async function getName(): Promise<string> {
return (await call_backend("name", []))[0];
return (await FAN_CLIENT!.name(true))?? "broken";
//return (await call_backend("name", []))[0];
}
export async function getCurve(): Promise<{"x": number, "y": number}[]> {
return (await call_backend("get_curve", []))[0];
var x_s = (await FAN_CLIENT!.get_curve_x(true))?? [];
var y_s = (await FAN_CLIENT!.get_curve_y(true))?? [];
let result: {"x": number, "y": number}[] = [];
for (let i = 0; i < x_s.length && i < y_s.length; i++) {
result.push({
x: x_s[i],
y: y_s[i],
});
}
return result;
}
export async function addCurvePoint(point: {"x": number, "y": number}): Promise<{"x": number, "y": number}[]> {
return (await call_backend("add_curve_point", [point]))[0];
await FAN_CLIENT!.add_curve_point(point.x, point.y);
return getCurve();
}
export async function removeCurvePoint(index: number): Promise<{"x": number, "y": number}[]> {
return (await call_backend("remove_curve_point", [index]))[0];
await FAN_CLIENT!.remove_curve_point(index);
return getCurve();
//return (await call_backend("remove_curve_point", [index]))[0];
}
export async function getFanRpm(): Promise<number> {
return (await call_backend("get_fan_rpm", []))[0];
return (await FAN_CLIENT!.get_fan_rpm(true))?? 1337;
//return (await call_backend("get_fan_rpm", []))[0];
}
export async function getTemperature(): Promise<number> {
return (await call_backend("get_temperature", []))[0];
return (await FAN_CLIENT!.get_temperature(true))?? -273;
//return (await call_backend("get_temperature", []))[0];
}
initBackend();

2
src/rust/Cargo.lock generated
View file

@ -141,7 +141,7 @@ checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0"
[[package]]
name = "fantastic-wasm"
version = "0.1.0"
version = "0.5.0"
dependencies = [
"nrpc 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
"prost",

View file

@ -1,6 +1,6 @@
[package]
name = "fantastic-wasm"
version = "0.1.0"
version = "0.5.0"
edition = "2021"
[lib]
@ -17,3 +17,11 @@ usdpl-build = { version = "0.11", path = "../../../usdpl-rs/usdpl-build" }
[features]
debug = ["usdpl-front/debug"]
decky = ["usdpl-front/decky"]
[profile.release]
# Tell `rustc` to optimize for small code size.
opt-level = "s"
debug = false
strip = true
lto = true
codegen-units = 4

View file

@ -1,7 +1,7 @@
import base64
if __name__ == "__main__":
print("Embedding WASM into udspl_front.js")
print("Embedding WASM into js")
# assumption: current working directory (relative to this script) is ../
# assumption: release wasm binary at ./pkg/usdpl_bg.wasm
with open("./pkg/fantastic_wasm_bg.wasm", mode="rb") as infile:
@ -40,6 +40,6 @@ export function init_embedded() {
return init(decode())
}
""".encode())
with open("./pkg/usdpl_front.d.ts", "a") as outfile:
with open("./pkg/fantastic_wasm.d.ts", "a") as outfile:
outfile.write("\n\n// USDPL customization\nexport function init_embedded();\n")
print("Done: Embedded WASM into udspl_front.js")
print("Done: Embedded WASM into js")