From 65fbaa323b9bdba3ed982e96aa6293f78c48aa83 Mon Sep 17 00:00:00 2001 From: dogeystamp Date: Sun, 10 Nov 2024 19:41:32 -0500 Subject: [PATCH] fix: linear velocity profile broken --- src/bin/piano_firmware.rs | 2 +- src/matrix.rs | 11 ++++------- src/pins.rs | 5 +++-- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/bin/piano_firmware.rs b/src/bin/piano_firmware.rs index 7211518..6016a32 100644 --- a/src/bin/piano_firmware.rs +++ b/src/bin/piano_firmware.rs @@ -448,7 +448,7 @@ async fn piano_task(pin_driver: pins::TransparentPins) { mat.scan( pin_driver, matrix::Config { - velocity_prof: VelocityProfile::Heavy, + velocity_prof: VelocityProfile::Linear, }, ) .await; diff --git a/src/matrix.rs b/src/matrix.rs index 865293a..df248b6 100644 --- a/src/matrix.rs +++ b/src/matrix.rs @@ -5,7 +5,7 @@ use crate::pins; use crate::unwrap; use core::cmp::{max, min}; use embassy_rp::gpio; -use embassy_time::{Duration, Instant, Ticker}; +use embassy_time::{Duration, Instant, Timer}; pub enum NormalState { /// Normal open @@ -39,7 +39,7 @@ fn velocity_heavy(us: u64) -> u8 { } fn velocity_linear(us: u64) -> u8 { - max(127000 - (us as i32), 0) as u8 + (max(116000 - (us as i32), 5000) / 1000) as u8 } pub struct Config { @@ -101,10 +101,6 @@ impl KeyMatrix { unwrap(pin_driver.set_pull(i, gpio::Pull::Up)).await; } - // scan frequency - // this might(?) panic if the scan takes longer than the tick - let mut ticker = Ticker::every(Duration::from_micros(4000)); - let chan = midi::MidiChannel::new(0); const MAX_NOTES: usize = 128; @@ -203,7 +199,8 @@ impl KeyMatrix { ); } - ticker.next().await; + // relinquish to other tasks for a moment + Timer::after_micros(50).await; } } } diff --git a/src/pins.rs b/src/pins.rs index fcc5398..ec1cd9e 100644 --- a/src/pins.rs +++ b/src/pins.rs @@ -303,7 +303,7 @@ impl TransparentPins { match pin { TransparentPin::Onboard(p) => self.onboard_pins[p].set_as_input(), TransparentPin::Extended(p) => { - extender!(self, p.ext_id)?.pin_mode(p.loc_pin, mcp23017::PinMode::INPUT)? + extender!(self, p.ext_id)?.pin_mode(p.loc_pin, mcp23017::PinMode::INPUT)?; } } Ok(()) @@ -316,7 +316,8 @@ impl TransparentPins { match pin { TransparentPin::Onboard(p) => self.onboard_pins[p].set_as_output(), TransparentPin::Extended(p) => { - extender!(self, p.ext_id)?.pin_mode(p.loc_pin, mcp23017::PinMode::OUTPUT)? + let mut ext = extender!(self, p.ext_id)?; + ext.pin_mode(p.loc_pin, mcp23017::PinMode::OUTPUT)?; } } Ok(())