From 32f4a4fa98d8a2054f6fd9d6df27f8cafff00b94 Mon Sep 17 00:00:00 2001 From: Jules Comte Date: Tue, 24 May 2022 12:03:48 -0400 Subject: [PATCH] first success --- sphinx-key/Cargo.toml | 8 +++--- sphinx-key/src/main.rs | 55 ++++++++++++++++++++++++++++++++++++++---- 2 files changed, 54 insertions(+), 9 deletions(-) diff --git a/sphinx-key/Cargo.toml b/sphinx-key/Cargo.toml index ec44def..d22c15b 100644 --- a/sphinx-key/Cargo.toml +++ b/sphinx-key/Cargo.toml @@ -21,7 +21,7 @@ sphinx-key-signer = { path = "../signer" } embedded-svc = { version = "0.21.2" } esp-idf-svc = "0.41" esp-idf-hal = "0.37" -embedded-hal = "=1.0.0-alpha.8" +embedded-hal = "0.2" anyhow = {version = "1", features = ["backtrace"]} log = "0.4" url = "2" @@ -37,6 +37,6 @@ anyhow = "1" name = "clear" path = "src/clear.rs" -[[bin]] -name = "led" -path = "src/led.rs" \ No newline at end of file +# [[bin]] +# name = "led" +# path = "src/led.rs" diff --git a/sphinx-key/src/main.rs b/sphinx-key/src/main.rs index 76a53d0..8f000f2 100644 --- a/sphinx-key/src/main.rs +++ b/sphinx-key/src/main.rs @@ -23,6 +23,15 @@ use embedded_svc::storage::Storage; // use log::*; // use url; +use anyhow::bail; + +const SSID: &str = env!("RUST_ESP32_STD_DEMO_WIFI_SSID"); +const PASS: &str = env!("RUST_ESP32_STD_DEMO_WIFI_PASS"); + +use esp_idf_hal::prelude::*; +use esp_idf_hal::adc; +use embedded_hal::adc::OneShot; + fn main() -> Result<()> { esp_idf_sys::link_patches(); esp_idf_svc::log::EspLogger::initialize_default(); @@ -69,15 +78,13 @@ fn main() -> Result<()> { info!("Wifi configuration set, about to get status"); - wifi.wait_status_with_timeout(Duration::from_secs(20), |status| !status.is_transitional()) - .map_err(|e| anyhow::anyhow!("Unexpected Wifi status: {:?}", e))?; + wifi.wait_status(|status| !status.is_transitional()); let status = wifi.get_status(); if let Status( - ClientStatus::Started(ClientConnectionStatus::Connected(ClientIpStatus::Done(_ip_settings))), - ApStatus::Started(ApIpStatus::Done), - ) = status + ClientStatus::Started(ClientConnectionStatus::Connected(ClientIpStatus::Done(_ip_settings))) + , _) = status { info!("Wifi connected"); @@ -85,6 +92,44 @@ fn main() -> Result<()> { bail!("Unexpected Wifi status: {:?}", status); } + let peripherals = Peripherals::take().unwrap(); + let pins = peripherals.pins; + + let mutex: Arc<(Mutex>, Condvar)> = Arc::new((Mutex::new(None), Condvar::new())); + + let mut wait = mutex.0.lock().unwrap(); + + #[cfg(esp32c3)] + let mut a2 = pins.gpio2.into_analog_atten_11db()?; + + let mut powered_adc1 = adc::PoweredAdc::new( + peripherals.adc1, + adc::config::Config::new().calibration(true), + )?; + + #[allow(unused)] + let cycles = loop { + if let Some(cycles) = *wait { + break cycles; + } else { + wait = mutex + .1 + .wait_timeout(wait, Duration::from_secs(1)) + .unwrap() + .0; + + #[cfg(esp32)] + log::info!( + "Hall sensor reading: {}mV", + powered_adc1.read(&mut hall_sensor).unwrap() + ); + log::info!( + "A2 sensor reading: {}mV", + powered_adc1.read(&mut a2).unwrap() + ); + } + }; + Ok(()) }