Compare commits

...

3 commits

Author SHA1 Message Date
0bb10275cc Merge remote-tracking branch 'origin/unites' 2020-05-30 15:18:33 +02:00
41a72076ac final 2020-05-30 15:18:21 +02:00
8cc143d24d ajout unités temperature et pression menu accueil 2020-05-29 11:39:33 +02:00
9 changed files with 81 additions and 75 deletions

BIN
BECppRapport.pdf Normal file

Binary file not shown.

View file

@ -10,20 +10,21 @@
class Menu { class Menu {
protected: protected:
int id; int id; //Défini l'écran actuel
int nbreChoices; int nbreChoices; //Nbre d'élémennts du menu actuel
int choice; int choice; //L'élement choisi du menu actuel
std::list<std::pair<int,std::string>> list; std::list<std::pair<int,std::string>> list; //liste de toutes les pairs d'Id et éléments
std::list<std::pair<int,int>> listId; std::list<std::pair<int,int>> listId; //Chemin d'Id parcouru
public: public:
Menu(); Menu(); //Constructeur
std::string getMessage();
void nextChoice();
//Getters
int getId() const; int getId() const;
int getChoice() const; int getChoice() const;
//Methods
std::string getMessage();
void nextChoice();
void previousChoice(); void previousChoice();
void menuBack(); void menuBack();
void menuNext(); void menuNext();

View file

@ -11,6 +11,7 @@ private:
int id; int id;
int radState; int radState;
int tapState; int tapState;
int NextState; int NextState;
int PrevState; int PrevState;
int OKState; int OKState;
@ -18,26 +19,18 @@ private:
public: public:
Terrarium(int id); Terrarium(int id);
//Getters and Setters
int getRadState() const; int getRadState() const;
void setRadState(int radState); void setRadState(int radState);
int getTapState() const; int getTapState() const;
void setTapState(int tadState); void setTapState(int tadState);
int getNextState() const; int getNextState() const;
void setNextState(int nextState); void setNextState(int nextState);
int getPrevState() const; int getPrevState() const;
void setPrevState(int prevState); void setPrevState(int prevState);
int getOkState() const; int getOkState() const;
void setOkState(int okState); void setOkState(int okState);
int getBackState() const; int getBackState() const;
void setBackState(int backState); void setBackState(int backState);
}; };

View file

@ -21,10 +21,11 @@ public:
float getValue() const; float getValue() const;
void setValue(float value); void setValue(float value);
float getThresholdHigh() const; float getThresholdHigh() const;
void setThresholdHigh(int thresholdHigh); void setThresholdHigh(float thresholdHigh);
float getThresholdLow() const; float getThresholdLow() const;
void setThresholdLow(int thresholdLow); void setThresholdLow(float thresholdLow);
//Methods
bool is2High(); bool is2High();
bool is2Low(); bool is2Low();
}; };

View file

@ -50,6 +50,18 @@ Menu::Menu() : id(0), choice(0), nbreChoices(1) {
std::string>(10,"\n Profondeur min"))); std::string>(10,"\n Profondeur min")));
} }
// Getters //
int Menu::getId() const {
return id;
}
int Menu::getChoice() const {
return choice;
}
//Methods
//Affiche tous les elements de liste qui ont la valeur Id
//dans leur pair, avec un indicateur sur l'élément choisi
std::string Menu::getMessage() { std::string Menu::getMessage() {
int cpt = 0; int cpt = 0;
@ -68,6 +80,7 @@ std::string Menu::getMessage() {
return message; return message;
} }
void Menu::nextChoice() { void Menu::nextChoice() {
choice = (choice + 1) % (nbreChoices); choice = (choice + 1) % (nbreChoices);
} }
@ -77,6 +90,8 @@ void Menu::previousChoice() {
choice = (choice - 1); choice = (choice - 1);
} }
//Reprendre les valeurs du dernier élément de
//la listeId, pour revenir sur le menu précédent
void Menu::menuBack() { void Menu::menuBack() {
if(!listId.empty()){ if(!listId.empty()){
choice = 0; choice = 0;
@ -87,6 +102,8 @@ void Menu::menuBack() {
} }
//En fonnction du menu actuel et de la
// valeur de choice, définir valeurs du menu suivant
void Menu::menuNext() { void Menu::menuNext() {
if(id ==0){ if(id ==0){
listId.push_back(*(new std::pair<int,int>(id,nbreChoices))); listId.push_back(*(new std::pair<int,int>(id,nbreChoices)));
@ -184,11 +201,13 @@ void Menu::menuNext() {
choice = 0; choice = 0;
} }
} }
//Renvoyer string avec l'écran d'accueil
std::string Menu::displayDefault(float temp, float press, int rad, int tap, int nbTortue) { std::string Menu::displayDefault(float temp,
float press, int rad,
int tap, int nbTortue) {
std:: string message = ""; std:: string message = "";
message = "\nTemperature : " + std::to_string(temp) + " \n"; message = "\nTemperature : " + std::to_string(temp) + " °C \n";
message += "Pression : " + std::to_string(press) + " \n"; message += "Pression : " + std::to_string(press) + " hPa\n";
if (rad) message += "Etat du radiateur : ON \n"; if (rad) message += "Etat du radiateur : ON \n";
else message += "Etat du radiateur : OFF \n"; else message += "Etat du radiateur : OFF \n";
@ -200,13 +219,7 @@ std::string Menu::displayDefault(float temp, float press, int rad, int tap, int
return message; return message;
} }
int Menu::getId() const {
return id;
}
int Menu::getChoice() const {
return choice;
}

View file

@ -8,6 +8,8 @@ Terrarium::Terrarium(int id) : id(id),
radState(LOW), tapState(LOW), NextState{LOW}, radState(LOW), tapState(LOW), NextState{LOW},
PrevState(LOW), OKState(LOW), BackState(LOW){} PrevState(LOW), OKState(LOW), BackState(LOW){}
//Getters and Setters //
int Terrarium::getRadState() const { int Terrarium::getRadState() const {
return radState; return radState;
} }

View file

@ -17,7 +17,7 @@ void TerrariumParameter::setValue(float value) {
float TerrariumParameter::getThresholdHigh() const { float TerrariumParameter::getThresholdHigh() const {
return thresholdHigh; return thresholdHigh;
} }
void TerrariumParameter::setThresholdHigh(int thresholdHigh) { void TerrariumParameter::setThresholdHigh(float thresholdHigh) {
if (thresholdHigh < thresholdLow){ if (thresholdHigh < thresholdLow){
throw ThresholdExcep(1); throw ThresholdExcep(1);
} else { } else {
@ -27,7 +27,7 @@ void TerrariumParameter::setThresholdHigh(int thresholdHigh) {
float TerrariumParameter::getThresholdLow() const { float TerrariumParameter::getThresholdLow() const {
return thresholdLow; return thresholdLow;
} }
void TerrariumParameter::setThresholdLow(int thresholdLow) { void TerrariumParameter::setThresholdLow(float thresholdLow) {
if (thresholdLow > thresholdHigh){ if (thresholdLow > thresholdHigh){
throw ThresholdExcep(2); throw ThresholdExcep(2);
} else { } else {

View file

@ -40,12 +40,12 @@ std::string Tortue::getAge() const {
timeinfo->tm_sec = s; timeinfo->tm_sec = s;
long naiss =std::mktime(timeinfo); long double naiss =std::mktime(timeinfo);
//std::cout << naiss << std::endl; //std::cout << naiss << std::endl;
std::time_t now = std::time(nullptr); std::time_t now = std::time(nullptr);
long time = now - naiss; long double time = now - naiss;
//std::cout << time <<std::endl; //std::cout << time <<std::endl;
int agean = time / 31557600; int agean = time / 31557600;
@ -119,15 +119,16 @@ void Tortue::setNaissance(std::string naissance) {
long naiss =std::mktime(timeinfo); long double naiss =std::mktime(timeinfo);
//std::cout << naiss << std::endl; //std::cout << naiss << std::endl;
std::time_t now = std::time(nullptr); std::time_t now = std::time(nullptr);
long time = now - naiss; long double time = now - naiss;
if (time < 0){ if (time < 0){
throw ExceptionDate(1); throw ExceptionDate(1);
} }
this->naissance = naissance;
} }
void Tortue::setSexe(const string &sexe) { void Tortue::setSexe(const string &sexe) {

View file

@ -40,18 +40,18 @@ void Board::setup(){
pinMode(2, OUTPUT); pinMode(2, OUTPUT);
digitalWrite(0,LOW); digitalWrite(0,LOW);
//pinMode(6, OUTPUT); //remplissage de la liste de tortues, un jour avec lien à une bdd
tortues->push_back(*(new Tortue("Marvin","03/09/1996","male"))); tortues->push_back(*(new Tortue("Marvin","03/09/1996","male")));
tortues->push_back(*(new Tortue("Clara","03/09/2008", "female"))); tortues->push_back(*(new Tortue("Clara","03/09/2008", "female")));
tortues->push_back(*(new Tortue("Camille","03/09/2017", "non binary"))); tortues->push_back(*(new Tortue("Camille","03/09/2017", "non binary")));
tortues->push_back(*(new Tortue("Clarisse","03/05/1843", "danseuse"))); tortues->push_back(*(new Tortue("Clarisse","03/05/1971", "female")));
} }
// la boucle de controle arduino // la boucle de controle arduino
void Board::loop() { void Board::loop() {
char buf[150]; char buf[150]; //buf utilisé en output
char inputBuf[150]; char inputBuf[150]; //buf utilisé en input
static int cpt = 0; static int cpt = 0;
static int bascule = 0; static int bascule = 0;
int i = 0; int i = 0;
@ -59,22 +59,18 @@ void Board::loop() {
for (i = 0; i < 10; i++) { for (i = 0; i < 10; i++) {
TemperatureManagement(); TemperatureManagement(); //Met à jour la valeur de temp
PressureManagement(); PressureManagement(); // Met à jour la valeur de pression
cout << tortues->back() << endl; //cout << tortues->back() << endl;
if (menu->getId() == 0 && menu->displayDefault(temperature->getValue(), if (menu->getId() == 0 ) { //Afficher écran d'accueil
pressure->getValue(),
terrarium->getRadState(),
terrarium->getTapState(),
0).c_str() != NULL) {
message = menu->displayDefault(temperature->getValue(), message = menu->displayDefault(temperature->getValue(),
pressure->getValue(), pressure->getValue(),
terrarium->getRadState(), terrarium->getRadState(),
terrarium->getTapState(), terrarium->getTapState(),
Tortue::getNbTortue()); Tortue::getNbTortue());
} else if (menu->getMessage().c_str() != NULL){ } else { //Afficher le l'écran du ième menu
message = menu->getMessage(); message = menu->getMessage();
} }
@ -82,6 +78,7 @@ void Board::loop() {
int a4 = analogRead(4); int a4 = analogRead(4);
int a6 = analogRead(6); int a6 = analogRead(6);
int a7 = analogRead(7); int a7 = analogRead(7);
//Conditions d'appui de bouton
if ( a3 == HIGH && (terrarium->getPrevState() != a3)) { if ( a3 == HIGH && (terrarium->getPrevState() != a3)) {
terrarium->setPrevState(HIGH); terrarium->setPrevState(HIGH);
menu->previousChoice(); menu->previousChoice();
@ -96,11 +93,9 @@ void Board::loop() {
} }
else if (a6 == HIGH && (terrarium->getOkState() != a6)) { else if (a6 == HIGH && (terrarium->getOkState() != a6)) {
terrarium->setOkState(HIGH); terrarium->setOkState(HIGH);
cout << "OK" << endl;
menu->menuNext(); menu->menuNext();
} else if (a6 == LOW && (terrarium->getOkState() != a6)) { } else if (a6 == LOW && (terrarium->getOkState() != a6)) {
terrarium->setOkState(LOW); terrarium->setOkState(LOW);
cout << "NOK" << endl;
} }
else if (a7 == HIGH && (terrarium->getBackState() != a7)) { else if (a7 == HIGH && (terrarium->getBackState() != a7)) {
terrarium->setBackState(HIGH); terrarium->setBackState(HIGH);
@ -109,66 +104,69 @@ void Board::loop() {
terrarium->setBackState(LOW); terrarium->setBackState(LOW);
} }
// cout << buf << endl;
//sprintf(buf,"%s",menu.getMessage().c_str());
//sprintf(buf,"%f",temperature.getValue()); if (menu->getId() == 2){ //Lister les tortues
if (menu->getId() == 2){
iteratorT = tortues->begin(); iteratorT = tortues->begin();
for (int j = 0; j < menu->getChoice(); ++j) { for (int j = 0; j < menu->getChoice(); ++j) {
iteratorT++; iteratorT++;
} }
//cout << iteratorT->getInfo() << endl;
message += iteratorT->getInfo(); message += iteratorT->getInfo();
} }
if (cpt % 2 == 0) {
if (cpt % 2 == 0) { //Afficher sur écran un tr sur 2
strcpy(buf, message.c_str()); strcpy(buf, message.c_str());
if (buf != NULL) bus.write(1, buf, 150); if (buf != NULL) bus.write(1, buf, 150);
} }
if (menu->getId() == 5 || menu->getId() == 11 //Menus nécessitant une saisie au clavier
|| menu->getId() == 12 || menu->getId() == 6 if (menu->getId() >= 5 && menu->getId() <= 12){
|| menu->getId() == 7 || menu->getId() == 8
|| menu->getId() == 9 || menu->getId() == 10){
Keyboard::saisie = true ; Keyboard::saisie = true ;
sleep(4); sleep(4);
if ( (&bus!=NULL)&&!(bus.isEmptyRegister(2))) { if ( (&bus!=NULL)&&!(bus.isEmptyRegister(2))) {
bus.requestFrom(2, inputBuf, 150); bus.requestFrom(2, inputBuf, 150);
if (inputBuf[0] != '\0') { if (inputBuf[0] != '\0') { //Si utilisateur a saisie au clavier
input = ""; input = "";
for (int j = 0; inputBuf[j] != '\0'; ++j) { for (int j = 0; inputBuf[j] != '\0'; ++j) {
input += inputBuf[j]; input += inputBuf[j];
} }
switch (menu->getId()) { switch (menu->getId()) {
case 5 : { case 5 : { //Création de nouvelle tortue et ajout dans la liste
Tortue *newTortue = new Tortue(); Tortue *newTortue = new Tortue("default","01/01/1970","none");
newTortue->setNom(input); newTortue->setNom(input);
tortues->push_back(*newTortue); tortues->push_back(*newTortue);
menu->menuNext(); menu->menuNext();
break; break;
} }
case 11 : case 11 : {//MàJ de la date de naissance de la nouvelle tortue
try { try {
tortues->back().setNaissance(input); tortues->back().setNaissance(input);
menu->menuNext(); menu->menuNext();
} catch (std::invalid_argument excep) { } catch (std::invalid_argument excep) {
// Valeurs rentrés ne sont pas des integers
cout << "Dates are not integers" << endl; cout << "Dates are not integers" << endl;
} catch (Tortue::ExceptionDate excep) { } catch (Tortue::ExceptionDate excep) {
if (excep.id == 1) cout << "Not yet born ? Time travelling turtles are not allowed in this terrarium"; // 1 : date postérieure à aujourd'hui
if (excep.id == 1)
cout << "Not yet born ? Time travelling turtles are not allowed in this terrarium";
// 2 : mauvais format
else if (excep.id == 2) cout << "The format of the date is not correct"; else if (excep.id == 2) cout << "The format of the date is not correct";
// 3 : date trop ancienne
else if (excep.id == 3) cout << "It wasn't really born before 1900... You were scammed"; else if (excep.id == 3) cout << "It wasn't really born before 1900... You were scammed";
// 4 : Mois > 12
else if (excep.id == 4) cout << "After December you start over at January"; else if (excep.id == 4) cout << "After December you start over at January";
// 5 : Jours > 3
else if (excep.id == 5) cout << "Months don't usually last more than 31 days !"; else if (excep.id == 5) cout << "Months don't usually last more than 31 days !";
} }
break; break;
case 12 : }
case 12 : {
tortues->back().setSexe(input); tortues->back().setSexe(input);
menu->menuNext(); menu->menuNext();
break; break;
case 6: { }
case 6: { //Supprimer la tortue ayant le nom input
int length = tortues->size(); int length = tortues->size();
iteratorT = tortues->begin(); iteratorT = tortues->begin();
for (int j = 0; j < length; ++j) { for (int j = 0; j < length; ++j) {
@ -248,9 +246,8 @@ void Board::loop() {
void Board::TemperatureManagement() { void Board::TemperatureManagement() {
char buf[100]; char buf[100];
temperature->setValue(analogRead(1)); temperature->setValue(analogRead(1));
//sprintf(buf, "temperature %f", temperature.getValue());
//Serial.println(buf);
//Rad allume si temp trop basse mais pas déjà allumé
if ((temperature->is2Low()) && (terrarium->getRadState() == LOW)) { if ((temperature->is2Low()) && (terrarium->getRadState() == LOW)) {
digitalWrite(0, HIGH); digitalWrite(0, HIGH);
terrarium->setRadState(HIGH); terrarium->setRadState(HIGH);
@ -263,9 +260,7 @@ void Board::TemperatureManagement() {
void Board::PressureManagement() { void Board::PressureManagement() {
char buf[100]; char buf[100];
pressure->setValue(analogRead(5)); pressure->setValue(analogRead(5));
//sprintf(buf, "pressure %f", pressure.getValue()); //Electrovanne ouverte si pression trop basse mais pas déjà ouverte
//Serial.println(buf);
if ((pressure->is2Low()) && (terrarium->getTapState() == LOW)) { if ((pressure->is2Low()) && (terrarium->getTapState() == LOW)) {
digitalWrite(2, HIGH); digitalWrite(2, HIGH);
terrarium->setTapState(HIGH); terrarium->setTapState(HIGH);