From ac143880d656cb0332843dbd1a0ba850061be0ed Mon Sep 17 00:00:00 2001 From: victorleroch Date: Mon, 25 May 2020 16:49:27 +0200 Subject: [PATCH] Avancement menu, probleme avec le bus.write --- app/include/Menu.h | 9 ++- app/include/Terrarium.h | 19 +++++ app/include/Tortue.h | 5 +- app/src/Menu.cpp | 160 ++++++++++++++++++++++++++++++++++++---- app/src/Terrarium.cpp | 32 ++++++++ app/src/Tortue.cpp | 6 ++ board.cpp | 5 +- sketch_ino.cpp | 66 ++++++++++++++--- 8 files changed, 275 insertions(+), 27 deletions(-) diff --git a/app/include/Menu.h b/app/include/Menu.h index 923fdf9..442544c 100644 --- a/app/include/Menu.h +++ b/app/include/Menu.h @@ -13,11 +13,18 @@ protected: int nbreChoices; int choice; std::list> list; + std::list listId; public: Menu(); std::string getMessage(); void nextChoice(); - void update(std::string message); + + int getId() const; + + void previousChoice(); + void menuBack(); + void menuNext(); + std::string displayDefault(float temp, float press, int rad, int tap, int nbTortue); }; diff --git a/app/include/Terrarium.h b/app/include/Terrarium.h index 14d770a..149818a 100644 --- a/app/include/Terrarium.h +++ b/app/include/Terrarium.h @@ -11,6 +11,10 @@ private: int id; int radState; int tapState; + int NextState; + int PrevState; + int OKState; + int BackState; public: Terrarium(int id); @@ -19,6 +23,21 @@ public: int getTapState() const; void setTapState(int tadState); + int getNextState() const; + + void setNextState(int nextState); + + int getPrevState() const; + + void setPrevState(int prevState); + + int getOkState() const; + + void setOkState(int okState); + + int getBackState() const; + + void setBackState(int backState); }; diff --git a/app/include/Tortue.h b/app/include/Tortue.h index 6c9cdb3..edd09b8 100644 --- a/app/include/Tortue.h +++ b/app/include/Tortue.h @@ -12,11 +12,14 @@ private: std::string nom; int naissance; std::string sexe; + static int nbTortue; + + public: Tortue(const std::string &nom, const std::string &sexe); const std::string &getNom() const; - + static int getNbTortue(); int getNaissance() const; int getAge() const; diff --git a/app/src/Menu.cpp b/app/src/Menu.cpp index f866971..9d31bf4 100644 --- a/app/src/Menu.cpp +++ b/app/src/Menu.cpp @@ -4,16 +4,17 @@ #include "../include/Menu.h" -Menu::Menu() : id(0), choice(0) { + +Menu::Menu() : id(0), choice(0), nbreChoices(1) { list.push_back(*(new std::pair(1,"liste tortue"))); + std::string>(1,"Liste tortue"))); list.push_back(*(new std::pair(1,"management tortue"))); + std::string>(1,"Management tortue"))); list.push_back(*(new std::pair(1,"Gestion terrarium"))); list.push_back(*(new std::pair(3,"ajouter tortue"))); + std::string>(3,"Ajouter tortue"))); list.push_back(*(new std::pair(3,"supprimer tortue"))); @@ -25,10 +26,30 @@ Menu::Menu() : id(0), choice(0) { std::string>(4,"Profondeur max"))); list.push_back(*(new std::pair(4,"Profondeur min"))); + + list.push_back(*(new std::pair(5,"Nom de la tortue a ajouter"))); + list.push_back(*(new std::pair(11,"Naissance"))); + list.push_back(*(new std::pair(12,"Sexe"))); + + list.push_back(*(new std::pair(6,"Nom de la tortue a supprimer"))); + + list.push_back(*(new std::pair(7,"Temperature max"))); + list.push_back(*(new std::pair(8,"Temperature min"))); + list.push_back(*(new std::pair(9,"Profondeur max"))); + list.push_back(*(new std::pair(10,"Profondeur min"))); } std::string Menu::getMessage() { int cpt = 0; + std::string message = ""; std::list>::iterator it; for (it = list.begin(); it != list.end() ; it++) { @@ -48,16 +69,125 @@ void Menu::nextChoice() { choice = (choice + 1) % nbreChoices; } -void Menu::update(std::string message) { - if (message == "n"){ - nextChoice(); - } else if (message == "liste tortue"){ - id = 2; - } else if (message == "management tortue"){ - id = 3; - nbreChoices = 2; - } else if (message == "gestion terrarium"){ - id = 4; - nbreChoices = 4; +void Menu::previousChoice() { + choice = (choice - 1) % nbreChoices; +} + + + + + + +void Menu::menuBack() { + if(listId.size() > 1){ + listId.pop_back(); + id = *listId.end(); } } + +void Menu::menuNext() { + if(id ==0){ + listId.push_back(id); + id = 1; + choice = 0; + nbreChoices = 3; + } + if (id == 1){ + listId.push_back(id); + switch (choice){ + case '0' : + id = 2; + choice = 0; + nbreChoices = 1; + break; + case '1' : + id = 3; + choice = 0; + nbreChoices = 2; + break; + case '2' : + id = 4; + choice = 0; + nbreChoices = 4; + break; + default: + id = 0; + choice = 0; + nbreChoices = 1; + } + + } + if(id == 3){ + listId.push_back(id); + switch (choice){ + case '0' : + id = 5; + choice = 0; + nbreChoices = 1; + break; + case '1' : + id = 6; + choice = 0; + nbreChoices = 1; + break; + default: + id = 0; + choice = 0; + nbreChoices = 1; + + } + } + if(id == 4){ + listId.push_back(id); + switch (choice){ + case '0' : + id = 7; + choice = 0; + nbreChoices = 1; + break; + case '1' : + id = 8; + choice = 0; + nbreChoices = 1; + break; + case '2' : + id = 9; + choice = 0; + nbreChoices = 1; + break; + case '3' : + id = 10; + choice = 0; + nbreChoices = 1; + break; + default: + id = 0; + choice = 0; + nbreChoices = 1; + } + } + if(id == 5){ + listId.push_back(id); + id = 11; + } + if (id == 11){ + listId.push_back(id); + id = 12; + } +} + +std::string Menu::displayDefault(float temp, float press, int rad, int tap, int nbTortue) { + std:: string message = ""; + message = "Temperature : " + std::to_string(temp) + " \n "; + message += " Pression : " + std::to_string(press) + " \n "; + message += " Etat du radiateur : " + std::to_string(rad) + " \n "; + message += " Etat du robinet : " + std::to_string(tap) + " \n "; + return message; +} + +int Menu::getId() const { + return id; +} + + + diff --git a/app/src/Terrarium.cpp b/app/src/Terrarium.cpp index 5231581..4171c3c 100644 --- a/app/src/Terrarium.cpp +++ b/app/src/Terrarium.cpp @@ -23,3 +23,35 @@ void Terrarium::setTapState(int tapState) { Terrarium::tapState = tapState; } +int Terrarium::getNextState() const { + return NextState; +} + +void Terrarium::setNextState(int nextState) { + NextState = nextState; +} + +int Terrarium::getPrevState() const { + return PrevState; +} + +void Terrarium::setPrevState(int prevState) { + PrevState = prevState; +} + +int Terrarium::getOkState() const { + return OKState; +} + +void Terrarium::setOkState(int okState) { + OKState = okState; +} + +int Terrarium::getBackState() const { + return BackState; +} + +void Terrarium::setBackState(int backState) { + BackState = backState; +} + diff --git a/app/src/Tortue.cpp b/app/src/Tortue.cpp index b3dd19b..4c6d77a 100644 --- a/app/src/Tortue.cpp +++ b/app/src/Tortue.cpp @@ -20,6 +20,7 @@ const std::string &Tortue::getSexe() const { Tortue::Tortue(const string &nom, const string &sexe) : nom(nom), sexe(sexe) { naissance = std::time(nullptr); + nbTortue ++; } int Tortue::getAge() const { @@ -29,5 +30,10 @@ int Tortue::getAge() const { int age = ageDay / 365.25; return age; } +int Tortue::nbTortue = 0; + +int Tortue::getNbTortue() { + return nbTortue; +} diff --git a/board.cpp b/board.cpp index 08bfdd6..05af237 100644 --- a/board.cpp +++ b/board.cpp @@ -34,12 +34,15 @@ int main(){ // branchement des capteurs actionneurs + esp8266.pin(0, radiator); esp8266.pin(1,temperature); //esp8266.pin(0,led1); esp8266.pin(2, electrovanne); + esp8266.pin(3, buttonPrev); esp8266.pin(4, buttonNext); esp8266.pin(5, manometre); - esp8266.pin(0, radiator); + esp8266.pin(6, buttonOK); + esp8266.pin(7, buttonBack); esp8266.i2c(1,screen); esp8266.i2c(2,keyboard); diff --git a/sketch_ino.cpp b/sketch_ino.cpp index 5f9baeb..1d9368d 100644 --- a/sketch_ino.cpp +++ b/sketch_ino.cpp @@ -2,6 +2,7 @@ #include "core_simulation.h" #include "app/include/Terrarium.h" #include "app/include/TerrariumParameter.h" +#include "app/include/Menu.h" Terrarium terrarium(1); @@ -9,6 +10,9 @@ TerrariumParameter temperature(25, 20); TerrariumParameter pressure(3000,2990); TerrariumParameter ph(8,6); +Menu menu; + + // la fonction d'initialisation d'arduino @@ -19,6 +23,9 @@ void Board::setup(){ pinMode(1, INPUT); pinMode(4, INPUT); pinMode(5, INPUT); + pinMode(3, INPUT); + pinMode(6, INPUT); + pinMode(7, INPUT); pinMode(0, OUTPUT); pinMode(2, OUTPUT); @@ -33,23 +40,64 @@ void Board::loop(){ static int cpt=0; static int bascule=0; int i=0; + std::string toDisplay; + + + + //for(i=0;i<10;i++){ TemperatureManagement(); PressureManagement(); + if(menu.getId() == 0){ + strcpy(buf, menu.displayDefault(temperature.getValue(), + pressure.getValue(), + terrarium.getRadState(), + terrarium.getTapState(), + 0).c_str()); + } else { + strcpy(buf,menu.getMessage().c_str()); + } - // if(cpt%5==0){ - // tous les 5 fois on affiche sur l ecran la temperature - sprintf(buf,"%f",temperature.getValue()); - bus.write(1,buf,100); - //bus.requestFrom(1,buf,100); - // } - cpt++; - sleep(1); - //} + if(analogRead(3) && (terrarium.getPrevState() != analogRead(3)) ){ + terrarium.setPrevState(HIGH); + menu.previousChoice(); + } else if (!analogRead(3) && (terrarium.getPrevState() != analogRead(3))){ + terrarium.setPrevState(LOW); + } + if(analogRead(4) && (terrarium.getNextState() != analogRead(4)) ){ + terrarium.setNextState(HIGH); + menu.nextChoice(); + }else if (!analogRead(4) && (terrarium.getNextState() != analogRead(4))){ + terrarium.setNextState(LOW); + } + if(analogRead(6) && (terrarium.getOkState() != analogRead(6)) ){ + terrarium.setOkState(HIGH); + menu.menuNext(); + }else if (!analogRead(6) && (terrarium.getOkState() != analogRead(6))){ + terrarium.setOkState(LOW); + } + if(analogRead(7) && (terrarium.getBackState() != analogRead(7)) ){ + terrarium.setBackState(HIGH); + menu.menuBack(); + }else if (!analogRead(7) && (terrarium.getBackState() != analogRead(7))){ + terrarium.setBackState(LOW); + } + + cout << buf << endl; + //sprintf(buf,"%s",menu.getMessage().c_str()); + + //sprintf(buf,"%f",temperature.getValue()); + //bus.write(1,buf,100); + + cpt++; + + + sleep(1); + }