Compare commits
No commits in common. "master" and "unites" have entirely different histories.
10 changed files with 75 additions and 94 deletions
BIN
BECppRapport.pdf
BIN
BECppRapport.pdf
Binary file not shown.
13
README.txt
13
README.txt
|
@ -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.
|
|
@ -10,21 +10,20 @@
|
|||
|
||||
class Menu {
|
||||
protected:
|
||||
int id; //Défini l'écran actuel
|
||||
int nbreChoices; //Nbre d'élémennts du menu actuel
|
||||
int choice; //L'élement choisi du menu actuel
|
||||
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; //Chemin d'Id parcouru
|
||||
int id;
|
||||
int nbreChoices;
|
||||
int choice;
|
||||
std::list<std::pair<int,std::string>> list;
|
||||
std::list<std::pair<int,int>> listId;
|
||||
public:
|
||||
Menu(); //Constructeur
|
||||
|
||||
//Getters
|
||||
int getId() const;
|
||||
int getChoice() const;
|
||||
|
||||
//Methods
|
||||
Menu();
|
||||
std::string getMessage();
|
||||
void nextChoice();
|
||||
|
||||
int getId() const;
|
||||
|
||||
int getChoice() const;
|
||||
|
||||
void previousChoice();
|
||||
void menuBack();
|
||||
void menuNext();
|
||||
|
|
|
@ -11,7 +11,6 @@ private:
|
|||
int id;
|
||||
int radState;
|
||||
int tapState;
|
||||
|
||||
int NextState;
|
||||
int PrevState;
|
||||
int OKState;
|
||||
|
@ -19,18 +18,26 @@ private:
|
|||
public:
|
||||
|
||||
Terrarium(int id);
|
||||
//Getters and Setters
|
||||
|
||||
int getRadState() const;
|
||||
void setRadState(int radState);
|
||||
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);
|
||||
};
|
||||
|
||||
|
|
|
@ -21,11 +21,10 @@ public:
|
|||
float getValue() const;
|
||||
void setValue(float value);
|
||||
float getThresholdHigh() const;
|
||||
void setThresholdHigh(float thresholdHigh);
|
||||
void setThresholdHigh(int thresholdHigh);
|
||||
float getThresholdLow() const;
|
||||
void setThresholdLow(float thresholdLow);
|
||||
void setThresholdLow(int thresholdLow);
|
||||
|
||||
//Methods
|
||||
bool is2High();
|
||||
bool is2Low();
|
||||
};
|
||||
|
|
|
@ -50,18 +50,6 @@ Menu::Menu() : id(0), choice(0), nbreChoices(1) {
|
|||
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() {
|
||||
int cpt = 0;
|
||||
|
||||
|
@ -80,7 +68,6 @@ std::string Menu::getMessage() {
|
|||
return message;
|
||||
}
|
||||
|
||||
|
||||
void Menu::nextChoice() {
|
||||
choice = (choice + 1) % (nbreChoices);
|
||||
}
|
||||
|
@ -90,8 +77,6 @@ void Menu::previousChoice() {
|
|||
choice = (choice - 1);
|
||||
}
|
||||
|
||||
//Reprendre les valeurs du dernier élément de
|
||||
//la listeId, pour revenir sur le menu précédent
|
||||
void Menu::menuBack() {
|
||||
if(!listId.empty()){
|
||||
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() {
|
||||
if(id ==0){
|
||||
listId.push_back(*(new std::pair<int,int>(id,nbreChoices)));
|
||||
|
@ -201,10 +184,8 @@ void Menu::menuNext() {
|
|||
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 = "";
|
||||
message = "\nTemperature : " + std::to_string(temp) + " °C \n";
|
||||
message += "Pression : " + std::to_string(press) + " hPa\n";
|
||||
|
@ -219,7 +200,13 @@ std::string Menu::displayDefault(float temp,
|
|||
return message;
|
||||
}
|
||||
|
||||
|
||||
int Menu::getId() const {
|
||||
return id;
|
||||
}
|
||||
|
||||
int Menu::getChoice() const {
|
||||
return choice;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -8,8 +8,6 @@ Terrarium::Terrarium(int id) : id(id),
|
|||
radState(LOW), tapState(LOW), NextState{LOW},
|
||||
PrevState(LOW), OKState(LOW), BackState(LOW){}
|
||||
|
||||
//Getters and Setters //
|
||||
|
||||
int Terrarium::getRadState() const {
|
||||
return radState;
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ void TerrariumParameter::setValue(float value) {
|
|||
float TerrariumParameter::getThresholdHigh() const {
|
||||
return thresholdHigh;
|
||||
}
|
||||
void TerrariumParameter::setThresholdHigh(float thresholdHigh) {
|
||||
void TerrariumParameter::setThresholdHigh(int thresholdHigh) {
|
||||
if (thresholdHigh < thresholdLow){
|
||||
throw ThresholdExcep(1);
|
||||
} else {
|
||||
|
@ -27,7 +27,7 @@ void TerrariumParameter::setThresholdHigh(float thresholdHigh) {
|
|||
float TerrariumParameter::getThresholdLow() const {
|
||||
return thresholdLow;
|
||||
}
|
||||
void TerrariumParameter::setThresholdLow(float thresholdLow) {
|
||||
void TerrariumParameter::setThresholdLow(int thresholdLow) {
|
||||
if (thresholdLow > thresholdHigh){
|
||||
throw ThresholdExcep(2);
|
||||
} else {
|
||||
|
|
|
@ -40,12 +40,12 @@ std::string Tortue::getAge() const {
|
|||
timeinfo->tm_sec = s;
|
||||
|
||||
|
||||
long double naiss =std::mktime(timeinfo);
|
||||
long naiss =std::mktime(timeinfo);
|
||||
//std::cout << naiss << std::endl;
|
||||
|
||||
|
||||
std::time_t now = std::time(nullptr);
|
||||
long double time = now - naiss;
|
||||
long time = now - naiss;
|
||||
//std::cout << time <<std::endl;
|
||||
|
||||
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::time_t now = std::time(nullptr);
|
||||
long double time = now - naiss;
|
||||
long time = now - naiss;
|
||||
if (time < 0){
|
||||
throw ExceptionDate(1);
|
||||
}
|
||||
this->naissance = naissance;
|
||||
}
|
||||
|
||||
void Tortue::setSexe(const string &sexe) {
|
||||
|
|
|
@ -40,18 +40,18 @@ void Board::setup(){
|
|||
pinMode(2, OUTPUT);
|
||||
|
||||
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("Clara","03/09/2008", "female")));
|
||||
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
|
||||
void Board::loop() {
|
||||
char buf[150]; //buf utilisé en output
|
||||
char inputBuf[150]; //buf utilisé en input
|
||||
char buf[150];
|
||||
char inputBuf[150];
|
||||
static int cpt = 0;
|
||||
static int bascule = 0;
|
||||
int i = 0;
|
||||
|
@ -59,18 +59,22 @@ void Board::loop() {
|
|||
|
||||
|
||||
for (i = 0; i < 10; i++) {
|
||||
TemperatureManagement(); //Met à jour la valeur de temp
|
||||
PressureManagement(); // Met à jour la valeur de pression
|
||||
//cout << tortues->back() << endl;
|
||||
TemperatureManagement();
|
||||
PressureManagement();
|
||||
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(),
|
||||
pressure->getValue(),
|
||||
terrarium->getRadState(),
|
||||
terrarium->getTapState(),
|
||||
Tortue::getNbTortue());
|
||||
|
||||
} else { //Afficher le l'écran du ième menu
|
||||
} else if (menu->getMessage().c_str() != NULL){
|
||||
message = menu->getMessage();
|
||||
}
|
||||
|
||||
|
@ -78,7 +82,6 @@ void Board::loop() {
|
|||
int a4 = analogRead(4);
|
||||
int a6 = analogRead(6);
|
||||
int a7 = analogRead(7);
|
||||
//Conditions d'appui de bouton
|
||||
if ( a3 == HIGH && (terrarium->getPrevState() != a3)) {
|
||||
terrarium->setPrevState(HIGH);
|
||||
menu->previousChoice();
|
||||
|
@ -93,9 +96,11 @@ void Board::loop() {
|
|||
}
|
||||
else if (a6 == HIGH && (terrarium->getOkState() != a6)) {
|
||||
terrarium->setOkState(HIGH);
|
||||
cout << "OK" << endl;
|
||||
menu->menuNext();
|
||||
} else if (a6 == LOW && (terrarium->getOkState() != a6)) {
|
||||
terrarium->setOkState(LOW);
|
||||
cout << "NOK" << endl;
|
||||
}
|
||||
else if (a7 == HIGH && (terrarium->getBackState() != a7)) {
|
||||
terrarium->setBackState(HIGH);
|
||||
|
@ -104,69 +109,66 @@ void Board::loop() {
|
|||
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();
|
||||
for (int j = 0; j < menu->getChoice(); ++j) {
|
||||
iteratorT++;
|
||||
}
|
||||
//cout << iteratorT->getInfo() << endl;
|
||||
message += iteratorT->getInfo();
|
||||
}
|
||||
|
||||
if (cpt % 2 == 0) { //Afficher sur écran un tr sur 2
|
||||
if (cpt % 2 == 0) {
|
||||
strcpy(buf, message.c_str());
|
||||
if (buf != NULL) bus.write(1, buf, 150);
|
||||
}
|
||||
|
||||
//Menus nécessitant une saisie au clavier
|
||||
if (menu->getId() >= 5 && menu->getId() <= 12){
|
||||
if (menu->getId() == 5 || menu->getId() == 11
|
||||
|| menu->getId() == 12 || menu->getId() == 6
|
||||
|| menu->getId() == 7 || menu->getId() == 8
|
||||
|| menu->getId() == 9 || menu->getId() == 10){
|
||||
Keyboard::saisie = true ;
|
||||
sleep(4);
|
||||
if ( (&bus!=NULL)&&!(bus.isEmptyRegister(2))) {
|
||||
bus.requestFrom(2, inputBuf, 150);
|
||||
if (inputBuf[0] != '\0') { //Si utilisateur a saisie au clavier
|
||||
if (inputBuf[0] != '\0') {
|
||||
input = "";
|
||||
for (int j = 0; inputBuf[j] != '\0'; ++j) {
|
||||
input += inputBuf[j];
|
||||
}
|
||||
|
||||
switch (menu->getId()) {
|
||||
case 5 : { //Création de nouvelle tortue et ajout dans la liste
|
||||
Tortue *newTortue = new Tortue("default","01/01/1970","none");
|
||||
case 5 : {
|
||||
Tortue *newTortue = new Tortue();
|
||||
newTortue->setNom(input);
|
||||
tortues->push_back(*newTortue);
|
||||
menu->menuNext();
|
||||
break;
|
||||
}
|
||||
case 11 : {//MàJ de la date de naissance de la nouvelle tortue
|
||||
case 11 :
|
||||
try {
|
||||
tortues->back().setNaissance(input);
|
||||
menu->menuNext();
|
||||
} catch (std::invalid_argument excep) {
|
||||
// Valeurs rentrés ne sont pas des integers
|
||||
cout << "Dates are not integers" << endl;
|
||||
} 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";
|
||||
// 2 : mauvais format
|
||||
if (excep.id == 1) cout << "Not yet born ? Time travelling turtles are not allowed in this terrarium";
|
||||
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";
|
||||
// 4 : Mois > 12
|
||||
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 !";
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case 12 : {
|
||||
case 12 :
|
||||
tortues->back().setSexe(input);
|
||||
menu->menuNext();
|
||||
break;
|
||||
}
|
||||
case 6: { //Supprimer la tortue ayant le nom input
|
||||
case 6: {
|
||||
int length = tortues->size();
|
||||
iteratorT = tortues->begin();
|
||||
for (int j = 0; j < length; ++j) {
|
||||
|
@ -246,8 +248,9 @@ void Board::loop() {
|
|||
void Board::TemperatureManagement() {
|
||||
char buf[100];
|
||||
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)) {
|
||||
digitalWrite(0, HIGH);
|
||||
terrarium->setRadState(HIGH);
|
||||
|
@ -260,7 +263,9 @@ void Board::TemperatureManagement() {
|
|||
void Board::PressureManagement() {
|
||||
char buf[100];
|
||||
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)) {
|
||||
digitalWrite(2, HIGH);
|
||||
terrarium->setTapState(HIGH);
|
||||
|
|
Loading…
Reference in a new issue