hertz inverted

This commit is contained in:
devdesk 2024-02-23 02:10:49 +02:00
parent 39551f3794
commit c993f74511

View File

@ -5,16 +5,18 @@ use futures_timer::Delay;
use crossterm::{ use crossterm::{
cursor::position, cursor::position,
event::{DisableMouseCapture, EnableMouseCapture, Event, EventStream, KeyCode}, event::{DisableMouseCapture, EnableMouseCapture, Event, EventStream, KeyCode, KeyEvent},
execute, execute,
terminal::{disable_raw_mode, enable_raw_mode}, terminal::{disable_raw_mode, enable_raw_mode},
}; };
async fn set_cutoff(cutoff: f64) -> Result<(), reqwest::Error> { async fn set_cutoff(cutoff: f64, freq: f64) -> Result<(), reqwest::Error> {
// Some simple CLI args requirements... // Some simple CLI args requirements...
let url = format!("http://localhost:3000/cutoff"); let url = format!("http://localhost:3000/cutoff");
let mut map = HashMap::new(); let mut map = HashMap::new();
map.insert("cutoff", cutoff); map.insert("min_cutoff", cutoff);
map.insert("max_cutoff", cutoff + 10.0);
map.insert("freq_hz", freq);
let client = reqwest::Client::new(); let client = reqwest::Client::new();
let res = client.post(url).json(&map).send().await?; let res = client.post(url).json(&map).send().await?;
@ -38,10 +40,12 @@ async fn print_events() {
let mut reader = EventStream::new(); let mut reader = EventStream::new();
let mut cutoff = 30.0; let mut cutoff = 30.0;
let mut last_cutoff = cutoff; let mut last_cutoff = cutoff;
let mut freq = 1.0;
loop { loop {
let mut delay = Delay::new(Duration::from_millis(1_000)).fuse(); let mut delay = Delay::new(Duration::from_millis(1_000)).fuse();
let mut event = reader.next().fuse(); let mut event = reader.next().fuse();
let mut change = false;
select! { select! {
_ = delay => { _ = delay => {
}, },
@ -55,15 +59,30 @@ async fn print_events() {
if event == Event::Key(KeyCode::Esc.into()) { if event == Event::Key(KeyCode::Esc.into()) {
break; break;
} }
if event == Event::Key(KeyCode::Char('[').into()) { if let Event::Key(k) = event {
cutoff -= 1.0; if let KeyCode::Char(c) = k.code {
change = true;
match c {
'[' => {
cutoff -= 1.0;
}
']' => {
cutoff += 1.0;
}
'1' => {
freq *= 0.9;
}
'2' => {
freq *= 1.1;
}
_ => {
change = false;
}
}
}
} }
if event == Event::Key(KeyCode::Char(']').into()) { if change {
cutoff += 1.0; set_cutoff(cutoff, freq).await.unwrap();
}
if last_cutoff != cutoff {
set_cutoff(cutoff).await;
last_cutoff = cutoff;
println!("cutoff = {}\r", cutoff); println!("cutoff = {}\r", cutoff);
} }
} }