le test

Dependencies:   LCD_DISCO_F429ZI mbed BSP_DISCO_F429ZI

Horloges/horloge.cpp

Committer:
ascheriit
Date:
2019-05-23
Revision:
42:53780e5a6acb
Parent:
39:b069cf6be013

File content as of revision 42:53780e5a6acb:

#include "horloge.h"

extern int GLOBAL_VALEUR_TICK;

char VRGL_AFFICHAGE_ELEMENTS = 0; //Cette variable globale vaut 1 si on affiche les éléments et vaut 0 sinon
DigitalIn PinSwEl(PG_2); //Bouton utile pour changer le mode d'affichage 
DigitalIn PinSeRT(PE_4); //Bouton pour rêgler l'heure actuelle

int H_toogleElem(){
    if(PinSwEl.read()){
        while(PinSwEl.read()){
            ;
        }
    VRGL_AFFICHAGE_ELEMENTS=!VRGL_AFFICHAGE_ELEMENTS;
    return 1;
    }
    return 0;
}

void H_ChangeHour(temps* moment,int mod){
    if(mod){
        if(mod==1){
            if((*moment).heure==23){
                (*moment).heure=0;
            }else{
                (*moment).heure=(*moment).heure+1;
            }
        }else{
            if((*moment).heure==0){
                (*moment).heure=23;
            }else{
                (*moment).heure=(*moment).heure-1;
            }
        }
    }
}

void H_ChangeMinute(temps* moment,int mod){
    if(mod){
        if(mod==1){
            if((*moment).minute==59){
                (*moment).minute=0;
                H_ChangeHour(moment,1);
            }else{
                (*moment).minute=(*moment).minute+1;
            }
        }else{
            if((*moment).minute==0){
                (*moment).minute=59;
                H_ChangeHour(moment,-1);
            }else{
                (*moment).minute=(*moment).minute-1;
            }
        }
    }
}

void H_afficheHorlogeElemClean(temps mnt,int x,int y,int taille,long long int couleur,long long int fond){
    H_afficheHorlogeElemTri(mnt,x,y,taille,couleur,couleur,couleur,fond);
}

void H_afficheHorlogeElemTri(temps mnt,int x,int y,int taille,long long int couleur1,long long int couleur2,long long int couleur3,long long int fond){
    if(VRGL_AFFICHAGE_ELEMENTS){
        DisplayMatrixClean(x,y,BS_ElemHeure(mnt.heure),taille,couleur1,fond);
        DisplayMatrixClean(x + 11 * taille,y,BS_dotdot(),taille,couleur2,fond);
        DisplayMatrixClean(x + 19 * taille,y,BS_ElemMinute(mnt.minute),taille,couleur3,fond);
    }else{
        BS_displayChiffre10Clean(x,y,mnt.heure,taille,couleur1,fond);
        DisplayMatrixClean(x + 11 * taille,y,BS_dotdot(),taille,couleur2,fond);
        BS_displayChiffre10Clean(x + 19 * taille,y,mnt.minute,taille,couleur3,fond);
    }
}

void H_reglage(temps* mnt,int x,int y,int taille,long long int couleur,long long int fond){
    H_afficheHorlogeElemTri(*mnt,x,y,taille,couleur,couleur,COULEUR_HEURE_EDIT,fond);
    int tamponClick=1; //Cette valeur sert à faire la distinction entre les moments où on veut changer l'heure et les moments où on veut passer au nombre suivant.
    while(tamponClick){ //réglage des minutes
        tamponClick=CdRelatif();
        H_ChangeMinute(mnt,tamponClick);
        H_afficheHorlogeElemTri(*mnt,x,y,taille,couleur,couleur,COULEUR_HEURE_EDIT,fond);
        wait(0.1); //réduit les problèmes de rebond
    }
    H_afficheHorlogeElemTri(*mnt,x,y,taille,COULEUR_HEURE_EDIT,couleur,couleur,fond);
    wait(0.3);//evite le double-click
    tamponClick=1;
    while(tamponClick){ //téglage de l'heure
        tamponClick=CdRelatif();
        H_ChangeHour(mnt,tamponClick);
        H_afficheHorlogeElemTri(*mnt,x,y,taille,COULEUR_HEURE_EDIT,couleur,couleur,fond);
        wait(0.1);        
    }
    H_afficheHorlogeElemClean(*mnt,x,y,taille,couleur,fond);
    wait(0.45);
}

void H_setTemps(temps* RT){
    if(PinSeRT.read()){
        while(PinSeRT.read()){
            ;
        }
    H_reglage(RT,150,120,5,COULEUR_HEURE,COULEUR_FOND);
    GLOBAL_VALEUR_TICK=0;
    }    
}

int H_updateHeure(temps* RT){
    int i = T_checkValue();
    if(i){
        H_ChangeMinute(RT,1);
        return 1;
    }
    return 0;
}

void H_test1(){
    temps tempsTest;
    tempsTest.heure = 15;
    tempsTest.minute = 01;
    for(int i=0;i<48;i++){
        for(int j=0;j<60;j++){
            H_ChangeMinute(&tempsTest,1);
            H_afficheHorlogeElemTri(tempsTest,50,50,4,0xFFA000E3,0xFFA03333,0xFF0000A5,0xFFFFFFFF);
            H_afficheHorlogeElemClean(tempsTest,50,150,4,0xFF0000FF,0xFFFFFFFF);
            wait(1);
        }
    }
}

void H_test2(){
    temps tempsTest;
    tempsTest.heure = 15;
    tempsTest.minute = 01;
    H_reglage(&tempsTest,50,50,4,0xFFA000E3,0xFFFFFFFF);
    H_afficheHorlogeElemClean(tempsTest,50,50,4,0xFF0000FF,0xFFFFFFFF);
}