/elec/propeller-clock

To get this branch, use:
bzr branch http://bzr.ed.am/elec/propeller-clock

« back to all changes in this revision

Viewing changes to src/time.cc

  • Committer: edam
  • Date: 2012-02-25 01:31:43 UTC
  • Revision ID: tim@ed.am-20120225013143-9fet2y2d3fjlrwez
added ulibc

Show diffs side-by-side

added added

removed removed

1
 
/*
2
 
 * time.cc
3
 
 *
4
 
 * Copyright (C) 2011 Tim Marston <tim@ed.am> and Dan Marston.
5
 
 *
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
8
 
 * information.
9
 
 *
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.
14
 
 *
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.
19
 
 *
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/>.
22
 
 */
23
1
#include "time.h"
24
2
#include <DS1307.h>
25
3
#include <Wire.h>
32
10
}
33
11
 
34
12
 
35
 
int Time::get_year()
36
 
{
37
 
        return _year;
38
 
}
39
 
 
40
 
 
41
 
int Time::get_month()
42
 
{
43
 
        return _month;
44
 
}
45
 
 
46
 
 
47
 
const char *Time::get_month_name()
48
 
{
49
 
        static const char *months[] = {
50
 
                "January",
51
 
                "February",
52
 
                "March",
53
 
                "April",
54
 
                "May",
55
 
                "June",
56
 
                "July",
57
 
                "August",
58
 
                "September",
59
 
                "October",
60
 
                "November",
61
 
                "December",
62
 
        };
63
 
 
64
 
        return months[ _month - 1 ];
65
 
}
66
 
 
67
 
 
68
 
int Time::get_day()
69
 
{
70
 
        return _day;
71
 
}
72
 
 
73
 
 
74
 
const char *Time::get_day_suffix()
75
 
{
76
 
        switch( _day )
77
 
        {
78
 
        case 1:
79
 
        case 21:
80
 
        case 31:
81
 
                return "st";
82
 
        case 2:
83
 
        case 22:
84
 
                return "nd";
85
 
        case 3:
86
 
        case 23:
87
 
                return "rd";
88
 
        default:
89
 
                return "th";
90
 
        }
91
 
}
92
 
 
93
 
 
94
13
int Time::get_hours()
95
14
{
96
15
        return _hours;
127
46
                if( _minutes >= 60 ) {
128
47
                        _minutes -= 60;
129
48
                        _hours++;
130
 
                        if( _hours >= 24 ) {
 
49
                        if( _hours >= 24 )
131
50
                                _hours -= 24;
132
 
 
133
 
                                // I mean we *could* work out the day... but FUCK IT! We bought
134
 
                                // some god damn HARDWARE to do that shit!
135
 
                                probe_rtc();
136
 
                        }
137
51
                }
138
52
        }
139
53
}
144
58
        _last_millis( millis() ),
145
59
        _carry( 0 )
146
60
{
147
 
        probe_rtc();
148
 
}
149
 
 
150
 
 
151
 
void Time::probe_rtc()
152
 
{
153
61
        // get the time from the real-time clock
154
62
        int rtc_data[ 7 ];
155
63
        RTC.get( rtc_data, true );
156
 
        _year = rtc_data[ DS1307_YR ];
157
 
        _month = rtc_data[ DS1307_MTH ];
158
 
        _day = rtc_data[ DS1307_DAY ];
159
64
        _hours = rtc_data[ DS1307_HR ];
160
65
        _minutes = rtc_data[ DS1307_MIN ];
161
66
        _seconds = rtc_data[ DS1307_SEC ];