Projet Interfacage
Dependencies: F746_GUI mbed SI7021
Diff: main.cpp
- Revision:
- 0:85f60e3f81ab
- Child:
- 1:0883bd051a78
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Tue Jun 22 06:37:09 2021 +0000 @@ -0,0 +1,152 @@ +#include "mbed.h" +#include "F746_GUI.hpp" +#include "SI7021.h" + +SI7021 myTempRHsensor ( I2C_SDA, I2C_SCL, SI7021::SI7021_ADDRESS, 400000 ); +Serial pc ( USBTX, USBRX ); +Timer t; + +Ticker newReading; +DigitalOut myled1 ( LED1 ); + +SI7021::SI7021_vector_data_t myData; +SI7021::SI7021_status_t mySI7021status; +uint32_t myState; + + +void readDATA ( void ) +{ + myState++; +} + +using namespace Mikami; + +int main() +{ + int NumBoutonGroupMode=0, nLap = 1; + float readTime = 0; + char text[100]; + + Label titre(240, 2, "Dashboard F1", Label::CENTER, Font16); + Label temperature(180, 110, "Temperature : "); + Label humidite(180, 135, "Humidite : "); + Label labelTime(180, 155,"Lap Time : "); + Label pneu(260, 40,"Pneu"); + Label allTime(180, 175,""); + + Button button1(10, 54, 30, 35, "1"); + Button button2(42, 54, 30, 35, "2"); + //Button doNotTouch(250, 220, 120, 40, "Page 2", Font12, GuiBase::ENUM_TEXT, GuiBase::ENUM_BACK, LCD_COLOR_DARKGREEN, LCD_COLOR_RED); + Button talk(10, 120, 60, 35, "Radio"); + + const int NUMBER_BUTTONS = 3; + const string PNEU[NUMBER_BUTTONS] = {"Soft", "Medium", "Hard"}; + ButtonGroup bGroup1(168, 54, 66, 35, NUMBER_BUTTONS, PNEU, 2, 2, 3, 1, Font12, LCD_COLOR_WHITE, LCD_COLOR_BLACK); + NumericLabel<int> bTouch(240, 112, "", Label::LEFT, Font12, LCD_COLOR_WHITE); + NumericLabel<float> valTemp(290,110, "", Label::CENTER, Font12, LCD_COLOR_WHITE, LCD_COLOR_BLACK); + NumericLabel<float> valHumi(260,135, "", Label::CENTER, Font12, LCD_COLOR_WHITE, LCD_COLOR_BLACK); + NumericLabel<float> time(280,155, "", Label::CENTER, Font12, LCD_COLOR_WHITE, LCD_COLOR_BLACK); + NumericLabel<int> lap(420,25, ""); + NumericLabel<int> valBias(110,250, ""); + NumericLabel<int> valDiff(350,250, ""); + + SeekBar bias(20, 230, 200, 0, 100, 50, "0", "Bias",""); + SeekBar diff(260, 230, 200, 0, 100, 50, "0", "Differentiel",""); + + bGroup1.Draw(0,0xFFFF0000,0xFFFFFFFF); //Red + bGroup1.Draw(1,0xFFFFE800,0xFFFFFFFF); //Yellow + bGroup1.Draw(2,0xFFFFFFFF,0xFF000000); //White + + pc.baud ( 115200 ); + + t.start(); + // Reset the device + mySI7021status = myTempRHsensor.SI7021_SoftReset (); + //wait_ms ( 15 ); + // Configure the device + mySI7021status = myTempRHsensor.SI7021_Conf ( SI7021::SI7021_RESOLUTION_RH_12_TEMP_14, SI7021::SI7021_HTRE_DISABLED ); + // Get the Electronic Serial Number + mySI7021status = myTempRHsensor.SI7021_GetElectronicSerialNumber ( &myData ); + // Get the Firmware revision + mySI7021status = myTempRHsensor.SI7021_GetFirmwareRevision ( &myData ); + + newReading.attach( &readDATA, 0.1 ); // the address of the function to be attached ( readDATA ) and the interval ( 1s ) + while (1) { + if (button1.Touched()) button2.Draw(); + if (button2.Touched()) button1.Draw(); + + NumBoutonGroupMode=bGroup1.GetTouchedNumber(); + if(bGroup1.GetTouchedNumber(NumBoutonGroupMode)) { + switch (NumBoutonGroupMode) { + case 0 : + bGroup1.Inactivate(0); + bGroup1.Activate(1); + bGroup1.Activate(2); + bGroup1.Draw(1,0xFFFFE800,0xFFFFFFFF); //Yellow + bGroup1.Draw(2,0xFFFFFFFF,0xFF000000); //White + break; + case 1 : + bGroup1.Inactivate(1); + bGroup1.Activate(0); + bGroup1.Activate(2); + bGroup1.Draw(0,0xFFFF0000,0xFFFFFFFF); //Red + bGroup1.Draw(2,0xFFFFFFFF,0xFF000000); //White + break; + case 2 : + bGroup1.Inactivate(2); + bGroup1.Activate(0); + bGroup1.Activate(1); + bGroup1.Draw(0,0xFFFF0000,0xFFFFFFFF); //Red + bGroup1.Draw(1,0xFFFFE800,0xFFFFFFFF); //Yellow + break; + } + } + + if (bias.Slide()) { + + valBias.Draw("%d",bias.GetValue()); + } + if (diff.Slide()) { + + valDiff.Draw("%d",diff.GetValue()); + } + + sleep(); + + if ( myState == 1 ) { + // Trigger a new Humidity conversion ( the temperature conversion is triggered by default ) + myled1 = 1; + + mySI7021status = myTempRHsensor.SI7021_TriggerHumidity ( SI7021::SI7021_NO_HOLD_MASTER_MODE ); + mySI7021status = myTempRHsensor.SI7021_TriggerTemperature ( SI7021::SI7021_NO_HOLD_MASTER_MODE ); + } + else if ( myState == 2 ) { + // Read Humidity and Temperature result + mySI7021status = myTempRHsensor.SI7021_ReadHumidity ( &myData ); + mySI7021status = myTempRHsensor.SI7021_ReadTemperatureFromRH ( &myData ); + + valTemp.Draw("%0.1f", myData.Temperature); + valHumi.Draw("%0.0f", myData.RelativeHumidity); + time.Draw("%3.3f", t.read()); + + myState = 0; // Reset state + myled1 = 0; + + readTime = t.read(); + //sprintf(text,"%0.3f",readTime); + + if(t.read() >= 30) { + nLap++; + //allTime.Draw(text); + t.reset(); + } + + if(nLap == 5) { + t.stop(); + t.reset(); + } + + lap.Draw("Lap %d/5",nLap); + } + } +}