// Version du 20/03/2018

//  Author:Frankie.Chu
//  Date:9 April,2012
//
//  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
//
//  Modified record:
//
//	Librairie augmentée par David Souder - souder.d@gmail.com pour DuinoEDU.com
//	Version du 20/02/2015
//
/*******************************************************************************/

#ifndef TM1637_h
#define TM1637_h
#include <inttypes.h>
#include <Arduino.h>
//************definitions for TM1637*********************
#define ADDR_AUTO  0x40
#define ADDR_FIXED 0x44

#define STARTADDR  0xc0 
/**** definitions for the clock point of the digit tube *******/
#define POINT_ON   1
#define POINT_OFF  0
/**************definitions for brightness***********************/
#define  BRIGHT_DARKEST 0
#define  BRIGHT_TYPICAL 2
#define  BRIGHTEST      7

//#define brancher init  			//Remplacé par une véritable méthode
#define luminosite set
//#define effacer clearDisplay		//Remplacé par une véritable méthode
#define luminositeA set
//#define afficher display
#define afficherSur1(val) display(0, val);
#define afficherSur2(val) display(1, val);
#define afficherSur3(val) display(2, val);
#define afficherSur4(val) display(3, val);


#define afficherPoints(void) point(POINT_ON)
#define effacerPoints(void)  point(POINT_OFF)

class TM1637
{
  public:
    uint8_t Cmd_SetData;
    uint8_t Cmd_SetAddr;
    uint8_t Cmd_DispCtrl;
    boolean _PointFlag;     //_PointFlag=1:the clock point on
    TM1637(uint8_t, uint8_t);
	/*EDU FR*/	void 	brancher();
	/*EDU US*/ 	void 	ecrire(int16_t number);
	/*EDU US*/ 	void 	writeInt(int16_t number);
    void init(void);        //To clear the display
    void writeByte(int8_t wr_data);//write 8bit data to tm1637
    void start(void);//send start bits
    void stop(void); //send stop bits
    void display(int8_t DispData[]);
    void display(uint8_t BitAddr,int8_t DispData);
	/*EDU FR*/	void 	effacer();
    void clearDisplay();
    void set(uint8_t = BRIGHT_TYPICAL,uint8_t = 0x40,uint8_t = 0xc0);//To take effect the next time it displays.
    void point(boolean PointFlag);//whether to light the clock point ":".To take effect the next time it displays.
    void coding(int8_t DispData[]); 
    int8_t coding(int8_t DispData); 
  private:
	/*EDU US*/	long 		m_lastValueInt;
	/*EDU US*/  uint16_t 	m_minRefresh;
	/*EDU US*/  uint16_t    m_moyRefresh;
	/*EDU US*/  uint16_t    m_maxRefresh;
	/*EDU US*/  long 		m_lastDate;
    uint8_t Clkpin;
    uint8_t Datapin;
};
#endif
