Skip to content

Commit 8720619

Browse files
committed
feat: Roll back the boot process when mfrc522 is not available
1 parent 2c9bf9f commit 8720619

File tree

8 files changed

+24
-35
lines changed

8 files changed

+24
-35
lines changed

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ box = ["_no_default"]
2828
cube = ["_no_default"]
2929
cube2 = ["_no_default"]
3030

31-
mfrc522 = ["ndef"]
31+
mfrc522 = ["ndef", "extra_server"]
32+
extra_server = []
3233

3334
[dependencies]
3435
log = "0.4"

src/app.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@ pub enum Event {
1616
MicAudioEnd,
1717
MicInterrupt(Vec<i16>),
1818
MicInterruptWaitTimeout,
19+
#[cfg_attr(not(feature = "extra_server"), allow(unused))]
1920
ServerUrl(String),
2021
}
2122

22-
#[allow(dead_code)]
23+
#[allow(unused)]
2324
impl Event {
2425
pub const IDLE: &'static str = "idle";
2526
pub const GAIA: &'static str = "gaia";

src/audio.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ impl AFE {
9090
}
9191
}
9292

93+
#[allow(unused)]
9394
fn feed(&self, data: &[u8]) -> i32 {
9495
let afe_handle = self.handle;
9596
let afe_data = self.data;

src/boards/base.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -204,15 +204,6 @@ macro_rules! start_hal {
204204
$evt_tx.clone(),
205205
);
206206
}
207-
#[cfg(not(feature = "mfrc522"))]
208-
{
209-
log::info!("MFRC522 feature not enabled, skipping RFID initialization");
210-
$evt_tx
211-
.blocking_send(crate::app::Event::ServerUrl(String::new()))
212-
.unwrap_or_else(|e| {
213-
log::error!("Failed to send ServerUrl event: {:?}", e);
214-
});
215-
}
216207
}};
217208
}
218209

src/boards/cube2.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -200,16 +200,6 @@ macro_rules! start_hal {
200200
{
201201
todo!("MFRC522 initialization not implemented yet");
202202
}
203-
204-
#[cfg(not(feature = "mfrc522"))]
205-
{
206-
log::info!("MFRC522 feature not enabled, skipping RFID initialization");
207-
$evt_tx
208-
.blocking_send(crate::app::Event::ServerUrl(String::new()))
209-
.unwrap_or_else(|e| {
210-
log::error!("Failed to send ServerUrl event: {:?}", e);
211-
});
212-
}
213203
}
214204
let _backlight = {
215205
let mut backlight = crate::boards::backlight_init($peripherals.pins.gpio13.into()).unwrap();

src/main.rs

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -98,24 +98,27 @@ fn main() -> anyhow::Result<()> {
9898

9999
log_heap();
100100

101-
gui.state = "Initializing...".to_string();
102-
gui.text = "Wait Loading Server URL...".to_string();
103-
gui.display_flush().unwrap();
101+
#[cfg(feature = "extra_server")]
102+
{
103+
gui.state = "Initializing...".to_string();
104+
gui.text = "Loading Server URL...".to_string();
105+
gui.display_flush().unwrap();
104106

105-
while let Some(event) = evt_rx.blocking_recv() {
106-
if let app::Event::ServerUrl(url) = event {
107-
log::info!("Received ServerUrl event: {}", url);
108-
if !url.is_empty() {
109-
server_url = url;
107+
while let Some(event) = evt_rx.blocking_recv() {
108+
if let app::Event::ServerUrl(url) = event {
109+
log::info!("Received ServerUrl event: {}", url);
110+
if !url.is_empty() {
111+
server_url = url;
112+
}
113+
break;
110114
}
111-
break;
112115
}
113-
}
114116

115-
std::thread::sleep(std::time::Duration::from_millis(500));
116-
gui.text = format!("Server URL: {}\nContinuing...", server_url);
117-
gui.display_flush().unwrap();
118-
std::thread::sleep(std::time::Duration::from_millis(3000));
117+
std::thread::sleep(std::time::Duration::from_millis(500));
118+
gui.text = format!("Server URL: {}\nContinuing...", server_url);
119+
gui.display_flush().unwrap();
120+
std::thread::sleep(std::time::Duration::from_millis(2000));
121+
}
119122

120123
let need_init = {
121124
button.is_low() || state == 1 || ssid.is_empty() || pass.is_empty() || server_url.is_empty()

src/ui.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ pub struct QrCanvas {
217217
width: u32,
218218
height: u32,
219219
dark_pixel: QrPixel,
220+
#[allow(unused)]
220221
light_pixel: QrPixel,
221222
pixels: Vec<embedded_graphics::Pixel<ColorFormat>>,
222223
}

src/ws.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ impl Server {
148148
})
149149
}
150150

151+
#[allow(unused)]
151152
pub fn set_timeout(&mut self, timeout: std::time::Duration) {
152153
self.timeout = timeout;
153154
}

0 commit comments

Comments
 (0)