Compare commits

..

No commits in common. "master" and "unites" have entirely different histories.

10 changed files with 75 additions and 94 deletions

Binary file not shown.

View file

@ -1,13 +0,0 @@
Nous avons fait un terrarium connecté pour tortues.
Ce terrarium utilise un thermomètre et un radiateur pour garder sa température entre deux
valeurs que l'utilisateur peut choisir, et un manomètre et une eletcrovanneattaché à une source d'eau
pour réguler la profondeur de l'eau.
L'outil contient aussi un écran affichant les caractéristiques, tels que la température, la pression,
l'état du radiateur et de l'électrovanne, et le nombre de tortues.
Il y a aussi 4 boutons (flèches), permettant de naviguer au sein d'un menu. Les fichiers pour simuler les boutons
doivent s'appeler :
ok.txt ; back.txt ; next.txt ; prev.txt
Ce menu permet de visualiser la liste des tortues, ajouter et supprimer des tortues de la liste, modifier les valeurs
min et max de température et pression. Ces valeurs sont vérifiés et doivent être possibles (min < max),
sinon une exception est levée. Le menu est navigable dans tous les sens.

View file

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

View file

@ -11,7 +11,6 @@ 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;
@ -19,18 +18,26 @@ 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,11 +21,10 @@ public:
float getValue() const; float getValue() const;
void setValue(float value); void setValue(float value);
float getThresholdHigh() const; float getThresholdHigh() const;
void setThresholdHigh(float thresholdHigh); void setThresholdHigh(int thresholdHigh);
float getThresholdLow() const; float getThresholdLow() const;
void setThresholdLow(float thresholdLow); void setThresholdLow(int thresholdLow);
//Methods
bool is2High(); bool is2High();
bool is2Low(); bool is2Low();
}; };

View file

@ -50,18 +50,6 @@ 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;
@ -80,7 +68,6 @@ std::string Menu::getMessage() {
return message; return message;
} }
void Menu::nextChoice() { void Menu::nextChoice() {
choice = (choice + 1) % (nbreChoices); choice = (choice + 1) % (nbreChoices);
} }
@ -90,8 +77,6 @@ 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;
@ -102,8 +87,6 @@ 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)));
@ -201,10 +184,8 @@ void Menu::menuNext() {
choice = 0; choice = 0;
} }
} }
//Renvoyer string avec l'écran d'accueil
std::string Menu::displayDefault(float temp, std::string Menu::displayDefault(float temp, float press, int rad, int tap, int nbTortue) {
float press, int rad,
int tap, int nbTortue) {
std:: string message = ""; std:: string message = "";
message = "\nTemperature : " + std::to_string(temp) + " °C \n"; message = "\nTemperature : " + std::to_string(temp) + " °C \n";
message += "Pression : " + std::to_string(press) + " hPa\n"; message += "Pression : " + std::to_string(press) + " hPa\n";
@ -219,7 +200,13 @@ std::string Menu::displayDefault(float temp,
return message; return message;
} }
int Menu::getId() const {
return id;
}
int Menu::getChoice() const {
return choice;
}

View file

@ -8,8 +8,6 @@ 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(float thresholdHigh) { void TerrariumParameter::setThresholdHigh(int thresholdHigh) {
if (thresholdHigh < thresholdLow){ if (thresholdHigh < thresholdLow){
throw ThresholdExcep(1); throw ThresholdExcep(1);
} else { } else {
@ -27,7 +27,7 @@ void TerrariumParameter::setThresholdHigh(float thresholdHigh) {
float TerrariumParameter::getThresholdLow() const { float TerrariumParameter::getThresholdLow() const {
return thresholdLow; return thresholdLow;
} }
void TerrariumParameter::setThresholdLow(float thresholdLow) { void TerrariumParameter::setThresholdLow(int 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 double naiss =std::mktime(timeinfo); long 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 double time = now - naiss; long time = now - naiss;
//std::cout << time <<std::endl; //std::cout << time <<std::endl;
int agean = time / 31557600; int agean = time / 31557600;
@ -119,16 +119,15 @@ void Tortue::setNaissance(std::string naissance) {
long double naiss =std::mktime(timeinfo); long 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 double time = now - naiss; long 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);
//remplissage de la liste de tortues, un jour avec lien à une bdd //pinMode(6, OUTPUT);
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/1971", "female"))); tortues->push_back(*(new Tortue("Clarisse","03/05/1843", "danseuse")));
} }
// la boucle de controle arduino // la boucle de controle arduino
void Board::loop() { void Board::loop() {
char buf[150]; //buf utilisé en output char buf[150];
char inputBuf[150]; //buf utilisé en input char inputBuf[150];
static int cpt = 0; static int cpt = 0;
static int bascule = 0; static int bascule = 0;
int i = 0; int i = 0;
@ -59,18 +59,22 @@ void Board::loop() {
for (i = 0; i < 10; i++) { for (i = 0; i < 10; i++) {
TemperatureManagement(); //Met à jour la valeur de temp TemperatureManagement();
PressureManagement(); // Met à jour la valeur de pression PressureManagement();
//cout << tortues->back() << endl; cout << tortues->back() << endl;
if (menu->getId() == 0 ) { //Afficher écran d'accueil if (menu->getId() == 0 && menu->displayDefault(temperature->getValue(),
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 { //Afficher le l'écran du ième menu } else if (menu->getMessage().c_str() != NULL){
message = menu->getMessage(); message = menu->getMessage();
} }
@ -78,7 +82,6 @@ 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();
@ -93,9 +96,11 @@ 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);
@ -104,69 +109,66 @@ void Board::loop() {
terrarium->setBackState(LOW); terrarium->setBackState(LOW);
} }
// cout << buf << endl;
//sprintf(buf,"%s",menu.getMessage().c_str());
if (menu->getId() == 2){ //Lister les tortues //sprintf(buf,"%f",temperature.getValue());
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);
} }
//Menus nécessitant une saisie au clavier if (menu->getId() == 5 || menu->getId() == 11
if (menu->getId() >= 5 && menu->getId() <= 12){ || menu->getId() == 12 || menu->getId() == 6
|| 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') { //Si utilisateur a saisie au clavier if (inputBuf[0] != '\0') {
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 : { //Création de nouvelle tortue et ajout dans la liste case 5 : {
Tortue *newTortue = new Tortue("default","01/01/1970","none"); Tortue *newTortue = new Tortue();
newTortue->setNom(input); newTortue->setNom(input);
tortues->push_back(*newTortue); tortues->push_back(*newTortue);
menu->menuNext(); menu->menuNext();
break; break;
} }
case 11 : {//MàJ de la date de naissance de la nouvelle tortue case 11 :
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) {
// 1 : date postérieure à aujourd'hui if (excep.id == 1) cout << "Not yet born ? Time travelling turtles are not allowed in this terrarium";
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) {
@ -246,8 +248,9 @@ 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);
@ -260,7 +263,9 @@ void Board::TemperatureManagement() {
void Board::PressureManagement() { void Board::PressureManagement() {
char buf[100]; char buf[100];
pressure->setValue(analogRead(5)); pressure->setValue(analogRead(5));
//Electrovanne ouverte si pression trop basse mais pas déjà ouverte //sprintf(buf, "pressure %f", pressure.getValue());
//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);