Projet Interfacage

Dependencies:   F746_GUI mbed SI7021

Committer:
teoff
Date:
Tue Jun 22 10:01:32 2021 +0000
Revision:
1:0883bd051a78
Parent:
0:85f60e3f81ab
Child:
2:8a932906e684
Programme termine;

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