-
Notifications
You must be signed in to change notification settings - Fork 2
/
sleep.rs
36 lines (30 loc) · 991 Bytes
/
sleep.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
use anyhow::Result;
use log::*;
use crate::events::{Kind, TwatchEvent};
use crate::tiles::WatchTile;
use crate::twatch::Hal;
#[derive(Copy, Clone, Debug, Default)]
pub struct SleepTile {}
unsafe impl Send for SleepTile {}
impl WatchTile for SleepTile {
fn run(&mut self, hal: &mut Hal<'static>) -> Result<()> {
hal.light_sleep()
}
fn process_event(
&mut self,
hal: &mut Hal<'static>,
event: crate::events::TwatchEvent,
) -> Option<TwatchEvent> {
if let (_, Kind::PmuButtonPressed) = (&event.time, &event.kind) {
let mut tile = Box::new(crate::tiles::time::TimeTile::default());
tile.init(hal)
.unwrap_or_else(|e| warn!("Error waking up: {}", e));
let event = TwatchEvent::new(Kind::NewTile(tile));
hal.wake_up()
.unwrap_or_else(|e| warn!("Error waking up: {}", e));
Some(event)
} else {
Some(event)
}
}
}