Browse Source

Fixed bug, added countries.

Wrong month was being calculated for US in Fall.  Added more countries selectable using the config script.
master^2
Rick Miller 11 years ago
parent
commit
df903d1702
  1. 4
      driver/timer.c
  2. 6
      logic/date.c
  3. 63
      logic/dst.c
  4. 4
      logic/rfsimpliciti.c
  5. 6
      tools/config.py

4
driver/timer.c

@ -80,7 +80,7 @@
#include "sidereal.h"
#endif
#ifdef CONFIG_DST
#if (CONFIG_DST > 0)
#include "dst.h"
#include "date.h"
#endif
@ -375,7 +375,7 @@ __interrupt void TIMER0_A0_ISR(void)
if (sAlarm.hourly == ALARM_ENABLED) {
request.flag.alarm_buzzer = 1;
}
#ifdef CONFIG_DST
#if (CONFIG_DST > 0)
if ((sTime.hour == 1) &&
(dst_state == 0) &&
dst_isDateInDST(sDate.month, sDate.day))

6
logic/date.c

@ -94,7 +94,7 @@ void reset_date(void)
// Show default display
sDate.view = 0;
#ifdef CONFIG_DST
#if (CONFIG_DST > 0)
dst_calculate_dates();
#endif
}
@ -164,7 +164,7 @@ void add_day(void)
sDate.month = 1;
sDate.year++;
#ifdef CONFIG_DST
#if (CONFIG_DST > 0)
dst_calculate_dates();
#endif
}
@ -230,7 +230,7 @@ void mx_date(line_t line)
if(sSidereal_time.sync>0)
sync_sidereal();
#endif
#ifdef CONFIG_DST
#if (CONFIG_DST > 0)
dst_calculate_dates();
#endif

63
logic/dst.c

@ -18,7 +18,7 @@
#include "project.h"
#ifdef CONFIG_DST
#if (CONFIG_DST > 0)
// driver
#include "altitude.h"
@ -47,25 +47,56 @@ void dst_init(void)
dst_calculate_dates();
}
#define N_SUN_OF_MON(n,mon) (((n)*7)-dst_day_of_week(sDate.year,(mon),((n)*7)))
#define LAST_SUN_OF_MON(mon,days) ((days)-dst_day_of_week(sDate.year,(mon),(days)))
void dst_calculate_dates(void)
{
// This should be run whenever sDate.year gets changed.
// DST in US: 2nd Sun in Mar to 1st Sun in Nov.
dst_dates[0].month = 3;
dst_dates[0].day = 15 - dst_day_of_week(sDate.year, 3, 1);
if (dst_dates[0].day == 15)
{
dst_dates[0].day = 8;
}
dst_dates[1].month = 3;
dst_dates[1].day = 8 - dst_day_of_week(sDate.year, 11, 1);
if (dst_dates[1].day == 8)
{
dst_dates[1].day = 1;
}
#if (CONFIG_DST == 1)
// DST in US/Canada: 2nd Sun in Mar to 1st Sun in Nov.
dst_dates[0].month = 3;
dst_dates[0].day = N_SUN_OF_MON(2, 3);
dst_dates[1].month = 11;
dst_dates[1].day = N_SUN_OF_MON(1, 11);
#endif
#if (CONFIG_DST == 2)
// DST in Mexico: first Sun in Apr to last Sun in Oct.
dst_dates[0].month = 4;
dst_dates[0].day = N_SUN_OF_MON(1, 4);
dst_dates[1].month = 10;
dst_dates[1].day = LAST_SUN_OF_MON(10, 31);
#endif
#if (CONFIG_DST == 3)
// DST in Brazil: third Sun in Oct to third Sun in Feb.
dst_dates[0].month = 10;
dst_dates[0].day = N_SUN_OF_MON(3, 10);
dst_dates[1].month = 2;
dst_dates[1].day = N_SUN_OF_MON(3, 2);
#endif
#if (CONFIG_DST == 4)
// DST in EU/UK: last Sun in Mar to last Sun in Oct.
dst_dates[0].month = 3;
dst_dates[0].day = LAST_SUN_OF_MON(3, 31);
dst_dates[1].month = 10;
dst_dates[1].day = LAST_SUN_OF_MON(10, 31);
#endif
#if (CONFIG_DST == 5)
// DST in Australia: first Sun in Oct to first Sun in Apr.
dst_dates[0].month = 10;
dst_dates[0].day = N_SUN_OF_MON(1, 10);
dst_dates[1].month = 4;
dst_dates[1].day = N_SUN_OF_MON(1, 4);
#endif
#if (CONFIG_DST == 6)
// DST in New Zealand: last Sun in Sep to first Sun in Apr.
dst_dates[0].month = 9;
dst_dates[0].day = LAST_SUN_OF_MON(9, 30);
dst_dates[1].month = 4;
dst_dates[1].day = N_SUN_OF_MON(1, 4);
#endif
// This test may be wrong if you set your watch
// on the time-change day.
@ -126,5 +157,5 @@ u8 dst_day_of_week(u16 year, u8 month, u8 day)
return (u8)((tmp + 6) % 7);
}
#endif /* CONFIG_DST */
#endif /* (CONFIG_DST > 0) */

4
logic/rfsimpliciti.c

@ -77,7 +77,7 @@
#include "sidereal.h"
#endif
#ifdef CONFIG_DST
#if (CONFIG_DST > 0)
#include "dst.h"
#endif
@ -711,7 +711,7 @@ void simpliciti_sync_decode_ap_cmd_callback(void)
sAlarm.minute = simpliciti_data[9];
#endif
#ifdef CONFIG_DST
#if (CONFIG_DST > 0)
dst_calculate_dates();
#endif
// Set temperature and temperature offset

6
tools/config.py

@ -164,8 +164,10 @@ DATA["CONFIG_SIDEREAL"] = {
DATA["CONFIG_DST"] = {
"name": "Daylight Saving Time",
"depends": [],
"default": False,
"help": "Automatically adjust Clock for Daylight Saving Time (US)"
"default": 0,
"type": "choices",
"values": [(0, "No DST"), (1, "US/Canada"), (2, "Mexico"), (3, "Brazil"), (4, "EU/UK/Eastern Europe"), (5, "Australia"), (6, "New Zealand")],
"help": "Automatically adjust Clock for Daylight Saving Time"
}

Loading…
Cancel
Save