Subversion Repositories idreammicro-arduino

Rev

Rev 21 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
21 jlesech 1
// Code by JeeLabs http://news.jeelabs.org/code/
2
// Released to the public domain! Enjoy!
3
 
4
// Simple general-purpose date/time class (no TZ / DST / leap second handling!)
5
class DateTime {
6
public:
7
    DateTime (uint32_t t =0);
8
    DateTime (uint16_t year, uint8_t month, uint8_t day,
9
                uint8_t hour =0, uint8_t min =0, uint8_t sec =0);
10
    DateTime (const char* date, const char* time);
11
    uint16_t year() const       { return 2000 + yOff; }
12
    uint8_t month() const       { return m; }
13
    uint8_t day() const         { return d; }
14
    uint8_t hour() const        { return hh; }
15
    uint8_t minute() const      { return mm; }
16
    uint8_t second() const      { return ss; }
17
    uint8_t dayOfWeek() const;
23 jlesech 18
 
19
    void setYear(uint16_t year) { yOff = year - 2000; }
20
    void setMonth(uint8_t month) { m = month; }
21
    void setDay(uint8_t day) { d = day; }
22
    void setHour(uint8_t hour) { hh = hour; }
23
    void setMinute(uint8_t minute) { mm = minute; }
24
    void setSecond(uint8_t second) { ss = second; }
21 jlesech 25
 
26
    // 32-bit times as seconds since 1/1/2000
27
    long secondstime() const;  
28
    // 32-bit times as seconds since 1/1/1970
29
    uint32_t unixtime(void) const;
30
 
31
protected:
32
    uint8_t yOff, m, d, hh, mm, ss;
33
};
34
 
35
// RTC based on the DS1307 chip connected via I2C and the Wire library
36
class RTC_DS1307 {
37
public:
38
  static uint8_t begin(void);
39
    static void adjust(const DateTime& dt);
40
    uint8_t isrunning(void);
41
    static DateTime now();
42
};
43
 
44
// RTC using the internal millis() clock, has to be initialized before use
45
// NOTE: this clock won't be correct once the millis() timer rolls over (>49d?)
46
class RTC_Millis {
47
public:
48
    static void begin(const DateTime& dt) { adjust(dt); }
49
    static void adjust(const DateTime& dt);
50
    static DateTime now();
51
 
52
protected:
53
    static long offset;
54
};