Status display + date display for future events

This commit is contained in:
FliegendeWurst 2022-06-20 15:35:05 +02:00
parent 892ed459b6
commit b856677b7f
3 changed files with 33 additions and 10 deletions

View File

@ -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

View File

@ -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<D: DrawTarget<Color = Rgb565>>(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,6 +363,12 @@ fn draw<D: DrawTarget<Color = Rgb565>>(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;
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)
@ -366,6 +376,7 @@ fn draw<D: DrawTarget<Color = Rgb565>>(mut disp: D, time: OffsetDateTime, rh: i6
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)

View File

@ -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();
}