Browse Source

Added tube refresh.

Vladimir N. Shilov 2 years ago
parent
commit
9a02db8cc8
3 changed files with 90 additions and 8 deletions
  1. 1 0
      Inc/board.h
  2. 76 0
      Src/board.c
  3. 13 8
      Src/clock.c

+ 1 - 0
Inc/board.h

@@ -188,5 +188,6 @@ void slideDigits(tube4_t dig);
 void tube_PowerOn(tube_pos_t tube);
 void tube_PowerOff(tube_pos_t tube);
 void tube_BrightLevel(tube_pos_t tube, uint8_t bright);
+void tube_Refresh(void);
 
 #endif /* _BPARD_H */

+ 76 - 0
Src/board.c

@@ -251,6 +251,82 @@ static void _show_digits(const uint32_t digits)
   }
 }
 
+/**
+ * @brief Refresh unused tube digits for avoiding degrade
+ * 
+ */
+void tube_Refresh(void)
+{
+  static int cnt = 0;
+  tube4_t buf;
+
+  /* We start ourselves every 125 ms to update 8 digits in a second. */
+  if (cnt == 0) {
+    RTOS_SetTask(tube_Refresh, 125, 125);
+  }
+
+  /* Fill buffer with values */
+  switch (cnt) {
+  case 0:
+    cnt = 1;
+    buf.s8.tA = 0;
+    buf.s8.tD = 6;
+    break;
+
+  case 1:
+    cnt = 2;
+    buf.s8.tA = 3;
+    break;
+
+  case 2:
+    cnt = 3;
+    buf.s8.tA = 4;
+    buf.s8.tD = 7;
+    break;
+
+  case 3:
+    cnt = 4;
+    buf.s8.tA = 5;
+    break;
+
+  case 4:
+    cnt = 5;
+    buf.s8.tA = 6;
+    buf.s8.tD = 8;
+    break;
+
+  case 5:
+    cnt = 6;
+    buf.s8.tA = 7;
+    break;
+
+  case 6:
+    cnt = 7;
+    buf.s8.tA = 8;
+    buf.s8.tD = 9;
+    break;
+
+  case 7:
+    cnt = 0;
+    buf.s8.tA = 9;
+    break;
+
+  default:
+    cnt = 0;
+  }
+
+  /* Self delete task */
+  if (cnt == 0) {
+    RTOS_DeleteTask(tube_Refresh);
+  }
+
+  /* Output buffer value to digits */
+  _show_digits(buf.u32);
+}
+
+/**
+ * Control power of tube
+ */
 void tube_PowerOn(tube_pos_t tube)
 {
   switch (tube) {

+ 13 - 8
Src/clock.c

@@ -229,16 +229,21 @@ void showTime(void) {
     break;
   }
 
-  tube4_t buf;
-  if ((Clock.Hr & 0xf0) == 0) {
-    buf.s8.tA = TUBE_BLANK;
+  if (Clock.Sec != 0) {
+    tube4_t buf;
+    uint8_t hour = Clock.Hr >> 4;
+    if (hour == 0) {
+      buf.s8.tA = TUBE_BLANK;
+    } else {
+      buf.s8.tA = hour;
+    }
+    buf.s8.tB = Clock.Hr & 0xf;
+    buf.s8.tD = Clock.Min >> 4;
+    buf.s8.tE = Clock.Min & 0xf;
+    showDigits(buf);
   } else {
-    buf.s8.tA = Clock.Hr >> 4;
+    tube_Refresh();
   }
-  buf.s8.tB = Clock.Hr & 0xf;
-  buf.s8.tD = Clock.Min >> 4;
-  buf.s8.tE = Clock.Min & 0xf;
-  showDigits(buf);
 }
 
 void showMMSS(void) {