fn steps_i(
    ld: &mut SDL1000X,
    v_thres: f32,
    i_start: f32,
    i_step: f32,
) -> anyhow::Result<(f32, usize)> {
    ld.set(":current", i_start)?;
    thread::sleep(time::Duration::new(2, 0));
    let v_initial = ld.meas(sdl1000x::Meas::Volt)?;

    // increase or decrease current?
    let i_sign = signum(v_initial - v_thres);

    let mut i_now = i_start;
    let mut n: usize = 0;
    loop {
        n += 1;
        i_now += i_sign * i_step;

        ld.set(":current", i_now)?;
        thread::sleep(time::Duration::new(1, 0));
        let v_now = ld.meas(sdl1000x::Meas::Volt)?;

        // did we cross the threshold?
        if (signum(v_now - v_thres) - i_sign).abs() > 0.1 {
            break;
        }
    }
    Ok((i_now, n))
}
/// return how many steps had to be taken to cross over threshold
return how many steps had to be taken to cross over threshold
return how many steps had to be taken to cross over threshold
fn steps_i(
    ld: &mut SDL1000X,
    v_thres: f32,
    i_start: f32,
    i_step: f32,
) -> anyhow::Result<(f32, usize)> {
    ld.set(":current", i_start)?;
    thread::sleep(time::Duration::new(2, 0));
    let v_initial = ld.meas(sdl1000x::Meas::Volt)?;
    // increase or decrease current?
    let i_sign = signum(v_initial - v_thres);
    let mut i_now = i_start;
    let mut n: usize = 0;
    loop {
        n += 1;
        i_now += i_sign * i_step;
        ld.set(":current", i_now)?;
        thread::sleep(time::Duration::new(1, 0));
        let v_now = ld.meas(sdl1000x::Meas::Volt)?;
        // did we cross the threshold?
        if (signum(v_now - v_thres) - i_sign).abs() > 0.1 {
            break;
        }
    }
    Ok((i_now, n))
}
fn steps_i ( ld : & mut SDL1000X , v_thres : f32 , i_start : f32 , i_step : f32 , ) -> anyhow :: Result < ( f32 , usize ) > { ld . set ( " " , i_start ) ? ; thread :: sleep ( time :: Duration :: new ( 2 , 0 ) ) ; let v_initial = ld . meas ( sdl1000x :: Meas :: Volt ) ? ; // increase or decrease current? let i_sign = signum ( v_initial - v_thres ) ; let mut i_now = i_start ; let mut n : usize = 0 ; loop { n += 1 ; i_now += i_sign * i_step ; ld . set ( " " , i_now ) ? ; thread :: sleep ( time :: Duration :: new ( 1 , 0 ) ) ; let v_now = ld . meas ( sdl1000x :: Meas :: Volt ) ? ; // did we cross the threshold? if ( signum ( v_now - v_thres ) - i_sign ) . abs ( ) > 0.1 { break ; } } Ok ( ( i_now , n ) ) }
return how many steps had to be taken to cross over threshold
return how many steps had to be taken to cross over threshold
ld
&mut SDL1000X
v_thres
f32
i_start
f32
i_step
f32
ld
&mut SDL1000X
v_thres
f32
i_start
f32
i_step
f32