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