Avancement menu, probleme avec le bus.write

This commit is contained in:
Victor Le Roch 2020-05-25 16:49:27 +02:00
parent ca90d0487b
commit ac143880d6
8 changed files with 275 additions and 27 deletions

View file

@ -13,11 +13,18 @@ protected:
int nbreChoices;
int choice;
std::list<std::pair<int,std::string>> list;
std::list<int> 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);
};

View file

@ -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);
};

View file

@ -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;

View file

@ -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<int,
std::string>(1,"liste tortue")));
std::string>(1,"Liste tortue")));
list.push_back(*(new std::pair<int,
std::string>(1,"management tortue")));
std::string>(1,"Management tortue")));
list.push_back(*(new std::pair<int,
std::string>(1,"Gestion terrarium")));
list.push_back(*(new std::pair<int,
std::string>(3,"ajouter tortue")));
std::string>(3,"Ajouter tortue")));
list.push_back(*(new std::pair<int,
std::string>(3,"supprimer tortue")));
@ -25,10 +26,30 @@ Menu::Menu() : id(0), choice(0) {
std::string>(4,"Profondeur max")));
list.push_back(*(new std::pair<int,
std::string>(4,"Profondeur min")));
list.push_back(*(new std::pair<int,
std::string>(5,"Nom de la tortue a ajouter")));
list.push_back(*(new std::pair<int,
std::string>(11,"Naissance")));
list.push_back(*(new std::pair<int,
std::string>(12,"Sexe")));
list.push_back(*(new std::pair<int,
std::string>(6,"Nom de la tortue a supprimer")));
list.push_back(*(new std::pair<int,
std::string>(7,"Temperature max")));
list.push_back(*(new std::pair<int,
std::string>(8,"Temperature min")));
list.push_back(*(new std::pair<int,
std::string>(9,"Profondeur max")));
list.push_back(*(new std::pair<int,
std::string>(10,"Profondeur min")));
}
std::string Menu::getMessage() {
int cpt = 0;
std::string message = "";
std::list<std::pair<int,std::string>>::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;
}

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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);

View file

@ -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);
}