From 213fbe31e275f6b3ebc499ed8d938d6300c9b064 Mon Sep 17 00:00:00 2001 From: xomf Date: Sun, 16 Jun 2024 13:02:15 -0400 Subject: [PATCH] battery --- Cargo.lock | 8 +++++++ Cargo.toml | 2 +- dim_plugins/battery/Cargo.toml | 12 ++++++++++ dim_plugins/battery/Makefile | 15 ++++++++++++ dim_plugins/battery/src/lib.rs | 44 ++++++++++++++++++++++++++++++++++ 5 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 dim_plugins/battery/Cargo.toml create mode 100644 dim_plugins/battery/Makefile create mode 100644 dim_plugins/battery/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index d552cf8..2d6c1d9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -78,6 +78,14 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" +[[package]] +name = "battery" +version = "0.1.0" +dependencies = [ + "dim_sdk", + "lazy_static", +] + [[package]] name = "bumpalo" version = "3.16.0" diff --git a/Cargo.toml b/Cargo.toml index 0e2b7b9..8784698 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,4 +1,4 @@ -workspace = { members = [ "sdk/rust","dim_plugins/example_rust", "dim_plugins/clock", "dim_plugins/counter"] } +workspace = { members = [ "sdk/rust","dim_plugins/example_rust", "dim_plugins/clock", "dim_plugins/counter", "dim_plugins/battery"] } [package] name = "dim" version = "0.1.0" diff --git a/dim_plugins/battery/Cargo.toml b/dim_plugins/battery/Cargo.toml new file mode 100644 index 0000000..abd9a7c --- /dev/null +++ b/dim_plugins/battery/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "battery" +version = "0.1.0" +edition = "2021" + +[lib] +crate-type=["cdylib"] +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +dim_sdk = {path="../../sdk/rust/"} +lazy_static = "1.4.0" \ No newline at end of file diff --git a/dim_plugins/battery/Makefile b/dim_plugins/battery/Makefile new file mode 100644 index 0000000..83ff5a2 --- /dev/null +++ b/dim_plugins/battery/Makefile @@ -0,0 +1,15 @@ +# Must match package name in Cargo.toml +PLUGIN_NAME=battery + + +build: $(PLUGIN_DIR)/$(PLUGIN_NAME).dim + +$(PLUGIN_DIR)/$(PLUGIN_NAME).dim: $(OBJECT_DIR)/$(PLUGIN_NAME)/debug/lib$(PLUGIN_NAME).so + cp $(OBJECT_DIR)/$(PLUGIN_NAME)/debug/lib$(PLUGIN_NAME).so $(PLUGIN_DIR)/$(PLUGIN_NAME).dim + +$(OBJECT_DIR)/$(PLUGIN_NAME)/debug/lib$(PLUGIN_NAME).so: + mkdir -p $(OBJECT_DIR)/$(PLUGIN_NAME) + cargo build --target-dir $(OBJECT_DIR)/$(PLUGIN_NAME) + + + diff --git a/dim_plugins/battery/src/lib.rs b/dim_plugins/battery/src/lib.rs new file mode 100644 index 0000000..adec380 --- /dev/null +++ b/dim_plugins/battery/src/lib.rs @@ -0,0 +1,44 @@ +use std::fmt::Write; +use dim_sdk::{plugin_info, DimPlugin}; +use std::fs::read_to_string; + +plugin_info!( + Plug, // Your main global structs name that implements `DimPlugin` + "battery", // Plugin name + "0.0.0", // Plugin Version (leave empty for none) + "GPLv3" // Plugin license (leave empty for none) + ); + +struct Plug { +} + +impl Plug { + pub fn new() -> Self { + Self { + } + } +} + +impl DimPlugin for Plug { + fn init(&mut self) { + } + fn poll(&mut self, f: &mut dim_sdk::CBuffer) -> dim_sdk::Result<()> { + let contents = read_to_string("/home/xomf/battery_test")?; + let cleaned_contents: String = contents.chars().filter(|c| c.is_digit(10)).collect(); + + write!(f, "Battery: {}%", cleaned_contents)?; + Ok(()) + } + fn pre_reload(&mut self) { + } + fn post_reload(&mut self) { + + } + fn free(&mut self) { + + } +} + + + +