Skip to content

Commit e96e2bd

Browse files
committed
Fix broken build
1 parent 6b55268 commit e96e2bd

File tree

3 files changed

+36
-17
lines changed

3 files changed

+36
-17
lines changed

src/config.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ pub struct Config {
5858
}
5959

6060
impl Config {
61-
pub fn read(file_path: &str) -> anyhow<Self> {
61+
pub fn read(file_path: &str) -> anyhow::Result<Self> {
6262
let mut config_str = String::new();
6363
File::open(file_path)?.read_to_string(&mut config_str)?;
64-
toml::from_str(&*config_str)?
64+
Ok(toml::from_str(&*config_str)?)
6565
}
6666
}

src/main.rs

+33-14
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ mod wifi;
66

77
use crate::api::processor::{process_events, DeviceInfo, DeviceInfoProducer};
88
use crate::api::websocket::{ConnectionState, SessionEvent, WebSocketSession};
9+
use crate::config::Config;
910
use crate::storage::spiflash::SPIFlashStorage;
1011
use crate::usb::msc_device::{MSCDevice, MSCDeviceConfig};
1112
use crate::wifi::session::WifiSession;
@@ -18,46 +19,64 @@ use esp_idf_svc::sys::{esp, esp_vfs_fat_info, free};
1819
use futures::executor::{LocalPool, LocalSpawner};
1920
use futures::task::LocalSpawnExt;
2021
use std::ffi::CString;
22+
use std::path::Path;
2123
use std::rc::Rc;
2224
use std::thread;
2325
use std::time::Duration;
2426
use time::OffsetDateTime;
2527

26-
const DEFAULT_PARTITION_LABEL: &str = "storage";
27-
const DEFAULT_MOUNT_PATH: &str = "/disk";
28-
2928
const PKG_NAME: &str = env!("CARGO_PKG_NAME");
3029
const VERSION: &str = env!("CARGO_PKG_VERSION");
3130

32-
const SSID: &str = env!("WIFI_SSID");
33-
const PASSWORD: &str = env!("WIFI_PASS");
34-
const API_ENDPOINT: &str = env!("API_ENDPOINT");
31+
const CONFIG_PATH: Option<&str> = option_env!("CONFIG_PATH");
32+
const DEFAULT_CONFIG_PATH: &str = "securedash.toml";
3533
const PARTITION_LABEL: Option<&str> = option_env!("PARTITION_LABEL");
34+
const DEFAULT_PARTITION_LABEL: &str = "storage";
3635
const MOUNT_PATH: Option<&str> = option_env!("MOUNT_PATH");
36+
const DEFAULT_MOUNT_PATH: &str = "/disk";
37+
38+
fn load_config(config_file: &str) -> Option<Config> {
39+
log::info!("Reading config from {}", config_file);
40+
let config = Config::read(&config_file);
41+
if let Err(error) = &config {
42+
log::error!("Failed to load config: {error}");
43+
}
44+
let config = config.ok();
45+
if let Some(config) = &config {
46+
log::info!("Loaded config: {config:#?}");
47+
}
48+
config
49+
}
3750

3851
async fn run_async(spawner: LocalSpawner) -> Result<(), anyhow::Error> {
39-
log::info!("Start {} - {}", PKG_NAME, VERSION,);
52+
let partition_label = PARTITION_LABEL.unwrap_or(DEFAULT_PARTITION_LABEL);
53+
let mount_path = MOUNT_PATH.unwrap_or(DEFAULT_MOUNT_PATH);
54+
let config_path = CONFIG_PATH.unwrap_or(DEFAULT_CONFIG_PATH);
55+
log::info!("Start {PKG_NAME} - version={VERSION}, partition_label={partition_label}, mount_path={mount_path}, config_path={config_path}");
4056

41-
let mount_path = MOUNT_PATH.unwrap_or(DEFAULT_MOUNT_PATH).to_string();
4257
let mut storage = Box::new(SPIFlashStorage::new());
43-
storage.initialize_partition(PARTITION_LABEL.unwrap_or(DEFAULT_PARTITION_LABEL))?;
58+
storage.initialize_partition(partition_label)?;
4459
storage.mount(&mount_path, 5);
4560

61+
let config = load_config(Path::new(mount_path).join(config_path).to_str().unwrap());
62+
63+
let mut msc_device = MSCDevice::new(&MSCDeviceConfig { high_speed: true }, storage);
64+
msc_device.install()?;
65+
4666
let peripherals = Peripherals::take()?;
67+
/*
4768
let mut wifi = WifiSession::new(SSID, PASSWORD, AuthMethod::WPA2Personal, peripherals.modem)?;
4869
wifi.connect().await?;
49-
log::info!("Connected wifi: {:#?}", wifi.get_ip_info());
70+
log::info!("Connected wifi: {:#?}", wifi.get_ip_info());*/
5071

5172
// Keep it around or else the SNTP service will stop
5273
let _sntp = EspSntp::new_default()?;
5374
log::info!("SNTP initialized");
5475

55-
let mut msc_device = MSCDevice::new(&MSCDeviceConfig { high_speed: true }, storage);
56-
msc_device.install()?;
57-
5876
let mut button = PinDriver::input(peripherals.pins.gpio14)?;
5977
button.set_pull(Pull::Up)?;
6078

79+
/*
6180
let mut client = WebSocketSession::new(API_ENDPOINT, Duration::from_secs(30));
6281
6382
let captured_mount_path = mount_path.clone();
@@ -86,7 +105,7 @@ async fn run_async(spawner: LocalSpawner) -> Result<(), anyhow::Error> {
86105
button.wait_for_low().await?;
87106
log::info!("Button pressed!");
88107
89-
spawner.spawn_local(process_events(client, device_info_producer, mount_path))?;
108+
spawner.spawn_local(process_events(client, device_info_producer, mount_path))?;*/
90109

91110
loop {
92111
// Asynchronously wait for GPIO events, allowing other tasks

src/usb/msc_device.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ impl MSCDevice {
7171
esp!(unsafe { tinyusb_driver_install(&tusb_cfg) })
7272
.with_context(|| "Failed to install TinyUSB driver")?;
7373

74-
log::info!("TinyUSB driver installed.");
74+
log::info!("TinyUSB MSC driver installed.");
7575
Ok(())
7676
}
7777
}

0 commit comments

Comments
 (0)