/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-29 21:56:32 UTC
  • Revision ID: edam@waxworlds.org-20120229215632-kypb9491vx7bicef
moved some stuf round, created a re-usable pool of message buffers, genericised "modes" for messages

Show diffs side-by-side

added added

removed removed

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