From b856677b7f98cdc0f30fed2ec703b68658f55403 Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Mon, 20 Jun 2022 15:35:05 +0200 Subject: [PATCH] Status display + date display for future events --- README.md | 3 ++- src/bin/display_all.rs | 29 ++++++++++++++++++++--------- src/bin/status_check_example.rs | 11 +++++++++++ 3 files changed, 33 insertions(+), 10 deletions(-) create mode 100644 src/bin/status_check_example.rs diff --git a/README.md b/README.md index e2ac4ba..2bd92f0 100644 --- a/README.md +++ b/README.md @@ -8,8 +8,9 @@ https://www.waveshare.com/wiki/1.5inch_RGB_OLED_Module > nix-shell > rustup target add arm-unknown-linux-musleabihf > cargo build --release --target arm-unknown-linux-musleabihf -> scp target/arm-unknown-linux-musleabihf/release/{display_all,display_off,refresh_json,take_measurement} 'pi@raspberrypi:~' +> scp target/arm-unknown-linux-musleabihf/release/{display_all,display_off,refresh_json,take_measurement,status_check_example} 'pi@raspberrypi:~' > # on the Pi, create sensors.db and events.json +> ./status_check_example > /run/user/1000/status.json > patchelf --set-interpreter /lib/ld-linux-armhf.so.3 display_all > ./display_off on > ./display_all sensors.db events.json temps diff --git a/src/bin/display_all.rs b/src/bin/display_all.rs index b64c27b..c6d381d 100644 --- a/src/bin/display_all.rs +++ b/src/bin/display_all.rs @@ -4,7 +4,7 @@ use display_interface_spi::SPIInterfaceNoCS; use embedded_graphics::{ draw_target::DrawTarget, mono_font::{ - ascii::{FONT_10X20, FONT_5X8, FONT_6X9, FONT_9X15}, + ascii::{FONT_10X20, FONT_4X6, FONT_5X8, FONT_6X9, FONT_9X15}, MonoTextStyleBuilder, }, pixelcolor::{Rgb565}, @@ -21,7 +21,7 @@ use rppal::{ use rusqlite::Connection; use serde_derive::Deserialize; //use ssd1306::{I2CDisplayInterface, Ssd1306, size::DisplaySize128x64, rotation::DisplayRotation, mode::DisplayConfig}; -use time::{format_description, OffsetDateTime, PrimitiveDateTime}; +use time::{format_description, OffsetDateTime, PrimitiveDateTime, Date}; use time_tz::{timezones::db::europe::BERLIN, OffsetDateTimeExt, PrimitiveDateTimeExt}; #[derive(Deserialize)] @@ -157,6 +157,10 @@ fn draw>(mut disp: D, time: OffsetDateTime, rh: i6 .font(&FONT_6X9) .text_color(Rgb565::new(0xff, 0xff, 0xff)) .build(); + let mut text_style_4x6 = MonoTextStyleBuilder::new() + .font(&FONT_4X6) + .text_color(Rgb565::new(0xff, 0xff, 0xff)) + .build(); let text_style4 = MonoTextStyleBuilder::new() .font(&FONT_5X8) .text_color(Rgb565::new(0xff, 0xff, 0xff)) @@ -359,13 +363,20 @@ fn draw>(mut disp: D, time: OffsetDateTime, rh: i6 let text = if event.4.len() > 19 { &event.4[0..19] } else { &event.4 }; let day = event.0 as usize; let y = y + 64 + 9 * i as i32 + 5; - text_style_6x9.set_text_color(Some(Rgb565::new(0xff, 0xff, 0xff))); - Text::new(days[day].0, (x, y).into(), text_style_6x9) - .draw(&mut disp) - .unwrap(); - Text::new(days[day].1, (x + 6, y).into(), text_style4) - .draw(&mut disp) - .unwrap(); + if event.5 > today && event.5 - today > 7 { + let dt = Date::from_julian_day(event.5).unwrap(); + Text::new(&format!("{}.{}.", dt.day(), dt.month() as u8), (0, y).into(), text_style_4x6) + .draw(&mut disp) + .unwrap(); + } else { + text_style_6x9.set_text_color(Some(Rgb565::new(0xff, 0xff, 0xff))); + Text::new(days[day].0, (x, y).into(), text_style_6x9) + .draw(&mut disp) + .unwrap(); + Text::new(days[day].1, (x + 6, y).into(), text_style4) + .draw(&mut disp) + .unwrap(); + } text_style_6x9.set_text_color(Some(colors[i])); Text::new(text, (x + 14, y).into(), text_style_6x9) .draw(&mut disp) diff --git a/src/bin/status_check_example.rs b/src/bin/status_check_example.rs new file mode 100644 index 0000000..9a8ea73 --- /dev/null +++ b/src/bin/status_check_example.rs @@ -0,0 +1,11 @@ +use std::process::Command; + +fn main() { + // adjust as needed + + let github_up = Command::new("ping").args(["-c1", "github.com"]).spawn().unwrap().wait().unwrap().success(); + let gitlab_up = Command::new("ping").args(["-c1", "gitlab.com"]).spawn().unwrap().wait().unwrap().success(); + + let status = format!("{} {} {} {} {}", true, github_up, true, gitlab_up, true); + std::fs::write("/run/user/1000/status.json", status).unwrap(); +} \ No newline at end of file