opening
This commit is contained in:
parent
23538ef624
commit
5031c09995
3 changed files with 52 additions and 6 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
|
@ -1101,6 +1101,7 @@ dependencies = [
|
|||
"embassy-executor",
|
||||
"embassy-net",
|
||||
"embassy-net-driver",
|
||||
"embassy-sync",
|
||||
"embassy-time",
|
||||
"embedded-hal-async",
|
||||
"embedded-io-async",
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ embedded-io-async = "0.6.1"
|
|||
embassy-net-driver = "0.2.0"
|
||||
const_format = "0.2.32"
|
||||
embedded-hal-async = "1.0.0"
|
||||
embassy-sync = "0.5.0"
|
||||
|
||||
[profile.dev]
|
||||
# Rust debug is too slow.
|
||||
|
|
|
|||
56
src/main.rs
56
src/main.rs
|
|
@ -5,6 +5,7 @@
|
|||
use embassy_executor::Spawner;
|
||||
use embassy_net::tcp::TcpSocket;
|
||||
use embassy_net::{Config, Ipv4Address, Stack, StackResources};
|
||||
use embassy_sync::{blocking_mutex::raw::CriticalSectionRawMutex, mutex::Mutex};
|
||||
use esp_hal::{self, IO};
|
||||
|
||||
use const_format::formatcp;
|
||||
|
|
@ -12,7 +13,7 @@ use embassy_time::{Duration, Timer};
|
|||
use embedded_hal_async::digital::Wait;
|
||||
use esp_backtrace as _;
|
||||
use esp_hal::clock::ClockControl;
|
||||
use esp_hal::gpio::{AnyPin, Input, PullUp};
|
||||
use esp_hal::gpio::{AnyPin, Input, Output, PullUp, PushPull};
|
||||
use esp_hal::Rng;
|
||||
use esp_hal::{embassy, peripherals::Peripherals, prelude::*, timer::TimerGroup};
|
||||
use esp_println::println;
|
||||
|
|
@ -86,9 +87,14 @@ async fn main(spawner: Spawner) {
|
|||
}
|
||||
|
||||
let io = IO::new(peripherals.GPIO, peripherals.IO_MUX);
|
||||
let button = io.pins.gpio12.into_pull_up_input();
|
||||
println!("Spawning button task");
|
||||
spawner.must_spawn(button_task(button.into(), stack));
|
||||
let ring_button = io.pins.gpio12.into_pull_up_input();
|
||||
let open_button = io.pins.gpio14.into_pull_up_input();
|
||||
let status_led = io.pins.gpio27.into_push_pull_output();
|
||||
let opener = make_static!(Mutex::new(io.pins.gpio26.into_push_pull_output().into()));
|
||||
|
||||
spawner.must_spawn(ring_button_task(ring_button.into(), stack));
|
||||
spawner.must_spawn(open_button_task(open_button.into(), opener));
|
||||
spawner.must_spawn(status_led_task(status_led.into()));
|
||||
}
|
||||
|
||||
async fn ring(stack: &'static Stack<WifiDevice<'static, WifiStaDevice>>) -> Result<(), &str> {
|
||||
|
|
@ -145,7 +151,7 @@ async fn ring(stack: &'static Stack<WifiDevice<'static, WifiStaDevice>>) -> Resu
|
|||
}
|
||||
|
||||
#[embassy_executor::task]
|
||||
async fn button_task(
|
||||
async fn ring_button_task(
|
||||
mut button: AnyPin<Input<PullUp>>,
|
||||
stack: &'static Stack<WifiDevice<'static, WifiStaDevice>>,
|
||||
) {
|
||||
|
|
@ -153,7 +159,7 @@ async fn button_task(
|
|||
button.wait_for_falling_edge().await.unwrap();
|
||||
Timer::after_millis(10).await;
|
||||
if button.is_low().unwrap() {
|
||||
println!("Button pressed");
|
||||
println!("Bell button pressed");
|
||||
ring(stack)
|
||||
.await
|
||||
.unwrap_or_else(|e| println!("ring error: {}", e));
|
||||
|
|
@ -161,6 +167,44 @@ async fn button_task(
|
|||
}
|
||||
}
|
||||
|
||||
#[embassy_executor::task]
|
||||
async fn status_led_task(mut status_led: AnyPin<Output<PushPull>>) {
|
||||
loop {
|
||||
status_led.set_high();
|
||||
Timer::after_millis(100).await;
|
||||
status_led.set_low();
|
||||
Timer::after_secs(1).await;
|
||||
}
|
||||
}
|
||||
|
||||
#[embassy_executor::task]
|
||||
async fn open_button_task(
|
||||
mut button: AnyPin<Input<PullUp>>,
|
||||
opener: &'static Mutex<CriticalSectionRawMutex, AnyPin<Output<PushPull>>>,
|
||||
) {
|
||||
loop {
|
||||
button.wait_for_falling_edge().await.unwrap();
|
||||
Timer::after_millis(10).await;
|
||||
if button.is_low().unwrap() {
|
||||
println!("Open button pressed");
|
||||
|
||||
let spawner = Spawner::for_current_executor().await;
|
||||
spawner
|
||||
.spawn(open_task(opener))
|
||||
.unwrap_or_else(|_| println!("Already opening"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[embassy_executor::task]
|
||||
async fn open_task(opener: &'static Mutex<CriticalSectionRawMutex, AnyPin<Output<PushPull>>>) {
|
||||
let mut opener = opener.lock().await;
|
||||
|
||||
opener.set_high();
|
||||
Timer::after_secs(1).await;
|
||||
opener.set_low();
|
||||
}
|
||||
|
||||
#[embassy_executor::task]
|
||||
async fn connection(mut controller: WifiController<'static>) {
|
||||
println!("start connection task");
|
||||
|
|
|
|||
Loading…
Reference in a new issue