Skip to content

Commit f5f144e

Browse files
committed
ledmatrix: Default to every 2nd col if no animation
Signed-off-by: Daniel Schaefer <[email protected]>
1 parent 0520b39 commit f5f144e

File tree

2 files changed

+47
-19
lines changed

2 files changed

+47
-19
lines changed

fl16-inputmodules/src/patterns.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,3 +359,17 @@ pub fn zigzag() -> Grid {
359359

360360
grid
361361
}
362+
363+
pub fn every_nth_col(n: usize) -> Grid {
364+
let mut grid = Grid::default();
365+
366+
for y in 0..HEIGHT {
367+
for x in 0..WIDTH {
368+
if x % n == 0 {
369+
grid.0[x][y] = 0xFF;
370+
}
371+
}
372+
}
373+
374+
grid
375+
}

ledmatrix/src/main.rs

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,18 @@ fn main() -> ! {
215215
&clocks.peripheral_clock,
216216
);
217217

218+
// Detect whether the dip1 pin is connected
219+
// We switched from bootsel button to DIP-switch with general purpose DIP1 pin in DVT2
220+
let mut dip1_present = false;
221+
let dip1 = pins.dip1.into_pull_up_input();
222+
if dip1.is_low().unwrap() {
223+
dip1_present = true;
224+
}
225+
let dip1 = dip1.into_pull_down_input();
226+
if dip1.is_high().unwrap() {
227+
dip1_present = true;
228+
}
229+
218230
let mut state = LedmatrixState {
219231
grid: percentage(0),
220232
col_buffer: Grid::default(),
@@ -226,6 +238,14 @@ fn main() -> ! {
226238
pwm_freq: PwmFreqArg::P29k,
227239
debug_mode: false,
228240
};
241+
if dip1_present {
242+
state.debug_mode = dip1.is_high().unwrap();
243+
}
244+
if !show_startup_animation(&state) {
245+
// If no startup animation, render another pattern
246+
// Lighting up every second column is a good pattern to test for noise.
247+
state.grid = every_nth_col(2);
248+
};
229249

230250
let mut matrix = LedMatrix::configure(i2c);
231251
matrix
@@ -246,9 +266,6 @@ fn main() -> ! {
246266
let mut sleep_timer = timer.get_counter().ticks();
247267

248268
let mut startup_percentage = Some(0);
249-
if !STARTUP_ANIMATION || state.debug_mode {
250-
state.grid = percentage(100);
251-
}
252269

253270
// Detect whether the sleep pin is connected
254271
// Early revisions of the hardware didn't have it wired up, if that is the
@@ -263,18 +280,6 @@ fn main() -> ! {
263280
sleep_present = true;
264281
}
265282

266-
// Detect whether the dip1 pin is connected
267-
// We switched from bootsel button to DIP-switch with general purpose DIP1 pin in DVT2
268-
let mut dip1_present = false;
269-
let dip1 = pins.dip1.into_pull_up_input();
270-
if dip1.is_low().unwrap() {
271-
dip1_present = true;
272-
}
273-
let dip1 = dip1.into_pull_down_input();
274-
if sleep.is_high().unwrap() {
275-
dip1_present = true;
276-
}
277-
278283
let mut usb_initialized = false;
279284
let mut usb_suspended = false;
280285
let mut last_usb_suspended = usb_suspended;
@@ -342,7 +347,7 @@ fn main() -> ! {
342347
if matches!(state.sleeping, SleepState::Awake) && render_again {
343348
// On startup slowly turn the screen on - it's a pretty effect :)
344349
match startup_percentage {
345-
Some(p) if p <= 100 && (STARTUP_ANIMATION || state.debug_mode) => {
350+
Some(p) if p <= 100 && show_startup_animation(&state) => {
346351
state.grid = percentage(p);
347352
startup_percentage = Some(p + 5);
348353
}
@@ -520,14 +525,23 @@ fn get_random_byte(rosc: &RingOscillator<Enabled>) -> u8 {
520525
byte
521526
}
522527

523-
fn dyn_sleep_mode(state: &mut LedmatrixState) -> SleepMode {
528+
fn dyn_sleep_mode(state: &LedmatrixState) -> SleepMode {
524529
if state.debug_mode {
525530
SleepMode::Debug
526531
} else {
527532
SLEEP_MODE
528533
}
529534
}
530535

536+
fn debug_mode(state: &LedmatrixState) -> bool {
537+
dyn_sleep_mode(state) == SleepMode::Debug
538+
}
539+
540+
fn show_startup_animation(state: &LedmatrixState) -> bool {
541+
// Show startup animation
542+
STARTUP_ANIMATION && !debug_mode(state)
543+
}
544+
531545
// Will do nothing if already in the right state
532546
fn handle_sleep(
533547
sleep_reason: Option<SleepReason>,
@@ -554,7 +568,7 @@ fn handle_sleep(
554568
}
555569

556570
// Turn LED controller off to save power
557-
if dyn_sleep_mode(state) == SleepMode::Debug {
571+
if debug_mode(state) {
558572
state.grid = display_sleep_reason(sleep_reason);
559573
fill_grid_pixels(state, matrix);
560574
} else {
@@ -572,7 +586,7 @@ fn handle_sleep(
572586
fill_grid_pixels(state, matrix);
573587

574588
// Power LED controller back on
575-
if dyn_sleep_mode(state) != SleepMode::Debug {
589+
if debug_mode(state) {
576590
led_enable.set_high().unwrap();
577591
}
578592

0 commit comments

Comments
 (0)