Lister tortues fonctionne, debut ajouter tortue

This commit is contained in:
Cameron Bray 2020-05-26 15:58:07 +02:00
parent 8e999d0e59
commit df8d16ef4c
5 changed files with 137 additions and 54 deletions

View file

@ -6,6 +6,7 @@
#define PROJET_VICTORAVECUNK_MENU_H
#include <string>
#include <list>
#include "Tortue.h"
class Menu {
protected:
@ -21,6 +22,8 @@ public:
int getId() const;
int getChoice() const;
void previousChoice();
void menuBack();
void menuNext();

View file

@ -10,7 +10,7 @@
class Tortue{
private:
std::string nom;
int naissance;
std::string naissance;
std::string sexe;
static int nbTortue;
@ -19,11 +19,19 @@ public:
Tortue(const std::string &nom, const std::string &sexe);
const std::string &getNom() const;
void setNom(const std::string &nom);
void setNaissance(std::string naissance);
void setSexe(const std::string &sexe);
static int getNbTortue();
int getNaissance() const;
int getAge() const;
const std::string &getSexe() const;
std::string getInfo();
};
#endif //BE_TORTUE_H

View file

@ -13,6 +13,9 @@ Menu::Menu() : id(0), choice(0), nbreChoices(1) {
list.push_back(*(new std::pair<int,
std::string>(1,"\n Gestion terrarium ")));
list.push_back(*(new std::pair<int,
std::string>(2,"\nInformation Tortue : ")));
list.push_back(*(new std::pair<int,
std::string>(3,"\n Ajouter tortue")));
list.push_back(*(new std::pair<int,
@ -54,7 +57,7 @@ std::string Menu::getMessage() {
std::list<std::pair<int,std::string>>::iterator it;
for (it = list.begin(); it != list.end() ; it++) {
if (it->first == id){
if (cpt == choice){
if (cpt == choice && id != 2){
message += it->second + "<--";
} else {
message += it->second;
@ -91,17 +94,17 @@ void Menu::menuNext() {
else if (id == 1){
listId.push_back(id);
switch (choice){
case '0' :
case 0 :
id = 2;
choice = 0;
nbreChoices = 1;
nbreChoices = Tortue::getNbTortue();
break;
case '1' :
case 1 :
id = 3;
choice = 0;
nbreChoices = 2;
break;
case '2' :
case 2 :
id = 4;
choice = 0;
nbreChoices = 4;
@ -116,12 +119,12 @@ void Menu::menuNext() {
else if(id == 3){
listId.push_back(id);
switch (choice){
case '0' :
case 0 :
id = 5;
choice = 0;
nbreChoices = 1;
break;
case '1' :
case 1 :
id = 6;
choice = 0;
nbreChoices = 1;
@ -136,22 +139,22 @@ void Menu::menuNext() {
else if(id == 4){
listId.push_back(id);
switch (choice){
case '0' :
case 0 :
id = 7;
choice = 0;
nbreChoices = 1;
break;
case '1' :
case 1 :
id = 8;
choice = 0;
nbreChoices = 1;
break;
case '2' :
case 2 :
id = 9;
choice = 0;
nbreChoices = 1;
break;
case '3' :
case 3 :
id = 10;
choice = 0;
nbreChoices = 1;
@ -174,7 +177,7 @@ void Menu::menuNext() {
std::string Menu::displayDefault(float temp, float press, int rad, int tap, int nbTortue) {
std:: string message = "";
message = "\n Temperature : " + std::to_string(temp) + " \n";
message = "\nTemperature : " + std::to_string(temp) + " \n";
message += "Pression : " + std::to_string(press) + " \n";
if (rad) message += "Etat du radiateur : ON \n";
else message += "Etat du radiateur : OFF \n";
@ -182,7 +185,7 @@ std::string Menu::displayDefault(float temp, float press, int rad, int tap, int
if (tap) message += "Etat du robinet : ON \n";
else message += "Etat du robinet : OFF \n";
message += "Il y a "+std::to_string(nbTortue)+" Tortues";
message += "Il y a "+std::to_string(nbTortue)+" Tortues \0";
return message;
}
@ -191,5 +194,9 @@ int Menu::getId() const {
return id;
}
int Menu::getChoice() const {
return choice;
}

View file

@ -36,4 +36,24 @@ int Tortue::getNbTortue() {
return nbTortue;
}
std::string Tortue::getInfo() {
std::string message;
message = "\nMy name is "+this->nom;
message += "\nI am 16 years old";
message += "\n"+this->sexe;
return message;
}
void Tortue::setNom(const string &nom) {
Tortue::nom = nom;
}
void Tortue::setNaissance(std::string naissance) {
Tortue::naissance = naissance;
}
void Tortue::setSexe(const string &sexe) {
Tortue::sexe = sexe;
}

View file

@ -3,15 +3,23 @@
#include "app/include/Terrarium.h"
#include "app/include/TerrariumParameter.h"
#include "app/include/Menu.h"
#include "app/include/Tortue.h"
Terrarium terrarium(1);
TerrariumParameter temperature(25, 20);
TerrariumParameter pressure(3000,2990);
TerrariumParameter ph(8,6);
Terrarium *terrarium = new Terrarium(1);
TerrariumParameter *temperature = new TerrariumParameter(25,
20);
TerrariumParameter *pressure = new TerrariumParameter(3000,
2990);
Menu *menu = new Menu();
list<Tortue> tortues;
list<Tortue>::iterator iteratorT;
string message;
string input;
@ -32,11 +40,14 @@ void Board::setup(){
digitalWrite(0,LOW);
//pinMode(6, OUTPUT);
tortues.push_back(*(new Tortue("Marvin","male")));
tortues.push_back(*(new Tortue("Clara","female")));
tortues.push_back(*(new Tortue("Camille","non binary")));
}
// la boucle de controle arduino
void Board::loop() {
char buf[100];
char buf[150];
static int cpt = 0;
static int bascule = 0;
int i = 0;
@ -48,46 +59,52 @@ void Board::loop() {
PressureManagement();
if (menu->getId() == 0 && menu->displayDefault(temperature.getValue(),
pressure.getValue(),
terrarium.getRadState(),
terrarium.getTapState(),
if (menu->getId() == 0 && menu->displayDefault(temperature->getValue(),
pressure->getValue(),
terrarium->getRadState(),
terrarium->getTapState(),
0).c_str() != NULL) {
strcpy(buf, menu->displayDefault(temperature.getValue(),
message = menu->displayDefault(temperature->getValue(),
pressure->getValue(),
terrarium->getRadState(),
terrarium->getTapState(),
0);
/*strcpy(buf, menu->displayDefault(temperature.getValue(),
pressure.getValue(),
terrarium.getRadState(),
terrarium.getTapState(),
0).c_str());
0).c_str());*/
} else if (menu->getMessage().c_str() != NULL){
strcpy(buf, menu->getMessage().c_str());
message = menu->getMessage();
//strcpy(buf, menu->getMessage().c_str());
}
if (i % 2 == 0) {
if (analogRead(3) == HIGH && (terrarium.getPrevState() != analogRead(3))) {
terrarium.setPrevState(HIGH);
if (analogRead(3) == HIGH && (terrarium->getPrevState() != analogRead(3))) {
terrarium->setPrevState(HIGH);
menu->previousChoice();
} else if (analogRead(3) == LOW && (terrarium.getPrevState() != analogRead(3))) {
terrarium.setPrevState(LOW);
} else if (analogRead(3) == LOW && (terrarium->getPrevState() != analogRead(3))) {
terrarium->setPrevState(LOW);
}
if (analogRead(4) == HIGH && (terrarium.getNextState() != analogRead(4))) {
terrarium.setNextState(HIGH);
if (analogRead(4) == HIGH && (terrarium->getNextState() != analogRead(4))) {
terrarium->setNextState(HIGH);
menu->nextChoice();
} else if (analogRead(4) == LOW && (terrarium.getNextState() != analogRead(4))) {
terrarium.setNextState(LOW);
} else if (analogRead(4) == LOW && (terrarium->getNextState() != analogRead(4))) {
terrarium->setNextState(LOW);
}
if (analogRead(6) == HIGH && (terrarium.getOkState() != analogRead(6))) {
terrarium.setOkState(HIGH);
if (analogRead(6) == HIGH && (terrarium->getOkState() != analogRead(6))) {
terrarium->setOkState(HIGH);
cout << "OK" << endl;
menu->menuNext();
} else if (analogRead(6) == LOW && (terrarium.getOkState() != analogRead(6))) {
terrarium.setOkState(LOW);
} else if (analogRead(6) == LOW && (terrarium->getOkState() != analogRead(6))) {
terrarium->setOkState(LOW);
cout << "NOK" << endl;
}
if (analogRead(7) == HIGH && (terrarium.getBackState() != analogRead(7))) {
terrarium.setBackState(HIGH);
if (analogRead(7) == HIGH && (terrarium->getBackState() != analogRead(7))) {
terrarium->setBackState(HIGH);
menu->menuBack();
} else if (analogRead(7) == LOW && (terrarium.getBackState() != analogRead(7))) {
terrarium.setBackState(LOW);
} else if (analogRead(7) == LOW && (terrarium->getBackState() != analogRead(7))) {
terrarium->setBackState(LOW);
}
}
@ -95,7 +112,35 @@ void Board::loop() {
//sprintf(buf,"%s",menu.getMessage().c_str());
//sprintf(buf,"%f",temperature.getValue());
if (cpt % 5 == 0) bus.write(1, buf, 100);
if (menu->getId() == 2){
iteratorT = tortues.begin();
for (int j = 0; j < menu->getChoice(); ++j) {
iteratorT++;
}
//cout << iteratorT->getInfo() << endl;
message += iteratorT->getInfo();
}
if (cpt % 5 == 0) {
strcpy(buf, message.c_str());
bus.write(1, buf, 150);
}
if (menu->getId() == 5){
Tortue * newTortue;
cin >> input;
newTortue->setNom(input);
tortues.push_back(*newTortue);
menu->menuNext();
} else if (menu->getId() == 11){
cin >> input;
tortues.back().setNaissance(input);
menu->menuNext();
} else if (menu->getId() == 12){
cin >> input;
tortues.back().setSexe(input);
}
cpt++;
sleep(1);
@ -105,30 +150,30 @@ void Board::loop() {
void Board::TemperatureManagement() {
char buf[100];
temperature.setValue(analogRead(1));
temperature->setValue(analogRead(1));
//sprintf(buf, "temperature %f", temperature.getValue());
//Serial.println(buf);
if ((temperature.is2Low()) && (terrarium.getRadState() == LOW)) {
if ((temperature->is2Low()) && (terrarium->getRadState() == LOW)) {
digitalWrite(0, HIGH);
terrarium.setRadState(HIGH);
} else if ((temperature.is2High()) && (terrarium.getRadState() == HIGH)) {
terrarium->setRadState(HIGH);
} else if ((temperature->is2High()) && (terrarium->getRadState() == HIGH)) {
digitalWrite(0, LOW);
terrarium.setRadState(LOW);
terrarium->setRadState(LOW);
}
}
void Board::PressureManagement() {
char buf[100];
pressure.setValue(analogRead(5));
pressure->setValue(analogRead(5));
//sprintf(buf, "pressure %f", pressure.getValue());
//Serial.println(buf);
if ((pressure.is2Low()) && (terrarium.getTapState() == LOW)) {
if ((pressure->is2Low()) && (terrarium->getTapState() == LOW)) {
digitalWrite(2, HIGH);
terrarium.setTapState(HIGH);
} else if ((pressure.is2High()) && (terrarium.getTapState() == HIGH)) {
terrarium->setTapState(HIGH);
} else if ((pressure->is2High()) && (terrarium->getTapState() == HIGH)) {
digitalWrite(2, LOW);
terrarium.setTapState(LOW);
terrarium->setTapState(LOW);
}
}