Skip to content

Commit

Permalink
added chicken module (wip)
Browse files Browse the repository at this point in the history
  • Loading branch information
geoffdudds committed Nov 18, 2023
1 parent 2805a69 commit a5bc5d2
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 9 deletions.
19 changes: 10 additions & 9 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,16 @@
}
},
"extensions": [
"rust-lang.rust-analyzer",
"tamasfe.even-better-toml",
"serayuzgur.crates",
"mutantdino.resourcemonitor",
"yzhang.markdown-all-in-one",
"ms-vscode.cpptools",
"actboy168.tasks",
"Wokwi.wokwi-vscode"
],
"rust-lang.rust-analyzer",
"tamasfe.even-better-toml",
"serayuzgur.crates",
"mutantdino.resourcemonitor",
"yzhang.markdown-all-in-one",
"ms-vscode.cpptools",
"actboy168.tasks",
"Wokwi.wokwi-vscode",
"albert.TabOut"
],
"forwardPorts": [
3333,
8000
Expand Down
Empty file modified scripts/build.sh
100644 → 100755
Empty file.
31 changes: 31 additions & 0 deletions src/chicken.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use std::time::SystemTime;

pub struct Chicken {
wake_up_time: SystemTime,
bed_time: SystemTime,
}
impl Chicken {
pub fn new() -> Self {
Self {
wake_up_time: Chicken::get_bed_time(),
bed_time: Chicken::get_bed_time(),
}
}

pub fn is_awake(&self) -> bool {
let now = SystemTime::now();
now > self.wake_up_time && now < self.bed_time
}

pub fn get_bed_time() -> SystemTime {
SystemTime::now()
}
}

#[cfg(test)]
mod tests {
#[test]
fn test_is_up() {
assert!(false);
}
}
13 changes: 13 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
mod chicken;
use crate::chicken::Chicken;

fn main() {
// It is necessary to call this function once. Otherwise some patches to the runtime
// implemented by esp-idf-sys might not link properly. See https://github.com/esp-rs/esp-idf-template/issues/71
Expand All @@ -7,4 +10,14 @@ fn main() {
esp_idf_svc::log::EspLogger::initialize_default();

log::info!("Hello, world!");

// create a chicken object (updates at midnight)
// future - add app overrides
// create a gate controller (init based on schedule, eg isAwake(offset))
// drive gate actuator

let chicken = Chicken::new();
if chicken.is_awake() {
log::info!("the chickens are awake!");
}
}

0 comments on commit a5bc5d2

Please sign in to comment.