Projet Interfacage

Dependencies:   F746_GUI mbed SI7021

Committer:
teoff
Date:
Tue Jun 22 13:00:33 2021 +0000
Revision:
3:96a6e9e58178
Parent:
2:8a932906e684
Final program

Who changed what in which revision?

UserRevisionLine numberNew contents of line
teoff 0:85f60e3f81ab 1 #include "mbed.h"
teoff 0:85f60e3f81ab 2 #include "F746_GUI.hpp"
teoff 0:85f60e3f81ab 3 #include "SI7021.h"
teoff 0:85f60e3f81ab 4
teoff 0:85f60e3f81ab 5 SI7021 myTempRHsensor ( I2C_SDA, I2C_SCL, SI7021::SI7021_ADDRESS, 400000 );
teoff 0:85f60e3f81ab 6 Timer t;
teoff 0:85f60e3f81ab 7
teoff 0:85f60e3f81ab 8 Ticker newReading;
teoff 1:0883bd051a78 9 DigitalOut led1 ( LED1 );
teoff 0:85f60e3f81ab 10
teoff 3:96a6e9e58178 11 //Déclaration pour le capteur
teoff 0:85f60e3f81ab 12 SI7021::SI7021_vector_data_t myData;
teoff 0:85f60e3f81ab 13 SI7021::SI7021_status_t mySI7021status;
teoff 0:85f60e3f81ab 14 uint32_t myState;
teoff 0:85f60e3f81ab 15
teoff 1:0883bd051a78 16 void readData ( void )
teoff 0:85f60e3f81ab 17 {
teoff 0:85f60e3f81ab 18 myState++;
teoff 0:85f60e3f81ab 19 }
teoff 0:85f60e3f81ab 20
teoff 0:85f60e3f81ab 21 using namespace Mikami;
teoff 0:85f60e3f81ab 22
teoff 0:85f60e3f81ab 23 int main()
teoff 0:85f60e3f81ab 24 {
teoff 1:0883bd051a78 25 int NumBoutonGroup1=0, NumBoutonGroup2=0, nLap = 1;
teoff 1:0883bd051a78 26
teoff 0:85f60e3f81ab 27 Label titre(240, 2, "Dashboard F1", Label::CENTER, Font16);
teoff 1:0883bd051a78 28 Label temperature(168, 110, "Temperature : ");
teoff 1:0883bd051a78 29 Label humidite(168, 135, "Humidite : ");
teoff 1:0883bd051a78 30 Label labelTime(168, 155,"Lap Time : ");
teoff 0:85f60e3f81ab 31 Label pneu(260, 40,"Pneu");
teoff 1:0883bd051a78 32 Label mode(57, 40,"Mode puissance",Label::CENTER);
teoff 0:85f60e3f81ab 33
teoff 1:0883bd051a78 34 Button stand(10, 145, 60, 40, "Stand", Font12, GuiBase::ENUM_TEXT, GuiBase::ENUM_BACK, LCD_COLOR_BLUE, LCD_COLOR_RED);
teoff 1:0883bd051a78 35 Button talk(10, 100, 60, 35, "Radio");
teoff 1:0883bd051a78 36 Button start(400, 135, 60, 35, "Start", Font12, GuiBase::ENUM_TEXT, GuiBase::ENUM_BACK, LCD_COLOR_DARKGREEN);
teoff 1:0883bd051a78 37
teoff 2:8a932906e684 38 const string PNEU[4] = {"Soft", "Medium", "Hard", "Wet"};
teoff 2:8a932906e684 39 const string MODE[3] = {"1", "2", "3"};
teoff 2:8a932906e684 40 ButtonGroup bGroup1(168, 54, 66, 35, 4, PNEU, 2, 2, 4, 1, Font12, LCD_COLOR_WHITE, LCD_COLOR_BLACK);
teoff 2:8a932906e684 41 ButtonGroup bGroupMode(10, 54, 30, 35, 3, MODE, 2, 2, 3, 1, Font12, LCD_COLOR_WHITE, LCD_COLOR_BLACK);
teoff 0:85f60e3f81ab 42 NumericLabel<int> bTouch(240, 112, "", Label::LEFT, Font12, LCD_COLOR_WHITE);
teoff 0:85f60e3f81ab 43 NumericLabel<float> valTemp(290,110, "", Label::CENTER, Font12, LCD_COLOR_WHITE, LCD_COLOR_BLACK);
teoff 0:85f60e3f81ab 44 NumericLabel<float> valHumi(260,135, "", Label::CENTER, Font12, LCD_COLOR_WHITE, LCD_COLOR_BLACK);
teoff 0:85f60e3f81ab 45 NumericLabel<float> time(280,155, "", Label::CENTER, Font12, LCD_COLOR_WHITE, LCD_COLOR_BLACK);
teoff 0:85f60e3f81ab 46 NumericLabel<int> lap(420,25, "");
teoff 1:0883bd051a78 47 NumericLabel<int> valBias(110,260, "");
teoff 1:0883bd051a78 48 NumericLabel<int> valDiff(350,260, "");
teoff 0:85f60e3f81ab 49
teoff 1:0883bd051a78 50 SeekBar bias(20, 240, 200, 0, 100, 50, "0", "Bias","");
teoff 1:0883bd051a78 51 SeekBar diff(260, 240, 200, 0, 100, 50, "0", "Differentiel","");
teoff 0:85f60e3f81ab 52
teoff 0:85f60e3f81ab 53 bGroup1.Draw(0,0xFFFF0000,0xFFFFFFFF); //Red
teoff 0:85f60e3f81ab 54 bGroup1.Draw(1,0xFFFFE800,0xFFFFFFFF); //Yellow
teoff 0:85f60e3f81ab 55 bGroup1.Draw(2,0xFFFFFFFF,0xFF000000); //White
teoff 0:85f60e3f81ab 56
teoff 1:0883bd051a78 57 // Reset le capteur
teoff 0:85f60e3f81ab 58 mySI7021status = myTempRHsensor.SI7021_SoftReset ();
teoff 1:0883bd051a78 59 // Configuration du capteur
teoff 0:85f60e3f81ab 60 mySI7021status = myTempRHsensor.SI7021_Conf ( SI7021::SI7021_RESOLUTION_RH_12_TEMP_14, SI7021::SI7021_HTRE_DISABLED );
teoff 1:0883bd051a78 61 // L'adresse de la fonction a utilisé ( readData ) l'intervale de temps ( 1s )
teoff 1:0883bd051a78 62 newReading.attach( &readData, 0.1 );
teoff 0:85f60e3f81ab 63 while (1) {
teoff 0:85f60e3f81ab 64
teoff 3:96a6e9e58178 65 NumBoutonGroup1=bGroup1.GetTouchedNumber();//Récupérer bouton touché
teoff 1:0883bd051a78 66 if(bGroup1.GetTouchedNumber(NumBoutonGroup1)) {
teoff 1:0883bd051a78 67 switch (NumBoutonGroup1) {
teoff 0:85f60e3f81ab 68 case 0 :
teoff 0:85f60e3f81ab 69 bGroup1.Inactivate(0);
teoff 0:85f60e3f81ab 70 bGroup1.Activate(1);
teoff 0:85f60e3f81ab 71 bGroup1.Activate(2);
teoff 3:96a6e9e58178 72 bGroup1.Activate(3);
teoff 0:85f60e3f81ab 73 bGroup1.Draw(1,0xFFFFE800,0xFFFFFFFF); //Yellow
teoff 0:85f60e3f81ab 74 bGroup1.Draw(2,0xFFFFFFFF,0xFF000000); //White
teoff 2:8a932906e684 75 bGroup1.Draw(3);
teoff 0:85f60e3f81ab 76 break;
teoff 0:85f60e3f81ab 77 case 1 :
teoff 0:85f60e3f81ab 78 bGroup1.Inactivate(1);
teoff 0:85f60e3f81ab 79 bGroup1.Activate(0);
teoff 2:8a932906e684 80 bGroup1.Activate(3);
teoff 0:85f60e3f81ab 81 bGroup1.Activate(2);
teoff 0:85f60e3f81ab 82 bGroup1.Draw(0,0xFFFF0000,0xFFFFFFFF); //Red
teoff 0:85f60e3f81ab 83 bGroup1.Draw(2,0xFFFFFFFF,0xFF000000); //White
teoff 2:8a932906e684 84 bGroup1.Draw(3);
teoff 0:85f60e3f81ab 85 break;
teoff 0:85f60e3f81ab 86 case 2 :
teoff 0:85f60e3f81ab 87 bGroup1.Inactivate(2);
teoff 0:85f60e3f81ab 88 bGroup1.Activate(0);
teoff 0:85f60e3f81ab 89 bGroup1.Activate(1);
teoff 2:8a932906e684 90 bGroup1.Activate(3);
teoff 0:85f60e3f81ab 91 bGroup1.Draw(0,0xFFFF0000,0xFFFFFFFF); //Red
teoff 0:85f60e3f81ab 92 bGroup1.Draw(1,0xFFFFE800,0xFFFFFFFF); //Yellow
teoff 2:8a932906e684 93 bGroup1.Draw(3);
teoff 2:8a932906e684 94 break;
teoff 2:8a932906e684 95 case 3 :
teoff 2:8a932906e684 96 bGroup1.Inactivate(3);
teoff 2:8a932906e684 97 bGroup1.Activate(0);
teoff 2:8a932906e684 98 bGroup1.Activate(1);
teoff 2:8a932906e684 99 bGroup1.Activate(2);
teoff 2:8a932906e684 100 bGroup1.Draw(1,0xFFFFE800,0xFFFFFFFF); //Yellow
teoff 2:8a932906e684 101 bGroup1.Draw(2,0xFFFFFFFF,0xFF000000); //White
teoff 2:8a932906e684 102 bGroup1.Draw(0,0xFFFF0000,0xFFFFFFFF); //Red
teoff 0:85f60e3f81ab 103 break;
teoff 0:85f60e3f81ab 104 }
teoff 0:85f60e3f81ab 105 }
teoff 0:85f60e3f81ab 106
teoff 3:96a6e9e58178 107 NumBoutonGroup2=bGroupMode.GetTouchedNumber();//Récupérer bouton touché
teoff 1:0883bd051a78 108 if(bGroupMode.GetTouchedNumber(NumBoutonGroup2)) {
teoff 1:0883bd051a78 109 switch (NumBoutonGroup2) {
teoff 1:0883bd051a78 110 case 0 :
teoff 1:0883bd051a78 111 bGroupMode.Inactivate(0);
teoff 1:0883bd051a78 112 bGroupMode.Activate(1);
teoff 1:0883bd051a78 113 bGroupMode.Activate(2);
teoff 1:0883bd051a78 114
teoff 1:0883bd051a78 115 break;
teoff 1:0883bd051a78 116 case 1 :
teoff 1:0883bd051a78 117 bGroupMode.Inactivate(1);
teoff 1:0883bd051a78 118 bGroupMode.Activate(0);
teoff 1:0883bd051a78 119 bGroupMode.Activate(2);
teoff 1:0883bd051a78 120
teoff 1:0883bd051a78 121 break;
teoff 1:0883bd051a78 122 case 2 :
teoff 1:0883bd051a78 123 bGroupMode.Inactivate(2);
teoff 1:0883bd051a78 124 bGroupMode.Activate(0);
teoff 1:0883bd051a78 125 bGroupMode.Activate(1);
teoff 1:0883bd051a78 126 break;
teoff 1:0883bd051a78 127 }
teoff 1:0883bd051a78 128 }
teoff 1:0883bd051a78 129
teoff 1:0883bd051a78 130 if(start.Touched()==1) {
teoff 1:0883bd051a78 131 t.start();
teoff 1:0883bd051a78 132 start.Inactivate();
teoff 1:0883bd051a78 133 }
teoff 1:0883bd051a78 134
teoff 1:0883bd051a78 135 // Si "stand" bouton appuyé, affichage retour au stand, on envoie plus aucune info
teoff 1:0883bd051a78 136 if (stand.Touched())
teoff 1:0883bd051a78 137 BlinkLabel warning(250, 180, "Retour au stand", Label::LEFT, Font16);
teoff 1:0883bd051a78 138
teoff 0:85f60e3f81ab 139 if (bias.Slide()) {
teoff 3:96a6e9e58178 140 valBias.Draw("%d",bias.GetValue());//Récupérer valeur du bias
teoff 0:85f60e3f81ab 141 }
teoff 0:85f60e3f81ab 142 if (diff.Slide()) {
teoff 3:96a6e9e58178 143 valDiff.Draw("%d",diff.GetValue());//Récupérer valeur du differentiel
teoff 0:85f60e3f81ab 144 }
teoff 0:85f60e3f81ab 145
teoff 0:85f60e3f81ab 146 sleep();
teoff 0:85f60e3f81ab 147
teoff 0:85f60e3f81ab 148 if ( myState == 1 ) {
teoff 1:0883bd051a78 149 //Déclenche une nouvelle mesure d'humidité et de température
teoff 1:0883bd051a78 150 led1 = 1;
teoff 0:85f60e3f81ab 151
teoff 1:0883bd051a78 152 mySI7021status = myTempRHsensor.SI7021_TriggerHumidity ( SI7021::SI7021_NO_HOLD_MASTER_MODE );
teoff 1:0883bd051a78 153 mySI7021status = myTempRHsensor.SI7021_TriggerTemperature( SI7021::SI7021_NO_HOLD_MASTER_MODE );
teoff 1:0883bd051a78 154 } else if ( myState == 2 ) {
teoff 1:0883bd051a78 155 // Lecture des mesures de température et d'humidité
teoff 1:0883bd051a78 156 mySI7021status = myTempRHsensor.SI7021_ReadHumidity ( &myData );
teoff 1:0883bd051a78 157 mySI7021status = myTempRHsensor.SI7021_ReadTemperatureFromRH ( &myData );
teoff 3:96a6e9e58178 158
teoff 1:0883bd051a78 159 //Affichage sur l'écran LCD des valeurs
teoff 0:85f60e3f81ab 160 valTemp.Draw("%0.1f", myData.Temperature);
teoff 0:85f60e3f81ab 161 valHumi.Draw("%0.0f", myData.RelativeHumidity);
teoff 0:85f60e3f81ab 162
teoff 1:0883bd051a78 163 myState = 0; // Reset state
teoff 1:0883bd051a78 164 led1 = 0;
teoff 0:85f60e3f81ab 165
teoff 1:0883bd051a78 166 }
teoff 1:0883bd051a78 167 time.Draw("%3.3f", t.read());
teoff 0:85f60e3f81ab 168
teoff 3:96a6e9e58178 169 if(t.read() >= 20) { //Condition fin de tour
teoff 1:0883bd051a78 170 nLap++;
teoff 1:0883bd051a78 171 t.reset();
teoff 1:0883bd051a78 172 }
teoff 1:0883bd051a78 173
teoff 1:0883bd051a78 174 lap.Draw("Lap %d/5",nLap);
teoff 0:85f60e3f81ab 175
teoff 1:0883bd051a78 176 if(nLap == 5) { //Condition pour arreter le nombre de tour
teoff 1:0883bd051a78 177 t.stop();
teoff 1:0883bd051a78 178 t.reset();
teoff 1:0883bd051a78 179 BlinkLabel finish(240, 180,"Course Termine",Label::CENTER);
teoff 1:0883bd051a78 180 }
teoff 0:85f60e3f81ab 181 }
teoff 0:85f60e3f81ab 182 }