Skip to content

Commit 274afed

Browse files
committed
vinscant: code cleanup
1 parent de0a232 commit 274afed

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

vinscant/src/card_request.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use esp_idf_svc::{
44
client::{Configuration, EspHttpConnection},
55
Method,
66
},
7-
io::EspIOError,
7+
io::EspIOError, sys::EspError,
88
};
99
use mfrc522::Uid;
1010

@@ -15,7 +15,13 @@ pub enum CardError {
1515
}
1616

1717
impl From<EspIOError> for CardError {
18-
fn from(value: EspIOError) -> Self {
18+
fn from(_: EspIOError) -> Self {
19+
CardError::ConnectionError
20+
}
21+
}
22+
23+
impl From<EspError> for CardError {
24+
fn from(_: EspError) -> Self {
1925
CardError::ConnectionError
2026
}
2127
}
@@ -26,8 +32,7 @@ pub fn hannes_is_the_best_in_sending_requests(uid: Uid, auth_key: &str) -> Resul
2632
use_global_ca_store: true,
2733
crt_bundle_attach: Some(esp_idf_svc::sys::esp_crt_bundle_attach),
2834
..Default::default()
29-
})
30-
.unwrap(),
35+
})?,
3136
);
3237
let mut request = client.request(
3338
Method::Post,
@@ -37,9 +42,11 @@ pub fn hannes_is_the_best_in_sending_requests(uid: Uid, auth_key: &str) -> Resul
3742
let _ = request.write(format!("{};{}", hex::encode(uid.as_bytes()), auth_key).as_bytes());
3843
let response = request.submit()?;
3944
log::info!("response code: {}", response.status());
40-
if response.status() == 200 {
45+
if 200 <= response.status() && response.status() < 300 {
4146
Ok(())
42-
} else {
47+
} else if response.status() == 404 {
4348
Err(CardError::NotFoundError)
49+
} else {
50+
Err(CardError::ServerError)
4451
}
4552
}

vinscant/src/main.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,22 @@
11
use core::str;
2-
use embedded_svc::http::{client::Client, Method};
32
use esp_idf_svc::{
43
eventloop::EspSystemEventLoop,
54
hal::{
65
delay::FreeRtos,
76
gpio::{InputPin, OutputPin},
8-
ledc::{config, LedcDriver, LedcTimerDriver},
7+
ledc::{config, LedcDriver, LedcTimer, LedcTimerDriver},
98
prelude::Peripherals,
109
spi::{self, SpiSingleDeviceDriver},
1110
units::Hertz,
1211
},
13-
http::client::{Configuration, EspHttpConnection},
14-
io::EspIOError,
1512
sys::esp_task_wdt_deinit,
1613
};
1714
use hex::ToHex;
1815
use smart_led_effects::{strip::EffectIterator, Srgb};
1916
use std::time::{Duration, SystemTime, UNIX_EPOCH};
2017
use ws2812_esp32_rmt_driver::{driver::color::LedPixelColorGrb24, LedPixelEsp32Rmt, RGB8};
2118

22-
use mfrc522::{comm::blocking::spi::SpiInterface, Mfrc522, Uid};
19+
use mfrc522::{comm::blocking::spi::SpiInterface, Mfrc522};
2320

2421
use lib::{
2522
card_request::{hannes_is_the_best_in_sending_requests, CardError},

0 commit comments

Comments
 (0)