/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: Tim Marston
  • Date: 2012-03-10 01:25:02 UTC
  • Revision ID: tim@ed.am-20120310012502-v0jwfjghpp63un6n
removed time singleton, not cause it saved much space, but cause i don't want singletons in this project!

Show diffs side-by-side

added added

removed removed

25
25
#include <Wire.h>
26
26
 
27
27
 
28
 
Time &Time::get_instance()
 
28
// year
 
29
static int _year;
 
30
 
 
31
// month
 
32
static int _month;
 
33
 
 
34
// day
 
35
static int _day;
 
36
 
 
37
// hours
 
38
static int _hours;
 
39
 
 
40
// minutes
 
41
static int _minutes;
 
42
 
 
43
// seconds
 
44
static int _seconds;
 
45
 
 
46
// milliseconds at last update
 
47
static unsigned long _last_millis = millis();
 
48
 
 
49
// milliseconds carries over from last update
 
50
static unsigned long _carry = 0;
 
51
 
 
52
 
 
53
static void probe_rtc()
29
54
{
30
 
        static Time time;
31
 
        return time;
 
55
        // get the time from the real-time clock
 
56
        int rtc_data[ 7 ];
 
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 ];
32
64
}
33
65
 
34
66
 
139
171
}
140
172
 
141
173
 
142
 
Time::Time()
143
 
        :
144
 
        _last_millis( millis() ),
145
 
        _carry( 0 )
 
174
void Time::init()
146
175
{
147
176
        probe_rtc();
148
177
}
149
178
 
150
179
 
151
 
void Time::probe_rtc()
152
 
{
153
 
        // get the time from the real-time clock
154
 
        int rtc_data[ 7 ];
155
 
        RTC.get( rtc_data, true );
156
 
        _year = rtc_data[ DS1307_YR ];
157
 
        _month = rtc_data[ DS1307_MTH ];
158
 
        _day = rtc_data[ DS1307_DAY ];
159
 
        _hours = rtc_data[ DS1307_HR ];
160
 
        _minutes = rtc_data[ DS1307_MIN ];
161
 
        _seconds = rtc_data[ DS1307_SEC ];
162
 
}
163