Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

simplified handling of Wire library differences for before and after …

…Arduino 1.0
  • Loading branch information...
commit 59b296df0575ab065f6d45ceb20257f6224198ee 1 parent 08c0e61
MrAlvin authored

Showing 1 changed file with 24 additions and 64 deletions. Show diff stats Hide diff stats

  1. +24 64 RTClib.cpp
88 RTClib.cpp
@@ -136,94 +136,54 @@ uint8_t RTC_DS1307::begin(void) {
136 136
137 137
138 138 #if (ARDUINO >= 100)
139   -
140   -uint8_t RTC_DS1307::isrunning(void) {
141   - Wire.beginTransmission(DS1307_ADDRESS);
142   - Wire.write(i);
143   - Wire.endTransmission();
144   -
145   - Wire.requestFrom(DS1307_ADDRESS, 1);
146   - uint8_t ss = Wire.read();
147   - return !(ss>>7);
148   -}
149   -
150   -void RTC_DS1307::adjust(const DateTime& dt) {
151   - Wire.beginTransmission(DS1307_ADDRESS);
152   - Wire.write(i);
153   - Wire.write(bin2bcd(dt.second()));
154   - Wire.write(bin2bcd(dt.minute()));
155   - Wire.write(bin2bcd(dt.hour()));
156   - Wire.write(bin2bcd(0));
157   - Wire.write(bin2bcd(dt.day()));
158   - Wire.write(bin2bcd(dt.month()));
159   - Wire.write(bin2bcd(dt.year() - 2000));
160   - Wire.write(i);
161   - Wire.endTransmission();
162   -}
163   -
164   -DateTime RTC_DS1307::now() {
165   - Wire.beginTransmission(DS1307_ADDRESS);
166   - Wire.write(i);
167   - Wire.endTransmission();
168   -
169   - Wire.requestFrom(DS1307_ADDRESS, 7);
170   - uint8_t ss = bcd2bin(Wire.read() & 0x7F);
171   - uint8_t mm = bcd2bin(Wire.read());
172   - uint8_t hh = bcd2bin(Wire.read());
173   - Wire.read();
174   - uint8_t d = bcd2bin(Wire.read());
175   - uint8_t m = bcd2bin(Wire.read());
176   - uint16_t y = bcd2bin(Wire.read()) + 2000;
177   -
178   - return DateTime (y, m, d, hh, mm, ss);
179   -}
180   -
  139 + #define WW_ Wire.write
  140 + #define WR_ Wire.read
181 141 #else
  142 + #define WW_ Wire.send
  143 + #define WR_ Wire.receive
  144 +#endif
182 145
183 146 uint8_t RTC_DS1307::isrunning(void) {
184 147 Wire.beginTransmission(DS1307_ADDRESS);
185   - Wire.send(i);
  148 + WW_(i);
186 149 Wire.endTransmission();
187 150
188 151 Wire.requestFrom(DS1307_ADDRESS, 1);
189   - uint8_t ss = Wire.receive();
  152 + uint8_t ss = WR_();
190 153 return !(ss>>7);
191 154 }
192 155
193 156 void RTC_DS1307::adjust(const DateTime& dt) {
194 157 Wire.beginTransmission(DS1307_ADDRESS);
195   - Wire.send(i);
196   - Wire.send(bin2bcd(dt.second()));
197   - Wire.send(bin2bcd(dt.minute()));
198   - Wire.send(bin2bcd(dt.hour()));
199   - Wire.send(bin2bcd(0));
200   - Wire.send(bin2bcd(dt.day()));
201   - Wire.send(bin2bcd(dt.month()));
202   - Wire.send(bin2bcd(dt.year() - 2000));
203   - Wire.send(i);
  158 + WW_(i);
  159 + WW_(bin2bcd(dt.second()));
  160 + WW_(bin2bcd(dt.minute()));
  161 + WW_(bin2bcd(dt.hour()));
  162 + WW_(bin2bcd(0));
  163 + WW_(bin2bcd(dt.day()));
  164 + WW_(bin2bcd(dt.month()));
  165 + WW_(bin2bcd(dt.year() - 2000));
  166 + WW_(i);
204 167 Wire.endTransmission();
205 168 }
206 169
207 170 DateTime RTC_DS1307::now() {
208 171 Wire.beginTransmission(DS1307_ADDRESS);
209   - Wire.send(i);
  172 + WW_(i);
210 173 Wire.endTransmission();
211 174
212 175 Wire.requestFrom(DS1307_ADDRESS, 7);
213   - uint8_t ss = bcd2bin(Wire.receive() & 0x7F);
214   - uint8_t mm = bcd2bin(Wire.receive());
215   - uint8_t hh = bcd2bin(Wire.receive());
216   - Wire.receive();
217   - uint8_t d = bcd2bin(Wire.receive());
218   - uint8_t m = bcd2bin(Wire.receive());
219   - uint16_t y = bcd2bin(Wire.receive()) + 2000;
  176 + uint8_t ss = bcd2bin(WR_() & 0x7F);
  177 + uint8_t mm = bcd2bin(WR_());
  178 + uint8_t hh = bcd2bin(WR_());
  179 + WR_();
  180 + uint8_t d = bcd2bin(WR_());
  181 + uint8_t m = bcd2bin(WR_());
  182 + uint16_t y = bcd2bin(WR_()) + 2000;
220 183
221 184 return DateTime (y, m, d, hh, mm, ss);
222 185 }
223 186
224   -#endif
225   -
226   -
227 187 ////////////////////////////////////////////////////////////////////////////////
228 188 // RTC_Millis implementation
229 189

0 comments on commit 59b296d

Please sign in to comment.
Something went wrong with that request. Please try again.