mirror of
https://github.com/FliegendeWurst/raspi-oled.git
synced 2024-11-08 13:20:37 +00:00
Fix schedules
This commit is contained in:
parent
13c5a472ce
commit
3e38684c17
@ -41,6 +41,8 @@ fn main() {
|
||||
|
||||
pub trait Context {
|
||||
fn do_action(&self, action: Action);
|
||||
|
||||
fn active_count(&self) -> usize;
|
||||
}
|
||||
|
||||
struct ContextDefault<D: DrawTarget<Color = Rgb565>> {
|
||||
@ -101,6 +103,10 @@ impl<D: DrawTarget<Color = Rgb565>> Context for ContextDefault<D> {
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
fn active_count(&self) -> usize {
|
||||
self.active.borrow().len()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "pc"))]
|
||||
@ -117,7 +123,6 @@ fn pc_main() {
|
||||
window::WindowBuilder,
|
||||
};
|
||||
|
||||
use crate::screensaver::{Screensaver, DUOLINGO};
|
||||
use raspi_oled::FrameOutput;
|
||||
|
||||
let args: Vec<_> = env::args().map(|x| x.to_string()).collect();
|
||||
|
@ -6,12 +6,12 @@ use crate::{action::Action, Context};
|
||||
/// Guaranteed to be checked at least once every minute.
|
||||
pub trait Schedule {
|
||||
fn check_and_do(&self, ctx: &dyn Context, time: OffsetDateTime) {
|
||||
if self.check(time) {
|
||||
if self.check(ctx, time) {
|
||||
self.execute(ctx, time);
|
||||
}
|
||||
}
|
||||
|
||||
fn check(&self, time: OffsetDateTime) -> bool;
|
||||
fn check(&self, ctx: &dyn Context, time: OffsetDateTime) -> bool;
|
||||
fn execute(&self, ctx: &dyn Context, time: OffsetDateTime);
|
||||
}
|
||||
|
||||
@ -23,8 +23,8 @@ pub struct Reminder {
|
||||
}
|
||||
|
||||
impl Schedule for Reminder {
|
||||
fn check(&self, time: OffsetDateTime) -> bool {
|
||||
time.hour() == self.hour && time.minute() == self.minute
|
||||
fn check(&self, ctx: &dyn Context, time: OffsetDateTime) -> bool {
|
||||
time.hour() == self.hour && time.minute() == self.minute && ctx.active_count() == 1
|
||||
}
|
||||
|
||||
fn execute(&self, ctx: &dyn Context, _time: OffsetDateTime) {
|
||||
|
Loading…
Reference in New Issue
Block a user