First commit
commit
bd4263e298
|
|
@ -0,0 +1,2 @@
|
|||
/target
|
||||
users.json
|
||||
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,18 @@
|
|||
[package]
|
||||
name = "eink_calendar"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
embedded-graphics = "0.7.1"
|
||||
linux-embedded-hal = "0.3"
|
||||
embedded-hal = "0.2.4"
|
||||
embedded-components = { git = "https://gitea.anshorei.me/Anshorei/embedded-components.git" }
|
||||
epd-waveshare = { git = "https://github.com/Anshorei/epd-waveshare", rev = "3011b5c" }
|
||||
chrono = "*"
|
||||
kitchen-fridge = { git = "https://gitea.anshorei.me/Anshorei/kitchen-fridge.git", branch = "feature/events" }
|
||||
tokio = "*"
|
||||
serde = "*"
|
||||
serde_json = "*"
|
||||
|
|
@ -0,0 +1,74 @@
|
|||
use epd_waveshare::{
|
||||
color::OctColor as Color,
|
||||
epd5in65f::{Display5in65f as EpdDisplay, Epd5in65f as Epd},
|
||||
prelude::*,
|
||||
};
|
||||
|
||||
use embedded_hal::prelude::*;
|
||||
use linux_embedded_hal::{
|
||||
spidev::{self, SpidevOptions},
|
||||
sysfs_gpio::Direction,
|
||||
Delay, Pin, Spidev,
|
||||
};
|
||||
|
||||
pub struct Display {
|
||||
pub display: EpdDisplay,
|
||||
epd: Epd<Spidev, Pin, Pin, Pin, Pin, Delay>,
|
||||
spi: Spidev,
|
||||
delay: Delay,
|
||||
}
|
||||
|
||||
impl Display {
|
||||
pub fn new() -> Self {
|
||||
let mut spi = Spidev::open("/dev/spidev0.0").expect("spidev directory");
|
||||
let options = SpidevOptions::new()
|
||||
.bits_per_word(8)
|
||||
.max_speed_hz(4_000_000)
|
||||
.mode(spidev::SpiModeFlags::SPI_MODE_0)
|
||||
.build();
|
||||
spi.configure(&options).expect("spi configuration");
|
||||
|
||||
let cs = Pin::new(26);
|
||||
cs.export().expect("cs export");
|
||||
while !cs.is_exported() {}
|
||||
cs.set_direction(Direction::Out).expect("CS direction");
|
||||
cs.set_value(1).expect("CS value set to 1");
|
||||
|
||||
let busy = Pin::new(24);
|
||||
busy.export().expect("busy export");
|
||||
while !busy.is_exported() {}
|
||||
busy.set_direction(Direction::In).expect("busy Direction");
|
||||
|
||||
let dc = Pin::new(25);
|
||||
dc.export().expect("dc export");
|
||||
while !dc.is_exported() {}
|
||||
dc.set_direction(Direction::Out).expect("dc Direction");
|
||||
dc.set_value(1).expect("dc Value set to 1");
|
||||
|
||||
let rst = Pin::new(17);
|
||||
rst.export().expect("rst export");
|
||||
while !rst.is_exported() {}
|
||||
rst.set_direction(Direction::Out).expect("rst Direction");
|
||||
rst.set_value(1).expect("rst Value set to 1");
|
||||
|
||||
let mut delay = Delay {};
|
||||
|
||||
let mut epd =
|
||||
Epd::new(&mut spi, cs, busy, dc, rst, &mut delay).expect("eink initialize error");
|
||||
|
||||
let mut display = EpdDisplay::default();
|
||||
|
||||
return Display {
|
||||
display,
|
||||
epd,
|
||||
spi,
|
||||
delay,
|
||||
};
|
||||
}
|
||||
|
||||
pub fn update(&mut self) {
|
||||
self.epd
|
||||
.update_and_display_frame(&mut self.spi, self.display.buffer(), &mut self.delay)
|
||||
.expect("updating");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
mod display;
|
||||
mod user;
|
||||
|
||||
use display::Display;
|
||||
use embedded_components::{Component, ComponentStyle, List, ScrollingCalendar, VSplit};
|
||||
use embedded_graphics::prelude::*;
|
||||
use epd_waveshare::color::OctColor as Color;
|
||||
use user::{get_user_data, User};
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
let contents = std::fs::read_to_string("users.json").expect("No user configuration found");
|
||||
let users: Vec<User> = serde_json::from_str(&contents).expect("User configuration invalid");
|
||||
|
||||
let mut tasks = vec![];
|
||||
|
||||
for user in users.iter() {
|
||||
let mut user_data = get_user_data(user).await;
|
||||
tasks.append(&mut user_data.tasks);
|
||||
}
|
||||
|
||||
let mut display = Display::new();
|
||||
|
||||
let style = ComponentStyle {
|
||||
fg_color: Color::Black,
|
||||
bg_color: Color::White,
|
||||
hi_color: Color::Red,
|
||||
border_color: Color::Black,
|
||||
border: 1,
|
||||
bezel: 1,
|
||||
};
|
||||
|
||||
let screen = VSplit::new(
|
||||
ScrollingCalendar::new(style.clone(), 2, 5),
|
||||
List::new(style, tasks, 10),
|
||||
);
|
||||
screen.draw(&mut display.display).expect("Could not draw!");
|
||||
|
||||
display.update();
|
||||
}
|
||||
|
|
@ -0,0 +1,57 @@
|
|||
use embedded_components::ListItemData;
|
||||
use kitchen_fridge::{
|
||||
cache::Cache,
|
||||
client::Client,
|
||||
traits::{CalDavSource, CompleteCalendar},
|
||||
CalDavProvider,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Deserialize, Serialize)]
|
||||
pub struct User {
|
||||
pub username: String,
|
||||
pub url: String,
|
||||
pub password: String,
|
||||
pub calendar_urls: Vec<String>,
|
||||
}
|
||||
|
||||
pub struct UserData {
|
||||
pub tasks: Vec<ListItemData>,
|
||||
}
|
||||
|
||||
pub async fn get_user_data(user: &User) -> UserData {
|
||||
let cache_path = format!("test_cache/{}", user.username);
|
||||
let cache_path = std::path::Path::new(&cache_path);
|
||||
|
||||
let client = Client::new(&user.url, &user.username, &user.password).unwrap();
|
||||
let cache = Cache::from_folder(&cache_path).unwrap_or(Cache::new(&cache_path));
|
||||
let mut provider = CalDavProvider::new(client, cache);
|
||||
provider.sync().await;
|
||||
provider.local().save_to_folder().unwrap();
|
||||
let mut tasks = vec![];
|
||||
let cals = provider.local().get_calendars().await.unwrap();
|
||||
for (url, cal) in cals {
|
||||
if !user
|
||||
.calendar_urls
|
||||
.iter()
|
||||
.any(|calendar_url| url == calendar_url.parse().unwrap())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
let cal = cal.lock().unwrap();
|
||||
let items = cal.get_items().await.unwrap();
|
||||
for (_, item) in items {
|
||||
match item {
|
||||
kitchen_fridge::Item::Event(_) => continue,
|
||||
kitchen_fridge::Item::Task(task) => {
|
||||
tasks.push(
|
||||
ListItemData::new(" ", &task.name().to_string())
|
||||
.with_progress(task.completion_percent()),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return UserData { tasks };
|
||||
}
|
||||
Loading…
Reference in New Issue