Skip to content

Commit

Permalink
Try reading from console
Browse files Browse the repository at this point in the history
  • Loading branch information
lptr committed Aug 11, 2024
1 parent ad93257 commit e56b9af
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
25 changes: 25 additions & 0 deletions src/kernel/console.rs
Original file line number Diff line number Diff line change
@@ -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;
}
}
1 change: 1 addition & 0 deletions src/kernel/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pub mod command;
pub mod console;
mod mdns;
mod mqtt;
mod rtc;
Expand Down
4 changes: 3 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -50,10 +51,11 @@ macro_rules! task {
async fn run_tasks() {
let peripherals = Peripherals::take().expect("Failed to take peripherals");

let tasks: [Pin<Box<dyn Future<Output = ()>>>; 3] = [
let tasks: [Pin<Box<dyn Future<Output = ()>>>; 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;
}
Expand Down

0 comments on commit e56b9af

Please sign in to comment.