forked from mindsensors/EVShield
-
Notifications
You must be signed in to change notification settings - Fork 0
/
EVs_RTC.cpp
77 lines (60 loc) · 1.84 KB
/
EVs_RTC.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// EVs_RTC.cpp
//
// This is a class for reading from Real-time Clock, made by Mindsensors.
// See http://www.mindsensors.com/index.php?module=pagemaster&PAGE_user_op=view_page&PAGE_id=101
// Initial version: 2010-06-10 by Andrew Sylvester
// Modified for EVShield: 2015-02-16 by Michael Giles
// Large parts of the code is ported from the NXC library for the device,
// written by Deepak Patil.
/*
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "EVs_RTC.h"
EVs_RTC::EVs_RTC(uint8_t i2c_address)
: EVShieldI2C(i2c_address)
{
}
uint8_t EVs_RTC::BCDToInteger(uint8_t b)
{
uint8_t i;
i = (b&0x0F) + (((b>>4)&0x0F)*10);
return i;
}
uint8_t EVs_RTC::getSeconds()
{
return BCDToInteger(readByte(RTC_Seconds));
}
uint8_t EVs_RTC::getMinutes()
{
return BCDToInteger(readByte(RTC_Minutes));
}
uint8_t EVs_RTC::getHours()
{
return BCDToInteger(readByte(RTC_Hours));
}
uint8_t EVs_RTC::getDayWeek()
{
return BCDToInteger(readByte(RTC_Day_of_Week));
}
uint8_t EVs_RTC::getDayMonth()
{
return BCDToInteger(readByte(RTC_Day_of_Month));
}
uint8_t EVs_RTC::getMonth()
{
return BCDToInteger(readByte(RTC_Month));
}
uint8_t EVs_RTC::getYear()
{
return BCDToInteger(readByte(RTC_Year));
}