Hacky hue flashing-- no locking multiple presses
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,2 +1,3 @@
|
||||
/target
|
||||
.emacs.desktop*
|
||||
hue.key
|
||||
|
||||
@@ -10,6 +10,7 @@ edition = "2018"
|
||||
futures-util = "0.3"
|
||||
log = "0.4.11"
|
||||
pretty_env_logger = "0.4.0"
|
||||
reqwest = { version = "0.10", default-features = false }
|
||||
rppal = { git = "https://github.com/golemparts/rppal/", rev = "2e980caf76756c97bb0b18fb3ab08fb51ed1f90e" }
|
||||
smallvec = "1.4.2"
|
||||
tokio = { version = "0.2", features = ["macros"] }
|
||||
|
||||
28
src/main.rs
28
src/main.rs
@@ -9,11 +9,13 @@ use futures_util::{FutureExt, select, stream, StreamExt};
|
||||
use rppal::gpio::{Gpio, Level, Trigger};
|
||||
use smallvec::SmallVec;
|
||||
use tokio::{ sync::mpsc,
|
||||
time::interval };
|
||||
time::{delay_for, interval} };
|
||||
use warp::{Filter, sse, sse::ServerSentEvent};
|
||||
|
||||
const HUE_ADDRESS: &str = "philips-hue.local";
|
||||
const OUTDOOR_CHIME_FILE: &str = "static/outdoor.mp3";
|
||||
|
||||
const HUE_KEY: &str = include_str!("../hue.key");
|
||||
const BUTTON_PIN: u8 = 26;
|
||||
const CHANNEL_VEC_SIZE: usize = 32;
|
||||
|
||||
@@ -34,12 +36,14 @@ async fn main() {
|
||||
pin.set_async_interrupt(Trigger::FallingEdge, move |level| button_pressed(level, &clients))
|
||||
.expect("set interrupt");
|
||||
|
||||
let reqwest = reqwest::Client::new();
|
||||
let (tx, rx) = mpsc::channel(1);
|
||||
events_clients.lock().unwrap().push(tx);
|
||||
let pushes = rx.for_each(|()| {
|
||||
let pushes = rx.for_each(|()| async {
|
||||
if !audio_busy() { play_chime() }
|
||||
else { debug!("doorbell still ringing, not playing new chime"); }
|
||||
futures_util::future::ready(())
|
||||
|
||||
flash_patio(&reqwest).await;
|
||||
});
|
||||
|
||||
select! {
|
||||
@@ -121,3 +125,21 @@ fn play_chime() {
|
||||
Err(err) => error!("Error playing outdoor chime: {}", err)
|
||||
};
|
||||
}
|
||||
|
||||
fn hue_base(reqwest: &reqwest::Client) -> reqwest::RequestBuilder {
|
||||
reqwest.put(&format!("http://{}/api/{}/lights/10/state", HUE_ADDRESS, HUE_KEY))
|
||||
}
|
||||
|
||||
async fn flash_patio(reqwest: &reqwest::Client) {
|
||||
for _ in 0..5 {
|
||||
let _ = hue_base(reqwest).body(r#"{"transitiontime":0,"sat":254, "bri":254,"hue":2125}"#) // orange
|
||||
.send().await;
|
||||
delay_for(Duration::from_millis(250)).await;
|
||||
let _ = hue_base(reqwest).body(r#"{"transitiontime":0,"hue":25500}"#) // green
|
||||
.send().await;
|
||||
delay_for(Duration::from_millis(250)).await;
|
||||
let _ = hue_base(reqwest).body(r#"{"transitiontime":0,"hue":56228}"#) // purple
|
||||
.send().await;
|
||||
delay_for(Duration::from_millis(250)).await;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user