From e56b9af869dc0d4408abc46301bbfa9a80c1534d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=B3r=C3=A1nt=20Pint=C3=A9r?= Date: Sun, 11 Aug 2024 11:03:43 +0200 Subject: [PATCH] Try reading from console --- Cargo.toml | 2 ++ src/kernel/console.rs | 25 +++++++++++++++++++++++++ src/kernel/mod.rs | 1 + src/main.rs | 4 +++- 4 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 src/kernel/console.rs diff --git a/Cargo.toml b/Cargo.toml index 39a4b3e..ceb022f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,6 +31,8 @@ embassy = ["esp-idf-svc/embassy-sync", "esp-idf-svc/embassy-time-driver"] log = { version = "0.4", default-features = false } anyhow = "1" embedded-hal-async = "1" +embedded-io = { version = "0.6.1", features = ["std"] } +embedded-io-adapters = { version = "0.6.1", features = ["std"] } embedded-svc = "0.28" esp-idf-hal = "0.44" esp-idf-svc = "0.49" diff --git a/src/kernel/console.rs b/src/kernel/console.rs new file mode 100644 index 0000000..7c9eb92 --- /dev/null +++ b/src/kernel/console.rs @@ -0,0 +1,25 @@ +use std::io::Read; + +use anyhow::Result; +use embassy_time::Timer; +use esp_idf_hal::gpio::{AnyOutputPin, PinDriver}; + +pub async fn console_handler_task(pin: AnyOutputPin) -> Result<()> { + let mut stdin = std::io::stdin(); + let mut buf = [0u8]; + let mut status = PinDriver::output(pin)?; + + loop { + match stdin.read_exact(&mut buf) { + Ok(()) => (), + _ => { + Timer::after_millis(100).await; + continue; + } + } + status.set_low()?; + Timer::after_millis(250).await; + status.set_high()?; + Timer::after_millis(250).await; + } +} diff --git a/src/kernel/mod.rs b/src/kernel/mod.rs index 261b920..58ef8b5 100644 --- a/src/kernel/mod.rs +++ b/src/kernel/mod.rs @@ -1,4 +1,5 @@ pub mod command; +pub mod console; mod mdns; mod mqtt; mod rtc; diff --git a/src/main.rs b/src/main.rs index 8c67019..45b9a2b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,6 +10,7 @@ use embassy_time::{Duration, Timer}; use esp_idf_hal::gpio::{AnyIOPin, AnyOutputPin, IOPin, PinDriver}; use esp_idf_hal::modem::Modem; use esp_idf_hal::prelude::Peripherals; +use kernel::console::console_handler_task; use serde_json::json; use std::future::Future; use std::pin::Pin; @@ -50,10 +51,11 @@ macro_rules! task { async fn run_tasks() { let peripherals = Peripherals::take().expect("Failed to take peripherals"); - let tasks: [Pin>>; 3] = [ + let tasks: [Pin>>; 4] = [ task!(blink(peripherals.pins.gpio4.into())), task!(reset_watcher(peripherals.pins.gpio0.downgrade())), task!(start_device(peripherals.modem)), + task!(console_handler_task(peripherals.pins.gpio2.into())), ]; join_array(tasks).await; }