reset button thread looper

This commit is contained in:
Evan Feenstra
2023-05-08 08:08:25 +01:00
parent 2c1127e2b8
commit 9b77aa2959
5 changed files with 34 additions and 4 deletions

View File

@@ -41,6 +41,9 @@ pub enum Status {
Connected,
Signing,
Ota,
Reset1,
Reset2,
Reset3,
}
pub const ROOT_STORE: &str = "/sdcard/store";

View File

@@ -7,6 +7,7 @@ mod periph;
use crate::core::control::{controller_from_seed, FlashPersister};
use crate::core::{config::*, events::*};
// use crate::periph::led::led_control_loop;
use crate::periph::button::button_loop;
#[allow(unused_imports)]
use crate::periph::sd::{mount_sd_card, simple_fs_test};
@@ -39,12 +40,15 @@ fn main() -> Result<()> {
thread::sleep(Duration::from_secs(1));
let peripherals = Peripherals::take().unwrap();
let _pins = peripherals.pins;
let pins = peripherals.pins;
let (led_tx, _led_rx) = mpsc::channel();
// LED control thread
// led_control_loop(pins.gpio0, peripherals.rmt.channel0, led_rx);
// BUTTON thread
button_loop(pins.gpio8, led_tx.clone());
led_tx.send(Status::MountingSDCard).unwrap();
println!("About to mount the sdcard...");
while let Err(_e) = mount_sd_card() {

View File

@@ -0,0 +1,23 @@
use crate::core::events::Status;
use esp_idf_hal::gpio;
use esp_idf_hal::gpio::*;
use std::sync::mpsc;
use std::thread;
use std::time::Duration;
pub fn button_loop(gpio8: gpio::Gpio8, tx: mpsc::Sender<Status>) {
thread::spawn(move || {
let mut button = PinDriver::input(gpio8).unwrap();
button.set_pull(Pull::Down).unwrap();
loop {
// we are using thread::sleep here to make sure the watchdog isn't triggered
thread::sleep(Duration::from_millis(10));
if button.is_high() {
log::info!("=> GPIO8 HIGH!");
tx.send(Status::Reset1).unwrap();
} else {
log::info!("=> GPIO8 LOW!");
}
}
});
}

View File

@@ -1,6 +1,4 @@
use crate::core::events::Status;
// use embedded_hal::delay::blocking::DelayUs;
use esp_idf_hal::delay::FreeRtos;
use esp_idf_hal::rmt::config::TransmitConfig;
use esp_idf_hal::rmt::{FixedLengthSignal, PinState, Pulse, TxRmtDriver};
use esp_idf_hal::{gpio, rmt};
@@ -84,7 +82,8 @@ impl Led {
}
// Set high and wait
tx.start_blocking(&signal).unwrap();
FreeRtos::delay_ms(self.blink_length);
// FreeRtos::delay_ms(self.blink_length);
thread::sleep(Duration::from_millis(self.blink_length.into()));
// Set low
let mut signal = FixedLengthSignal::<24>::new();
for i in 0..24 {

View File

@@ -1,2 +1,3 @@
pub mod button;
pub mod led;
pub mod sd;