fix: linear velocity profile broken

This commit is contained in:
dogeystamp 2024-11-10 19:41:32 -05:00
parent 66d04dacc2
commit 65fbaa323b
3 changed files with 8 additions and 10 deletions

View File

@ -448,7 +448,7 @@ async fn piano_task(pin_driver: pins::TransparentPins) {
mat.scan( mat.scan(
pin_driver, pin_driver,
matrix::Config { matrix::Config {
velocity_prof: VelocityProfile::Heavy, velocity_prof: VelocityProfile::Linear,
}, },
) )
.await; .await;

View File

@ -5,7 +5,7 @@ use crate::pins;
use crate::unwrap; use crate::unwrap;
use core::cmp::{max, min}; use core::cmp::{max, min};
use embassy_rp::gpio; use embassy_rp::gpio;
use embassy_time::{Duration, Instant, Ticker}; use embassy_time::{Duration, Instant, Timer};
pub enum NormalState { pub enum NormalState {
/// Normal open /// Normal open
@ -39,7 +39,7 @@ fn velocity_heavy(us: u64) -> u8 {
} }
fn velocity_linear(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 { pub struct Config {
@ -101,10 +101,6 @@ impl<const N_ROWS: usize, const N_COLS: usize> KeyMatrix<N_ROWS, N_COLS> {
unwrap(pin_driver.set_pull(i, gpio::Pull::Up)).await; 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); let chan = midi::MidiChannel::new(0);
const MAX_NOTES: usize = 128; const MAX_NOTES: usize = 128;
@ -203,7 +199,8 @@ impl<const N_ROWS: usize, const N_COLS: usize> KeyMatrix<N_ROWS, N_COLS> {
); );
} }
ticker.next().await; // relinquish to other tasks for a moment
Timer::after_micros(50).await;
} }
} }
} }

View File

@ -303,7 +303,7 @@ impl TransparentPins {
match pin { match pin {
TransparentPin::Onboard(p) => self.onboard_pins[p].set_as_input(), TransparentPin::Onboard(p) => self.onboard_pins[p].set_as_input(),
TransparentPin::Extended(p) => { 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(()) Ok(())
@ -316,7 +316,8 @@ impl TransparentPins {
match pin { match pin {
TransparentPin::Onboard(p) => self.onboard_pins[p].set_as_output(), TransparentPin::Onboard(p) => self.onboard_pins[p].set_as_output(),
TransparentPin::Extended(p) => { 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(()) Ok(())