front panel write data
This commit is contained in:
parent
bd7b3fb287
commit
f7ab1c119a
3 changed files with 22 additions and 5 deletions
1
interface/Cargo.lock
generated
1
interface/Cargo.lock
generated
|
@ -393,6 +393,7 @@ dependencies = [
|
|||
"anyhow",
|
||||
"common",
|
||||
"cpal",
|
||||
"heapless",
|
||||
"pitch-detection",
|
||||
"postcard",
|
||||
"rust-music-theory",
|
||||
|
|
|
@ -12,3 +12,4 @@ rust-music-theory = {git = "https://github.com/the-drunk-coder/rust-music-theory
|
|||
serde = "1.0.217"
|
||||
tokio = { version = "1.43.0", features = ["full"] }
|
||||
common = {path = "../common"}
|
||||
heapless = "0.7.0"
|
||||
|
|
|
@ -2,11 +2,11 @@
|
|||
use std::{thread::sleep, time::Duration};
|
||||
|
||||
use anyhow::{Context, Ok, Result};
|
||||
use common::TelemetryPacket;
|
||||
use common::{ControlPacket, TelemetryPacket};
|
||||
use cpal::traits::{DeviceTrait, HostTrait, StreamTrait};
|
||||
use pitch_detection::{detector::{mcleod::McLeodDetector, PitchDetector}, utils};
|
||||
use rust_music_theory::note::{Note, NoteLetter, Pitch, Tuning};
|
||||
use tokio::{io::{AsyncReadExt, WriteHalf}, net::{tcp::{OwnedReadHalf, OwnedWriteHalf}, TcpStream}, sync::mpsc};
|
||||
use tokio::{io::{AsyncReadExt, AsyncWriteExt, BufWriter, WriteHalf}, net::{tcp::{OwnedReadHalf, OwnedWriteHalf}, TcpStream}, sync::mpsc};
|
||||
|
||||
fn main() -> Result<()> {
|
||||
// assumes pulseaudio system with f32 samples and 2204 sample packets
|
||||
|
@ -75,8 +75,11 @@ async fn telemetry_handler(mut telem: OwnedReadHalf) -> Result<()> {
|
|||
}
|
||||
}
|
||||
|
||||
async fn controller(mut notes: mpsc::Receiver<(Option<pitch_detection::Pitch<f32>>, f32)>, control: OwnedWriteHalf) -> Result<()> {
|
||||
async fn controller(mut notes: mpsc::Receiver<(Option<pitch_detection::Pitch<f32>>, f32)>, controller: OwnedWriteHalf) -> Result<()> {
|
||||
let mut controller = BufWriter::new(controller);
|
||||
loop {
|
||||
let mut control = ControlPacket::Stop;
|
||||
|
||||
let (note,vol) = notes.recv().await.context("channel closed")?;
|
||||
if let Some(note) = note {
|
||||
//dbg!(note.frequency);
|
||||
|
@ -86,31 +89,43 @@ async fn controller(mut notes: mpsc::Receiver<(Option<pitch_detection::Pitch<f32
|
|||
match note.pitch {
|
||||
Pitch { letter: NoteLetter::A, accidental: 0} => {
|
||||
println!("forward");
|
||||
control = ControlPacket::Twist(1.0, 0.0);
|
||||
}
|
||||
Pitch { letter: NoteLetter::A, accidental: 1} => {
|
||||
println!("backward");
|
||||
control = ControlPacket::Twist(-1.0, 0.0);
|
||||
}
|
||||
Pitch { letter: NoteLetter::C, accidental: 0} => {
|
||||
println!("right");
|
||||
control = ControlPacket::Twist(0.0, 1.0);
|
||||
}
|
||||
Pitch { letter: NoteLetter::C, accidental: 1} => {
|
||||
println!("left");
|
||||
control = ControlPacket::Twist(0.0, -1.0);
|
||||
}
|
||||
Pitch { letter: NoteLetter::G, accidental: 0} => {
|
||||
println!("fire");
|
||||
control = ControlPacket::Fire;
|
||||
}
|
||||
Pitch { letter: NoteLetter::E, accidental: 0} => {
|
||||
println!("fire");
|
||||
control = ControlPacket::Fire;
|
||||
}
|
||||
pitch => {
|
||||
_pitch => {
|
||||
if vol > 3000. {
|
||||
println!("fire");
|
||||
control = ControlPacket::FireOverride(1.0);
|
||||
} else {
|
||||
//dbg!(pitch);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
let control: heapless::Vec<u8, 2048> = postcard::to_vec(&control)?;
|
||||
controller.write_u32(control.len() as u32).await?;
|
||||
controller.write_all(&control).await?;
|
||||
controller.flush().await?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue