Horloge_Lepot_2016_2017/horloge/main.cpp

146 lines
2.8 KiB
C++
Raw Normal View History

2017-12-12 10:47:31 +01:00
/*
* horloge.cpp
*
* Created: 17-10-17 20:53:10
* Author : Adrien
*|----------------------------
*| LCONF | RCONF |
*|____________________________
*| D4 | D3 | D2 | D1 |
*|----------------------------
*| ### ### ### ### |
*| # # # # o # # # # |
*| ### ### ### ### |
*| # # # # o # # # # |
*| ### o ### o ### o ### o|
*|----------------------------
*| o = dot ; pour activer mettre <EFBFBD> 1 le bit 7 digit|_BV(7)
*/
#define F_CPU 16000000UL
#include <avr/io.h>
#include <util/delay.h>
#include "util.h"
//#include "max7219.h"
#include "horlogeLepot.h"
#include "global.h"
uint8_t appuisBPflag = 0;
int main(void)
{
max7219 max(2,3,4, 4);
horloge horloge0(&max);
/* Replace with your application qcode */
DDRB &= ~(_BV(__BP_PLUS__)|_BV(__BP_MOIN__)|_BV(__BP_CONF__)|_BV(__BP_START__));
PORTB |= _BV(__BP_PLUS__)|_BV(__BP_MOIN__)|_BV(__BP_CONF__)|_BV(__BP_START__); //PULL-UP
mode_t mode = NORMALMODE;
setup_t setup = NONE;
setupMilis();
unsigned int tempoBP = __TMP_BP_MAX__;
unsigned int tempoBPi = 0;
unsigned long millisBPStart = 0;
_delay_ms(50);
unsigned long t = millis();
while (1)
{
t = millis();
#pragma region GestionTempoBP
if((millis()-millisBPStart) > tempoBP && appuisBPflag)
{
millisBPStart = millis();
appuisBPflag = 0;
tempoBPi++;
if(tempoBP>__TMP_BP_MIN__ && tempoBPi == __TMP_BP_NLOOP_DEC__)
{
tempoBP *=0.75;
tempoBPi = 0;
}
}
if(PINB&_BV(__BP_MOIN__) && PINB&_BV(__BP_PLUS__) && PINB&_BV(__BP_START__) && PINB&_BV(__BP_CONF__) ) //Reset des var lors du relachement
{
appuisBPflag = 0;
tempoBPi = 0;
tempoBP = __TMP_BP_MAX__;
}
#pragma endregion GestionTempoBP
#pragma region GestionConfig
if(!(PINB&_BV(__BP_CONF__))) //Getsion config
{
_delay_ms(10);//Anti rebon soft
unsigned int tapuis = millis();
while(!(PINB&_BV(__BP_CONF__)))
{
//Routine a exe si besoin
}
if(millis()-tapuis < __TMP_BP_SETUP__ && !setup)
{
switch(mode)
{
case NORMALMODE:
mode = CHRONO;
break;
case CHRONO:
mode = MINUTERIE;
break;
case MINUTERIE:
mode = REVEIL;
break;
case REVEIL:
mode = NORMALMODE;
break;
}
}
else
{
switch(setup)
{
case NONE:
setup = RCONF;
break;
case RCONF:
setup = LCONF;
break;
case LCONF:
setup = NONE;
break;
}
}
}
#pragma endregion GestionConfig
if(!setup)
{
switch(mode)
{
default:
horloge0.afficherHeur();
break;
}
}
else
{
switch (setup)
{
case RCONF:
horloge0.configMinute();
break;
case LCONF:
horloge0.configHeure();
break;
}
}
}
}