/*
 * DS3231.h
 *
 * Arduino Library for the DS3231 Real-Time Clock chip
 *
 * (c) Eric Ayars
 * 4/1/11
 * Updated to Arduino 1.0 By john Hubert
 * Feb 7 2012
 * released into the public domain. If you use this, please let me know
 * (just out of pure curiosity!) by sending me an email:
 * eric@ayars.org
 *
 */

#ifndef myDS3231_h
#define myDS3231_h

#include <Wiring.h>
#include <Wire.h>

class myDS3231 {
	public:
			
		//Constructor
		myDS3231();
		void getTime(byte& year, byte& month, byte& date, byte& DoW, byte& hour, byte& minute, byte& second); 
		byte getSecond(); 
		byte getMinute(); 
		byte getHour(bool& h12, bool& PM); 
			// In addition to returning the hour register, this function
			// returns the values of the 12/24-hour flag and the AM/PM flag.
		byte getDoW(); 
		byte getDate(); 
		byte getMonth(bool& Century); 
			// Also sets the flag indicating century roll-over.
		byte getYear(); 
			// Last 2 digits only

		// Time-setting functions
		// Note that none of these check for sensibility: You can set the
		// date to July 42nd and strange things will probably result.
		
		void setSecond(byte Second); 
			// In addition to setting the seconds, this clears the 
			// "Oscillator Stop Flag".
		void setMinute(byte Minute); 
			// Sets the minute
		void setHour(byte Hour); 
			// Sets the hour
		void setDoW(byte DoW); 
			// Sets the Day of the Week (1-7);
		void setDate(byte Date); 
			// Sets the Date of the Month
		void setMonth(byte Month); 
			// Sets the Month of the year
		void setYear(byte Year); 
			// Last two digits of the year
		void setClockMode(bool h12); 
			// Set 12/24h mode. True is 12-h, false is 24-hour.

		// Temperature function

		float getTemperature(); 

		// Alarm functions

		// Oscillator functions
		void enableOscillator(bool TF, bool battery, byte frequency); 
		void enable32kHz(bool TF); 
		bool oscillatorCheck();;

	private:

		byte decToBcd(byte val); 
			// Convert normal decimal numbers to binary coded decimal
		byte bcdToDec(byte val); 
			// Convert binary coded decimal to normal decimal numbers
		byte readControlByte(bool which); 
			// Read selected control byte: (0); reads 0x0e, (1) reads 0x0f
		void writeControlByte(byte control, bool which); 
			// Write the selected control byte. 
			// which == false -> 0x0e, true->0x0f.

};

#endif
