Browse Source

Bugfix for DS3231 weekday offset

Kevin Lee 2 years ago
parent
commit
9458c18277
2 changed files with 9 additions and 8 deletions
  1. 2 1
      Nixie_Firmware_Mbed/ds3231.cpp
  2. 7 7
      Nixie_Firmware_Mbed/ds3231.h

+ 2 - 1
Nixie_Firmware_Mbed/ds3231.cpp

@@ -85,7 +85,8 @@ bool IsDst(int DayOfWeek, int Day, int Month, int Hour_24) {
     // April through October are always in DST
     if (Month > 3 && Month < 11) return true;
 
-    int prevSunday = Day - DayOfWeek;
+    // Compute the last sunday, given that DoW enum starts at 1
+    int prevSunday = Day - DayOfWeek + 1;
     // In March, in DST if previous sunday is between 8th and 14th
     if (Month == 3) {
         if (prevSunday < 8) return false;

+ 7 - 7
Nixie_Firmware_Mbed/ds3231.h

@@ -170,13 +170,13 @@ typedef union {
 } DS3231_REGS;
 
 enum {
-    SUNDAY      = 0,
-    MONDAY      = 1,
-    TUESDAY     = 2,
-    WEDNESDAY   = 3,
-    THURSDAY    = 4,
-    FRIDAY      = 5,
-    SATURDAY    = 6
+    SUNDAY      = 1,
+    MONDAY      = 2,
+    TUESDAY     = 3,
+    WEDNESDAY   = 4,
+    THURSDAY    = 5,
+    FRIDAY      = 6,
+    SATURDAY    = 7
 };
 
 void DS3231_Init(void (*Callback)());