Projet Interfacage

Dependencies:   F746_GUI mbed SI7021

Committer:
teoff
Date:
Tue Jun 22 06:37:09 2021 +0000
Revision:
0:85f60e3f81ab
Child:
1:0883bd051a78
First commit

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 0:85f60e3f81ab 10 DigitalOut myled1 ( 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 0:85f60e3f81ab 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 0:85f60e3f81ab 26 int NumBoutonGroupMode=0, nLap = 1;
teoff 0:85f60e3f81ab 27 float readTime = 0;
teoff 0:85f60e3f81ab 28 char text[100];
teoff 0:85f60e3f81ab 29
teoff 0:85f60e3f81ab 30 Label titre(240, 2, "Dashboard F1", Label::CENTER, Font16);
teoff 0:85f60e3f81ab 31 Label temperature(180, 110, "Temperature : ");
teoff 0:85f60e3f81ab 32 Label humidite(180, 135, "Humidite : ");
teoff 0:85f60e3f81ab 33 Label labelTime(180, 155,"Lap Time : ");
teoff 0:85f60e3f81ab 34 Label pneu(260, 40,"Pneu");
teoff 0:85f60e3f81ab 35 Label allTime(180, 175,"");
teoff 0:85f60e3f81ab 36
teoff 0:85f60e3f81ab 37 Button button1(10, 54, 30, 35, "1");
teoff 0:85f60e3f81ab 38 Button button2(42, 54, 30, 35, "2");
teoff 0:85f60e3f81ab 39 //Button doNotTouch(250, 220, 120, 40, "Page 2", Font12, GuiBase::ENUM_TEXT, GuiBase::ENUM_BACK, LCD_COLOR_DARKGREEN, LCD_COLOR_RED);
teoff 0:85f60e3f81ab 40 Button talk(10, 120, 60, 35, "Radio");
teoff 0:85f60e3f81ab 41
teoff 0:85f60e3f81ab 42 const int NUMBER_BUTTONS = 3;
teoff 0:85f60e3f81ab 43 const string PNEU[NUMBER_BUTTONS] = {"Soft", "Medium", "Hard"};
teoff 0:85f60e3f81ab 44 ButtonGroup bGroup1(168, 54, 66, 35, NUMBER_BUTTONS, PNEU, 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 0:85f60e3f81ab 50 NumericLabel<int> valBias(110,250, "");
teoff 0:85f60e3f81ab 51 NumericLabel<int> valDiff(350,250, "");
teoff 0:85f60e3f81ab 52
teoff 0:85f60e3f81ab 53 SeekBar bias(20, 230, 200, 0, 100, 50, "0", "Bias","");
teoff 0:85f60e3f81ab 54 SeekBar diff(260, 230, 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 0:85f60e3f81ab 62 t.start();
teoff 0:85f60e3f81ab 63 // Reset the device
teoff 0:85f60e3f81ab 64 mySI7021status = myTempRHsensor.SI7021_SoftReset ();
teoff 0:85f60e3f81ab 65 //wait_ms ( 15 );
teoff 0:85f60e3f81ab 66 // Configure the device
teoff 0:85f60e3f81ab 67 mySI7021status = myTempRHsensor.SI7021_Conf ( SI7021::SI7021_RESOLUTION_RH_12_TEMP_14, SI7021::SI7021_HTRE_DISABLED );
teoff 0:85f60e3f81ab 68 // Get the Electronic Serial Number
teoff 0:85f60e3f81ab 69 mySI7021status = myTempRHsensor.SI7021_GetElectronicSerialNumber ( &myData );
teoff 0:85f60e3f81ab 70 // Get the Firmware revision
teoff 0:85f60e3f81ab 71 mySI7021status = myTempRHsensor.SI7021_GetFirmwareRevision ( &myData );
teoff 0:85f60e3f81ab 72
teoff 0:85f60e3f81ab 73 newReading.attach( &readDATA, 0.1 ); // the address of the function to be attached ( readDATA ) and the interval ( 1s )
teoff 0:85f60e3f81ab 74 while (1) {
teoff 0:85f60e3f81ab 75 if (button1.Touched()) button2.Draw();
teoff 0:85f60e3f81ab 76 if (button2.Touched()) button1.Draw();
teoff 0:85f60e3f81ab 77
teoff 0:85f60e3f81ab 78 NumBoutonGroupMode=bGroup1.GetTouchedNumber();
teoff 0:85f60e3f81ab 79 if(bGroup1.GetTouchedNumber(NumBoutonGroupMode)) {
teoff 0:85f60e3f81ab 80 switch (NumBoutonGroupMode) {
teoff 0:85f60e3f81ab 81 case 0 :
teoff 0:85f60e3f81ab 82 bGroup1.Inactivate(0);
teoff 0:85f60e3f81ab 83 bGroup1.Activate(1);
teoff 0:85f60e3f81ab 84 bGroup1.Activate(2);
teoff 0:85f60e3f81ab 85 bGroup1.Draw(1,0xFFFFE800,0xFFFFFFFF); //Yellow
teoff 0:85f60e3f81ab 86 bGroup1.Draw(2,0xFFFFFFFF,0xFF000000); //White
teoff 0:85f60e3f81ab 87 break;
teoff 0:85f60e3f81ab 88 case 1 :
teoff 0:85f60e3f81ab 89 bGroup1.Inactivate(1);
teoff 0:85f60e3f81ab 90 bGroup1.Activate(0);
teoff 0:85f60e3f81ab 91 bGroup1.Activate(2);
teoff 0:85f60e3f81ab 92 bGroup1.Draw(0,0xFFFF0000,0xFFFFFFFF); //Red
teoff 0:85f60e3f81ab 93 bGroup1.Draw(2,0xFFFFFFFF,0xFF000000); //White
teoff 0:85f60e3f81ab 94 break;
teoff 0:85f60e3f81ab 95 case 2 :
teoff 0:85f60e3f81ab 96 bGroup1.Inactivate(2);
teoff 0:85f60e3f81ab 97 bGroup1.Activate(0);
teoff 0:85f60e3f81ab 98 bGroup1.Activate(1);
teoff 0:85f60e3f81ab 99 bGroup1.Draw(0,0xFFFF0000,0xFFFFFFFF); //Red
teoff 0:85f60e3f81ab 100 bGroup1.Draw(1,0xFFFFE800,0xFFFFFFFF); //Yellow
teoff 0:85f60e3f81ab 101 break;
teoff 0:85f60e3f81ab 102 }
teoff 0:85f60e3f81ab 103 }
teoff 0:85f60e3f81ab 104
teoff 0:85f60e3f81ab 105 if (bias.Slide()) {
teoff 0:85f60e3f81ab 106
teoff 0:85f60e3f81ab 107 valBias.Draw("%d",bias.GetValue());
teoff 0:85f60e3f81ab 108 }
teoff 0:85f60e3f81ab 109 if (diff.Slide()) {
teoff 0:85f60e3f81ab 110
teoff 0:85f60e3f81ab 111 valDiff.Draw("%d",diff.GetValue());
teoff 0:85f60e3f81ab 112 }
teoff 0:85f60e3f81ab 113
teoff 0:85f60e3f81ab 114 sleep();
teoff 0:85f60e3f81ab 115
teoff 0:85f60e3f81ab 116 if ( myState == 1 ) {
teoff 0:85f60e3f81ab 117 // Trigger a new Humidity conversion ( the temperature conversion is triggered by default )
teoff 0:85f60e3f81ab 118 myled1 = 1;
teoff 0:85f60e3f81ab 119
teoff 0:85f60e3f81ab 120 mySI7021status = myTempRHsensor.SI7021_TriggerHumidity ( SI7021::SI7021_NO_HOLD_MASTER_MODE );
teoff 0:85f60e3f81ab 121 mySI7021status = myTempRHsensor.SI7021_TriggerTemperature ( SI7021::SI7021_NO_HOLD_MASTER_MODE );
teoff 0:85f60e3f81ab 122 }
teoff 0:85f60e3f81ab 123 else if ( myState == 2 ) {
teoff 0:85f60e3f81ab 124 // Read Humidity and Temperature result
teoff 0:85f60e3f81ab 125 mySI7021status = myTempRHsensor.SI7021_ReadHumidity ( &myData );
teoff 0:85f60e3f81ab 126 mySI7021status = myTempRHsensor.SI7021_ReadTemperatureFromRH ( &myData );
teoff 0:85f60e3f81ab 127
teoff 0:85f60e3f81ab 128 valTemp.Draw("%0.1f", myData.Temperature);
teoff 0:85f60e3f81ab 129 valHumi.Draw("%0.0f", myData.RelativeHumidity);
teoff 0:85f60e3f81ab 130 time.Draw("%3.3f", t.read());
teoff 0:85f60e3f81ab 131
teoff 0:85f60e3f81ab 132 myState = 0; // Reset state
teoff 0:85f60e3f81ab 133 myled1 = 0;
teoff 0:85f60e3f81ab 134
teoff 0:85f60e3f81ab 135 readTime = t.read();
teoff 0:85f60e3f81ab 136 //sprintf(text,"%0.3f",readTime);
teoff 0:85f60e3f81ab 137
teoff 0:85f60e3f81ab 138 if(t.read() >= 30) {
teoff 0:85f60e3f81ab 139 nLap++;
teoff 0:85f60e3f81ab 140 //allTime.Draw(text);
teoff 0:85f60e3f81ab 141 t.reset();
teoff 0:85f60e3f81ab 142 }
teoff 0:85f60e3f81ab 143
teoff 0:85f60e3f81ab 144 if(nLap == 5) {
teoff 0:85f60e3f81ab 145 t.stop();
teoff 0:85f60e3f81ab 146 t.reset();
teoff 0:85f60e3f81ab 147 }
teoff 0:85f60e3f81ab 148
teoff 0:85f60e3f81ab 149 lap.Draw("Lap %d/5",nLap);
teoff 0:85f60e3f81ab 150 }
teoff 0:85f60e3f81ab 151 }
teoff 0:85f60e3f81ab 152 }