Skip to content

Commit 8302248

Browse files
committed
wip: card signing UI
1 parent 9b913cc commit 8302248

File tree

4 files changed

+73
-0
lines changed

4 files changed

+73
-0
lines changed

src/buttons.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,16 @@ async fn submit_up(
155155
return Ok(true);
156156
}
157157

158+
if unsafe { crate::state::SIGN_CARDS_MODE || crate::state::UNSIGN_CARDS_MODE } {
159+
unsafe {
160+
crate::state::SIGN_CARDS_MODE = false;
161+
crate::state::UNSIGN_CARDS_MODE = false;
162+
}
163+
164+
state.state.signal();
165+
return Ok(true);
166+
}
167+
158168
if let Some(sel) = state_val.selected_config_menu {
159169
match sel {
160170
0 => {
@@ -175,10 +185,14 @@ async fn submit_up(
175185
2 => {
176186
// Sign Cards
177187
unsafe { crate::state::SIGN_CARDS_MODE = true };
188+
// TODO: change this shit
189+
// MAYBE make second scene set (for things like this)
178190
}
179191
3 => {
180192
// Un-Sign Cards
181193
unsafe { crate::state::UNSIGN_CARDS_MODE = true };
194+
// TODO: change this shit
195+
// MAYBE make second scene set (for things like this)
182196
}
183197
4 => {} // Exit
184198
_ => {

src/lcd.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,42 @@ async fn process_lcd<T: OutputPin, D: DelayNs>(
222222
return Some(());
223223
}
224224

225+
if unsafe { crate::state::SIGN_CARDS_MODE || crate::state::UNSIGN_CARDS_MODE } {
226+
lcd_driver.clear_all().ok()?;
227+
lcd_driver
228+
.print(0, "Signing | Submit To Exit", PrintAlign::Left, true)
229+
.ok()?;
230+
231+
if global_state.sign_unsign_progress.signaled() {
232+
let status = if global_state.sign_unsign_progress.wait().await {
233+
"OK"
234+
} else {
235+
"FAIL"
236+
};
237+
238+
lcd_driver
239+
.print(
240+
1,
241+
&alloc::format!("Operation {}", status),
242+
PrintAlign::Center,
243+
true,
244+
)
245+
.ok()?;
246+
lcd_driver.display_on_lcd(lcd).await;
247+
248+
Timer::after_millis(300).await;
249+
lcd_driver
250+
.print(1, "Scan the card", PrintAlign::Center, true)
251+
.ok()?;
252+
} else {
253+
lcd_driver
254+
.print(1, "Scan the card", PrintAlign::Center, true)
255+
.ok()?;
256+
}
257+
258+
return Some(());
259+
}
260+
225261
let overwritten = process_lcd_overwrite(&current_state, global_state, lcd_driver).await;
226262
if overwritten {
227263
return Some(());

src/rfid.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,19 @@ pub async fn rfid_task(
158158
let res = mfrc522.mifare_write(63, &buff, 16).await;
159159
if let Err(e) = res {
160160
log::error!("cannot unsecure card error: {e:?}");
161+
global_state.sign_unsign_progress.signal(false);
162+
global_state.state.signal();
161163
_ = mfrc522.picc_halta().await;
162164
_ = mfrc522.pcd_stop_crypto1().await;
163165
continue;
164166
}
167+
168+
global_state.sign_unsign_progress.signal(true);
169+
global_state.state.signal();
170+
} else {
171+
log::error!("unsign auth failed!");
172+
global_state.sign_unsign_progress.signal(false);
173+
global_state.state.signal();
165174
}
166175

167176
_ = mfrc522.picc_halta().await;
@@ -198,6 +207,8 @@ pub async fn rfid_task(
198207
let res = mfrc522.mifare_write(63, &buff, 16).await;
199208
if let Err(e) = res {
200209
log::error!("write res: {e:?}");
210+
global_state.sign_unsign_progress.signal(false);
211+
global_state.state.signal();
201212
_ = mfrc522.picc_halta().await;
202213
_ = mfrc522.pcd_stop_crypto1().await;
203214
continue;
@@ -214,6 +225,8 @@ pub async fn rfid_task(
214225
.await;
215226
if status.is_err() {
216227
log::error!("Cannot auth card!");
228+
global_state.sign_unsign_progress.signal(false);
229+
global_state.state.signal();
217230
_ = mfrc522.picc_halta().await;
218231
_ = mfrc522.pcd_stop_crypto1().await;
219232
continue;
@@ -224,10 +237,18 @@ pub async fn rfid_task(
224237
let res = mfrc522.mifare_write(62, &buff, 16).await;
225238
if res.is_err() {
226239
log::error!("Cannot write secured rfid info!");
240+
global_state.sign_unsign_progress.signal(false);
241+
global_state.state.signal();
227242
_ = mfrc522.picc_halta().await;
228243
_ = mfrc522.pcd_stop_crypto1().await;
229244
continue;
230245
}
246+
247+
global_state.sign_unsign_progress.signal(true);
248+
global_state.state.signal();
249+
} else {
250+
global_state.sign_unsign_progress.signal(false);
251+
global_state.state.signal();
231252
}
232253

233254
_ = mfrc522.picc_halta().await;

src/state.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ pub struct GlobalStateInner {
133133
pub timer_signal: Signal<NoopRawMutex, u64>,
134134
pub show_battery: Signal<CriticalSectionRawMutex, u8>,
135135
pub update_progress: Signal<CriticalSectionRawMutex, u8>,
136+
pub sign_unsign_progress: Signal<CriticalSectionRawMutex, bool>,
136137

137138
pub nvs: Nvs,
138139
pub aes: Mutex<NoopRawMutex, Aes<'static>>,
@@ -148,6 +149,7 @@ impl GlobalStateInner {
148149
timer_signal: Signal::new(),
149150
show_battery: Signal::new(),
150151
update_progress: Signal::new(),
152+
sign_unsign_progress: Signal::new(),
151153

152154
nvs: nvs.clone(),
153155
aes: Mutex::new(Aes::new(aes)),

0 commit comments

Comments
 (0)