|
@@ -1,4 +1,4 @@
|
|
|
-use core::{cell::RefCell, ops::DerefMut, panic};
|
|
|
+use core::{cell::RefCell, ops::DerefMut};
|
|
|
|
|
|
use cortex_m::interrupt::{free, Mutex};
|
|
|
use stm32l4xx_hal::{
|
|
@@ -22,7 +22,7 @@ pub const PCA9685_SUB_CALL_1: u8 = 0x71; // Default disabled
|
|
|
pub const PCA9685_SUB_CALL_2: u8 = 0x72; // Default disabled
|
|
|
pub const PCA9685_SUB_CALL_3: u8 = 0x73; // Default disabled
|
|
|
|
|
|
-pub const DISPLAY_REFRESH_FPS: u32 = 1000;
|
|
|
+pub const DISPLAY_REFRESH_FPS: u32 = 500;
|
|
|
|
|
|
pub const DIGIT_FADE_DURATION_MS: u32 = 1000;
|
|
|
pub const CYCLE_FADE_DURATION_MS: u32 = 200;
|
|
@@ -279,11 +279,12 @@ struct CycleSettings {
|
|
|
last_digit: Option<u32>,
|
|
|
next_digit: u32,
|
|
|
iteration: usize,
|
|
|
+ last_fade_duration: u32,
|
|
|
}
|
|
|
|
|
|
struct Tube {
|
|
|
digits: [Digit; NUM_DIGITS],
|
|
|
- last_active_digit: Option<u32>,
|
|
|
+ last_digit: Option<u32>,
|
|
|
cycle: Option<CycleSettings>,
|
|
|
}
|
|
|
|
|
@@ -292,7 +293,7 @@ impl Tube {
|
|
|
const DIGIT_INIT: Digit = Digit::default();
|
|
|
Self {
|
|
|
digits: [DIGIT_INIT; 10],
|
|
|
- last_active_digit: None,
|
|
|
+ last_digit: None,
|
|
|
cycle: None,
|
|
|
}
|
|
|
}
|
|
@@ -309,6 +310,7 @@ impl Tube {
|
|
|
if let Some(ref mut cycle) = self.cycle {
|
|
|
if !cycle_cmd {
|
|
|
cycle.last_digit = digit;
|
|
|
+ cycle.last_fade_duration = fade_duration;
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -330,7 +332,7 @@ impl Tube {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- self.last_active_digit = digit;
|
|
|
+ self.last_digit = digit;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -455,7 +457,7 @@ impl Clock {
|
|
|
tube.digits.iter_mut().for_each(|digit| {
|
|
|
|
|
|
if let Some(fade_duration) = digit.fade_duration {
|
|
|
- let ticks = fade_duration * 1000 / DISPLAY_REFRESH_FPS;
|
|
|
+ let ticks = fade_duration * 1000 / (1000 / DISPLAY_REFRESH_FPS * 1000);
|
|
|
let steps = ((DIGIT_MAX_BRIGHTNESS - DIGIT_MIN_BRIGHTNESS) + ticks - 1) / ticks;
|
|
|
update_fn(digit, DIGIT_MIN_BRIGHTNESS, DIGIT_MAX_BRIGHTNESS, steps);
|
|
|
}
|
|
@@ -467,7 +469,7 @@ impl Clock {
|
|
|
for (d, digit) in tube.digits.iter_mut().enumerate() {
|
|
|
|
|
|
if let Some(fade_duration) = digit.fade_duration {
|
|
|
- let ticks = fade_duration * 1000 / DISPLAY_REFRESH_FPS;
|
|
|
+ let ticks = fade_duration * 1000 / (1000 / DISPLAY_REFRESH_FPS * 1000);
|
|
|
let steps = ((DIGIT_MAX_BRIGHTNESS - DIGIT_MIN_BRIGHTNESS) + ticks - 1) / ticks;
|
|
|
update_fn(digit, DIGIT_MIN_BRIGHTNESS, DIGIT_MAX_BRIGHTNESS, steps);
|
|
|
}
|
|
@@ -483,7 +485,7 @@ impl Clock {
|
|
|
|
|
|
// Handle dot
|
|
|
if let Some(fade_duration) = self.dot.fade_duration {
|
|
|
- let ticks = fade_duration * 1000 / DISPLAY_REFRESH_FPS;
|
|
|
+ let ticks = fade_duration * 1000 / (1000 / DISPLAY_REFRESH_FPS * 1000);
|
|
|
let steps = ((DOT_MAX_BRIGHTNESS - DOT_MIN_BRIGHTNESS) + ticks - 1) / ticks;
|
|
|
update_fn(&mut self.dot, DOT_MIN_BRIGHTNESS, DOT_MAX_BRIGHTNESS, steps);
|
|
|
}
|
|
@@ -517,8 +519,9 @@ impl Clock {
|
|
|
cycle_ended = false;
|
|
|
} else {
|
|
|
let last_digit = cycle.last_digit;
|
|
|
+ let last_fade = cycle.last_fade_duration;
|
|
|
tube.cycle = None;
|
|
|
- tube.fade_in_out_digit(last_digit, CYCLE_FADE_DURATION_MS, true);
|
|
|
+ tube.fade_in_out_digit(last_digit, last_fade, false);
|
|
|
}
|
|
|
}
|
|
|
});
|
|
@@ -725,9 +728,10 @@ pub fn cycle_start(tube: usize) {
|
|
|
let clock = clock_ref.deref_mut();
|
|
|
|
|
|
clock.tubes[tube].cycle = Some(CycleSettings {
|
|
|
- last_digit: clock.tubes[tube].last_active_digit,
|
|
|
+ last_digit: clock.tubes[tube].last_digit,
|
|
|
next_digit: 0,
|
|
|
iteration: CYCLE_ITERATIONS,
|
|
|
+ last_fade_duration: DIGIT_FADE_DURATION_MS,
|
|
|
});
|
|
|
});
|
|
|
|