Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions keyboard_keyboard/code/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ pub const DIAG_LOGGING: bool = false; // set true to see raw ADC / calibration l
pub const LOG_INTERVAL_MS: u32 = 500;
pub const LOG_SWITCH: usize = 0; // HE1 — first switch

// ── Settings buttons ──────────────────────────────────────────────────────────
pub const SETTINGS_CHAN1: usize = 72; // HE73 → melody MIDI ch 1
pub const SETTINGS_CHAN2: usize = 75; // HE76 → melody MIDI ch 2
// ── Settings screen ───────────────────────────────────────────────────────────
pub const SETTINGS_OPEN: usize = 73; // HE74 → open / close settings
pub const SETTINGS_NAV_PREV: usize = 76; // HE77 → previous item
pub const SETTINGS_VAL_DOWN: usize = 77; // HE78 → value −1
pub const SETTINGS_NAV_NEXT: usize = 78; // HE79 → next item
pub const SETTINGS_VAL_UP: usize = 79; // HE80 → value +1

// ── Drum pads (switches 81–100, MIDI ch 10) ───────────────────────────────────
pub const DRUM_CHANNEL: u8 = 9; // 0-indexed
// ── Drum pads (switches 81–100) ───────────────────────────────────────────────
pub const DRUM_SWITCH_START: usize = 80;
#[rustfmt::skip]
pub const DRUM_NOTE: [u8; 20] = [
Expand Down
2 changes: 1 addition & 1 deletion keyboard_keyboard/code/src/display/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pub mod screens;
pub use screens::{draw_main, draw_splash};
pub use screens::{draw_main, draw_settings, draw_splash};

const NOTE_NAMES: [&str; 12] = [
"C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B",
Expand Down
65 changes: 60 additions & 5 deletions keyboard_keyboard/code/src/display/screens.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::display::note_name;
use crate::settings::{Settings, NUM_SETTINGS_ITEMS, SETTINGS_ITEMS};
use crate::types::{DisplayState, LastEvent, LcdDisplay};
use core::fmt::Write;
use embedded_graphics::{
Expand All @@ -9,7 +10,7 @@ use embedded_graphics::{
},
pixelcolor::BinaryColor,
prelude::*,
primitives::Rectangle,
primitives::{Line, PrimitiveStyle, Rectangle},
text::{Alignment, Text},
};
use heapless::String;
Expand Down Expand Up @@ -45,8 +46,8 @@ pub fn draw_main(disp: &mut LcdDisplay, state: &DisplayState) {
match state.last_event {
Some(LastEvent::Note { note }) => {
let (name, oct) = note_name(note);
write!(label, "{}{}", name, oct).ok();
write!(number, "{}", note).ok();
write!(label, "{}", note).ok();
write!(number, "{}{}", name, oct).ok();
}
Some(LastEvent::Cc { num, value }) => {
write!(label, "CC {}", num).ok();
Expand Down Expand Up @@ -89,9 +90,11 @@ pub fn draw_main(disp: &mut LcdDisplay, state: &DisplayState) {
.draw(disp)
.ok();

// Drums channel — top-right, always 10
// Drums channel — top-right
let mut drum_ch: String<4> = String::new();
write!(drum_ch, "{}", state.drum_channel + 1).ok();
Text::with_alignment(
"10",
drum_ch.as_str(),
center + Point::new(54, -9),
MonoTextStyle::new(&FONT_6X9, off),
Alignment::Center,
Expand All @@ -101,3 +104,55 @@ pub fn draw_main(disp: &mut LcdDisplay, state: &DisplayState) {

disp.flush().ok();
}

/// Draws the settings screen: 3 items (prev / current / next) with name left,
/// value right. The current item has an underline under its value.
pub fn draw_settings(disp: &mut LcdDisplay, selected: usize, settings: &Settings) {
disp.clear();

let style = MonoTextStyle::new(&FONT_6X9, BinaryColor::On);
let underline_style = PrimitiveStyle::with_stroke(BinaryColor::On, 1);

// Baseline y-coordinates for the three rows (font is 9px tall).
let y_rows: [i32; 3] = [9, 20, 30];

let prev = (selected + NUM_SETTINGS_ITEMS - 1) % NUM_SETTINGS_ITEMS;
let next = (selected + 1) % NUM_SETTINGS_ITEMS;
let slots = [prev, selected, next];

for (row, &item_idx) in slots.iter().enumerate() {
let y = y_rows[row];
let item = &SETTINGS_ITEMS[item_idx];
let value = settings.get(item_idx);

// Name: left-aligned
Text::new(item.name, Point::new(0, y), style)
.draw(disp)
.ok();

// Value: right-aligned
let mut val_str: String<8> = String::new();
write!(val_str, "{}", value).ok();
Text::with_alignment(
val_str.as_str(),
Point::new(127, y),
style,
Alignment::Right,
)
.draw(disp)
.ok();

// Underline under the value of the current (middle) row
if row == 1 {
let val_px_width = val_str.len() as i32 * 6;
let x0 = 127 - val_px_width + 1;
let uy = y + 1;
Line::new(Point::new(x0, uy), Point::new(127, uy))
.into_styled(underline_style)
.draw(disp)
.ok();
}
}

disp.flush().ok();
}
Loading
Loading