battery
This commit is contained in:
parent
ca71830262
commit
213fbe31e2
8
Cargo.lock
generated
8
Cargo.lock
generated
|
@ -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"
|
||||
|
|
|
@ -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"
|
||||
|
|
12
dim_plugins/battery/Cargo.toml
Normal file
12
dim_plugins/battery/Cargo.toml
Normal file
|
@ -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"
|
15
dim_plugins/battery/Makefile
Normal file
15
dim_plugins/battery/Makefile
Normal file
|
@ -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)
|
||||
|
||||
|
||||
|
44
dim_plugins/battery/src/lib.rs
Normal file
44
dim_plugins/battery/src/lib.rs
Normal file
|
@ -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) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user