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

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

View file

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

View file

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