/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:01:54 UTC
  • Revision ID: tim@ed.am-20120310010154-lv041mt4275k5jxo
removed most OOP/inheritance crap, saved loads of space!

Show diffs side-by-side

added added

removed removed

25
25
#include <Wire.h>
26
26
 
27
27
 
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()
 
28
Time &Time::get_instance()
54
29
{
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 ];
 
30
        static Time time;
 
31
        return time;
64
32
}
65
33
 
66
34
 
143
111
 
144
112
void Time::update()
145
113
{
146
 
        // how many milliseconds have elapsed since we last checked?
 
114
        // how many milliseonds have elapsed since we last checked?
147
115
        unsigned long millis = ::millis();
148
116
        unsigned long delta = millis - _last_millis + _carry;
149
117
 
171
139
}
172
140
 
173
141
 
174
 
void Time::init()
 
142
Time::Time()
 
143
        :
 
144
        _last_millis( millis() ),
 
145
        _carry( 0 )
175
146
{
176
147
        probe_rtc();
177
148
}
178
149
 
179
150
 
 
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