use async interrupt. blank web service.
This commit is contained in:
@@ -7,4 +7,8 @@ edition = "2018"
|
|||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
log = "0.4.11"
|
||||||
|
pretty_env_logger = "0.4.0"
|
||||||
rppal = "0.11.3"
|
rppal = "0.11.3"
|
||||||
|
tokio = { version = "0.2", features = ["macros"] }
|
||||||
|
warp = "0.2.5"
|
||||||
|
|||||||
35
src/main.rs
35
src/main.rs
@@ -1,26 +1,31 @@
|
|||||||
use std::thread::sleep;
|
use std::thread::sleep;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
use rppal::gpio::{Gpio, Trigger};
|
use log::info;
|
||||||
|
use rppal::gpio::{Gpio, Level, Trigger};
|
||||||
|
use warp::Filter;
|
||||||
|
|
||||||
const BUTTON_PIN: u8 = 26;
|
const BUTTON_PIN: u8 = 26;
|
||||||
|
|
||||||
fn main() {
|
fn button_pressed(_level: Level) {
|
||||||
|
println!("pushed");
|
||||||
|
sleep(Duration::from_millis(25));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::main]
|
||||||
|
async fn main() {
|
||||||
|
pretty_env_logger::init();
|
||||||
|
|
||||||
let gpio = Gpio::new().expect("gpio init");
|
let gpio = Gpio::new().expect("gpio init");
|
||||||
let mut pin = gpio.get(BUTTON_PIN).expect("pin init").into_input_pulldown();
|
let mut pin = gpio.get(BUTTON_PIN).expect("pin init").into_input_pulldown();
|
||||||
|
|
||||||
pin.set_interrupt(Trigger::RisingEdge).expect("set interrupt");
|
pin.set_async_interrupt(Trigger::RisingEdge, button_pressed).expect("set interrupt");
|
||||||
|
|
||||||
let mut count = 0;
|
// GET /
|
||||||
loop {
|
let root = warp::path::end()
|
||||||
match pin.poll_interrupt(true, Some(Duration::from_secs(5))) {
|
.and(warp::get())
|
||||||
Ok(Some(_)) => {
|
.map(|| info!("GET /")).untuple_one()
|
||||||
count += 1;
|
.and(warp::fs::file("./static/main.html"));
|
||||||
println!("pushed: {}", count);
|
|
||||||
sleep(Duration::from_millis(25));
|
warp::serve(root).run(([0, 0, 0, 0], 8060)).await;
|
||||||
},
|
|
||||||
Ok(None) => println!("time"),
|
|
||||||
err => { err.expect("poll"); }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
9
static/main.html
Normal file
9
static/main.html
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||||
|
<title>Fáfnir Doorbell</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Reference in New Issue
Block a user