Centre de contrôle d'un dessiccateur de fruits et légumes

Dependencies:   F746_GUI DS1820 JMAPwmOut OneWire QSPI_DISCO_F746NG mbed

Centre de contrôle d'un dessiccateur de fruits et légumes

Le dessiccateur utilise une résistance de chauffage qui sont commandés par deux triacs contrôlés par la carte de développement STMICROELECTRONICS STM32F746G-DISCO. La température est mesurée par du capteur DS18B20. L'écran LCD TFT du STM32F746G-DISCO permet une interface conviviale.

Fournitures :

  • carte de développement STMICROELECTRONICS STM32F746G-DISCO (car elle a un écran LCD TFT) montée sur un circuit imprimé réalisé sous Windows avec le programme TCI.exe;
  • un capteur de température OneWire DS18B20;
  • un module de commande des triacs monté sur un circuit imprimé réalisé avec le programme TCI.exe;
  • un dispositif de chauffage/ventilation obtenu du démontage d'un chauffage électrique d'appoint (à 7€ chez Mr Bricolage);
  • un boitier parallélépipédique réalisé en résine polyester/fibre de verre et équipé de grille en inox;

A faire pour la publication :

  • circuit imprimé carte microcontrôleur
  • circuit imprimé commande triacs
  • boitier
Committer:
jmambroi
Date:
Sat May 27 09:03:02 2017 +0000
Revision:
3:5dff448d2ed1
Parent:
2:96d32c19b5be
Suppression de r?f?rence multiples dans les biblioth?ques.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jmambroi 0:3f519e465338 1 #include "main.hpp"
jmambroi 0:3f519e465338 2
jmambroi 0:3f519e465338 3 Serial pc(SERIAL_TX, SERIAL_RX);
jmambroi 0:3f519e465338 4 using namespace Mikami;
jmambroi 0:3f519e465338 5
jmambroi 0:3f519e465338 6 DigitalOut led(LED1);
jmambroi 0:3f519e465338 7
jmambroi 0:3f519e465338 8 //Les pattes de commande
jmambroi 0:3f519e465338 9 //DigitalIn patteDS1820(D14); // Inutile et néfaste
jmambroi 0:3f519e465338 10 JMAPwmOut triacChauffage(D9);
jmambroi 0:3f519e465338 11 //JMAPwmOut triacVentilateur(D10);
jmambroi 0:3f519e465338 12 JMAPwmOut triacVentilateur(D7); // D10 ne semble plus fonctionner donc D7
jmambroi 0:3f519e465338 13 //JMAPwmOut triacChauffage(D0); // Premier essai
jmambroi 0:3f519e465338 14 //JMAPwmOut triacVentilateur(D1);
jmambroi 0:3f519e465338 15
jmambroi 0:3f519e465338 16 float periodeVentilateur = 200;
jmambroi 0:3f519e465338 17 float periodeChauffage = 200;
jmambroi 0:3f519e465338 18
jmambroi 0:3f519e465338 19 int dureeAttenteTotale[4] = {0, 0, 0, 10}; //durée d'attente totale, ie départ dans j-h:m:s en décimal, elle est fixe
jmambroi 0:3f519e465338 20 int dureeAttenteRestante[4] = {0, 0, 0, 10}; //durée d'attente restante j-h:m:s en décimal, elle est décrémentée
jmambroi 0:3f519e465338 21 int dureeMarcheTotale[4] = {0, 1, 4, 20}; //durée de marche totale j-h:m:s en décimal
jmambroi 0:3f519e465338 22 int dureeMarcheRestante[4] = {0, 1, 4, 20}; //durée de marche restante j-h:m:s en décimal, elle est décrémentée
jmambroi 0:3f519e465338 23
jmambroi 0:3f519e465338 24 uint8_t tamponQSPI[TAILLE_TAMPON];
jmambroi 0:3f519e465338 25 uint8_t etat = ARRETE; // par defaut, il est arrété
jmambroi 0:3f519e465338 26 uint8_t etatPrecedent = ARRETE; // par defaut, il est arrété
jmambroi 0:3f519e465338 27 uint8_t ecranActuel = ECRAN_ACCUEIL;// c'est l'écran par defaut
jmambroi 0:3f519e465338 28 // Ventilateur
jmambroi 0:3f519e465338 29 uint8_t vitesseVentilateur = 5; // moyen par defaut, 0 -> 10 ?
jmambroi 0:3f519e465338 30 int tableauDureeImpulsionVentilateur[11]= {periodeVentilateur, 9 * (periodeVentilateur / 10), 8 * periodeVentilateur / 10, 7 * periodeVentilateur / 10, 6 * periodeVentilateur / 10, 5 * periodeVentilateur / 10, 4 * periodeVentilateur / 10, 3 * periodeVentilateur / 10, 2 * periodeVentilateur / 10, 1 * periodeVentilateur / 10, 1};
jmambroi 0:3f519e465338 31 bool ventilateurEnMarche = false;
jmambroi 0:3f519e465338 32 // Chauffage
jmambroi 0:3f519e465338 33 int seuilChauffage = 0;
jmambroi 0:3f519e465338 34 int tableauSeuilsChauffage[11] = {10, 9, 8, 6, 5, 4, 3, 2, 1, 1, 0}; // % de la puissance de chauffage 100%, 90%... 20%, 10%, 0%
jmambroi 0:3f519e465338 35 //int tableauSeuilsChauffage[11] = {10, 10, 9, 9, 8, 8, 6, 6, 3, 1, 0}; // % de la puissance de chauffage 100%, 90%... 20%, 10%, 0%
jmambroi 0:3f519e465338 36 //int tableauSeuilsChauffage[11] = {6, 6, 6, 6, 5, 5, 4, 4, 3, 1, 0}; // % de la puissance de chauffage 100%, 90%... 20%, 10%, 0%
jmambroi 0:3f519e465338 37 //int tableauSeuilsChauffage[11] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; // % de la puissance de chauffage 100%, 90%... 20%, 10%
jmambroi 0:3f519e465338 38
jmambroi 0:3f519e465338 39 //int tableauDureeImpulsionChauffage[11] = {1, (periodeChauffage / 10), 2*periodeChauffage / 10, 3 * periodeChauffage / 10, 4 * periodeChauffage / 10, 5 * periodeChauffage / 10, 6 * periodeChauffage / 10, 7 * periodeChauffage / 10, 8 * periodeChauffage / 10, 9 * periodeChauffage / 10, periodeChauffage};
jmambroi 0:3f519e465338 40 int tableauDureeImpulsionChauffage[11] = {periodeChauffage, 9 * (periodeChauffage / 10), 8 * periodeChauffage / 10, 7 * periodeChauffage / 10, 6 * periodeChauffage / 10, 5 * periodeChauffage / 10, 4 * periodeChauffage / 10, 3 * periodeChauffage / 10, 2 * periodeChauffage / 10, 1 * periodeChauffage / 10, 1};
jmambroi 0:3f519e465338 41 float tableauSeuilsTemperature[11]; // temperatureConsigne - x% de temperatureConsigne
jmambroi 0:3f519e465338 42 float temperatureConsigne = 30.0; // La température de consigne
jmambroi 0:3f519e465338 43 float temperature = 0.0; // La température
jmambroi 0:3f519e465338 44 float temperature2 = 0.0; // La température ancienne
jmambroi 0:3f519e465338 45
jmambroi 0:3f519e465338 46 bool ok = false;
jmambroi 0:3f519e465338 47 bool qspiOk = false;
jmambroi 0:3f519e465338 48 bool donneesModifiees = false;
jmambroi 0:3f519e465338 49 int numero = 0;
jmambroi 0:3f519e465338 50 volatile bool clicHorloge = false;// Ticker Horloge
jmambroi 0:3f519e465338 51 volatile bool clicSauvegarde = false;// Ticker Sauvegarde
jmambroi 0:3f519e465338 52
jmambroi 0:3f519e465338 53 // l'interface d'accueil
jmambroi 0:3f519e465338 54 Label attente(0, 20, "", Label::LEFT, Font12, CYAN, NOIR);
jmambroi 0:3f519e465338 55 Label marche(0, 35, "", Label::LEFT, Font12, CYAN, NOIR);
jmambroi 2:96d32c19b5be 56 Label temperatureDessiccateur(0, 50, "", Label::LEFT, Font12, CYAN, NOIR);
jmambroi 2:96d32c19b5be 57 Label temperatureConsigneDessiccateur(0, 65, "", Label::LEFT, Font12, CYAN, NOIR);
jmambroi 2:96d32c19b5be 58 Label vitesseDessiccateur(0, 80, "", Label::LEFT, Font12, CYAN, NOIR);
jmambroi 2:96d32c19b5be 59 Label etatDessiccateur(0, 95, "", Label::LEFT, Font12, ROUGE, NOIR);
jmambroi 0:3f519e465338 60 Label alerte(0, 250, "", Label::LEFT, Font12, ROUGE, NOIR);
jmambroi 0:3f519e465338 61 ButtonGroup* groupeBoutons = NULL; //
jmambroi 0:3f519e465338 62
jmambroi 0:3f519e465338 63 // Les objets
jmambroi 3:5dff448d2ed1 64 LCD_DISCO_F746NG lcd = attente.GetLcd();
jmambroi 0:3f519e465338 65 QSPI_DISCO_F746NG qspi;
jmambroi 0:3f519e465338 66 Ticker horloge;
jmambroi 0:3f519e465338 67 Ticker sauvegarde;
jmambroi 0:3f519e465338 68 //DS1820 ds1820(D14); // D14 : patte de donnees du DS1820
jmambroi 0:3f519e465338 69 DS1820 ds1820(D8); // D8 : patte de donnees du DS1820
jmambroi 0:3f519e465338 70
jmambroi 0:3f519e465338 71 int main() {
jmambroi 0:3f519e465338 72 led = 0;
jmambroi 0:3f519e465338 73 pc.baud(115200); // Connexion au pc
jmambroi 0:3f519e465338 74 // Initialisation du capteur de température
jmambroi 0:3f519e465338 75 initialiseDS1820();
jmambroi 0:3f519e465338 76 initialiseQSPI();
jmambroi 0:3f519e465338 77
jmambroi 0:3f519e465338 78 // Les interruptions
jmambroi 0:3f519e465338 79 horloge.attach(&interruptionHorloge, 1.0);
jmambroi 0:3f519e465338 80 sauvegarde.attach(&interruptionSauvegarde, 60.0);
jmambroi 0:3f519e465338 81 triacChauffage.period_ms(periodeChauffage);
jmambroi 0:3f519e465338 82 triacChauffage.pulsewidth_ms(0); // toujours éteint
jmambroi 0:3f519e465338 83 triacVentilateur.period_ms(periodeVentilateur);
jmambroi 0:3f519e465338 84 triacVentilateur.pulsewidth_ms(0); // toujours éteint
jmambroi 0:3f519e465338 85
jmambroi 0:3f519e465338 86 // set_time(1483228800); // Sun Jan 1 00:00:00 2017
jmambroi 0:3f519e465338 87 // set_time(1483228800 + 3600*24*51+ 12*3600 + 10*60 + 5); // localtime = Tue Feb 21 12:10:05 2017
jmambroi 0:3f519e465338 88 for (int i = 0; i < 11; i++) {
jmambroi 0:3f519e465338 89 tableauSeuilsTemperature[i] = temperatureConsigne - tableauSeuilsChauffage[i] * temperatureConsigne / 100; // temperatureConsigne - tableauSeuilsChauffage[i]% de temperatureConsigne
jmambroi 0:3f519e465338 90 }
jmambroi 0:3f519e465338 91 calculeLargeurImpulsion();
jmambroi 0:3f519e465338 92 char infos[TAILLE_TAMPON]; // Tampon des infos
jmambroi 0:3f519e465338 93 memset(infos, 0, TAILLE_TAMPON);
jmambroi 0:3f519e465338 94 sprintf(infos, "Seuils : %3.1f, %3.1f %3.1f %3.1f %3.1f %3.1f %3.1f %3.1f %3.1f %3.1f %3.1f\n", tableauSeuilsTemperature[0], tableauSeuilsTemperature[1], tableauSeuilsTemperature[2], tableauSeuilsTemperature[3], tableauSeuilsTemperature[4], tableauSeuilsTemperature[5], tableauSeuilsTemperature[6], tableauSeuilsTemperature[7], tableauSeuilsTemperature[8], tableauSeuilsTemperature[9], tableauSeuilsTemperature[10]);
jmambroi 0:3f519e465338 95 pc.printf(infos);
jmambroi 0:3f519e465338 96 groupeBoutons = new ButtonGroup(posXBoutonHaut, posYBoutonHaut, largeurBouton, hauteurBouton, 4, boutonsAccueil, 5, 15, 1, -1,
jmambroi 0:3f519e465338 97 Font12, BLANC, 0xFF003538, 0xFFB70068, 0xFFFF7FFF);
jmambroi 0:3f519e465338 98 // Initialisation avec l'écran d'accueil
jmambroi 3:5dff448d2ed1 99 lcd.Clear(NOIR);
jmambroi 3:5dff448d2ed1 100 lcd.SetBackColor(NOIR);
jmambroi 0:3f519e465338 101 // alerte.Draw(" ", NOIR);
jmambroi 0:3f519e465338 102 afficheInfos();
jmambroi 0:3f519e465338 103 afficheEcranAccueil();
jmambroi 0:3f519e465338 104 while(1) {
jmambroi 0:3f519e465338 105 if (clicSauvegarde && ((etat == EN_MARCHE) || (etat == EN_ATTENTE) || (etat == EN_PAUSE) || donneesModifiees)) {
jmambroi 0:3f519e465338 106 clicSauvegarde = false;
jmambroi 0:3f519e465338 107 donneesModifiees = false;
jmambroi 0:3f519e465338 108 sauveDonnees();
jmambroi 0:3f519e465338 109 }
jmambroi 0:3f519e465338 110 else {
jmambroi 0:3f519e465338 111 int num = -1;
jmambroi 0:3f519e465338 112 groupeBoutons->GetTouchedNumber(num);
jmambroi 2:96d32c19b5be 113 if (num == 3) { //réglage du dessiccateur
jmambroi 0:3f519e465338 114 //pc.printf(".");
jmambroi 0:3f519e465338 115 etatPrecedent = etat;
jmambroi 2:96d32c19b5be 116 ecranActuel = ECRAN_REGLAGE_DESSICCATEUR;
jmambroi 2:96d32c19b5be 117 afficheEcranReglageDessiccateur();
jmambroi 0:3f519e465338 118 etat = etatPrecedent;
jmambroi 0:3f519e465338 119 ecranActuel = ECRAN_ACCUEIL;
jmambroi 0:3f519e465338 120 // pc.printf("Reglage\n");
jmambroi 0:3f519e465338 121 afficheEcranAccueil();
jmambroi 0:3f519e465338 122 num = -1;
jmambroi 0:3f519e465338 123 }
jmambroi 0:3f519e465338 124 /* else if (num == 1) {
jmambroi 0:3f519e465338 125 etatPrecedent = etat;
jmambroi 0:3f519e465338 126 etat = EN_PAUSE;
jmambroi 0:3f519e465338 127 pc.printf("En pause\n");
jmambroi 0:3f519e465338 128 triacChauffage.pulsewidth_ms(0); // toujours éteint
jmambroi 0:3f519e465338 129 triacVentilateur.pulsewidth_ms(0); // toujours éteint
jmambroi 0:3f519e465338 130 afficheEcranAccueil();
jmambroi 0:3f519e465338 131 num = -1;
jmambroi 0:3f519e465338 132 }*/
jmambroi 0:3f519e465338 133 else if (num >= 0) {
jmambroi 0:3f519e465338 134 /* sprintf(infos, "->%d\n", num);
jmambroi 0:3f519e465338 135 pc.printf(infos);*/
jmambroi 0:3f519e465338 136 afficheEcranAccueil();
jmambroi 0:3f519e465338 137 num = -1;
jmambroi 0:3f519e465338 138 }
jmambroi 0:3f519e465338 139 }
jmambroi 0:3f519e465338 140 }
jmambroi 0:3f519e465338 141 }
jmambroi 0:3f519e465338 142
jmambroi 0:3f519e465338 143 void afficheEcranAccueil(void) {
jmambroi 0:3f519e465338 144 int numero = -1;
jmambroi 0:3f519e465338 145 if (etat == ARRETE) {
jmambroi 0:3f519e465338 146 groupeBoutons->Activate(0);
jmambroi 0:3f519e465338 147 groupeBoutons->Inactivate(1);
jmambroi 0:3f519e465338 148 groupeBoutons->Inactivate(2);
jmambroi 0:3f519e465338 149 groupeBoutons->Activate(3);
jmambroi 0:3f519e465338 150 }
jmambroi 0:3f519e465338 151 else if (etat == EN_ATTENTE) {
jmambroi 0:3f519e465338 152 groupeBoutons->Inactivate(0);
jmambroi 0:3f519e465338 153 groupeBoutons->Activate(1);
jmambroi 0:3f519e465338 154 groupeBoutons->Activate(2);
jmambroi 0:3f519e465338 155 groupeBoutons->Activate(3);
jmambroi 0:3f519e465338 156 }
jmambroi 0:3f519e465338 157 else if (etat == EN_MARCHE) {
jmambroi 0:3f519e465338 158 groupeBoutons->Inactivate(0);
jmambroi 0:3f519e465338 159 groupeBoutons->Activate(1);
jmambroi 0:3f519e465338 160 groupeBoutons->Activate(2);
jmambroi 0:3f519e465338 161 groupeBoutons->Activate(3);
jmambroi 0:3f519e465338 162 }
jmambroi 0:3f519e465338 163 else if (etat == EN_PAUSE) {
jmambroi 0:3f519e465338 164 groupeBoutons->Activate(0);
jmambroi 0:3f519e465338 165 groupeBoutons->Inactivate(1);
jmambroi 0:3f519e465338 166 groupeBoutons->Inactivate(2);
jmambroi 0:3f519e465338 167 groupeBoutons->Activate(3);
jmambroi 0:3f519e465338 168 }
jmambroi 0:3f519e465338 169 groupeBoutons->DrawAll();
jmambroi 3:5dff448d2ed1 170 lcd.SetBackColor(NOIR);
jmambroi 0:3f519e465338 171 groupeBoutons->GetTouchedNumber(numero);
jmambroi 0:3f519e465338 172 // wait(0.2);
jmambroi 0:3f519e465338 173 switch (numero) {
jmambroi 0:3f519e465338 174 case 0 : // Demarrer
jmambroi 3:5dff448d2ed1 175 // lcd.SetBackColor(NOIR);
jmambroi 0:3f519e465338 176 // alerte.Draw(" je passe en attente !", BLEU);
jmambroi 0:3f519e465338 177 etat = EN_ATTENTE;
jmambroi 0:3f519e465338 178 seuilChauffage = 0;
jmambroi 0:3f519e465338 179 ecranActuel = ECRAN_ACCUEIL;
jmambroi 0:3f519e465338 180 groupeBoutons->Inactivate(0);
jmambroi 0:3f519e465338 181 groupeBoutons->Activate(1);
jmambroi 0:3f519e465338 182 groupeBoutons->Activate(2);
jmambroi 0:3f519e465338 183 groupeBoutons->Activate(3);
jmambroi 0:3f519e465338 184 break;
jmambroi 0:3f519e465338 185 case 1 : // Arreter -> Suspendre
jmambroi 3:5dff448d2ed1 186 // lcd.SetBackColor(NOIR);
jmambroi 0:3f519e465338 187 // alerte.Draw(" je me mets en pause !", BLEU);
jmambroi 0:3f519e465338 188 etat = ARRETE;
jmambroi 0:3f519e465338 189 triacChauffage.pulsewidth_ms(0); // toujours éteint
jmambroi 0:3f519e465338 190 triacVentilateur.pulsewidth_ms(0); // toujours éteint
jmambroi 0:3f519e465338 191 ecranActuel = ECRAN_ACCUEIL;
jmambroi 0:3f519e465338 192 seuilChauffage = 0;
jmambroi 0:3f519e465338 193 groupeBoutons->Activate(0);
jmambroi 0:3f519e465338 194 groupeBoutons->Inactivate(1);
jmambroi 0:3f519e465338 195 groupeBoutons->Inactivate(2);
jmambroi 0:3f519e465338 196 groupeBoutons->Activate(3);
jmambroi 0:3f519e465338 197 afficheInfos();
jmambroi 0:3f519e465338 198 break;
jmambroi 0:3f519e465338 199 case 2 : // Arreter
jmambroi 3:5dff448d2ed1 200 // lcd.SetBackColor(NOIR);
jmambroi 0:3f519e465338 201 // alerte.Draw(" je m'arrete !", BLEU);
jmambroi 0:3f519e465338 202 triacChauffage.pulsewidth_ms(0); // toujours éteint
jmambroi 0:3f519e465338 203 triacVentilateur.pulsewidth_ms(0); // toujours éteint
jmambroi 0:3f519e465338 204 etat = ARRETE;
jmambroi 0:3f519e465338 205 ecranActuel = ECRAN_ACCUEIL;
jmambroi 0:3f519e465338 206 seuilChauffage = 0;
jmambroi 0:3f519e465338 207 groupeBoutons->Activate(0);
jmambroi 0:3f519e465338 208 groupeBoutons->Inactivate(1);
jmambroi 0:3f519e465338 209 groupeBoutons->Inactivate(2);
jmambroi 0:3f519e465338 210 groupeBoutons->Activate(3);
jmambroi 0:3f519e465338 211 initialiseDurees();
jmambroi 0:3f519e465338 212 afficheDureeAttenteRestante(CYAN);
jmambroi 0:3f519e465338 213 afficheDureeMarcheRestante(CYAN);
jmambroi 0:3f519e465338 214 sauveDonnees();
jmambroi 0:3f519e465338 215 break;
jmambroi 2:96d32c19b5be 216 case 3 : // Regler le dessiccateur
jmambroi 0:3f519e465338 217 // etat = ARRETE;
jmambroi 2:96d32c19b5be 218 ecranActuel = ECRAN_REGLAGE_DESSICCATEUR;
jmambroi 0:3f519e465338 219 seuilChauffage = 0;
jmambroi 0:3f519e465338 220 break;
jmambroi 0:3f519e465338 221 default :
jmambroi 0:3f519e465338 222 break;
jmambroi 0:3f519e465338 223 }
jmambroi 0:3f519e465338 224 numero = -1;
jmambroi 0:3f519e465338 225 }
jmambroi 0:3f519e465338 226
jmambroi 0:3f519e465338 227 void decrementeDuree(int* ptr) {
jmambroi 0:3f519e465338 228 int i = 3;
jmambroi 0:3f519e465338 229 bool retenue = false;
jmambroi 0:3f519e465338 230 int valeur = ptr[i];
jmambroi 0:3f519e465338 231 valeur--;
jmambroi 0:3f519e465338 232 if(valeur < 0) {
jmambroi 0:3f519e465338 233 valeur = 59; //59
jmambroi 0:3f519e465338 234 retenue = true; //il faut décrémenter les minutes
jmambroi 0:3f519e465338 235 }
jmambroi 0:3f519e465338 236 ptr[i] = valeur;
jmambroi 0:3f519e465338 237 i--; // Les minutes
jmambroi 0:3f519e465338 238 valeur = ptr[i];
jmambroi 0:3f519e465338 239 if (retenue) {
jmambroi 0:3f519e465338 240 retenue = false;
jmambroi 0:3f519e465338 241 valeur--; //on décrémente les minutes
jmambroi 0:3f519e465338 242 if (valeur < 0) {
jmambroi 0:3f519e465338 243 valeur = 59; //59
jmambroi 0:3f519e465338 244 retenue = true; //il faut décrémenter les heures
jmambroi 0:3f519e465338 245 }
jmambroi 0:3f519e465338 246 ptr[i] = valeur;
jmambroi 0:3f519e465338 247 }
jmambroi 0:3f519e465338 248 i--; // Les heures
jmambroi 0:3f519e465338 249 valeur = ptr[i];
jmambroi 0:3f519e465338 250 if (retenue) {
jmambroi 0:3f519e465338 251 retenue = false;
jmambroi 0:3f519e465338 252 valeur--; //on décrémente les heures
jmambroi 0:3f519e465338 253 if (valeur < 0) {
jmambroi 0:3f519e465338 254 valeur = 23; //23
jmambroi 0:3f519e465338 255 retenue = true; //il faut décrémenter les jours
jmambroi 0:3f519e465338 256 }
jmambroi 0:3f519e465338 257 ptr[i] = valeur;
jmambroi 0:3f519e465338 258 }
jmambroi 0:3f519e465338 259 i--; // Les jours
jmambroi 0:3f519e465338 260 valeur = ptr[i];
jmambroi 0:3f519e465338 261 if (retenue) {
jmambroi 0:3f519e465338 262 valeur--; //on décrémente les jours
jmambroi 0:3f519e465338 263 if (valeur < 0) {
jmambroi 0:3f519e465338 264 valeur = 0; // pas de jour négatifs
jmambroi 0:3f519e465338 265 }
jmambroi 0:3f519e465338 266 ptr[i] = valeur;
jmambroi 0:3f519e465338 267 }
jmambroi 0:3f519e465338 268 }
jmambroi 0:3f519e465338 269
jmambroi 0:3f519e465338 270 void afficheInfos(void) {
jmambroi 0:3f519e465338 271 if (ecranActuel == ECRAN_ACCUEIL) {
jmambroi 0:3f519e465338 272 afficheDureeAttenteRestante(CYAN);
jmambroi 0:3f519e465338 273 afficheDureeMarcheRestante(CYAN);
jmambroi 0:3f519e465338 274 afficheVitesseVentilateur(CYAN);
jmambroi 0:3f519e465338 275 afficheTemperatureConsigne(JAUNE);
jmambroi 0:3f519e465338 276 afficheTemperature(CYAN);
jmambroi 0:3f519e465338 277 afficheEtat(ROUGE);
jmambroi 0:3f519e465338 278 }
jmambroi 0:3f519e465338 279 }
jmambroi 0:3f519e465338 280
jmambroi 0:3f519e465338 281 void afficheDureeAttenteRestante(uint32_t couleur) {
jmambroi 0:3f519e465338 282 char infos[TAILLE_TAMPON]; // Tampon des infos
jmambroi 0:3f519e465338 283 memset(infos, 0, TAILLE_TAMPON);
jmambroi 0:3f519e465338 284 sprintf(infos, "Duree d'attente : %dj %dh %dmn %ds", dureeAttenteRestante[0], dureeAttenteRestante[1], dureeAttenteRestante[2], dureeAttenteRestante[3]);
jmambroi 3:5dff448d2ed1 285 lcd.SetBackColor(NOIR);
jmambroi 0:3f519e465338 286 attente.Draw(infos, CYAN);
jmambroi 0:3f519e465338 287 }
jmambroi 0:3f519e465338 288
jmambroi 0:3f519e465338 289 void afficheDureeMarcheRestante(uint32_t couleur) {
jmambroi 0:3f519e465338 290 char infos[TAILLE_TAMPON]; // Tampon des infos
jmambroi 0:3f519e465338 291 memset(infos, 0, TAILLE_TAMPON);
jmambroi 0:3f519e465338 292 sprintf(infos, "Duree marche : %dj %dh %dmn %ds", dureeMarcheRestante[0], dureeMarcheRestante[1], dureeMarcheRestante[2], dureeMarcheRestante[3]);
jmambroi 3:5dff448d2ed1 293 lcd.SetBackColor(NOIR);
jmambroi 0:3f519e465338 294 marche.Draw(infos, couleur);
jmambroi 0:3f519e465338 295 }
jmambroi 0:3f519e465338 296
jmambroi 0:3f519e465338 297 void afficheEtat(uint32_t couleur) {
jmambroi 0:3f519e465338 298 char infos[TAILLE_TAMPON]; // Tampon des infos
jmambroi 0:3f519e465338 299 memset(infos, 0, TAILLE_TAMPON);
jmambroi 2:96d32c19b5be 300 sprintf(infos, "Etat du dessiccateur : %s", etats[etat]);
jmambroi 3:5dff448d2ed1 301 lcd.SetBackColor(NOIR);
jmambroi 2:96d32c19b5be 302 etatDessiccateur.Draw(infos, couleur);
jmambroi 0:3f519e465338 303 }
jmambroi 0:3f519e465338 304
jmambroi 0:3f519e465338 305 void afficheTemperature(uint32_t couleur) {
jmambroi 0:3f519e465338 306 char infos[TAILLE_TAMPON]; // Tampon des infos
jmambroi 0:3f519e465338 307 memset(infos, 0, TAILLE_TAMPON);
jmambroi 0:3f519e465338 308 sprintf(infos, "Temperature : %.1f degres (%d, %d)", temperature, seuilChauffage, tableauDureeImpulsionChauffage[seuilChauffage]);
jmambroi 0:3f519e465338 309 // sprintf(infos, "Temperature : %.1f degres (%d)", temperature, seuilChauffage);
jmambroi 3:5dff448d2ed1 310 lcd.SetBackColor(NOIR);
jmambroi 2:96d32c19b5be 311 temperatureDessiccateur.Draw(infos, couleur);
jmambroi 0:3f519e465338 312 }
jmambroi 0:3f519e465338 313
jmambroi 0:3f519e465338 314 void afficheTemperatureConsigne(uint32_t couleur) {
jmambroi 0:3f519e465338 315 char infos[TAILLE_TAMPON]; // Tampon des infos
jmambroi 0:3f519e465338 316 memset(infos, 0, TAILLE_TAMPON);
jmambroi 0:3f519e465338 317 sprintf(infos, "Consigne temperature : %.1f degres", temperatureConsigne);
jmambroi 3:5dff448d2ed1 318 lcd.SetBackColor(NOIR);
jmambroi 2:96d32c19b5be 319 temperatureConsigneDessiccateur.Draw(infos, couleur);
jmambroi 0:3f519e465338 320 }
jmambroi 0:3f519e465338 321
jmambroi 0:3f519e465338 322 void afficheVitesseVentilateur(uint32_t couleur) {
jmambroi 0:3f519e465338 323 char infos[TAILLE_TAMPON]; // Tampon des infos
jmambroi 0:3f519e465338 324 memset(infos, 0, TAILLE_TAMPON);
jmambroi 0:3f519e465338 325 sprintf(infos, "Vitesse du ventilateur : %d (%d)", vitesseVentilateur, tableauDureeImpulsionVentilateur[vitesseVentilateur]);
jmambroi 3:5dff448d2ed1 326 lcd.SetBackColor(NOIR);
jmambroi 2:96d32c19b5be 327 vitesseDessiccateur.Draw(infos, couleur);
jmambroi 0:3f519e465338 328 }
jmambroi 0:3f519e465338 329
jmambroi 0:3f519e465338 330 void initialiseDonnees(void) {
jmambroi 0:3f519e465338 331 memset(tamponQSPI, 0, TAILLE_TAMPON);
jmambroi 0:3f519e465338 332 if (qspi.Read(tamponQSPI, ADRESSE_LECTURE_ECRITURE, TAILLE_TAMPON) != QSPI_OK) {
jmambroi 0:3f519e465338 333 pc.printf("Impossible de lire les donnees dans la memoire QSPI\n");
jmambroi 0:3f519e465338 334 qspiOk = false;
jmambroi 0:3f519e465338 335 }
jmambroi 0:3f519e465338 336 else {
jmambroi 0:3f519e465338 337 dureeAttenteTotale[0] = tamponQSPI[4];
jmambroi 0:3f519e465338 338 dureeAttenteTotale[1] = tamponQSPI[5];
jmambroi 0:3f519e465338 339 dureeAttenteTotale[2] = tamponQSPI[6];
jmambroi 0:3f519e465338 340 dureeAttenteTotale[3] = tamponQSPI[7];
jmambroi 0:3f519e465338 341 dureeAttenteRestante[0] = tamponQSPI[8];
jmambroi 0:3f519e465338 342 dureeAttenteRestante[1] = tamponQSPI[9];
jmambroi 0:3f519e465338 343 dureeAttenteRestante[2] = tamponQSPI[10];
jmambroi 0:3f519e465338 344 dureeAttenteRestante[3] = tamponQSPI[11];
jmambroi 0:3f519e465338 345 dureeMarcheTotale[0] = tamponQSPI[12];
jmambroi 0:3f519e465338 346 dureeMarcheTotale[1] = tamponQSPI[13];
jmambroi 0:3f519e465338 347 dureeMarcheTotale[2] = tamponQSPI[14];
jmambroi 0:3f519e465338 348 dureeMarcheTotale[3] = tamponQSPI[15];
jmambroi 0:3f519e465338 349 dureeMarcheRestante[0] = tamponQSPI[16];
jmambroi 0:3f519e465338 350 dureeMarcheRestante[1] = tamponQSPI[17];
jmambroi 0:3f519e465338 351 dureeMarcheRestante[2] = tamponQSPI[18];
jmambroi 0:3f519e465338 352 dureeMarcheRestante[3] = tamponQSPI[19];
jmambroi 0:3f519e465338 353 etat = tamponQSPI[20]; // etat
jmambroi 0:3f519e465338 354 temperatureConsigne = (float)tamponQSPI[22]; // temp
jmambroi 0:3f519e465338 355 vitesseVentilateur = tamponQSPI[24]; // vitesse du ventilateur
jmambroi 0:3f519e465338 356 pc.printf("Valeurs lues -> attente : %u, %u, %u, %u, %u, %u, %u, %u, marche : %u, %u, %u, %u, %u, %u, %u, %u, etat %u(%u), temp : %u.%u, ventilo : %u\n", tamponQSPI[4], tamponQSPI[5], tamponQSPI[6], tamponQSPI[7], tamponQSPI[8], tamponQSPI[9], tamponQSPI[10], tamponQSPI[11],
jmambroi 0:3f519e465338 357 tamponQSPI[12], tamponQSPI[13], tamponQSPI[14], tamponQSPI[15], tamponQSPI[16], tamponQSPI[17], tamponQSPI[18], tamponQSPI[19], tamponQSPI[20], tamponQSPI[3], tamponQSPI[22] , tamponQSPI[23] , tamponQSPI[24]);
jmambroi 0:3f519e465338 358 qspiOk = true;
jmambroi 0:3f519e465338 359 }
jmambroi 0:3f519e465338 360 }
jmambroi 0:3f519e465338 361
jmambroi 0:3f519e465338 362 void initialiseDurees(void) {
jmambroi 0:3f519e465338 363 for (int i = 0; i < 4; i++) {
jmambroi 0:3f519e465338 364 dureeAttenteRestante[i] = dureeAttenteTotale[i];
jmambroi 0:3f519e465338 365 dureeMarcheRestante[i] = dureeMarcheTotale[i];
jmambroi 0:3f519e465338 366 }
jmambroi 0:3f519e465338 367 }
jmambroi 0:3f519e465338 368
jmambroi 0:3f519e465338 369 void interruptionHorloge(void) {
jmambroi 0:3f519e465338 370 clicHorloge = true;
jmambroi 0:3f519e465338 371 if (ecranActuel == ECRAN_ACCUEIL) {
jmambroi 0:3f519e465338 372 afficheInfos();
jmambroi 0:3f519e465338 373 }
jmambroi 0:3f519e465338 374 if (ok) {
jmambroi 0:3f519e465338 375 temperature = ds1820.read();
jmambroi 0:3f519e465338 376 ds1820.startConversion();
jmambroi 0:3f519e465338 377 }
jmambroi 0:3f519e465338 378 if (etat == ARRETE) {
jmambroi 0:3f519e465338 379 if (etatPrecedent != etat) {
jmambroi 0:3f519e465338 380 triacChauffage.pulsewidth_ms(0); // toujours éteint
jmambroi 0:3f519e465338 381 triacVentilateur.pulsewidth_ms(0); // toujours éteint
jmambroi 0:3f519e465338 382 if (ecranActuel == ECRAN_ACCUEIL) {
jmambroi 0:3f519e465338 383 afficheEtat(ROUGE);
jmambroi 0:3f519e465338 384 }
jmambroi 0:3f519e465338 385 etatPrecedent = etat;
jmambroi 0:3f519e465338 386 }
jmambroi 0:3f519e465338 387 }
jmambroi 0:3f519e465338 388 else if (etat == EN_ATTENTE) {
jmambroi 0:3f519e465338 389 if ((dureeAttenteRestante[0] <= 0) && (dureeAttenteRestante[1] <= 0) && (dureeAttenteRestante[2] <= 0) && (dureeAttenteRestante[3] <= 0)) {
jmambroi 0:3f519e465338 390 if (ecranActuel == ECRAN_ACCUEIL) {
jmambroi 0:3f519e465338 391 // alerte.Draw(" je passe en marche !", VERT);
jmambroi 0:3f519e465338 392 }
jmambroi 0:3f519e465338 393 etat = EN_MARCHE;
jmambroi 0:3f519e465338 394 etatPrecedent = EN_ATTENTE;
jmambroi 0:3f519e465338 395 sauveDonnees();
jmambroi 0:3f519e465338 396 calculeLargeurImpulsion();
jmambroi 0:3f519e465338 397 triacChauffage.pulsewidth_ms(tableauDureeImpulsionChauffage[seuilChauffage]); // marche
jmambroi 0:3f519e465338 398 triacVentilateur.pulsewidth_ms(tableauDureeImpulsionVentilateur[vitesseVentilateur]); // marche
jmambroi 0:3f519e465338 399 dureeAttenteRestante[0] = 0;
jmambroi 0:3f519e465338 400 dureeAttenteRestante[1] = 0;
jmambroi 0:3f519e465338 401 dureeAttenteRestante[2] = 0;
jmambroi 0:3f519e465338 402 dureeAttenteRestante[3] = 0;
jmambroi 0:3f519e465338 403 }
jmambroi 0:3f519e465338 404 else {
jmambroi 0:3f519e465338 405 decrementeDuree(dureeAttenteRestante);
jmambroi 0:3f519e465338 406 if (ecranActuel == ECRAN_ACCUEIL) {
jmambroi 0:3f519e465338 407 afficheDureeAttenteRestante(CYAN);
jmambroi 0:3f519e465338 408 afficheVitesseVentilateur(CYAN);
jmambroi 0:3f519e465338 409 }
jmambroi 0:3f519e465338 410 }
jmambroi 0:3f519e465338 411 if (etatPrecedent != etat) {
jmambroi 0:3f519e465338 412 if (ecranActuel == ECRAN_ACCUEIL) {
jmambroi 0:3f519e465338 413 afficheEtat(ROUGE);
jmambroi 0:3f519e465338 414 }
jmambroi 0:3f519e465338 415 etatPrecedent = etat;
jmambroi 0:3f519e465338 416 }
jmambroi 0:3f519e465338 417 }
jmambroi 0:3f519e465338 418 else if (etat == EN_MARCHE) {
jmambroi 0:3f519e465338 419 if ((dureeMarcheRestante[0] <= 0) && (dureeMarcheRestante[1] <= 0) && (dureeMarcheRestante[2] <= 0) && (dureeMarcheRestante[3] <= 0)) {
jmambroi 0:3f519e465338 420 /* if (ecranActuel == ECRAN_ACCUEIL) {
jmambroi 3:5dff448d2ed1 421 lcd.SetBackColor(NOIR);
jmambroi 0:3f519e465338 422 alerte.Draw(" je m'arrete !", BLEU);
jmambroi 0:3f519e465338 423 }*/
jmambroi 0:3f519e465338 424
jmambroi 0:3f519e465338 425
jmambroi 0:3f519e465338 426 etat = ARRETE;
jmambroi 0:3f519e465338 427 seuilChauffage = 0;
jmambroi 0:3f519e465338 428 etatPrecedent = EN_MARCHE;
jmambroi 0:3f519e465338 429 triacChauffage.pulsewidth_ms(0); // toujours éteint
jmambroi 0:3f519e465338 430 triacVentilateur.pulsewidth_ms(0); // toujours éteint
jmambroi 0:3f519e465338 431 initialiseDurees();
jmambroi 0:3f519e465338 432 sauveDonnees();
jmambroi 0:3f519e465338 433 clicSauvegarde = true;
jmambroi 0:3f519e465338 434 afficheDureeAttenteRestante(CYAN);
jmambroi 0:3f519e465338 435 afficheDureeMarcheRestante(CYAN);
jmambroi 0:3f519e465338 436 groupeBoutons->Activate(0);
jmambroi 0:3f519e465338 437 groupeBoutons->Inactivate(1);
jmambroi 0:3f519e465338 438 groupeBoutons->Inactivate(2);
jmambroi 0:3f519e465338 439 groupeBoutons->Activate(3);
jmambroi 0:3f519e465338 440 groupeBoutons->Inactivate(4);
jmambroi 0:3f519e465338 441 }
jmambroi 0:3f519e465338 442 else {
jmambroi 0:3f519e465338 443 decrementeDuree(dureeMarcheRestante);
jmambroi 0:3f519e465338 444 if (ecranActuel == ECRAN_ACCUEIL) {
jmambroi 0:3f519e465338 445 calculeLargeurImpulsion();
jmambroi 0:3f519e465338 446 triacChauffage.pulsewidth_ms(tableauDureeImpulsionChauffage[seuilChauffage]); // marche
jmambroi 0:3f519e465338 447 triacVentilateur.pulsewidth_ms(tableauDureeImpulsionVentilateur[vitesseVentilateur]); // marche
jmambroi 0:3f519e465338 448 afficheDureeMarcheRestante(CYAN);
jmambroi 0:3f519e465338 449 }
jmambroi 0:3f519e465338 450 }
jmambroi 0:3f519e465338 451 if (etatPrecedent != etat) {
jmambroi 0:3f519e465338 452 afficheEtat(ROUGE);
jmambroi 0:3f519e465338 453 etatPrecedent = etat;
jmambroi 0:3f519e465338 454 }
jmambroi 0:3f519e465338 455 }
jmambroi 0:3f519e465338 456 else if (etat == EN_PAUSE) {
jmambroi 0:3f519e465338 457 pc.printf("\nJe suis en pause\n");
jmambroi 0:3f519e465338 458 triacChauffage.pulsewidth_ms(0); // toujours éteint
jmambroi 0:3f519e465338 459 triacVentilateur.pulsewidth_ms(0); // toujours éteint
jmambroi 0:3f519e465338 460 etat = ARRETE;
jmambroi 0:3f519e465338 461 }
jmambroi 0:3f519e465338 462 else {
jmambroi 0:3f519e465338 463 if ((ecranActuel == ECRAN_ACCUEIL) && (etat == EN_MARCHE)) {
jmambroi 0:3f519e465338 464 calculeLargeurImpulsion();
jmambroi 0:3f519e465338 465 triacChauffage.pulsewidth_ms(tableauDureeImpulsionChauffage[seuilChauffage]); // marche
jmambroi 0:3f519e465338 466 triacVentilateur.pulsewidth_ms(tableauDureeImpulsionVentilateur[vitesseVentilateur]); // marche
jmambroi 0:3f519e465338 467 }
jmambroi 0:3f519e465338 468 }
jmambroi 0:3f519e465338 469 clicHorloge = false;
jmambroi 0:3f519e465338 470 }
jmambroi 0:3f519e465338 471
jmambroi 2:96d32c19b5be 472 void afficheEcranReglageDessiccateur(void) {
jmambroi 3:5dff448d2ed1 473 lcd.Clear(NOIR);
jmambroi 0:3f519e465338 474 triacChauffage.pulsewidth_ms(0); // toujours éteint
jmambroi 0:3f519e465338 475 triacVentilateur.pulsewidth_ms(0); // toujours éteint
jmambroi 0:3f519e465338 476
jmambroi 0:3f519e465338 477 // alerte.Draw(etats[etat], VERT);
jmambroi 0:3f519e465338 478 Button ok(100, 225, 100, 40, "Valider", Font16, GRIS_SOMBRE, GuiBase::ENUM_BACK, VERT, ROUGE);
jmambroi 0:3f519e465338 479 Button annuler(300, 225, 100, 40, "Annuler", Font16, VERT, GuiBase::ENUM_BACK, ROUGE, BLEU);
jmambroi 0:3f519e465338 480 // Durée d'attente
jmambroi 0:3f519e465338 481 Label duree(15, 0, "Duree d'attente", Label::LEFT, Font16);
jmambroi 0:3f519e465338 482 Button plusJ(10, 20, 48, 40, "+");
jmambroi 0:3f519e465338 483 Button moinsJ(10, 90, 48, 40, "-");
jmambroi 0:3f519e465338 484 Button plusH(60, 20, 48, 40, "+");
jmambroi 0:3f519e465338 485 Button moinsH(60, 90, 48, 40, "-");
jmambroi 0:3f519e465338 486 Button plusM(110, 20, 48, 40, "+");
jmambroi 0:3f519e465338 487 Button moinsM(110, 90, 48, 40, "-");
jmambroi 0:3f519e465338 488 Button plusS(160, 20, 48, 40, "+");
jmambroi 0:3f519e465338 489 Button moinsS(160, 90, 48, 40, "-");
jmambroi 0:3f519e465338 490 Label jour(12, 70, "", Label::LEFT, Font16);
jmambroi 0:3f519e465338 491 Label heure(62, 70, "", Label::LEFT, Font16);
jmambroi 0:3f519e465338 492 Label minute(112, 70, "", Label::LEFT, Font16);
jmambroi 0:3f519e465338 493 Label seconde(162, 70, "", Label::LEFT, Font16);
jmambroi 0:3f519e465338 494 // Durée de chauffage
jmambroi 0:3f519e465338 495 Label dureec(260, 0, "Duree de chauffage", Label::LEFT, Font16);
jmambroi 0:3f519e465338 496 Button plusJc(260, 20, 48, 40, "+");
jmambroi 0:3f519e465338 497 Button moinsJc(260, 90, 48, 40, "-");
jmambroi 0:3f519e465338 498 Button plusHc(310, 20, 48, 40, "+");
jmambroi 0:3f519e465338 499 Button moinsHc(310, 90, 48, 40, "-");
jmambroi 0:3f519e465338 500 Button plusMc(360, 20, 48, 40, "+");
jmambroi 0:3f519e465338 501 Button moinsMc(360, 90, 48, 40, "-");
jmambroi 0:3f519e465338 502 Button plusSc(410, 20, 48, 40, "+");
jmambroi 0:3f519e465338 503 Button moinsSc(410, 90, 48, 40, "-");
jmambroi 0:3f519e465338 504 Label jourc(262, 70, "", Label::LEFT, Font16);
jmambroi 0:3f519e465338 505 Label heurec(312, 70, "", Label::LEFT, Font16);
jmambroi 0:3f519e465338 506 Label minutec(362, 70, "", Label::LEFT, Font16);
jmambroi 0:3f519e465338 507 Label secondec(412, 70, "", Label::LEFT, Font16);
jmambroi 0:3f519e465338 508
jmambroi 0:3f519e465338 509 // Réglage de la température
jmambroi 3:5dff448d2ed1 510 lcd.SetBackColor(NOIR);
jmambroi 0:3f519e465338 511 Label temperature(10, 140, "Temperature : ", Label::LEFT, Font16);
jmambroi 3:5dff448d2ed1 512 lcd.SetBackColor(NOIR);
jmambroi 0:3f519e465338 513 SeekBar barreTemperature(10, 190, 200, 20.0, 60.0, temperatureConsigne,
jmambroi 0:3f519e465338 514 "20", "40", "60", 0xFFB0B0FF, 30, 4, GRIS_CLAIR, 0xFFB0B0B0, NOIR);
jmambroi 3:5dff448d2ed1 515 lcd.SetBackColor(NOIR);
jmambroi 0:3f519e465338 516 NumericLabel<int> labelTemperature(180, 140, "%3d", (int) barreTemperature.GetValue());
jmambroi 0:3f519e465338 517
jmambroi 0:3f519e465338 518 // Réglage de la vitesse du vetitateur
jmambroi 3:5dff448d2ed1 519 lcd.SetBackColor(NOIR);
jmambroi 0:3f519e465338 520 Label vitesse(250, 140, "Vitesse : ", Label::LEFT, Font16);
jmambroi 3:5dff448d2ed1 521 lcd.SetBackColor(NOIR);
jmambroi 0:3f519e465338 522 SeekBar barreVitesse(250, 190, 200, 0, 10, vitesseVentilateur,
jmambroi 0:3f519e465338 523 "0", "5", "10", 0xFFB0B0FF, 40, 5, GRIS_CLAIR, 0xFFB0B0B0, NOIR);
jmambroi 3:5dff448d2ed1 524 lcd.SetBackColor(NOIR);
jmambroi 0:3f519e465338 525 NumericLabel<int> labelVitesse(400, 140, "%3d", (int) barreVitesse.GetValue());
jmambroi 0:3f519e465338 526
jmambroi 0:3f519e465338 527 uint8_t j, h, m, s;
jmambroi 0:3f519e465338 528 uint8_t jc, hc, mc, sc;
jmambroi 0:3f519e465338 529 if (etat == ARRETE) {
jmambroi 0:3f519e465338 530 j = dureeAttenteTotale[0];
jmambroi 0:3f519e465338 531 h = dureeAttenteTotale[1];
jmambroi 0:3f519e465338 532 m = dureeAttenteTotale[2];
jmambroi 0:3f519e465338 533 s = dureeAttenteTotale[3];
jmambroi 0:3f519e465338 534 jc = dureeMarcheTotale[0];
jmambroi 0:3f519e465338 535 hc = dureeMarcheTotale[1];
jmambroi 0:3f519e465338 536 mc = dureeMarcheTotale[2];
jmambroi 0:3f519e465338 537 sc = dureeMarcheTotale[3];
jmambroi 0:3f519e465338 538 }
jmambroi 0:3f519e465338 539 else if (etat == EN_ATTENTE) {
jmambroi 0:3f519e465338 540 j = dureeAttenteRestante[0];
jmambroi 0:3f519e465338 541 h = dureeAttenteRestante[1];
jmambroi 0:3f519e465338 542 m = dureeAttenteRestante[2];
jmambroi 0:3f519e465338 543 s = dureeAttenteRestante[3];
jmambroi 0:3f519e465338 544 jc = dureeMarcheTotale[0];
jmambroi 0:3f519e465338 545 hc = dureeMarcheTotale[1];
jmambroi 0:3f519e465338 546 mc = dureeMarcheTotale[2];
jmambroi 0:3f519e465338 547 sc = dureeMarcheTotale[3];
jmambroi 0:3f519e465338 548 }
jmambroi 0:3f519e465338 549 else if (etat == EN_MARCHE) {
jmambroi 0:3f519e465338 550 j = dureeAttenteTotale[0];
jmambroi 0:3f519e465338 551 h = dureeAttenteTotale[1];
jmambroi 0:3f519e465338 552 m = dureeAttenteTotale[2];
jmambroi 0:3f519e465338 553 s = dureeAttenteTotale[3];
jmambroi 0:3f519e465338 554 jc = dureeMarcheRestante[0];
jmambroi 0:3f519e465338 555 hc = dureeMarcheRestante[1];
jmambroi 0:3f519e465338 556 mc = dureeMarcheRestante[2];
jmambroi 0:3f519e465338 557 sc = dureeMarcheRestante[3];
jmambroi 0:3f519e465338 558 }
jmambroi 0:3f519e465338 559 else if (etat == EN_PAUSE) {
jmambroi 0:3f519e465338 560 j = dureeAttenteTotale[0];
jmambroi 0:3f519e465338 561 h = dureeAttenteTotale[1];
jmambroi 0:3f519e465338 562 m = dureeAttenteTotale[2];
jmambroi 0:3f519e465338 563 s = dureeAttenteTotale[3];
jmambroi 0:3f519e465338 564 jc = dureeMarcheRestante[0];
jmambroi 0:3f519e465338 565 hc = dureeMarcheRestante[1];
jmambroi 0:3f519e465338 566 mc = dureeMarcheRestante[2];
jmambroi 0:3f519e465338 567 sc = dureeMarcheRestante[3];
jmambroi 0:3f519e465338 568 }
jmambroi 0:3f519e465338 569 char tampon[TAILLE_TAMPON];
jmambroi 0:3f519e465338 570 sprintf(tampon, "%us", s);
jmambroi 0:3f519e465338 571 seconde.Draw(tampon);
jmambroi 0:3f519e465338 572 sprintf(tampon, "%umn", m);
jmambroi 0:3f519e465338 573 minute.Draw(tampon);
jmambroi 0:3f519e465338 574 sprintf(tampon, "%uh", h);
jmambroi 0:3f519e465338 575 heure.Draw(tampon);
jmambroi 0:3f519e465338 576 sprintf(tampon, "%uj", j);
jmambroi 0:3f519e465338 577 jour.Draw(tampon);
jmambroi 0:3f519e465338 578
jmambroi 0:3f519e465338 579 sprintf(tampon, "%us", sc);
jmambroi 0:3f519e465338 580 secondec.Draw(tampon);
jmambroi 0:3f519e465338 581 sprintf(tampon, "%umn", mc);
jmambroi 0:3f519e465338 582 minutec.Draw(tampon);
jmambroi 0:3f519e465338 583 sprintf(tampon, "%uh", hc);
jmambroi 0:3f519e465338 584 heurec.Draw(tampon);
jmambroi 0:3f519e465338 585 sprintf(tampon, "%uj", jc);
jmambroi 0:3f519e465338 586 jourc.Draw(tampon);
jmambroi 0:3f519e465338 587
jmambroi 0:3f519e465338 588 while (!(ok.Touched() || annuler.Touched())) {
jmambroi 0:3f519e465338 589 if (barreTemperature.Slide()) {
jmambroi 3:5dff448d2ed1 590 lcd.SetBackColor(NOIR);
jmambroi 0:3f519e465338 591 labelTemperature.Draw("%3d", (int) barreTemperature.GetValue());
jmambroi 0:3f519e465338 592 }
jmambroi 0:3f519e465338 593 if (barreVitesse.Slide()) {
jmambroi 3:5dff448d2ed1 594 lcd.SetBackColor(NOIR);
jmambroi 0:3f519e465338 595 labelVitesse.Draw("%3d", (int) barreVitesse.GetValue());
jmambroi 0:3f519e465338 596 }
jmambroi 0:3f519e465338 597 if (plusJ.Touched()) {
jmambroi 0:3f519e465338 598 if (j < 31)
jmambroi 0:3f519e465338 599 j++;
jmambroi 0:3f519e465338 600 sprintf(tampon, "%uj", j);
jmambroi 0:3f519e465338 601 jour.Draw(tampon);
jmambroi 0:3f519e465338 602 wait(0.2);
jmambroi 0:3f519e465338 603 plusJ.Draw();
jmambroi 0:3f519e465338 604 }
jmambroi 0:3f519e465338 605 else if (plusH.Touched()) {
jmambroi 0:3f519e465338 606 if (h < 23)
jmambroi 0:3f519e465338 607 h++;
jmambroi 0:3f519e465338 608 else if (h >= 23)
jmambroi 0:3f519e465338 609 h = 0;
jmambroi 0:3f519e465338 610 sprintf(tampon, "%uh", h);
jmambroi 0:3f519e465338 611 heure.Draw(tampon);
jmambroi 0:3f519e465338 612 wait(0.2);
jmambroi 0:3f519e465338 613 plusH.Draw();
jmambroi 0:3f519e465338 614 }
jmambroi 0:3f519e465338 615 else if (plusM.Touched()) {
jmambroi 0:3f519e465338 616 if (m < 59)
jmambroi 0:3f519e465338 617 m++;
jmambroi 0:3f519e465338 618 else if (m >= 59)
jmambroi 0:3f519e465338 619 m = 0;
jmambroi 0:3f519e465338 620 sprintf(tampon, "%umn", m);
jmambroi 0:3f519e465338 621 minute.Draw(tampon);
jmambroi 0:3f519e465338 622 wait(0.2);
jmambroi 0:3f519e465338 623 plusM.Draw();
jmambroi 0:3f519e465338 624 }
jmambroi 0:3f519e465338 625 else if (plusS.Touched()) {
jmambroi 0:3f519e465338 626 if (s < 59)
jmambroi 0:3f519e465338 627 s++;
jmambroi 0:3f519e465338 628 else if (s >= 59)
jmambroi 0:3f519e465338 629 s = 0;
jmambroi 0:3f519e465338 630 sprintf(tampon, "%us", s);
jmambroi 0:3f519e465338 631 seconde.Draw(tampon);
jmambroi 0:3f519e465338 632 wait(0.2);
jmambroi 0:3f519e465338 633 plusS.Draw();
jmambroi 0:3f519e465338 634 }
jmambroi 0:3f519e465338 635 else if (moinsJ.Touched()) {
jmambroi 0:3f519e465338 636 if (j > 0)
jmambroi 0:3f519e465338 637 j--;
jmambroi 0:3f519e465338 638 sprintf(tampon, "%uj", j);
jmambroi 0:3f519e465338 639 jour.Draw(tampon);
jmambroi 0:3f519e465338 640 wait(0.2);
jmambroi 0:3f519e465338 641 moinsJ.Draw();
jmambroi 0:3f519e465338 642 }
jmambroi 0:3f519e465338 643 else if (moinsH.Touched()) {
jmambroi 0:3f519e465338 644 if (h > 0)
jmambroi 0:3f519e465338 645 h--;
jmambroi 0:3f519e465338 646 else if (h <= 0)
jmambroi 0:3f519e465338 647 h = 23;
jmambroi 0:3f519e465338 648 sprintf(tampon, "%uh", h);
jmambroi 0:3f519e465338 649 heure.Draw(tampon);
jmambroi 0:3f519e465338 650 wait(0.2);
jmambroi 0:3f519e465338 651 moinsH.Draw();
jmambroi 0:3f519e465338 652 }
jmambroi 0:3f519e465338 653 else if (moinsM.Touched()) {
jmambroi 0:3f519e465338 654 if (m > 0)
jmambroi 0:3f519e465338 655 m--;
jmambroi 0:3f519e465338 656 else if (m <= 0)
jmambroi 0:3f519e465338 657 m = 59;
jmambroi 0:3f519e465338 658 sprintf(tampon, "%umn", m);
jmambroi 0:3f519e465338 659 minute.Draw(tampon);
jmambroi 0:3f519e465338 660 wait(0.2);
jmambroi 0:3f519e465338 661 moinsM.Draw();
jmambroi 0:3f519e465338 662 }
jmambroi 0:3f519e465338 663 else if (moinsS.Touched()) {
jmambroi 0:3f519e465338 664 if (s > 0)
jmambroi 0:3f519e465338 665 s--;
jmambroi 0:3f519e465338 666 else if (s <= 0)
jmambroi 0:3f519e465338 667 s = 59;
jmambroi 0:3f519e465338 668 sprintf(tampon, "%us", s);
jmambroi 0:3f519e465338 669 seconde.Draw(tampon);
jmambroi 0:3f519e465338 670 wait(0.2);
jmambroi 0:3f519e465338 671 moinsS.Draw();
jmambroi 0:3f519e465338 672 }
jmambroi 0:3f519e465338 673 // Durée chauffage, plus
jmambroi 0:3f519e465338 674 else if (plusJc.Touched()) {
jmambroi 0:3f519e465338 675 if (jc < 31)
jmambroi 0:3f519e465338 676 jc++;
jmambroi 0:3f519e465338 677 sprintf(tampon, "%uj", jc);
jmambroi 0:3f519e465338 678 jourc.Draw(tampon);
jmambroi 0:3f519e465338 679 wait(0.2);
jmambroi 0:3f519e465338 680 plusJc.Draw();
jmambroi 0:3f519e465338 681 }
jmambroi 0:3f519e465338 682 else if (plusHc.Touched()) {
jmambroi 0:3f519e465338 683 if (hc < 23)
jmambroi 0:3f519e465338 684 hc++;
jmambroi 0:3f519e465338 685 else if (hc >= 23)
jmambroi 0:3f519e465338 686 hc = 0;
jmambroi 0:3f519e465338 687 sprintf(tampon, "%uh", hc);
jmambroi 0:3f519e465338 688 heurec.Draw(tampon);
jmambroi 0:3f519e465338 689 wait(0.2);
jmambroi 0:3f519e465338 690 plusHc.Draw();
jmambroi 0:3f519e465338 691 }
jmambroi 0:3f519e465338 692 else if (plusMc.Touched()) {
jmambroi 0:3f519e465338 693 if (mc < 59)
jmambroi 0:3f519e465338 694 mc++;
jmambroi 0:3f519e465338 695 else if (mc >= 59)
jmambroi 0:3f519e465338 696 mc = 0;
jmambroi 0:3f519e465338 697 sprintf(tampon, "%umn", mc);
jmambroi 0:3f519e465338 698 minutec.Draw(tampon);
jmambroi 0:3f519e465338 699 wait(0.2);
jmambroi 0:3f519e465338 700 plusMc.Draw();
jmambroi 0:3f519e465338 701 }
jmambroi 0:3f519e465338 702 else if (plusSc.Touched()) {
jmambroi 0:3f519e465338 703 if (sc < 59)
jmambroi 0:3f519e465338 704 sc++;
jmambroi 0:3f519e465338 705 else if (sc >= 59)
jmambroi 0:3f519e465338 706 sc = 0;
jmambroi 0:3f519e465338 707 sprintf(tampon, "%us", sc);
jmambroi 0:3f519e465338 708 secondec.Draw(tampon);
jmambroi 0:3f519e465338 709 wait(0.2);
jmambroi 0:3f519e465338 710 plusSc.Draw();
jmambroi 0:3f519e465338 711 }
jmambroi 0:3f519e465338 712 // Moins
jmambroi 0:3f519e465338 713 else if (moinsJc.Touched()) {
jmambroi 0:3f519e465338 714 if (jc > 0)
jmambroi 0:3f519e465338 715 jc--;
jmambroi 0:3f519e465338 716 sprintf(tampon, "%uj", jc);
jmambroi 0:3f519e465338 717 jourc.Draw(tampon);
jmambroi 0:3f519e465338 718 wait(0.2);
jmambroi 0:3f519e465338 719 moinsJc.Draw();
jmambroi 0:3f519e465338 720 }
jmambroi 0:3f519e465338 721 else if (moinsHc.Touched()) {
jmambroi 0:3f519e465338 722 if (hc > 0)
jmambroi 0:3f519e465338 723 hc--;
jmambroi 0:3f519e465338 724 else if (hc <= 0)
jmambroi 0:3f519e465338 725 hc = 23;
jmambroi 0:3f519e465338 726 sprintf(tampon, "%uh", hc);
jmambroi 0:3f519e465338 727 heurec.Draw(tampon);
jmambroi 0:3f519e465338 728 wait(0.2);
jmambroi 0:3f519e465338 729 moinsHc.Draw();
jmambroi 0:3f519e465338 730 }
jmambroi 0:3f519e465338 731 else if (moinsMc.Touched()) {
jmambroi 0:3f519e465338 732 if (mc > 0)
jmambroi 0:3f519e465338 733 mc--;
jmambroi 0:3f519e465338 734 else if (mc <= 0)
jmambroi 0:3f519e465338 735 mc = 59;
jmambroi 0:3f519e465338 736 sprintf(tampon, "%umn", mc);
jmambroi 0:3f519e465338 737 minutec.Draw(tampon);
jmambroi 0:3f519e465338 738 wait(0.2);
jmambroi 0:3f519e465338 739 moinsMc.Draw();
jmambroi 0:3f519e465338 740 }
jmambroi 0:3f519e465338 741 else if (moinsSc.Touched()) {
jmambroi 0:3f519e465338 742 if (sc > 0)
jmambroi 0:3f519e465338 743 sc--;
jmambroi 0:3f519e465338 744 else if (sc <= 0)
jmambroi 0:3f519e465338 745 sc = 59;
jmambroi 0:3f519e465338 746 sprintf(tampon, "%us", sc);
jmambroi 0:3f519e465338 747 secondec.Draw(tampon);
jmambroi 0:3f519e465338 748 wait(0.2);
jmambroi 0:3f519e465338 749 moinsSc.Draw();
jmambroi 0:3f519e465338 750 }
jmambroi 0:3f519e465338 751 }
jmambroi 0:3f519e465338 752 if (ok.Touched()) {
jmambroi 0:3f519e465338 753 temperatureConsigne = (int) barreTemperature.GetValue();
jmambroi 0:3f519e465338 754 vitesseVentilateur = (int) barreVitesse.GetValue();
jmambroi 0:3f519e465338 755 // Il faut que la vitesse du ventilateur soit cohérente par rapport à la puissance de chauffage
jmambroi 0:3f519e465338 756 if ((temperatureConsigne >= 50) && (vitesseVentilateur < 10))
jmambroi 0:3f519e465338 757 vitesseVentilateur = 10;
jmambroi 0:3f519e465338 758 else if ((temperatureConsigne >= 40) && (vitesseVentilateur < 5))
jmambroi 0:3f519e465338 759 vitesseVentilateur = 5;
jmambroi 0:3f519e465338 760 else if ((temperatureConsigne >= 30) && (vitesseVentilateur < 3))
jmambroi 0:3f519e465338 761 vitesseVentilateur = 3;
jmambroi 0:3f519e465338 762 for (int i = 0; i < 11; i++) {
jmambroi 0:3f519e465338 763 tableauSeuilsTemperature[i] = temperatureConsigne - tableauSeuilsChauffage[i] * temperatureConsigne / 100; // temperatureConsigne - tableauSeuilsChauffage[i]% de temperatureConsigne
jmambroi 0:3f519e465338 764 }
jmambroi 0:3f519e465338 765 if (etat == ARRETE) {
jmambroi 0:3f519e465338 766 triacChauffage.pulsewidth_ms(0);
jmambroi 0:3f519e465338 767 triacVentilateur.pulsewidth_ms(0);
jmambroi 0:3f519e465338 768 dureeAttenteTotale[0] = j;
jmambroi 0:3f519e465338 769 dureeAttenteTotale[1] = h;
jmambroi 0:3f519e465338 770 dureeAttenteTotale[2] = m;
jmambroi 0:3f519e465338 771 dureeAttenteTotale[3] = s;
jmambroi 0:3f519e465338 772 dureeMarcheTotale[0] = jc;
jmambroi 0:3f519e465338 773 dureeMarcheTotale[1] = hc;
jmambroi 0:3f519e465338 774 dureeMarcheTotale[2] = mc;
jmambroi 0:3f519e465338 775 dureeMarcheTotale[3] = sc;
jmambroi 0:3f519e465338 776 dureeAttenteRestante[0] = j;
jmambroi 0:3f519e465338 777 dureeAttenteRestante[1] = h;
jmambroi 0:3f519e465338 778 dureeAttenteRestante[2] = m;
jmambroi 0:3f519e465338 779 dureeAttenteRestante[3] = s;
jmambroi 0:3f519e465338 780 dureeMarcheRestante[0] = jc;
jmambroi 0:3f519e465338 781 dureeMarcheRestante[1] = hc;
jmambroi 0:3f519e465338 782 dureeMarcheRestante[2] = mc;
jmambroi 0:3f519e465338 783 dureeMarcheRestante[3] = sc;
jmambroi 0:3f519e465338 784 }
jmambroi 0:3f519e465338 785 else if (etat == EN_ATTENTE) {
jmambroi 0:3f519e465338 786 triacChauffage.pulsewidth_ms(0);
jmambroi 0:3f519e465338 787 triacVentilateur.pulsewidth_ms(0);
jmambroi 0:3f519e465338 788 dureeMarcheTotale[0] = jc;
jmambroi 0:3f519e465338 789 dureeMarcheTotale[1] = hc;
jmambroi 0:3f519e465338 790 dureeMarcheTotale[2] = mc;
jmambroi 0:3f519e465338 791 dureeMarcheTotale[3] = sc;
jmambroi 0:3f519e465338 792 dureeAttenteRestante[0] = j;
jmambroi 0:3f519e465338 793 dureeAttenteRestante[1] = h;
jmambroi 0:3f519e465338 794 dureeAttenteRestante[2] = m;
jmambroi 0:3f519e465338 795 dureeAttenteRestante[3] = s;
jmambroi 0:3f519e465338 796 }
jmambroi 0:3f519e465338 797 else if (etat == EN_PAUSE) {
jmambroi 0:3f519e465338 798 triacChauffage.pulsewidth_ms(0);
jmambroi 0:3f519e465338 799 triacVentilateur.pulsewidth_ms(0);
jmambroi 0:3f519e465338 800 dureeMarcheTotale[0] = jc;
jmambroi 0:3f519e465338 801 dureeMarcheTotale[1] = hc;
jmambroi 0:3f519e465338 802 dureeMarcheTotale[2] = mc;
jmambroi 0:3f519e465338 803 dureeMarcheTotale[3] = sc;
jmambroi 0:3f519e465338 804 dureeAttenteRestante[0] = j;
jmambroi 0:3f519e465338 805 dureeAttenteRestante[1] = h;
jmambroi 0:3f519e465338 806 dureeAttenteRestante[2] = m;
jmambroi 0:3f519e465338 807 dureeAttenteRestante[3] = s;
jmambroi 0:3f519e465338 808 }
jmambroi 0:3f519e465338 809 else if (etat == EN_MARCHE) {
jmambroi 0:3f519e465338 810 calculeLargeurImpulsion();
jmambroi 0:3f519e465338 811 triacChauffage.pulsewidth_ms(tableauDureeImpulsionChauffage[seuilChauffage]); // marche
jmambroi 0:3f519e465338 812 triacVentilateur.pulsewidth_ms(tableauDureeImpulsionVentilateur[vitesseVentilateur]); // marche
jmambroi 0:3f519e465338 813 dureeAttenteTotale[0] = j;
jmambroi 0:3f519e465338 814 dureeAttenteTotale[1] = h;
jmambroi 0:3f519e465338 815 dureeAttenteTotale[2] = m;
jmambroi 0:3f519e465338 816 dureeAttenteTotale[3] = s;
jmambroi 0:3f519e465338 817 dureeMarcheRestante[0] = jc;
jmambroi 0:3f519e465338 818 dureeMarcheRestante[1] = hc;
jmambroi 0:3f519e465338 819 dureeMarcheRestante[2] = mc;
jmambroi 0:3f519e465338 820 dureeMarcheRestante[3] = sc;
jmambroi 0:3f519e465338 821 }
jmambroi 0:3f519e465338 822 char infos[TAILLE_TAMPON]; // Tampon des infos
jmambroi 0:3f519e465338 823 memset(infos, 0, TAILLE_TAMPON);
jmambroi 0:3f519e465338 824 sprintf(infos, "Seuils : %3.1f, %3.1f %3.1f %3.1f, %3.1f %3.1f %3.1f %3.1f %3.1f %3.1f %3.1f", tableauSeuilsTemperature[0], tableauSeuilsTemperature[1], tableauSeuilsTemperature[2], tableauSeuilsTemperature[3], tableauSeuilsTemperature[4], tableauSeuilsTemperature[5], tableauSeuilsTemperature[6], tableauSeuilsTemperature[7], tableauSeuilsTemperature[8], tableauSeuilsTemperature[9], tableauSeuilsTemperature[10]);
jmambroi 0:3f519e465338 825 pc.printf("\n");
jmambroi 0:3f519e465338 826 pc.printf(infos);
jmambroi 0:3f519e465338 827 pc.printf("\n");
jmambroi 0:3f519e465338 828 numero = 0;
jmambroi 3:5dff448d2ed1 829 lcd.SetBackColor(NOIR);
jmambroi 0:3f519e465338 830 // alerte.Draw(infos, CYAN);
jmambroi 0:3f519e465338 831 // donneesModifiees = true;
jmambroi 0:3f519e465338 832 sauveDonnees();
jmambroi 0:3f519e465338 833 // wait(1);
jmambroi 0:3f519e465338 834 }
jmambroi 0:3f519e465338 835 else if (annuler.Touched()) {
jmambroi 0:3f519e465338 836 if (etat == EN_MARCHE) {
jmambroi 0:3f519e465338 837 calculeLargeurImpulsion();
jmambroi 0:3f519e465338 838 triacChauffage.pulsewidth_ms(tableauDureeImpulsionChauffage[seuilChauffage]); // marche
jmambroi 0:3f519e465338 839 triacVentilateur.pulsewidth_ms(tableauDureeImpulsionVentilateur[vitesseVentilateur]); // marche
jmambroi 0:3f519e465338 840 }
jmambroi 0:3f519e465338 841 }
jmambroi 3:5dff448d2ed1 842 lcd.Clear(NOIR);
jmambroi 0:3f519e465338 843 ecranActuel = ECRAN_ACCUEIL;
jmambroi 0:3f519e465338 844 etat = etatPrecedent;
jmambroi 0:3f519e465338 845 afficheEcranAccueil();
jmambroi 0:3f519e465338 846 // alerte.Draw(etats[etat], VERT_SOMBRE);
jmambroi 0:3f519e465338 847 // wait(0.5);
jmambroi 0:3f519e465338 848 }
jmambroi 0:3f519e465338 849
jmambroi 0:3f519e465338 850 void sauveDonnees(void) {
jmambroi 0:3f519e465338 851 int temperature, dixieme;
jmambroi 0:3f519e465338 852 qspi.Erase_Block(ADRESSE_LECTURE_ECRITURE);
jmambroi 0:3f519e465338 853 memset(tamponQSPI, 0, TAILLE_TAMPON);
jmambroi 0:3f519e465338 854 tamponQSPI[0] = (uint8_t)'J';
jmambroi 0:3f519e465338 855 tamponQSPI[1] = (uint8_t)'M';
jmambroi 0:3f519e465338 856 tamponQSPI[2] = (uint8_t)'A';
jmambroi 0:3f519e465338 857 tamponQSPI[3] = etat;
jmambroi 0:3f519e465338 858 tamponQSPI[4] = dureeAttenteTotale[0];
jmambroi 0:3f519e465338 859 tamponQSPI[5] = dureeAttenteTotale[1];
jmambroi 0:3f519e465338 860 tamponQSPI[6] = dureeAttenteTotale[2];
jmambroi 0:3f519e465338 861 tamponQSPI[7] = dureeAttenteTotale[3];
jmambroi 0:3f519e465338 862 tamponQSPI[8] = dureeAttenteRestante[0];
jmambroi 0:3f519e465338 863 tamponQSPI[9] = dureeAttenteRestante[1];
jmambroi 0:3f519e465338 864 tamponQSPI[10] = dureeAttenteRestante[2];
jmambroi 0:3f519e465338 865 tamponQSPI[11] = dureeAttenteRestante[3];
jmambroi 0:3f519e465338 866 tamponQSPI[12] = dureeMarcheTotale[0];
jmambroi 0:3f519e465338 867 tamponQSPI[13] = dureeMarcheTotale[1];
jmambroi 0:3f519e465338 868 tamponQSPI[14] = dureeMarcheTotale[2];
jmambroi 0:3f519e465338 869 tamponQSPI[15] = dureeMarcheTotale[3];
jmambroi 0:3f519e465338 870 tamponQSPI[16] = dureeMarcheRestante[0];
jmambroi 0:3f519e465338 871 tamponQSPI[17] = dureeMarcheRestante[1];
jmambroi 0:3f519e465338 872 tamponQSPI[18] = dureeMarcheRestante[2];
jmambroi 0:3f519e465338 873 tamponQSPI[19] = dureeMarcheRestante[3];
jmambroi 0:3f519e465338 874 tamponQSPI[20] = etat; // etat
jmambroi 0:3f519e465338 875 tamponQSPI[21] = 1; // Température de consigne ; signe 0 = -; 1 = +
jmambroi 0:3f519e465338 876 temperature = (int) temperatureConsigne;
jmambroi 0:3f519e465338 877 dixieme = (int)((temperatureConsigne - temperature) * 10);
jmambroi 0:3f519e465338 878 tamponQSPI[22] = temperature; // temp
jmambroi 0:3f519e465338 879 tamponQSPI[23] = dixieme; // dixiemes de degré
jmambroi 0:3f519e465338 880 tamponQSPI[24] = vitesseVentilateur; // force du ventilateur
jmambroi 0:3f519e465338 881 if (qspi.Write(tamponQSPI, ADRESSE_LECTURE_ECRITURE, TAILLE_TAMPON) != QSPI_OK) {
jmambroi 0:3f519e465338 882 pc.printf("\nSauvegarde en memoire QSPI non realisee\n");
jmambroi 0:3f519e465338 883 qspiOk = false;
jmambroi 0:3f519e465338 884 }
jmambroi 0:3f519e465338 885 else {
jmambroi 0:3f519e465338 886 pc.printf("\nSauvegarde en memoire QSPI reussie\n");
jmambroi 0:3f519e465338 887 numero = 0;
jmambroi 0:3f519e465338 888 /* pc.printf("Valeur sauvegardee, attente : %u, %u, %u, %u, %u, %u, %u, %u, marche : %u, %u, %u, %u, %u, %u, %u, %u, etat %u, temp : %u.%u, ventilo : %u\n", tamponQSPI[4], tamponQSPI[5], tamponQSPI[6], tamponQSPI[7], tamponQSPI[8], tamponQSPI[9], tamponQSPI[10], tamponQSPI[11],
jmambroi 0:3f519e465338 889 tamponQSPI[12], tamponQSPI[13], tamponQSPI[14], tamponQSPI[15], tamponQSPI[16], tamponQSPI[17], tamponQSPI[18], tamponQSPI[19], tamponQSPI[20], tamponQSPI[22] , tamponQSPI[23] , tamponQSPI[24]);
jmambroi 0:3f519e465338 890 pc.printf("Verif temperatures : %3.1f -> %u, %u, \n", temperatureConsigne, temperature, dixieme);
jmambroi 0:3f519e465338 891 memset(tamponQSPI, 0, TAILLE_TAMPON);
jmambroi 0:3f519e465338 892 qspi.Read(tamponQSPI, ADRESSE_LECTURE_ECRITURE, TAILLE_TAMPON);
jmambroi 0:3f519e465338 893 pc.printf("Valeurs enregistrees, attente : %u, %u, %u, %u, %u, %u, %u, %u, marche : %u, %u, %u, %u, %u, %u, %u, %u, etat %u, temp : %u.%u, ventilo : %u\n", tamponQSPI[4], tamponQSPI[5], tamponQSPI[6], tamponQSPI[7], tamponQSPI[8], tamponQSPI[9], tamponQSPI[10], tamponQSPI[11],
jmambroi 0:3f519e465338 894 tamponQSPI[12], tamponQSPI[13], tamponQSPI[14], tamponQSPI[15], tamponQSPI[16], tamponQSPI[17], tamponQSPI[18], tamponQSPI[19], tamponQSPI[20], tamponQSPI[22] , tamponQSPI[23] , tamponQSPI[24]);*/
jmambroi 0:3f519e465338 895 }
jmambroi 0:3f519e465338 896
jmambroi 0:3f519e465338 897 }
jmambroi 0:3f519e465338 898
jmambroi 0:3f519e465338 899 void interruptionSauvegarde(void) {
jmambroi 0:3f519e465338 900 clicSauvegarde = true;
jmambroi 0:3f519e465338 901 }
jmambroi 0:3f519e465338 902
jmambroi 0:3f519e465338 903 void initialise(void) {
jmambroi 0:3f519e465338 904 // qspi.Erase_Block(ADRESSE_LECTURE_ECRITURE);
jmambroi 0:3f519e465338 905 memset(tamponQSPI, 0, TAILLE_TAMPON);
jmambroi 0:3f519e465338 906 tamponQSPI[0] = (uint8_t)'J';
jmambroi 0:3f519e465338 907 tamponQSPI[1] = (uint8_t)'M';
jmambroi 0:3f519e465338 908 tamponQSPI[2] = (uint8_t)'A';
jmambroi 0:3f519e465338 909 tamponQSPI[3] = ARRETE; // etat
jmambroi 0:3f519e465338 910 tamponQSPI[4] = dureeAttenteTotale[0];
jmambroi 0:3f519e465338 911 tamponQSPI[5] = dureeAttenteTotale[1];
jmambroi 0:3f519e465338 912 tamponQSPI[6] = dureeAttenteTotale[2];
jmambroi 0:3f519e465338 913 tamponQSPI[7] = dureeAttenteTotale[3];
jmambroi 0:3f519e465338 914 tamponQSPI[8] = dureeAttenteRestante[0];
jmambroi 0:3f519e465338 915 tamponQSPI[9] = dureeAttenteRestante[1];
jmambroi 0:3f519e465338 916 tamponQSPI[10] = dureeAttenteRestante[2];
jmambroi 0:3f519e465338 917 tamponQSPI[11] = dureeAttenteRestante[3];
jmambroi 0:3f519e465338 918 tamponQSPI[12] = dureeMarcheTotale[0];
jmambroi 0:3f519e465338 919 tamponQSPI[13] = dureeMarcheTotale[1];
jmambroi 0:3f519e465338 920 tamponQSPI[14] = dureeMarcheTotale[2];
jmambroi 0:3f519e465338 921 tamponQSPI[15] = dureeMarcheTotale[3];
jmambroi 0:3f519e465338 922 tamponQSPI[16] = dureeMarcheRestante[0];
jmambroi 0:3f519e465338 923 tamponQSPI[17] = dureeMarcheRestante[1];
jmambroi 0:3f519e465338 924 tamponQSPI[18] = dureeMarcheRestante[2];
jmambroi 0:3f519e465338 925 tamponQSPI[19] = dureeMarcheRestante[3];
jmambroi 0:3f519e465338 926 tamponQSPI[20] = ARRETE; // etat
jmambroi 0:3f519e465338 927 tamponQSPI[21] = 1; // Température de consigne ; signe 0 = -; 1 = +
jmambroi 0:3f519e465338 928 tamponQSPI[22] = 30; // temp
jmambroi 0:3f519e465338 929 tamponQSPI[23] = 5; // dixiemes de degré
jmambroi 0:3f519e465338 930 tamponQSPI[24] = 5; // force du ventilateur
jmambroi 0:3f519e465338 931 if (qspi.Write(tamponQSPI, ADRESSE_LECTURE_ECRITURE, TAILLE_TAMPON) != QSPI_OK) {
jmambroi 0:3f519e465338 932 pc.printf("Memoire non initialisee\n");
jmambroi 0:3f519e465338 933 qspiOk = false;
jmambroi 0:3f519e465338 934 }
jmambroi 0:3f519e465338 935 else {
jmambroi 0:3f519e465338 936 pc.printf("Memoire initialisee\n");
jmambroi 0:3f519e465338 937 pc.printf("Valeurs initiales, attente : %u, %u, %u, %u, %u, %u, %u, %u, marche : %u, %u, %u, %u, %u, %u, %u, %u, etat %u, temp : %u.%u, ventilo : %u\n", tamponQSPI[4], tamponQSPI[5], tamponQSPI[6], tamponQSPI[7], tamponQSPI[8], tamponQSPI[9], tamponQSPI[10], tamponQSPI[11],
jmambroi 0:3f519e465338 938 tamponQSPI[12], tamponQSPI[13], tamponQSPI[14], tamponQSPI[15], tamponQSPI[16], tamponQSPI[17], tamponQSPI[18], tamponQSPI[19], tamponQSPI[20], tamponQSPI[22] , tamponQSPI[23] , tamponQSPI[24]);
jmambroi 0:3f519e465338 939 memset(tamponQSPI, 0, TAILLE_TAMPON);
jmambroi 0:3f519e465338 940 qspi.Read(tamponQSPI, ADRESSE_LECTURE_ECRITURE, TAILLE_TAMPON);
jmambroi 0:3f519e465338 941 pc.printf("Valeurs enregistrees, attente : %u, %u, %u, %u, %u, %u, %u, %u, marche : %u, %u, %u, %u, %u, %u, %u, %u, etat %u, temp : %u.%u, ventilo : %u\n", tamponQSPI[4], tamponQSPI[5], tamponQSPI[6], tamponQSPI[7], tamponQSPI[8], tamponQSPI[9], tamponQSPI[10], tamponQSPI[11],
jmambroi 0:3f519e465338 942 tamponQSPI[12], tamponQSPI[13], tamponQSPI[14], tamponQSPI[15], tamponQSPI[16], tamponQSPI[17], tamponQSPI[18], tamponQSPI[19], tamponQSPI[20], tamponQSPI[22] , tamponQSPI[23] , tamponQSPI[24]);
jmambroi 0:3f519e465338 943
jmambroi 0:3f519e465338 944 }
jmambroi 0:3f519e465338 945 }
jmambroi 0:3f519e465338 946
jmambroi 0:3f519e465338 947 void initialiseDS1820(void) {
jmambroi 0:3f519e465338 948 if(ds1820.begin()) {
jmambroi 3:5dff448d2ed1 949 lcd.SetBackColor(NOIR);
jmambroi 0:3f519e465338 950 alerte.Draw("DS1820 initialise sur D8 (PI_2)", JAUNE);
jmambroi 0:3f519e465338 951 pc.printf("DS1820 initialise sur D8 (PI_2)");
jmambroi 0:3f519e465338 952 ds1820.setResolution(12);
jmambroi 0:3f519e465338 953 ds1820.startConversion();
jmambroi 0:3f519e465338 954 wait(1);
jmambroi 0:3f519e465338 955 temperature = ds1820.read();
jmambroi 0:3f519e465338 956 ok = true;
jmambroi 0:3f519e465338 957 alerte.Draw("", NOIR);
jmambroi 0:3f519e465338 958 }
jmambroi 0:3f519e465338 959 else {
jmambroi 3:5dff448d2ed1 960 lcd.SetBackColor(NOIR);
jmambroi 0:3f519e465338 961 alerte.Draw("Pas de capteur DS1820 sur le bus OneWire (D8) !", ROUGE);
jmambroi 0:3f519e465338 962 pc.printf("Pas de capteur DS1820 sur le bus OneWire (D8) !");
jmambroi 0:3f519e465338 963 wait(1);
jmambroi 0:3f519e465338 964 alerte.Draw("", NOIR);
jmambroi 0:3f519e465338 965 ok = false;
jmambroi 0:3f519e465338 966 }
jmambroi 0:3f519e465338 967 }
jmambroi 0:3f519e465338 968
jmambroi 0:3f519e465338 969 void initialiseQSPI(void) {
jmambroi 0:3f519e465338 970 QSPI_Info pQSPI_Info;
jmambroi 0:3f519e465338 971 if (qspi.Init() != QSPI_OK) {
jmambroi 3:5dff448d2ed1 972 lcd.SetBackColor(NOIR);
jmambroi 0:3f519e465338 973 alerte.Draw("Initialisation QSPI ratee", ROUGE);
jmambroi 0:3f519e465338 974 pc.printf("Initialisation QSPI ratee");
jmambroi 0:3f519e465338 975 // pc.printf();
jmambroi 0:3f519e465338 976 qspiOk = false;
jmambroi 0:3f519e465338 977 wait(1);
jmambroi 0:3f519e465338 978 alerte.Draw("", NOIR);
jmambroi 0:3f519e465338 979 }
jmambroi 0:3f519e465338 980 else {
jmambroi 3:5dff448d2ed1 981 lcd.SetBackColor(NOIR);
jmambroi 0:3f519e465338 982 alerte.Draw("Initialisation QSPI reussie", JAUNE);
jmambroi 0:3f519e465338 983 pc.printf("\n\nInitialisation QSPI reussie\n");
jmambroi 0:3f519e465338 984 qspiOk = true;
jmambroi 0:3f519e465338 985 wait(1);
jmambroi 0:3f519e465338 986 alerte.Draw("", NOIR);
jmambroi 0:3f519e465338 987 }
jmambroi 0:3f519e465338 988
jmambroi 0:3f519e465338 989 // Check memory informations
jmambroi 0:3f519e465338 990 qspi.GetInfo(&pQSPI_Info);
jmambroi 0:3f519e465338 991 if ((pQSPI_Info.FlashSize != N25Q128A_FLASH_SIZE) ||
jmambroi 0:3f519e465338 992 (pQSPI_Info.EraseSectorSize != N25Q128A_SUBSECTOR_SIZE) ||
jmambroi 0:3f519e465338 993 (pQSPI_Info.ProgPageSize != N25Q128A_PAGE_SIZE) ||
jmambroi 0:3f519e465338 994 (pQSPI_Info.EraseSectorsNumber != N25Q128A_SUBSECTOR_SIZE) ||
jmambroi 0:3f519e465338 995 (pQSPI_Info.ProgPagesNumber != N25Q128A_SECTOR_SIZE)) {
jmambroi 0:3f519e465338 996 led = 1;
jmambroi 3:5dff448d2ed1 997 lcd.SetBackColor(NOIR);
jmambroi 0:3f519e465338 998 alerte.Draw("Lecture des informations ratee\n");
jmambroi 0:3f519e465338 999 qspiOk = false;
jmambroi 0:3f519e465338 1000 }
jmambroi 0:3f519e465338 1001 else {
jmambroi 0:3f519e465338 1002 pc.printf("Lecture des informations reussie\n");
jmambroi 0:3f519e465338 1003 if (qspi.Read(tamponQSPI, ADRESSE_LECTURE_ECRITURE, TAILLE_TAMPON) != QSPI_OK) {
jmambroi 0:3f519e465338 1004 qspiOk = false;
jmambroi 3:5dff448d2ed1 1005 lcd.SetBackColor(NOIR);
jmambroi 0:3f519e465338 1006 alerte.Draw("Lecture de la memoire QSPI ratee\n", ROUGE);
jmambroi 0:3f519e465338 1007 led = 1;
jmambroi 0:3f519e465338 1008 wait(1);
jmambroi 0:3f519e465338 1009 led = 0;
jmambroi 0:3f519e465338 1010 }
jmambroi 0:3f519e465338 1011 else if ((tamponQSPI[0] == 'J') && (tamponQSPI[1] == 'M') && (tamponQSPI[2] == 'A')) { // on teste la signature
jmambroi 0:3f519e465338 1012 pc.printf("Memoire QSPI deja initialisee\n");
jmambroi 0:3f519e465338 1013 led = 1;
jmambroi 0:3f519e465338 1014 initialiseDonnees();
jmambroi 0:3f519e465338 1015 led = 0;
jmambroi 0:3f519e465338 1016 }
jmambroi 0:3f519e465338 1017 else { // on initialise la memoire
jmambroi 0:3f519e465338 1018 pc.printf("Memoire QSPI non initialisee\nInitialisation en cours\n");
jmambroi 0:3f519e465338 1019 if (qspi.Erase_Block(ADRESSE_LECTURE_ECRITURE) != QSPI_OK) {
jmambroi 0:3f519e465338 1020 pc.printf("Bloc non efface\n");
jmambroi 0:3f519e465338 1021 qspiOk = false;
jmambroi 0:3f519e465338 1022 }
jmambroi 0:3f519e465338 1023 else {
jmambroi 0:3f519e465338 1024 pc.printf("Bloc efface\n");
jmambroi 0:3f519e465338 1025 led = 1;
jmambroi 0:3f519e465338 1026 initialise();
jmambroi 0:3f519e465338 1027 led = 0;
jmambroi 0:3f519e465338 1028 }
jmambroi 0:3f519e465338 1029 }
jmambroi 0:3f519e465338 1030 }
jmambroi 0:3f519e465338 1031 }
jmambroi 0:3f519e465338 1032
jmambroi 0:3f519e465338 1033 void calculeLargeurImpulsion(void) {
jmambroi 0:3f519e465338 1034 seuilChauffage = 0;
jmambroi 0:3f519e465338 1035 if ((temperature <= tableauSeuilsTemperature[0])) {
jmambroi 0:3f519e465338 1036 seuilChauffage = tableauSeuilsChauffage[0];
jmambroi 0:3f519e465338 1037 }
jmambroi 0:3f519e465338 1038 else if (temperature < temperatureConsigne) {
jmambroi 0:3f519e465338 1039 if ((temperature >= tableauSeuilsTemperature[0]) && (temperature < tableauSeuilsTemperature[1])) {
jmambroi 0:3f519e465338 1040 seuilChauffage = tableauSeuilsChauffage[0];
jmambroi 0:3f519e465338 1041 }
jmambroi 0:3f519e465338 1042 else if ((temperature >= tableauSeuilsTemperature[1]) && (temperature < tableauSeuilsTemperature[2])) {
jmambroi 0:3f519e465338 1043 seuilChauffage = tableauSeuilsChauffage[1];
jmambroi 0:3f519e465338 1044 }
jmambroi 0:3f519e465338 1045 else if ((temperature >= tableauSeuilsTemperature[2]) && (temperature < tableauSeuilsTemperature[3])) {
jmambroi 0:3f519e465338 1046 seuilChauffage = tableauSeuilsChauffage[2];
jmambroi 0:3f519e465338 1047 }
jmambroi 0:3f519e465338 1048 else if ((temperature >= tableauSeuilsTemperature[3]) && (temperature < tableauSeuilsTemperature[4])) {
jmambroi 0:3f519e465338 1049 seuilChauffage = tableauSeuilsChauffage[3];
jmambroi 0:3f519e465338 1050 }
jmambroi 0:3f519e465338 1051 else if ((temperature >= tableauSeuilsTemperature[4]) && (temperature < tableauSeuilsTemperature[5])) {
jmambroi 0:3f519e465338 1052 seuilChauffage = tableauSeuilsChauffage[4];
jmambroi 0:3f519e465338 1053 }
jmambroi 0:3f519e465338 1054 else if ((temperature >= tableauSeuilsTemperature[5]) && (temperature < tableauSeuilsTemperature[6])) {
jmambroi 0:3f519e465338 1055 seuilChauffage = tableauSeuilsChauffage[5];
jmambroi 0:3f519e465338 1056 }
jmambroi 0:3f519e465338 1057 else if ((temperature >= tableauSeuilsTemperature[6]) && (temperature < tableauSeuilsTemperature[7])) {
jmambroi 0:3f519e465338 1058 seuilChauffage = tableauSeuilsChauffage[6];
jmambroi 0:3f519e465338 1059 }
jmambroi 0:3f519e465338 1060 else if ((temperature >= tableauSeuilsTemperature[7]) && (temperature < tableauSeuilsTemperature[8])) {
jmambroi 0:3f519e465338 1061 seuilChauffage = tableauSeuilsChauffage[7];
jmambroi 0:3f519e465338 1062 }
jmambroi 0:3f519e465338 1063 else if ((temperature >= tableauSeuilsTemperature[8]) && (temperature < tableauSeuilsTemperature[9])) {
jmambroi 0:3f519e465338 1064 seuilChauffage = tableauSeuilsChauffage[8];
jmambroi 0:3f519e465338 1065 }
jmambroi 0:3f519e465338 1066 else if ((temperature >= tableauSeuilsTemperature[9]) && (temperature < tableauSeuilsTemperature[10])) {
jmambroi 0:3f519e465338 1067 seuilChauffage = tableauSeuilsChauffage[9];
jmambroi 0:3f519e465338 1068 }
jmambroi 0:3f519e465338 1069 }
jmambroi 0:3f519e465338 1070 else if (temperature >= temperatureConsigne) {
jmambroi 0:3f519e465338 1071 seuilChauffage = tableauSeuilsChauffage[10]/*0*/;
jmambroi 0:3f519e465338 1072 }
jmambroi 0:3f519e465338 1073 if (seuilChauffage > 10)
jmambroi 0:3f519e465338 1074 seuilChauffage = 10;
jmambroi 0:3f519e465338 1075 if (seuilChauffage < 0)
jmambroi 0:3f519e465338 1076 seuilChauffage = 0;
jmambroi 0:3f519e465338 1077 /* char infos[TAILLE_TAMPON];
jmambroi 0:3f519e465338 1078 memset(infos, 0, TAILLE_TAMPON);
jmambroi 0:3f519e465338 1079 sprintf(infos, "%d (%.1f, %d) ", seuilChauffage, temperature, tableauDureeImpulsionChauffage[seuilChauffage]);
jmambroi 0:3f519e465338 1080 pc.printf(infos);
jmambroi 0:3f519e465338 1081 numero++;
jmambroi 0:3f519e465338 1082 if (numero > 5) {
jmambroi 0:3f519e465338 1083 numero = 0;
jmambroi 0:3f519e465338 1084 pc.printf("\n");
jmambroi 0:3f519e465338 1085 }*/
jmambroi 0:3f519e465338 1086 }
jmambroi 0:3f519e465338 1087