Skip to content

Commit

Permalink
Support to write NFC uids directly to JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
zargony committed Dec 19, 2024
1 parent f3bf294 commit 2104f4f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
12 changes: 12 additions & 0 deletions firmware/src/nfc.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
// Use custom pn532 driver instead of pn532 crate
use crate::pn532;

use crate::json::{self, ToJson};
use alloc::string::ToString;
use const_hex::FromHex;
use core::convert::Infallible;
use core::fmt::{self, Debug};
use core::str::FromStr;
use embassy_time::{Duration, Timer};
use embedded_hal_async::digital::Wait;
use embedded_hal_async::i2c::I2c;
use embedded_io_async::Write;
use log::{debug, info, warn};
use pn532::{Error as Pn532Error, I2CInterfaceWithIrq, Pn532, Request, SAMMode};

Expand Down Expand Up @@ -267,3 +270,12 @@ impl AsRef<[u8]> for Uid {
}
}
}

impl ToJson for Uid {
async fn to_json<W: Write>(
&self,
json: &mut json::Writer<W>,
) -> Result<(), json::Error<W::Error>> {
json.write(self.to_string()).await
}
}
5 changes: 2 additions & 3 deletions firmware/src/telemetry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use crate::http::Http;
use crate::mixpanel::{self, Mixpanel};
use crate::{article, json, nfc, user};
use alloc::collections::VecDeque;
use alloc::string::ToString;
use embassy_time::{Duration, Instant};
use embedded_io_async::Write;
use log::{debug, info, warn};
Expand Down Expand Up @@ -72,10 +71,10 @@ impl Event {
.await?;
}
Event::AuthenticationFailed(uid) => {
object.field("uid", uid.to_string()).await?;
object.field("uid", uid).await?;
}
Event::UserAuthenticated(_user_id, uid) => {
object.field("uid", uid.to_string()).await?;
object.field("uid", uid).await?;
}
Event::ArticlePurchased(_user_id, article_id, amount, total_price) => {
object
Expand Down

0 comments on commit 2104f4f

Please sign in to comment.