no_std printing of QR code (kind of...)

This commit is contained in:
ivmarkov 2023-04-24 09:48:39 +00:00
parent d558c73f8d
commit faf5af3e1f
2 changed files with 21 additions and 10 deletions

View file

@ -22,7 +22,6 @@ pub mod qr;
pub mod vendor_identifiers;
use log::info;
use qrcode::{render::unicode, QrCode, Version};
use verhoeff::Verhoeff;
use crate::{

View file

@ -315,16 +315,28 @@ fn estimate_struct_overhead(first_field_size: usize) -> usize {
}
pub(super) fn print_qr_code(qr_data: &str) {
#[cfg(not(feature = "std"))]
{
info!("\n QR CODE DATA: {}", qr_data);
}
#[cfg(feature = "std")]
{
use qrcode::{render::unicode, QrCode, Version};
let needed_version = compute_qr_version(qr_data);
let code =
QrCode::with_version(qr_data, Version::Normal(needed_version), qrcode::EcLevel::M).unwrap();
QrCode::with_version(qr_data, Version::Normal(needed_version), qrcode::EcLevel::M)
.unwrap();
let image = code
.render::<unicode::Dense1x2>()
.dark_color(unicode::Dense1x2::Light)
.light_color(unicode::Dense1x2::Dark)
.build();
info!("\n{}", image);
}
}
fn compute_qr_version(qr_data: &str) -> i16 {
match qr_data.len() {