feat: internal date time sensors
This commit is contained in:
Generated
+61
-8
@@ -42,6 +42,15 @@ dependencies = [
|
||||
"equator",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "android_system_properties"
|
||||
version = "0.1.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anstream"
|
||||
version = "0.6.20"
|
||||
@@ -150,6 +159,7 @@ dependencies = [
|
||||
"ab_glyph",
|
||||
"anyhow",
|
||||
"asterctl-lcd",
|
||||
"chrono",
|
||||
"clap",
|
||||
"env_logger",
|
||||
"image",
|
||||
@@ -284,6 +294,19 @@ version = "1.0.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2fd1289c04a9ea8cb22300a459a72a385d7c73d3259e2ed7dcb2af674838cfa9"
|
||||
|
||||
[[package]]
|
||||
name = "chrono"
|
||||
version = "0.4.42"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "145052bdd345b87320e369255277e3fb5152762ad123a901ef5c262dd38fe8d2"
|
||||
dependencies = [
|
||||
"iana-time-zone",
|
||||
"js-sys",
|
||||
"num-traits",
|
||||
"wasm-bindgen",
|
||||
"windows-link 0.2.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap"
|
||||
version = "4.5.46"
|
||||
@@ -612,6 +635,30 @@ version = "0.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
|
||||
|
||||
[[package]]
|
||||
name = "iana-time-zone"
|
||||
version = "0.1.64"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "33e57f83510bb73707521ebaffa789ec8caf86f9657cad665b092b581d40e9fb"
|
||||
dependencies = [
|
||||
"android_system_properties",
|
||||
"core-foundation-sys",
|
||||
"iana-time-zone-haiku",
|
||||
"js-sys",
|
||||
"log",
|
||||
"wasm-bindgen",
|
||||
"windows-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "iana-time-zone-haiku"
|
||||
version = "0.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f"
|
||||
dependencies = [
|
||||
"cc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "image"
|
||||
version = "0.25.6"
|
||||
@@ -1989,7 +2036,7 @@ dependencies = [
|
||||
"windows-collections",
|
||||
"windows-core",
|
||||
"windows-future",
|
||||
"windows-link",
|
||||
"windows-link 0.1.3",
|
||||
"windows-numerics",
|
||||
]
|
||||
|
||||
@@ -2010,7 +2057,7 @@ checksum = "c0fdd3ddb90610c7638aa2b3a3ab2904fb9e5cdbecc643ddb3647212781c4ae3"
|
||||
dependencies = [
|
||||
"windows-implement",
|
||||
"windows-interface",
|
||||
"windows-link",
|
||||
"windows-link 0.1.3",
|
||||
"windows-result",
|
||||
"windows-strings",
|
||||
]
|
||||
@@ -2022,7 +2069,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fc6a41e98427b19fe4b73c550f060b59fa592d7d686537eebf9385621bfbad8e"
|
||||
dependencies = [
|
||||
"windows-core",
|
||||
"windows-link",
|
||||
"windows-link 0.1.3",
|
||||
"windows-threading",
|
||||
]
|
||||
|
||||
@@ -2054,6 +2101,12 @@ version = "0.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5e6ad25900d524eaabdbbb96d20b4311e1e7ae1699af4fb28c17ae66c80d798a"
|
||||
|
||||
[[package]]
|
||||
name = "windows-link"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "45e46c0661abb7180e7b9c281db115305d49ca1709ab8242adf09666d2173c65"
|
||||
|
||||
[[package]]
|
||||
name = "windows-numerics"
|
||||
version = "0.2.0"
|
||||
@@ -2061,7 +2114,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9150af68066c4c5c07ddc0ce30421554771e528bde427614c61038bc2c92c2b1"
|
||||
dependencies = [
|
||||
"windows-core",
|
||||
"windows-link",
|
||||
"windows-link 0.1.3",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -2070,7 +2123,7 @@ version = "0.3.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "56f42bd332cc6c8eac5af113fc0c1fd6a8fd2aa08a0119358686e5160d0586c6"
|
||||
dependencies = [
|
||||
"windows-link",
|
||||
"windows-link 0.1.3",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -2079,7 +2132,7 @@ version = "0.4.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "56e6c93f3a0c3b36176cb1327a4958a0353d5d166c2a35cb268ace15e91d3b57"
|
||||
dependencies = [
|
||||
"windows-link",
|
||||
"windows-link 0.1.3",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -2122,7 +2175,7 @@ version = "0.53.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d5fe6031c4041849d7c496a8ded650796e7b6ecc19df1a431c1a363342e5dc91"
|
||||
dependencies = [
|
||||
"windows-link",
|
||||
"windows-link 0.1.3",
|
||||
"windows_aarch64_gnullvm 0.53.0",
|
||||
"windows_aarch64_msvc 0.53.0",
|
||||
"windows_i686_gnu 0.53.0",
|
||||
@@ -2139,7 +2192,7 @@ version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b66463ad2e0ea3bbf808b7f1d371311c80e115c0b71d60efc142cafbcfb057a6"
|
||||
dependencies = [
|
||||
"windows-link",
|
||||
"windows-link 0.1.3",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
||||
@@ -44,6 +44,3 @@ storage_hdd[5]['used']: storage_hdd[5]_usage_percent
|
||||
# TODO not (yet) available in aster-sysinfo
|
||||
# gpu_core:
|
||||
# motherboard_temperature:
|
||||
|
||||
# Not yet supported
|
||||
# DATE_m_d_h_m_2:
|
||||
|
||||
@@ -15,6 +15,7 @@ asterctl-lcd = { path = "../asterctl-lcd", version = "0.2.0" }
|
||||
|
||||
anyhow = "1.0.98"
|
||||
clap = { version = "4.5.42", features = ["derive"] }
|
||||
chrono = "0.4"
|
||||
image = "0.25.6"
|
||||
imageproc = { version = "0.25.0", default-features = false }
|
||||
ab_glyph = { version = "0.2.31", default-features = false, features = ["std"] }
|
||||
|
||||
@@ -7,7 +7,9 @@ use crate::cfg::{Panel, Sensor, SensorDirection, SensorMode, TextAlign};
|
||||
use crate::font::FontHandler;
|
||||
use crate::format_value;
|
||||
use crate::img::{ImageCache, Size, rotate_image};
|
||||
use crate::sensors::get_date_time_value;
|
||||
use ab_glyph::Font;
|
||||
use chrono::{DateTime, Local};
|
||||
use image::{ImageBuffer, Rgba, RgbaImage};
|
||||
use imageproc::drawing::{draw_text_mut, text_size};
|
||||
use log::{debug, error};
|
||||
@@ -160,6 +162,8 @@ impl PanelRenderer {
|
||||
values: &HashMap<String, String>,
|
||||
mut background: RgbaImage,
|
||||
) -> Result<RgbaImage, ImageProcessingError> {
|
||||
let now: DateTime<Local> = Local::now();
|
||||
|
||||
for sensor in &panel.sensor {
|
||||
let value = values.get(&sensor.label).cloned();
|
||||
let unit = values
|
||||
@@ -170,6 +174,8 @@ impl PanelRenderer {
|
||||
|
||||
if let Some(value) = value {
|
||||
self.render_sensor(&mut background, sensor, &value, &unit)?;
|
||||
} else if let Some(value) = get_date_time_value(&sensor.label, &now) {
|
||||
self.render_sensor(&mut background, sensor, &value, &unit)?;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,8 +3,11 @@
|
||||
|
||||
//! Sensor value sources.
|
||||
//!
|
||||
//! Only implementation is a file-based value provider with simple key-value pairs.
|
||||
//! Implementations:
|
||||
//! - internal date time sensors
|
||||
//! - file-based value provider with simple key-value pairs.
|
||||
|
||||
use chrono::{DateTime, Datelike, Local, Timelike};
|
||||
use log::{debug, error, info, warn};
|
||||
use notify::event::{ModifyKind, RenameMode};
|
||||
use notify::{Event, EventKind, RecursiveMode, Watcher};
|
||||
@@ -16,6 +19,46 @@ use std::path::{Path, PathBuf};
|
||||
use std::process::exit;
|
||||
use std::sync::{Arc, RwLock, mpsc};
|
||||
|
||||
pub fn get_date_time_value(label: &str, now: &DateTime<Local>) -> Option<String> {
|
||||
if !label.starts_with("DATE_") {
|
||||
return None;
|
||||
}
|
||||
|
||||
let year = now.year();
|
||||
let month = format!("{:02}", now.month());
|
||||
let day = format!("{:02}", now.day());
|
||||
let hour = format!("{:02}", now.hour());
|
||||
let minute = format!("{:02}", now.minute());
|
||||
let second = format!("{:02}", now.second());
|
||||
|
||||
// same formatting logic as in AOOSTAR-X
|
||||
let value = match label {
|
||||
"DATE_year" => year.to_string(),
|
||||
"DATE_month" => month,
|
||||
"DATE_day" => day,
|
||||
"DATE_hour" => hour,
|
||||
"DATE_minute" => minute,
|
||||
"DATE_second" => second,
|
||||
"DATE_m_d_h_m_1" => format!("{month}月{day}日 {hour}:{minute}"),
|
||||
"DATE_m_d_h_m_2" => format!("{month}/{day} {hour}:{minute}"),
|
||||
"DATE_m_d_1" => format!("{month}月{day}日"),
|
||||
"DATE_m_d_2" => format!("{month}-{day}"),
|
||||
"DATE_y_m_d_1" => format!("{year}年{month}月{day}日"),
|
||||
"DATE_y_m_d_2" => format!("{year}-{month}-{day}"),
|
||||
"DATE_y_m_d_3" => format!("{year}/{month}/{day}"),
|
||||
"DATE_y_m_d_4" => format!("{year} {month} {day}"),
|
||||
"DATE_h_m_s_1" => format!("{hour}:{minute}:{second}"),
|
||||
"DATE_h_m_s_2" => format!("{hour}时{minute}分{second}秒"),
|
||||
"DATE_h_m_s_3" => format!("{hour} {minute} {second}"),
|
||||
"DATE_h_m_1" => format!("{hour}时{minute}分"),
|
||||
"DATE_h_m_2" => format!("{hour} : {minute}"),
|
||||
"DATE_h_m_3" => format!("{hour}:{minute}"),
|
||||
_ => return None,
|
||||
};
|
||||
|
||||
Some(value)
|
||||
}
|
||||
|
||||
/// Read all sensor value source files from the given path and stort monitoring for changes.
|
||||
///
|
||||
/// The source path is either a single sensor source file or a directory containing multiple sensor
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
- [Progress Sensor](sensor/cfg/mode3_progress.md)
|
||||
- [Pointer Sensor](sensor/cfg/mode4_pointer.md)
|
||||
- [Sensor Value Provider](sensor/provider/README.md)
|
||||
- [Internal Date Time](sensor/provider/internal_date_time.md)
|
||||
- [Text File Data Source](sensor/provider/text_file.md)
|
||||
- [Shell Scripts](sensor/provider/shell_scripts.md)
|
||||
- [aster-sysinfo Tool](sensor/provider/sysinfo.md)
|
||||
|
||||
@@ -15,10 +15,12 @@ Different sensor modes are supported:
|
||||
|
||||
## Sensor Data Sources
|
||||
|
||||
The sensor value reading is separated from the `asterctl` tool.
|
||||
The sensor value reading is separated from the `asterctl` tool, with the exception of some internal sensors:
|
||||
|
||||
- Internal [date time sensors](provider/internal_date_time.md)
|
||||
|
||||
Sensor values are provided in separate text files and are automatically read when the file changes.
|
||||
Only the file data source is supported at the moment, other sources like pipes, sockets etc. might be supported later.
|
||||
Only the file data source is supported at the moment; other sources like pipes, sockets, etc. might be supported later.
|
||||
|
||||
- [Text file data source](provider/text_file.md)
|
||||
|
||||
|
||||
@@ -1 +1,6 @@
|
||||
# Sensor Value Provider
|
||||
|
||||
- Internal [date time sensors](internal_date_time.md)
|
||||
- Proof of concept [Linux shell scripts](shell_scripts.md)
|
||||
- [aster-sysinfo tool](sysinfo.md)
|
||||
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
# Internal Date Time Sensors
|
||||
|
||||
## Individual Components
|
||||
|
||||
- `DATE_year`: `{year}`
|
||||
- `DATE_month`: `{month}` with leading zero
|
||||
- `DATE_day`: `{day}` with leading zero
|
||||
- `DATE_hour`: `{hour}` 24h format with leading zero
|
||||
- `DATE_minute`: `{minute}` with leading zero
|
||||
- `DATE_second`: `{second}` with leading zero
|
||||
|
||||
## Month/Day with Hour/Minute
|
||||
- `DATE_m_d_h_m_1`: `{month}月{day}日 {hour}:{minute}`
|
||||
- `DATE_m_d_h_m_2`: `{month}/{day} {hour}:{minute}`
|
||||
|
||||
## Month/Day Only
|
||||
- `DATE_m_d_1`: `{month}月{day}日`
|
||||
- `DATE_m_d_2`: `{month}-{day}`
|
||||
|
||||
## Year/Month/Day
|
||||
- `DATE_y_m_d_1`: `{year}年{month}月{day}日`
|
||||
- `DATE_y_m_d_2`: `{year}-{month}-{day}`
|
||||
- `DATE_y_m_d_3`: `{year}/{month}/{day}`
|
||||
- `DATE_y_m_d_4`: `{year} {month} {day}`
|
||||
|
||||
## Hour/Minute/Second
|
||||
- `DATE_h_m_s_1`: `{hour}:{minute}:{second}`
|
||||
- `DATE_h_m_s_2`: `{hour}时{minute}分{second}秒`
|
||||
- `DATE_h_m_s_3`: `{hour} {minute} {second}`
|
||||
|
||||
## Hour/Minute Only
|
||||
- `DATE_h_m_1`: `{hour}时{minute}分`
|
||||
- `DATE_h_m_2`: `{hour} : {minute}`
|
||||
- `DATE_h_m_3`: `{hour}:{minute}`
|
||||
Reference in New Issue
Block a user