33
static int _year = 2012;
36
static int _month = 5;
42
static int _hours = 15;
45
static int _minutes = 36;
48
static int _seconds = 0;
50
// milliseconds at last update
51
static unsigned long _last_millis = millis();
53
// milliseconds carries over from last update
54
static unsigned long _carry = 0;
57
static int days_in_month( int month, int year )
60
return !( year % 4 ) && ( ( year % 100 ) || !( year % 400 ) )? 29 : 28;
61
else if( month == 9 || month == 6 || month == 4 || month == 11 )
68
void Time::load_time()
70
// get the time from the real-time clock
72
RTC.get( rtc_data, true );
73
_year = rtc_data[ DS1307_YR ];
74
_month = rtc_data[ DS1307_MTH ];
75
_day = rtc_data[ DS1307_DAY ];
76
_hours = rtc_data[ DS1307_HR ];
77
_minutes = rtc_data[ DS1307_MIN ];
78
_seconds = rtc_data[ DS1307_SEC ];
80
// make sure some numbers are in range
81
if( _year < YEAR_MIN || _year > YEAR_MAX ) _year = YEAR_MIN;
82
if( _month < 1 || _month > 12 ) _month = 1;
83
if( _day < 1 || _day > days_in_month( _year, _month ) ) _day = 1;
87
void Time::save_time()
89
// set the time on the real-time clock
91
RTC.set( DS1307_YR, _year );
92
RTC.set( DS1307_MTH, _month );
93
RTC.set( DS1307_DAY, _day );
94
RTC.set( DS1307_HR, _hours );
95
RTC.set( DS1307_MIN, _minutes );
96
RTC.set( DS1307_SEC, _seconds );
107
int Time::get_month()
113
const char *Time::get_month_name()
115
static const char *months[] = {
130
return months[ _month - 1 ];
140
const char *Time::get_day_suffix()
28
Time &Time::get_instance()
178
53
void Time::update()
180
// how many milliseconds have elapsed since we last checked?
55
// how many milliseonds have elapsed since we last checked?
181
56
unsigned long millis = ::millis();
182
57
unsigned long delta = millis - _last_millis + _carry;
193
68
if( _minutes >= 60 ) {
199
// We *could* manually work out the day here... but we might as
200
// well ask the RTC hardware. We can't do this *all* the time
201
// though, because it isn't fast enough and will actually cause
202
// a minor display glitch.
210
void Time::inc_hours()
217
void Time::inc_minutes()
219
if( ++_minutes >= 60 )
224
void Time::reset_seconds()
230
void Time::inc_year()
232
if( ++_year >= YEAR_MAX )
237
void Time::inc_month()
246
if( ++_day > days_in_month( _month, _year ) )
80
_last_millis( millis() ),
83
// get the time from the real-time clock
85
RTC.get( rtc_data, true );
86
_hours = rtc_data[ DS1307_HR ];
87
_minutes = rtc_data[ DS1307_MIN ];
88
_seconds = rtc_data[ DS1307_SEC ];