4
* Copyright (C) 2011 Tim Marston <tim@ed.am> and Dan Marston.
6
* This file is part of propeller-clock (hereafter referred to as "this
7
* program"). See http://ed.am/dev/software/arduino/propeller-clock for more
10
* This program is free software: you can redistribute it and/or modify
11
* it under the terms of the GNU Lesser General Public License as published
12
* by the Free Software Foundation, either version 3 of the License, or
13
* (at your option) any later version.
15
* This program is distributed in the hope that it will be useful,
16
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
* GNU Lesser General Public License for more details.
20
* You should have received a copy of the GNU Lesser General Public License
21
* along with this program. If not, see <http://www.gnu.org/licenses/>.
46
// milliseconds at last update
47
static unsigned long _last_millis = millis();
49
// milliseconds carries over from last update
50
static unsigned long _carry = 0;
53
static void probe_rtc()
55
// get the time from the real-time clock
57
RTC.get( rtc_data, true );
58
_year = rtc_data[ DS1307_YR ];
59
_month = rtc_data[ DS1307_MTH ];
60
_day = rtc_data[ DS1307_DAY ];
61
_hours = rtc_data[ DS1307_HR ];
62
_minutes = rtc_data[ DS1307_MIN ];
63
_seconds = rtc_data[ DS1307_SEC ];
79
const char *Time::get_month_name()
81
static const char *months[] = {
96
return months[ _month - 1 ];
106
const char *Time::get_day_suffix()
126
int Time::get_hours()
132
int Time::get_minutes()
138
int Time::get_seconds()
146
// how many milliseconds have elapsed since we last checked?
147
unsigned long millis = ::millis();
148
unsigned long delta = millis - _last_millis + _carry;
150
// update the previous time and carried-over milliseconds
151
_last_millis = millis;
152
_carry = delta % 1000;
154
// add the seconds that have passed to the time
155
_seconds += delta / 1000;
156
while( _seconds >= 60 ) {
159
if( _minutes >= 60 ) {
165
// I mean we *could* work out the day... but FUCK IT! We bought
166
// some god damn HARDWARE to do that shit!