move time zone selection to config.rs
This commit is contained in:
parent
1970d37d51
commit
5b58040975
2 changed files with 8 additions and 6 deletions
|
@ -9,6 +9,9 @@ pub(crate) const T_ON: &'static str = "17:00";
|
|||
/// End of "on" cycle for switch, in 24 hour "HH:MM" format.
|
||||
pub(crate) const T_OFF: &'static str = "09:00";
|
||||
|
||||
/// Time zone for T_ON and T_OFF.
|
||||
pub(crate) const TZ: chrono_tz::Tz = chrono_tz::US::Pacific;
|
||||
|
||||
/// Access point SSID.
|
||||
pub(crate) const WIFI_SSID: &'static str = "Example";
|
||||
|
||||
|
|
11
src/main.rs
11
src/main.rs
|
@ -2,7 +2,6 @@ use std::default::Default;
|
|||
|
||||
use anyhow::{bail, Result};
|
||||
use chrono::{NaiveTime, Utc};
|
||||
use chrono_tz::US::Pacific;
|
||||
use esp_idf_svc::{
|
||||
eventloop::EspSystemEventLoop,
|
||||
hal::{
|
||||
|
@ -44,12 +43,12 @@ fn main() -> Result<()> {
|
|||
|
||||
// ======== Main Control Loop ======== //
|
||||
loop {
|
||||
let now = Utc::now().with_timezone(&Pacific);
|
||||
info!("Current time: {}", now);
|
||||
let dt = Utc::now().with_timezone(&config::TZ);
|
||||
info!("Current time: {}", dt);
|
||||
|
||||
let t = now.time();
|
||||
let t = dt.time();
|
||||
|
||||
let active = match (t_on < t_off, t > t_on, t > t_off) {
|
||||
let switch_active = match (t_on < t_off, t > t_on, t > t_off) {
|
||||
// Active period falls within single day, and t falls between t_on
|
||||
// and t_off.
|
||||
(true, true, false) => true,
|
||||
|
@ -61,7 +60,7 @@ fn main() -> Result<()> {
|
|||
_ => false,
|
||||
};
|
||||
|
||||
if active {
|
||||
if switch_active {
|
||||
switch_driver.set_high()?;
|
||||
} else {
|
||||
switch_driver.set_low()?;
|
||||
|
|
Loading…
Add table
Reference in a new issue