|
@@ -21,40 +21,37 @@ void RefreshCallback(void) {
|
|
|
RefreshTick = true;
|
|
|
}
|
|
|
|
|
|
-typedef union {
|
|
|
- struct {
|
|
|
- char Hour10;
|
|
|
- char Hour1;
|
|
|
- char Minute10;
|
|
|
- char Minute1;
|
|
|
- };
|
|
|
-} DigitValue;
|
|
|
-
|
|
|
-DigitValue DigitPrev, DigitNext;
|
|
|
-int DigitNextValue[4][10] = {0};
|
|
|
-int DigitPrevValue[4][10] = {0};
|
|
|
+typedef struct {
|
|
|
+ char Prev;
|
|
|
+ ushort PrevValue;
|
|
|
+ char Next;
|
|
|
+ ushort NextValue;
|
|
|
+} Digit;
|
|
|
+
|
|
|
+Digit Digits[NUM_DIGITS] = {0};
|
|
|
+
|
|
|
int DotNextValue, DotPrevValue;
|
|
|
+bool DotIncrement = false;
|
|
|
|
|
|
bool StartupFlag = true;
|
|
|
bool RuntimeFlag = false;
|
|
|
-bool DotIncrement = false;
|
|
|
|
|
|
Ticker StartupTicker;
|
|
|
int StartupTickerIter = 1024;
|
|
|
|
|
|
void StartupTickerCallback(void) {
|
|
|
|
|
|
- DigitNextValue[3][DigitNext.Minute1] += 4;
|
|
|
- DigitNextValue[2][DigitNext.Minute10] += 4;
|
|
|
- DigitNextValue[1][DigitNext.Hour1] += 4;
|
|
|
- if (DigitNext.Hour10 != 0) {
|
|
|
- DigitNextValue[0][DigitNext.Hour10] += 4;
|
|
|
+ for (int i = 0; i < NUM_DIGITS; i++) {
|
|
|
+ Digits[i].NextValue = (i == 0 && Digits[i].Next == 0) ? 0 : Digits[i].NextValue + 4;
|
|
|
}
|
|
|
+
|
|
|
DotNextValue += 4;
|
|
|
|
|
|
if (--StartupTickerIter == 0) {
|
|
|
StartupTicker.detach();
|
|
|
- memcpy(&DigitPrev, &DigitNext, sizeof(DigitValue));
|
|
|
+ for (int i = 0; i < NUM_DIGITS; i++) {
|
|
|
+ Digits[i].Prev = Digits[i].Next;
|
|
|
+ }
|
|
|
RuntimeFlag = true;
|
|
|
}
|
|
|
}
|
|
@@ -64,25 +61,10 @@ int RuntimeTickerIter = 1024;
|
|
|
|
|
|
void RuntimeTickerCallback(void) {
|
|
|
|
|
|
- if (DigitPrev.Minute1 != DigitNext.Minute1) {
|
|
|
- DigitNextValue[3][DigitPrev.Minute1] -= 4;
|
|
|
- DigitNextValue[3][DigitNext.Minute1] += 4;
|
|
|
- }
|
|
|
-
|
|
|
- if (DigitPrev.Minute10 != DigitNext.Minute10) {
|
|
|
- DigitNextValue[2][DigitPrev.Minute10] -= 4;
|
|
|
- DigitNextValue[2][DigitNext.Minute10] += 4;
|
|
|
- }
|
|
|
-
|
|
|
- if (DigitPrev.Hour1 != DigitNext.Hour1) {
|
|
|
- DigitNextValue[1][DigitPrev.Hour1] -= 4;
|
|
|
- DigitNextValue[1][DigitNext.Hour1] += 4;
|
|
|
- }
|
|
|
-
|
|
|
- if (DigitPrev.Hour10 != DigitNext.Hour10) {
|
|
|
- DigitNextValue[0][DigitPrev.Hour10] -= 4;
|
|
|
- if (DigitNext.Hour10 != 0) {
|
|
|
- DigitNextValue[0][DigitNext.Hour10] += 4;
|
|
|
+ for (int i = 0; i < NUM_DIGITS; i++) {
|
|
|
+ if(Digits[i].Prev != Digits[i].Next) {
|
|
|
+ Digits[i].PrevValue -= 4;
|
|
|
+ Digits[i].NextValue = (i == 0 && Digits[i].Next == 0) ? 0 : Digits[i].NextValue + 4;
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -90,7 +72,9 @@ void RuntimeTickerCallback(void) {
|
|
|
|
|
|
if (--RuntimeTickerIter == 0) {
|
|
|
RuntimeTicker.detach();
|
|
|
- memcpy(&DigitPrev, &DigitNext, sizeof(DigitValue));
|
|
|
+ for (int i = 0; i < NUM_DIGITS; i++) {
|
|
|
+ Digits[i].Prev = Digits[i].Next;
|
|
|
+ }
|
|
|
DotIncrement = !DotIncrement;
|
|
|
}
|
|
|
}
|
|
@@ -142,18 +126,23 @@ int main() {
|
|
|
|
|
|
|
|
|
|
|
|
- for (int i = 0; i < 4; i++) {
|
|
|
- for (int j = 0; j < 10; j++) {
|
|
|
- if (DigitNextValue[i][j] != DigitPrevValue[i][j]) {
|
|
|
- PCA9685_SetDigit(i, j, DigitNextValue[i][j]);
|
|
|
- }
|
|
|
+
|
|
|
+ for (int i = 0; i < NUM_DIGITS; i++) {
|
|
|
+ if (Digits[i].NextValue != Digits[i].PrevValue) {
|
|
|
+ PCA9685_SetDigit(i, Digits[i].Prev, Digits[i].PrevValue);
|
|
|
+ PCA9685_SetDigit(i, Digits[i].Next, Digits[i].NextValue);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
if (DotNextValue != DotPrevValue) {
|
|
|
PCA9685_SetDot(DotNextValue);
|
|
|
}
|
|
|
|
|
|
- memcpy(DigitPrevValue, DigitNextValue, sizeof(DigitPrevValue));
|
|
|
+
|
|
|
+
|
|
|
+ for (int i = 0; i < NUM_DIGITS; i++) {
|
|
|
+ Digits[i].PrevValue = Digits[i].NextValue;
|
|
|
+ }
|
|
|
DotPrevValue = DotNextValue;
|
|
|
}
|
|
|
|
|
@@ -166,10 +155,10 @@ int main() {
|
|
|
int nextSecond, nextMinute, nextHour;
|
|
|
DS3231_GetTime(&nextSecond, &nextMinute, &nextHour);
|
|
|
|
|
|
- DigitNext.Minute1 = nextMinute % 10;
|
|
|
- DigitNext.Minute10 = nextMinute / 10;
|
|
|
- DigitNext.Hour1 = nextHour % 10;
|
|
|
- DigitNext.Hour10 = nextHour / 10;
|
|
|
+ Digits[3].Next = nextMinute % 10;
|
|
|
+ Digits[2].Next = nextMinute / 10;
|
|
|
+ Digits[1].Next = nextHour % 10;
|
|
|
+ Digits[0].Next = nextHour / 10;
|
|
|
|
|
|
if (StartupFlag) {
|
|
|
|