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