|
@@ -327,7 +327,7 @@ pub struct RandomizePen {
|
|
speed: Option<(f64, f64, f64)>,
|
|
speed: Option<(f64, f64, f64)>,
|
|
power: Option<(f64, f64, f64)>,
|
|
power: Option<(f64, f64, f64)>,
|
|
frequency: Option<(u32, u32, u32)>,
|
|
frequency: Option<(u32, u32, u32)>,
|
|
- pulse_width: Option<(PulseWidth, PulseWidth)>,
|
|
|
|
|
|
+ pulse_width: Option<(PulseWidth, PulseWidth, usize)>,
|
|
}
|
|
}
|
|
|
|
|
|
impl RandomizePen {
|
|
impl RandomizePen {
|
|
@@ -344,34 +344,39 @@ impl RandomizePen {
|
|
.take(self.count)
|
|
.take(self.count)
|
|
.enumerate()
|
|
.enumerate()
|
|
{
|
|
{
|
|
- if let Some((min, max, incr)) = self.speed {
|
|
|
|
- let offset: usize = rand::thread_rng().gen_range(0..=((max - min) / incr) as usize);
|
|
|
|
- let value: f64 = min + incr * offset as f64;
|
|
|
|
|
|
+ if let Some((min, max, step)) = self.speed {
|
|
|
|
+ let offset: usize = rand::thread_rng().gen_range(0..=((max - min) / step) as usize);
|
|
|
|
+ let value: f64 = min + step * offset as f64;
|
|
debug!("Randomizing speed for pen #{} to {}", index, value);
|
|
debug!("Randomizing speed for pen #{} to {}", index, value);
|
|
*pen.speed = value;
|
|
*pen.speed = value;
|
|
}
|
|
}
|
|
|
|
|
|
- if let Some((min, max, incr)) = self.power {
|
|
|
|
- let offset: usize = rand::thread_rng().gen_range(0..=((max - min) / incr) as usize);
|
|
|
|
- let value: f64 = min + incr * offset as f64;
|
|
|
|
|
|
+ if let Some((min, max, step)) = self.power {
|
|
|
|
+ let offset: usize = rand::thread_rng().gen_range(0..=((max - min) / step) as usize);
|
|
|
|
+ let value: f64 = min + step * offset as f64;
|
|
debug!("Randomizing power for pen #{} to {}", index, value);
|
|
debug!("Randomizing power for pen #{} to {}", index, value);
|
|
*pen.power = value;
|
|
*pen.power = value;
|
|
}
|
|
}
|
|
|
|
|
|
- if let Some((min, max, incr)) = self.frequency {
|
|
|
|
- let offset: usize = rand::thread_rng().gen_range(0..=((max - min) / incr) as usize);
|
|
|
|
- let value: u32 = min + incr * offset as u32;
|
|
|
|
|
|
+ if let Some((min, max, step)) = self.frequency {
|
|
|
|
+ let offset: usize = rand::thread_rng().gen_range(0..=((max - min) / step) as usize);
|
|
|
|
+ let value: u32 = min + step * offset as u32;
|
|
debug!("Randomizing frequency for pen #{} to {}", index, value);
|
|
debug!("Randomizing frequency for pen #{} to {}", index, value);
|
|
*pen.frequency = value;
|
|
*pen.frequency = value;
|
|
*pen.frequency_2 = value.try_into().unwrap();
|
|
*pen.frequency_2 = value.try_into().unwrap();
|
|
}
|
|
}
|
|
|
|
|
|
- if let Some((min, max)) = self.pulse_width {
|
|
|
|
|
|
+ if let Some((min, max, step)) = self.pulse_width {
|
|
let mut pw = PulseWidth::iter();
|
|
let mut pw = PulseWidth::iter();
|
|
- let mut v: Vec<PulseWidth> = vec![pw.find(|x| *x == min).unwrap()];
|
|
|
|
- v.extend(pw.take_while_inclusive(|x| *x != max).collect_vec());
|
|
|
|
|
|
+ let mut values: Vec<PulseWidth> = vec![pw.find(|x| *x == min).unwrap()];
|
|
|
|
+ values.extend(
|
|
|
|
+ pw.skip(step - 1)
|
|
|
|
+ .step_by(step)
|
|
|
|
+ .take_while_inclusive(|x| *x != max)
|
|
|
|
+ .collect_vec(),
|
|
|
|
+ );
|
|
|
|
|
|
- let width: &PulseWidth = v
|
|
|
|
|
|
+ let width: &PulseWidth = values
|
|
.choose_multiple(&mut rand::thread_rng(), 1)
|
|
.choose_multiple(&mut rand::thread_rng(), 1)
|
|
.next()
|
|
.next()
|
|
.unwrap();
|
|
.unwrap();
|