Skip to content
Snippets Groups Projects
Commit afcf71dc authored by Matt Johnston's avatar Matt Johnston
Browse files

Moved to step() function

Changed to separate LOOP vs BUF. No change to algorithm
parent 0f3d95f2
No related merge requests found
......@@ -117,12 +117,21 @@ async fn run<'d, P: Pin>(pin: &mut Flex<'d, P>, syst: &mut SYST) -> Result<(), D
loop {
const LOOP: usize = 20;
const BUF: usize = 16;
const T: u32 = 8192;
let mut dels = [0u32; LOOP];
let mut ups = [0u32; LOOP];
let mut downs = [0u32; LOOP];
let mut upx = [0u32; LOOP];
let mut downx = [0u32; LOOP];
let mut dels = [0u32; BUF];
let mut ups = [0u32; BUF];
let mut downs = [0u32; BUF];
let mut upx = [0u32; BUF];
let mut downx = [0u32; BUF];
let step = |prev: u32, meas: u32| {
if meas < T || prev < T {
prev * 2
} else {
prev.saturating_sub(T / 2)
}.max(1)
};
critical_section::with(|_cs| {
......@@ -135,11 +144,7 @@ async fn run<'d, P: Pin>(pin: &mut Flex<'d, P>, syst: &mut SYST) -> Result<(), D
let t2 = SYST::get_current();
up = t1 - t2;
up_x = if down < T {
up_x * 2
} else {
up_x.saturating_sub(down/2)
}.max(1);
up_x = step(up_x, down);
cortex_m::asm::delay(up_x);
pin.set_pull(Pull::Down);
......@@ -149,22 +154,22 @@ async fn run<'d, P: Pin>(pin: &mut Flex<'d, P>, syst: &mut SYST) -> Result<(), D
let t2 = SYST::get_current();
down = t1 - t2;
down_x = if up < T {
down_x * 2
} else {
down_x.saturating_sub(up/2)
}.max(1);
ups[i] = up;
upx[i] = up_x;
downs[i] = down;
downx[i] = down_x;
dels[i] = up + down;
down_x = step(down_x, up);
if i < BUF {
let n = i;
ups[n] = up;
upx[n] = up_x;
downs[n] = down;
downx[n] = down_x;
dels[n] = up + down;
}
}
pin.set_pull(Pull::None);
});
for i in 0..LOOP {
for i in 0..BUF {
info!("{} U {} x {} D {} x {}", dels[i], ups[i], upx[i], downs[i], downx[i]);
}
info!("===");
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment