revert some changes

- scan frequency slightly reduced in hopes of not missing ticks
- pedal normally closed by default again
This commit is contained in:
dogeystamp 2024-10-18 22:24:41 -04:00
parent 10fd3bae41
commit ce0949ad4f
2 changed files with 20 additions and 6 deletions

View File

@ -489,7 +489,7 @@ async fn main(_spawner: Spawner) {
.spawn(matrix::pedal( .spawn(matrix::pedal(
midi::Controller::SustainPedal, midi::Controller::SustainPedal,
p.PIN_8.into(), p.PIN_8.into(),
true, matrix::NormalState::NC,
)) ))
.unwrap(); .unwrap();
} }

View File

@ -7,16 +7,25 @@ use core::cmp::min;
use embassy_rp::gpio; use embassy_rp::gpio;
use embassy_time::{Duration, Instant, Ticker}; use embassy_time::{Duration, Instant, Ticker};
pub enum NormalState {
/// Normal open
NO,
/// Normal closed
NC,
}
/// Task to handle pedals in MIDI /// Task to handle pedals in MIDI
/// ///
/// `norm_open` represents a normally open switch /// `norm_open` represents a normally open switch
#[embassy_executor::task] #[embassy_executor::task]
pub async fn pedal(pedal: midi::Controller, pin: gpio::AnyPin, norm_open: bool) { pub async fn pedal(pedal: midi::Controller, pin: gpio::AnyPin, norm_state: NormalState) {
let mut inp = gpio::Input::new(pin, gpio::Pull::Up); let mut inp = gpio::Input::new(pin, gpio::Pull::Up);
let chan = midi::MidiChannel::new(0); let chan = midi::MidiChannel::new(0);
loop { loop {
let on_val = if norm_open { 64 } else { 0 }; let (off_val, on_val) = match norm_state {
let off_val = if norm_open { 0 } else { 64 }; NormalState::NO => (0, 64),
NormalState::NC => (64, 0),
};
inp.wait_for_low().await; inp.wait_for_low().await;
chan.controller(pedal, on_val).await; chan.controller(pedal, on_val).await;
defmt::debug!("{} set to {}", pedal, on_val); defmt::debug!("{} set to {}", pedal, on_val);
@ -62,7 +71,7 @@ impl<const N_ROWS: usize, const N_COLS: usize> KeyMatrix<N_ROWS, N_COLS> {
// scan frequency // scan frequency
// this might(?) panic if the scan takes longer than the tick // this might(?) panic if the scan takes longer than the tick
let mut ticker = Ticker::every(Duration::from_micros(3600)); 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;
@ -120,7 +129,12 @@ impl<const N_ROWS: usize, const N_COLS: usize> KeyMatrix<N_ROWS, N_COLS> {
} else { } else {
(127 - min(dur, 240) / 4 - 60) as u8 (127 - min(dur, 240) / 4 - 60) as u8
}; };
defmt::debug!("{} velocity {} from dur {}ms", note, velocity, dur); defmt::debug!(
"{} velocity {} from dur {}ms",
note,
velocity,
dur
);
note_on[note as usize] = true; note_on[note as usize] = true;
chan.note_on(note, velocity).await; chan.note_on(note, velocity).await;
} }