Browse Source

Fixed bug on simultaneous updates

Kevin Lee 5 years ago
parent
commit
5312133f5e
1 changed files with 12 additions and 5 deletions
  1. 12 5
      Nixie_Firmware_Mbed/main.cpp

+ 12 - 5
Nixie_Firmware_Mbed/main.cpp

@@ -78,7 +78,7 @@ TUBE_CALLBACK(2)
 Timeout Tube3UpdateTimeout;
 TUBE_CALLBACK(3)
 
-void FadeInOutDigit(int T, int D, int Duration) {
+void FadeInOutDigit(int T, int D, int Duration, bool HighPrio = false) {
     for (int i = 0; i < NUM_DIGITS; i++) {
         Tubes[T].Digits[i].CurrentState = Decrementing;
     }
@@ -88,6 +88,13 @@ void FadeInOutDigit(int T, int D, int Duration) {
     Tubes[T].FadeDuration = Duration;
     Tubes[T].LastActiveDigit = D;
 
+    // If the tube is in the middle of a refresh sequence and a call comes 
+    // in to update the tube digit (for time), override the last value of 
+    // the refresh sequence with the new digit.
+    if (Tubes[T].Refresh && HighPrio) {
+        Tubes[T].RefreshLastDigit = D;
+    }
+
     if (T == 0) {
         Tube0UpdateTimeout.attach_us(Tube0UpdateCallback, REFRESH_RATE_US);
     } else if (T == 1) {
@@ -238,16 +245,16 @@ int main() {
 
             // Update the display configuration based on the new/previous time
             if (startup || prevHour / 10 != nextHour / 10) {
-                FadeInOutDigit(0, (nextHour / 10 != 0) ? nextHour / 10 : -1 , DIGIT_FADE_DURATION_US);
+                FadeInOutDigit(0, (nextHour / 10 != 0) ? nextHour / 10 : -1 , DIGIT_FADE_DURATION_US, true);
             } 
             if (startup || prevHour % 10 != nextHour % 10) {
-                FadeInOutDigit(1, nextHour % 10, DIGIT_FADE_DURATION_US);
+                FadeInOutDigit(1, nextHour % 10, DIGIT_FADE_DURATION_US, true);
             } 
             if (startup || prevMinute / 10 != nextMinute / 10) {
-                FadeInOutDigit(2, nextMinute / 10, DIGIT_FADE_DURATION_US);
+                FadeInOutDigit(2, nextMinute / 10, DIGIT_FADE_DURATION_US, true);
             } 
             if (startup || prevMinute % 10 != nextMinute % 10) {
-                FadeInOutDigit(3, nextMinute % 10, DIGIT_FADE_DURATION_US);
+                FadeInOutDigit(3, nextMinute % 10, DIGIT_FADE_DURATION_US, true);
             }
 
             Dot.CurrentState = (Dot.CurrentState == Decrementing) ? Incrementing : Decrementing;