/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-28 17:11:15 UTC
  • Revision ID: edam@waxworlds.org-20120228171115-j3k91a3v71d3wnc1
cleanu

Show diffs side-by-side

added added

removed removed

32
32
}
33
33
 
34
34
 
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
35
int Time::get_hours()
95
36
{
96
37
        return _hours;
127
68
                if( _minutes >= 60 ) {
128
69
                        _minutes -= 60;
129
70
                        _hours++;
130
 
                        if( _hours >= 24 ) {
 
71
                        if( _hours >= 24 )
131
72
                                _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
73
                }
138
74
        }
139
75
}
144
80
        _last_millis( millis() ),
145
81
        _carry( 0 )
146
82
{
147
 
        probe_rtc();
148
 
}
149
 
 
150
 
 
151
 
void Time::probe_rtc()
152
 
{
153
83
        // get the time from the real-time clock
154
84
        int rtc_data[ 7 ];
155
85
        RTC.get( rtc_data, true );
156
 
        _year = rtc_data[ DS1307_YR ];
157
 
        _month = rtc_data[ DS1307_MTH ];
158
 
        _day = rtc_data[ DS1307_DAY ];
159
86
        _hours = rtc_data[ DS1307_HR ];
160
87
        _minutes = rtc_data[ DS1307_MIN ];
161
88
        _seconds = rtc_data[ DS1307_SEC ];