Permalink
Browse files

Merge pull request #5 from zevenwolf/master

Did the changes that you asked for. Works with 22 and 1.0
  • Loading branch information...
ladyada committed Nov 5, 2011
2 parents 72fc1a4 + 4ce3c8b commit 8e266db7dc68ff5d8136711a05c62d9fc734043f
Showing with 66 additions and 5 deletions.
  1. +66 −5 RTClib.cpp
View
@@ -4,13 +4,22 @@
#include <Wire.h>
#include <avr/pgmspace.h>
#include "RTClib.h"
-#include <WProgram.h>
#define DS1307_ADDRESS 0x68
#define SECONDS_PER_DAY 86400L
#define SECONDS_FROM_1970_TO_2000 946684800
+#if ARDUINO > 22
+#include <arduino.h>
+#endif
+
+#if ARDUINO <= 22
+#include <WProgram.h>
+#endif
+
+
+int i = 0; //The new wire library needs to take an int when you are sending for the zero register
////////////////////////////////////////////////////////////////////////////////
// utility code, some of this could be exposed in the DateTime API if needed
@@ -128,9 +137,58 @@ uint8_t RTC_DS1307::begin(void) {
return 1;
}
+
+#if ARDUINO > 22
+
+
+uint8_t RTC_DS1307::isrunning(void) {
+ Wire.beginTransmission(DS1307_ADDRESS);
+ Wire.write(i);
+ Wire.endTransmission();
+
+ Wire.requestFrom(DS1307_ADDRESS, 1);
+ uint8_t ss = Wire.read();
+ return !(ss>>7);
+}
+
+void RTC_DS1307::adjust(const DateTime& dt) {
+ Wire.beginTransmission(DS1307_ADDRESS);
+ Wire.write(i);
+ Wire.write(bin2bcd(dt.second()));
+ Wire.write(bin2bcd(dt.minute()));
+ Wire.write(bin2bcd(dt.hour()));
+ Wire.write(bin2bcd(0));
+ Wire.write(bin2bcd(dt.day()));
+ Wire.write(bin2bcd(dt.month()));
+ Wire.write(bin2bcd(dt.year() - 2000));
+ Wire.write(i);
+ Wire.endTransmission();
+}
+
+DateTime RTC_DS1307::now() {
+ Wire.beginTransmission(DS1307_ADDRESS);
+ Wire.write(i);
+ Wire.endTransmission();
+
+ Wire.requestFrom(DS1307_ADDRESS, 7);
+ uint8_t ss = bcd2bin(Wire.read() & 0x7F);
+ uint8_t mm = bcd2bin(Wire.read());
+ uint8_t hh = bcd2bin(Wire.read());
+ Wire.read();
+ uint8_t d = bcd2bin(Wire.read());
+ uint8_t m = bcd2bin(Wire.read());
+ uint16_t y = bcd2bin(Wire.read()) + 2000;
+
+ return DateTime (y, m, d, hh, mm, ss);
+}
+
+#endif
+
+#if ARDUINO <= 22
+
uint8_t RTC_DS1307::isrunning(void) {
Wire.beginTransmission(DS1307_ADDRESS);
- Wire.send(0);
+ Wire.send(i);
Wire.endTransmission();
Wire.requestFrom(DS1307_ADDRESS, 1);
@@ -140,21 +198,21 @@ uint8_t RTC_DS1307::isrunning(void) {
void RTC_DS1307::adjust(const DateTime& dt) {
Wire.beginTransmission(DS1307_ADDRESS);
- Wire.send(0);
+ Wire.send(i);
Wire.send(bin2bcd(dt.second()));
Wire.send(bin2bcd(dt.minute()));
Wire.send(bin2bcd(dt.hour()));
Wire.send(bin2bcd(0));
Wire.send(bin2bcd(dt.day()));
Wire.send(bin2bcd(dt.month()));
Wire.send(bin2bcd(dt.year() - 2000));
- Wire.send(0);
+ Wire.send(i);
Wire.endTransmission();
}
DateTime RTC_DS1307::now() {
Wire.beginTransmission(DS1307_ADDRESS);
- Wire.send(0);
+ Wire.send(i);
Wire.endTransmission();
Wire.requestFrom(DS1307_ADDRESS, 7);
@@ -169,6 +227,9 @@ DateTime RTC_DS1307::now() {
return DateTime (y, m, d, hh, mm, ss);
}
+#endif
+
+
////////////////////////////////////////////////////////////////////////////////
// RTC_Millis implementation

0 comments on commit 8e266db

Please sign in to comment.