2012-10-20 12:31:03 +00:00
|
|
|
/*
|
|
|
|
Copyright (C) 2012 Nathanaël Restori
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person
|
|
|
|
obtaining a copy of this software and associated documentation
|
|
|
|
files (the "Software"), to deal in the Software without
|
|
|
|
restriction, including without limitation the rights to use, copy,
|
|
|
|
modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
|
|
of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be
|
|
|
|
included in all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
|
|
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
|
|
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
SOFTWARE.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <Wire.h>
|
|
|
|
#include "Chronodot.h"
|
|
|
|
|
|
|
|
#define CHRONODOT_ADDRESS 0x68
|
|
|
|
|
|
|
|
static uint8_t bcd2bin (uint8_t val) { return val - 6 * (val >> 4); }
|
|
|
|
|
2012-10-27 13:50:57 +00:00
|
|
|
// no-cost stream operator as described at
|
|
|
|
// http://sundial.org/arduino/?page_id=119
|
|
|
|
template<class T>
|
|
|
|
inline Print &operator <<(Print &obj, T arg)
|
|
|
|
{ obj.print(arg); return obj; }
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
inline Print &operator >>(Print &obj, T arg)
|
|
|
|
{
|
|
|
|
for (unsigned int mask = 0x80; mask; mask >>= 1) {
|
|
|
|
obj.print(mask&arg?'1':'0');
|
|
|
|
}
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
2012-10-20 12:31:03 +00:00
|
|
|
void setup() {
|
|
|
|
Serial.begin(9600);
|
|
|
|
|
|
|
|
Wire.begin();
|
|
|
|
|
|
|
|
Serial.println("BEGIN transmission");
|
|
|
|
|
|
|
|
Wire.beginTransmission(CHRONODOT_ADDRESS);
|
|
|
|
Wire.write((byte)0);
|
|
|
|
Wire.endTransmission();
|
|
|
|
|
|
|
|
Wire.requestFrom(CHRONODOT_ADDRESS, 19);
|
|
|
|
byte blah[20];
|
|
|
|
int i;
|
|
|
|
for(i=0; i<20; i++) {
|
|
|
|
blah[i] = Wire.read();
|
|
|
|
}
|
|
|
|
|
|
|
|
Serial.println("END transmission");
|
|
|
|
|
|
|
|
uint8_t ss = bcd2bin(blah[0] & 0x7F);
|
|
|
|
uint8_t mm = bcd2bin(blah[1]);
|
|
|
|
uint8_t hh = bcd2bin(blah[2]);
|
2012-10-27 13:50:57 +00:00
|
|
|
uint8_t d = bcd2bin(blah[4]);
|
|
|
|
uint8_t m = bcd2bin(blah[5]);
|
2012-10-20 12:31:03 +00:00
|
|
|
uint16_t y = bcd2bin(blah[6]) + 2000;
|
|
|
|
float ttc = (float)(int)blah[17];
|
|
|
|
byte portion = blah[18];
|
|
|
|
if(portion == 0b01000000) ttc += 0.25;
|
|
|
|
if(portion == 0b10000000) ttc += 0.5;
|
|
|
|
if(portion == 0b11000000) ttc += 0.75;
|
|
|
|
float degF = (((ttc * 9.0) / 5.0) + 32.5);
|
|
|
|
int ttf = (int)degF;
|
|
|
|
//return DateTime (y, m, d, hh, mm, ss, ttf, ttc);
|
|
|
|
|
|
|
|
Serial.println();
|
|
|
|
Serial.println("What\tByte\tCorrespondance");
|
|
|
|
Serial.println("------------------------------");
|
2012-10-27 13:50:57 +00:00
|
|
|
|
|
|
|
Serial
|
|
|
|
<< "seconds\t" << blah[0] << "\t" << ss << "\r\n"
|
|
|
|
<< "minutes\t" << blah[1] << "\t" << mm << "\r\n"
|
|
|
|
<< "hours\t" << blah[2] << "\t" << hh << "\r\n"
|
|
|
|
<< "days\t" << blah[4] << "\t" << d << "\r\n"
|
|
|
|
<< "months\t" << blah[5] << "\t" << m << "\r\n"
|
|
|
|
<< "years\t" << blah[6] << "\t" << y << "\r\n"
|
|
|
|
<< "temp\t" << blah[17] << "\t" << ttc << "\r\n"
|
|
|
|
<< "temp\t" << blah[18] << "\t" << portion << "\r\n";
|
2012-10-20 12:31:03 +00:00
|
|
|
|
|
|
|
Serial.println();
|
2012-10-27 13:50:57 +00:00
|
|
|
Serial.println("Byte\tDecimal\tBinary");
|
|
|
|
Serial.println("----------------------");
|
|
|
|
|
|
|
|
Serial
|
|
|
|
<< "0\t" << blah[0] << "\t" >> blah[0] << "\r\n"
|
|
|
|
<< "1\t" << blah[1] << "\t" >> blah[1] << "\r\n"
|
|
|
|
<< "2\t" << blah[2] << "\t" >> blah[2] << "\r\n"
|
|
|
|
<< "3\t" << blah[3] << "\t" >> blah[3] << "\r\n"
|
|
|
|
<< "4\t" << blah[4] << "\t" >> blah[4] << "\r\n"
|
|
|
|
<< "5\t" << blah[5] << "\t" >> blah[5] << "\r\n"
|
|
|
|
<< "6\t" << blah[6] << "\t" >> blah[6] << "\r\n"
|
|
|
|
<< "7\t" << blah[7] << "\t" >> blah[7] << "\r\n"
|
|
|
|
<< "8\t" << blah[8] << "\t" >> blah[8] << "\r\n"
|
|
|
|
<< "9\t" << blah[9] << "\t" >> blah[9] << "\r\n"
|
|
|
|
<< "10\t" << blah[10] << "\t" >> blah[10] << "\r\n"
|
|
|
|
<< "11\t" << blah[11] << "\t" >> blah[11] << "\r\n"
|
|
|
|
<< "12\t" << blah[12] << "\t" >> blah[12] << "\r\n"
|
|
|
|
<< "13\t" << blah[13] << "\t" >> blah[13] << "\r\n"
|
|
|
|
<< "14\t" << blah[14] << "\t" >> blah[14] << "\r\n"
|
|
|
|
<< "15\t" << blah[15] << "\t" >> blah[15] << "\r\n"
|
|
|
|
<< "16\t" << blah[16] << "\t" >> blah[16] << "\r\n"
|
|
|
|
<< "17\t" << blah[17] << "\t" >> blah[17] << "\r\n"
|
|
|
|
<< "18\t" << blah[18] << "\t" >> blah[18] << "\r\n"
|
|
|
|
<< "19\t" << blah[19] << "\t" >> blah[19] << "\r\n";
|
2012-10-20 12:31:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void loop() {
|
|
|
|
delay(1000);
|
|
|
|
}
|