Added color map to waterfall

This commit is contained in:
Sebastian 2023-08-08 20:02:27 +02:00
parent e6ab8845b3
commit 60da60250e
2 changed files with 15 additions and 24 deletions

View File

@ -21,6 +21,7 @@ num = {version = "0.4", default-features = false}
microfft = "0.5.1"
st7735-lcd = "0.9.0"
embedded-graphics = "0.8.0"
colorous = { version="1.0.12", default-features = false}
[features]

View File

@ -80,6 +80,7 @@ mod app {
disp_cs: gpioa::PA15<Output<PushPull>>,
disp: ST7735<Spi<SPI1>, gpio::Pin<'A', 12, Output>, gpio::Pin<'A', 11, Output>>,
col_pos: u16,
max_mag: f32,
}
#[init]
@ -237,33 +238,38 @@ mod app {
disp_cs,
disp,
col_pos: 0,
max_mag: 0.0,
},
)
}
#[task(priority = 0, local = [disp, col_pos])]
#[task(priority = 0, local = [disp, col_pos, max_mag])]
async fn update_display(cx: update_display::Context, col: [Complex<f32>; 128]) {
let mut max_intens = 0.0;
for samp in col {
let intens = (samp.re.pow(2) + samp.im.pow(2)) as f32;
max_intens = if intens > max_intens {
intens
let mag = (samp.re.pow(2) + samp.im.pow(2)) as f32;
*cx.local.max_mag = if mag > *cx.local.max_mag {
mag
} else {
max_intens
*cx.local.max_mag
};
}
let gradient = colorous::TURBO;
for y in 0..128 {
let norm_intens = (col[y].re.pow(2) + col[y].im.pow(2)) / max_intens;
let norm_intens = (col[y].re.pow(2) + col[y].im.pow(2)) / *cx.local.max_mag;
let color = gradient.eval_continuous(norm_intens as f64);
Pixel(
Point::new(*cx.local.col_pos as i32, y as i32),
Rgb565::new(0, (norm_intens * 64.0f32) as u8, 0),
Rgb565::new(color.r >> 3, color.g >> 2, color.b >> 3),
)
.draw(cx.local.disp)
.unwrap();
}
*cx.local.col_pos = (*cx.local.col_pos + 1) % 160;
*cx.local.max_mag *= 0.999;
defmt::info!("Position is {}", cx.local.col_pos);
}
@ -303,22 +309,6 @@ mod app {
update_display::spawn(spectrum.clone()).unwrap();
let mut max_idx: usize = 0;
let mut max_mag = 0.0;
for idx in 0..spectrum.len() {
let mag_cur = ((spectrum[idx].re.pow(2) + spectrum[idx].im.pow(2)) as f32).sqrt();
if mag_cur > max_mag {
max_idx = idx;
max_mag = mag_cur;
}
}
defmt::debug!(
"Max at {}kHz: {}",
max_idx as f32 * (8.0 / 128.0) - 4.0,
max_mag
);
*cx.local.iq_buffer = Some(buffer);
}
}