diff --git a/sphinx-key/src/btn.rs b/sphinx-key/src/btn.rs index 4b4bd4c..346ac50 100644 --- a/sphinx-key/src/btn.rs +++ b/sphinx-key/src/btn.rs @@ -1,18 +1,23 @@ +mod conn; +mod core; +mod ota; mod periph; mod status; -use status::Status; - -use esp_idf_sys as _; // If using the `binstart` feature of `esp-idf-sys`, always keep this module imported - -// use embedded_svc::storage::StorageBase; +pub use crate::core::control::FlashPersister; use esp_idf_hal::peripherals::Peripherals; +use esp_idf_svc::nvs::EspDefaultNvsPartition; use esp_idf_svc::nvs::EspNvs; use esp_idf_svc::nvs::*; +use esp_idf_sys as _; // If using the `binstart` feature of `esp-idf-sys`, always keep this module imported +use status::Status; use std::sync::mpsc; +use std::sync::{Arc, Mutex}; use std::thread; use std::time::Duration; +const ID_LEN: usize = 12; + fn main() -> anyhow::Result<()> { esp_idf_sys::link_patches(); @@ -28,7 +33,10 @@ fn main() -> anyhow::Result<()> { periph::led::led_control_loop(pins.gpio0, peripherals.rmt.channel0, led_rx); // BUTTON thread - periph::button::button_loop(pins.gpio9, led_tx.clone()); + let default_nvs = EspDefaultNvsPartition::take()?; + let flash_per = FlashPersister::new(default_nvs.clone()); + let flash_arc = Arc::new(Mutex::new(flash_per)); + periph::button::button_loop(pins.gpio9, led_tx.clone(), flash_arc); loop { thread::sleep(Duration::from_millis(1000)); diff --git a/sphinx-key/src/main.rs b/sphinx-key/src/main.rs index 82dd2b6..ed92749 100644 --- a/sphinx-key/src/main.rs +++ b/sphinx-key/src/main.rs @@ -21,7 +21,7 @@ use std::time::Duration; use std::time::SystemTime; use esp_idf_hal::peripherals::Peripherals; -use esp_idf_svc::nvs::*; +use esp_idf_svc::nvs::EspDefaultNvsPartition; use sphinx_signer::lightning_signer::bitcoin::Network; use sphinx_signer::sphinx_glyph::control::{Config, ControlPersist, Policy, Velocity}; diff --git a/sphinx-key/src/periph/led.rs b/sphinx-key/src/periph/led.rs index 0b9e266..bc76d2f 100644 --- a/sphinx-key/src/periph/led.rs +++ b/sphinx-key/src/periph/led.rs @@ -17,7 +17,6 @@ pub struct Led { fn states() -> BTreeMap { let mut s = BTreeMap::new(); - s.insert(Status::Starting, (0x000001, 100)); // Blue s.insert(Status::MountingSDCard, (0x000102, 100)); // Cyan s.insert(Status::SyncingTime, (0x000122, 100)); // Cyan s.insert(Status::WifiAccessPoint, (0x000100, 100)); // Green @@ -27,8 +26,13 @@ fn states() -> BTreeMap { s.insert(Status::Connected, (0x000101, 400)); // Cyan s.insert(Status::Signing, (0x111111, 100)); // White s.insert(Status::Ota, (0xffa500, 100)); // Orange - s.insert(Status::Reset1, (0x017700, 100)); // yellow? - s.insert(Status::Reset2, (0xffa500, 100)); // orange? + s.insert(Status::Waiting, (0x000001, 100)); // Blue + s.insert(Status::Starting, (0x000001, 100)); // Blue + s.insert(Status::Reset1a, (0x017700, 100)); // yellow + s.insert(Status::Reset1, (0x017700, 100)); // yellow + s.insert(Status::Reset2a, (0xffa500, 100)); // orange + s.insert(Status::Reset2, (0xffa500, 100)); // orange + s.insert(Status::Reset3a, (0x010000, 100)); // Red s.insert(Status::Reset3, (0x010000, 100)); // Red s }