Skip to content

Commit

Permalink
cleanup warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
bunnie committed Nov 14, 2024
1 parent fac7adc commit 4a99341
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 14 deletions.
28 changes: 17 additions & 11 deletions services/bao-video/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use cramium_hal::iox::IoGpio;
use cramium_hal::iox::{IoxPort, IoxValue};
use cramium_hal::minigfx::*;
use cramium_hal::sh1107::{Mono, Oled128x128};
use cramium_hal::udma::{PeriphId, Udma};
use cramium_hal::{minigfx::*, sh1107};

mod gfx;
mod homography;
Expand Down Expand Up @@ -53,7 +52,6 @@ fn wrapped_main() -> ! {
log::set_max_level(log::LevelFilter::Info);

let tt = ticktimer::Ticktimer::new().unwrap();
let xns = xous_names::XousNames::new().unwrap();

let iox = cram_hal_service::IoxHal::new();
let udma_global = cram_hal_service::UdmaGlobal::new();
Expand Down Expand Up @@ -91,17 +89,16 @@ fn wrapped_main() -> ! {

let mut frames = 0;
let mut frame = [0u8; IMAGE_WIDTH * IMAGE_HEIGHT];
let mut decode_success = false;
let mut decode_success;
// while iox.get_gpio_pin_value(IoxPort::PB, 9) == IoxValue::High {}
loop {
#[cfg(not(feature = "decongest-udma"))]
cam.capture_async();

let mut candidates = Vec::<Point>::new();
decode_success = false;
log::info!("------------- SEARCH -----------");
log::info!("------------- SEARCH {} -----------", frames);
let finder_width = qr::find_finders(&mut candidates, &frame, BW_THRESH, IMAGE_WIDTH) as isize;
const CROSSHAIR_LEN: isize = 3;
if candidates.len() == 3 {
let candidates_orig = candidates.clone();
let mut x_candidates: [Point; 3] = [Point::new(0, 0); 3];
Expand Down Expand Up @@ -293,7 +290,7 @@ fn wrapped_main() -> ! {
for c in candidates_orig.iter() {
log::debug!("****** candidate: {}, {} ******", c.x, c.y);
// remap image to screen coordinates (it's 2:1)
let mut c_screen = *c / 2;
let c_screen = *c / 2;
// flip coordinates to match the camera data
// c_screen = Point::new(c_screen.x, sh1107.dimensions().y - 1 - c_screen.y);
qr::draw_crosshair(&mut sh1107, c_screen);
Expand Down Expand Up @@ -328,23 +325,32 @@ fn wrapped_main() -> ! {
// clear the front buffer
sh1107.clear();

let mut start = tt.elapsed_ms();
let mut now = tt.elapsed_ms();
const TIMEOUT_MS: u64 = 100;
#[cfg(feature = "decongest-udma")]
{
// don't parallelize the camera capture to avoid triggering a hardware bug
// in the SPIM block.
while iox.get_gpio_pin_value(IoxPort::PB, 9) == IoxValue::High
&& ((tt.elapsed_ms() - now) < TIMEOUT_MS)
{}
while iox.get_gpio_pin_value(IoxPort::PB, 9) == IoxValue::High && ((now - start) < TIMEOUT_MS) {
now = tt.elapsed_ms();
}
if now - start >= TIMEOUT_MS {
log::info!("Timeout before capture_async()!");
}
cam.capture_async();
}

// wait for the transfer to finish
start = tt.elapsed_ms();
now = tt.elapsed_ms();
while cam.udma_busy(cramium_hal::udma::Bank::Rx) && ((tt.elapsed_ms() - now) < TIMEOUT_MS) {
while cam.udma_busy(cramium_hal::udma::Bank::Rx) && ((now - start) < TIMEOUT_MS) {
now = tt.elapsed_ms();
// busy-wait to get better time resolution on when the frame ends
}
if now - start >= TIMEOUT_MS {
log::info!("Timeout before rx_buf()!");
}
let fb: &[u32] = cam.rx_buf();

// fb is an array of IMAGE_WIDTH x IMAGE_HEIGHT x u16
Expand Down
7 changes: 7 additions & 0 deletions services/bao-video/src/modules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ impl FracIter {
self.count = 0;
}

#[allow(dead_code)]
/// Untested, but reserved API for adjusting grid streaming if we need better performance on
/// higher resolution QR codes
pub fn error(&self) -> isize {
if (self.current & (FIXED_POINT - 1)) == 0 {
0
Expand All @@ -82,6 +85,10 @@ impl FracIter {
}
}

#[allow(dead_code)]
/// Untested, but reserved API for adjusting grid streaming if we need better performance on
/// higher resolution QR codes
///
/// The sign on m applies to n, but n is represented as a sign-less quantity
pub fn nudge(&mut self, m: isize, n: usize) {
assert!(n < FIXED_POINT);
Expand Down
8 changes: 5 additions & 3 deletions services/bao-video/src/qr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ const UPPER_1: usize = 2 << SEQ_FP_SHIFT;
const LOWER_3: usize = 2 << SEQ_FP_SHIFT;
const UPPER_3: usize = 4 << SEQ_FP_SHIFT;

pub const STORAGE: usize = 92;

pub const BW_THRESH: u8 = 128;
/// Finder search margin, as defined by expected QR code code widths (so this scales with the effective
/// resolution of the code)
pub const FINDER_SEARCH_MARGIN: isize = 2;
Expand All @@ -44,6 +41,8 @@ pub fn draw_crosshair(image: &mut dyn FrameBuffer, p: Point) {
);
}

#[allow(dead_code)]
/// Used for debugging QR code algorithms
pub fn draw_line(image: &mut dyn FrameBuffer, l: &LineDerivation, color: ColorNative) {
let axis = l.independent_axis;
let (m, b) = l.equation.unwrap();
Expand Down Expand Up @@ -292,8 +291,10 @@ impl QrCorners {
}
}

#[allow(dead_code)]
pub fn derived_corner(&self) -> Direction { self.derived_corner }

#[allow(dead_code)]
pub fn center_point(&self, dir: Direction) -> Option<Point> { self.corners[dir as usize].finder_ref }

fn outline_search(&mut self, ir: &mut ImageRoi) {
Expand Down Expand Up @@ -689,6 +690,7 @@ impl<'a> ImageRoi<'a> {
}
}

#[allow(dead_code)]
pub fn absolute_to_roi(&self, point: Point) -> Option<Point> {
let x = point.x - self.x0 as isize;
let y = point.y - self.y0 as isize;
Expand Down

0 comments on commit 4a99341

Please sign in to comment.