Browse Source

Fix fade calculation

Kevin Lee 2 years ago
parent
commit
60676e6551
2 changed files with 10 additions and 16 deletions
  1. 3 3
      Nixie_Firmware_Rust/src/main.rs
  2. 7 13
      Nixie_Firmware_Rust/src/nixie.rs

+ 3 - 3
Nixie_Firmware_Rust/src/main.rs

@@ -216,7 +216,7 @@ fn main() -> ! {
     // Initialize the PCA9685 display refresh timer
     let fps_timer = Timer::tim2(
         dp.TIM2,
-        nixie::REFRESH_RATE_HZ.hz(),
+        nixie::DISPLAY_REFRESH_FPS.hz(),
         clocks,
         &mut rcc.apb1r1,
     );
@@ -245,7 +245,7 @@ fn main() -> ! {
 
     let cycle_timer = Timer::tim7(
         dp.TIM7,
-        (1_000_000 / nixie::CYCLE_FADE_DURATION_MS).hz(),
+        (1000 / nixie::CYCLE_FADE_DURATION_MS).hz(),
         clocks,
         &mut rcc.apb1r1,
     );
@@ -298,7 +298,7 @@ fn EXTI9_5() {
         if let Some(ref mut rtc_int) = rtc_int_ref.deref_mut() {
             if let Some(ref mut i2c) = i2c_int_ref.deref_mut() {
                 if rtc_int.check_interrupt() {
-                    // nixie::rtc_interrupt(i2c);
+                    nixie::rtc_interrupt(i2c);
                     rtc_int.clear_interrupt_pending_bit();
                 }
             }

+ 7 - 13
Nixie_Firmware_Rust/src/nixie.rs

@@ -22,10 +22,10 @@ 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 REFRESH_RATE_HZ: u32 = 1000;
+pub const DISPLAY_REFRESH_FPS: u32 = 1000;
 
-pub const DIGIT_FADE_DURATION_MS: u32 = 1_000_000;
-pub const CYCLE_FADE_DURATION_MS: u32 = 200_000;
+pub const DIGIT_FADE_DURATION_MS: u32 = 1000;
+pub const CYCLE_FADE_DURATION_MS: u32 = 200;
 pub const CYCLE_ITERATIONS: usize = 20;
 pub const CYCLE_REFRESH_INTERVAL: u32 = 60;
 pub const CYCLE_REFRESH_VARIANCE: u32 = 30;
@@ -455,7 +455,7 @@ impl Clock {
             tube.digits.iter_mut().for_each(|digit| {
 
                 if let Some(fade_duration) = digit.fade_duration {
-                    let ticks = fade_duration / REFRESH_RATE_HZ;
+                    let ticks = fade_duration  * 1000 / DISPLAY_REFRESH_FPS;
                     let steps = ((DIGIT_MAX_BRIGHTNESS - DIGIT_MIN_BRIGHTNESS) + ticks - 1) / ticks;
                     update_fn(digit, DIGIT_MIN_BRIGHTNESS, DIGIT_MAX_BRIGHTNESS, steps);
                 }
@@ -467,7 +467,7 @@ impl Clock {
             for (d, digit) in tube.digits.iter_mut().enumerate() {
 
                 if let Some(fade_duration) = digit.fade_duration {
-                    let ticks = fade_duration / REFRESH_RATE_HZ;
+                    let ticks = fade_duration * 1000 / DISPLAY_REFRESH_FPS;
                     let steps = ((DIGIT_MAX_BRIGHTNESS - DIGIT_MIN_BRIGHTNESS) + ticks - 1) / ticks;
                     update_fn(digit, DIGIT_MIN_BRIGHTNESS, DIGIT_MAX_BRIGHTNESS, steps);
                 }
@@ -483,7 +483,7 @@ impl Clock {
 
         // Handle dot
         if let Some(fade_duration) = self.dot.fade_duration {
-            let ticks = fade_duration / REFRESH_RATE_HZ;
+            let ticks = fade_duration * 1000 / DISPLAY_REFRESH_FPS;
             let steps = ((DOT_MAX_BRIGHTNESS - DOT_MIN_BRIGHTNESS) + ticks - 1) / ticks;
             update_fn(&mut self.dot, DOT_MIN_BRIGHTNESS, DOT_MAX_BRIGHTNESS, steps);
         }
@@ -523,12 +523,6 @@ impl Clock {
             }
         });
 
-        // self.tubes.iter_mut().for_each(|tube| {
-        //     tube.fade_in_out_digit(Some(0), CYCLE_FADE_DURATION_US, true);
-        // });
-
-        // self.tubes[3].fade_in_out_digit(Some(0), CYCLE_FADE_DURATION_US, true);
-
         #[cfg(not(test))]
         free(|cs| {
             let mut timer_ref = super::FPS_TIMER.borrow(cs).borrow_mut();
@@ -672,7 +666,7 @@ where
 }
 
 // This function is called by an interrupt that is triggered every
-// REFRESH_RATE_HZ to update the display with a new brightness value.
+// DISPLAY_REFRESH_FPS to update the display with a new brightness value.
 pub fn fps_interrupt<T>(i2c: &mut T)
 where
     T: _embedded_hal_blocking_i2c_WriteRead