hertz inverted

This commit is contained in:
devdesk 2024-02-23 02:10:49 +02:00
parent 39551f3794
commit c993f74511
1 changed files with 30 additions and 11 deletions

View File

@ -5,16 +5,18 @@ use futures_timer::Delay;
use crossterm::{
cursor::position,
event::{DisableMouseCapture, EnableMouseCapture, Event, EventStream, KeyCode},
event::{DisableMouseCapture, EnableMouseCapture, Event, EventStream, KeyCode, KeyEvent},
execute,
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...
let url = format!("http://localhost:3000/cutoff");
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 res = client.post(url).json(&map).send().await?;
@ -38,10 +40,12 @@ async fn print_events() {
let mut reader = EventStream::new();
let mut cutoff = 30.0;
let mut last_cutoff = cutoff;
let mut freq = 1.0;
loop {
let mut delay = Delay::new(Duration::from_millis(1_000)).fuse();
let mut event = reader.next().fuse();
let mut change = false;
select! {
_ = delay => {
},
@ -55,15 +59,30 @@ async fn print_events() {
if event == Event::Key(KeyCode::Esc.into()) {
break;
}
if event == Event::Key(KeyCode::Char('[').into()) {
cutoff -= 1.0;
if let Event::Key(k) = event {
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()) {
cutoff += 1.0;
}
if last_cutoff != cutoff {
set_cutoff(cutoff).await;
last_cutoff = cutoff;
if change {
set_cutoff(cutoff, freq).await.unwrap();
println!("cutoff = {}\r", cutoff);
}
}