Compare commits
3 commits
5c3d503b30
...
0bb10275cc
Author | SHA1 | Date | |
---|---|---|---|
0bb10275cc | |||
41a72076ac | |||
8cc143d24d |
9 changed files with 81 additions and 75 deletions
BIN
BECppRapport.pdf
Normal file
BIN
BECppRapport.pdf
Normal file
Binary file not shown.
|
@ -10,20 +10,21 @@
|
|||
|
||||
class Menu {
|
||||
protected:
|
||||
int id;
|
||||
int nbreChoices;
|
||||
int choice;
|
||||
std::list<std::pair<int,std::string>> list;
|
||||
std::list<std::pair<int,int>> listId;
|
||||
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
|
||||
public:
|
||||
Menu();
|
||||
std::string getMessage();
|
||||
void nextChoice();
|
||||
Menu(); //Constructeur
|
||||
|
||||
//Getters
|
||||
int getId() const;
|
||||
|
||||
int getChoice() const;
|
||||
|
||||
//Methods
|
||||
std::string getMessage();
|
||||
void nextChoice();
|
||||
void previousChoice();
|
||||
void menuBack();
|
||||
void menuNext();
|
||||
|
|
|
@ -11,6 +11,7 @@ private:
|
|||
int id;
|
||||
int radState;
|
||||
int tapState;
|
||||
|
||||
int NextState;
|
||||
int PrevState;
|
||||
int OKState;
|
||||
|
@ -18,26 +19,18 @@ 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,10 +21,11 @@ public:
|
|||
float getValue() const;
|
||||
void setValue(float value);
|
||||
float getThresholdHigh() const;
|
||||
void setThresholdHigh(int thresholdHigh);
|
||||
void setThresholdHigh(float thresholdHigh);
|
||||
float getThresholdLow() const;
|
||||
void setThresholdLow(int thresholdLow);
|
||||
void setThresholdLow(float thresholdLow);
|
||||
|
||||
//Methods
|
||||
bool is2High();
|
||||
bool is2Low();
|
||||
};
|
||||
|
|
|
@ -50,6 +50,18 @@ 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;
|
||||
|
||||
|
@ -68,6 +80,7 @@ std::string Menu::getMessage() {
|
|||
return message;
|
||||
}
|
||||
|
||||
|
||||
void Menu::nextChoice() {
|
||||
choice = (choice + 1) % (nbreChoices);
|
||||
}
|
||||
|
@ -77,6 +90,8 @@ 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;
|
||||
|
@ -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() {
|
||||
if(id ==0){
|
||||
listId.push_back(*(new std::pair<int,int>(id,nbreChoices)));
|
||||
|
@ -184,11 +201,13 @@ void Menu::menuNext() {
|
|||
choice = 0;
|
||||
}
|
||||
}
|
||||
|
||||
std::string Menu::displayDefault(float temp, float press, int rad, int tap, int nbTortue) {
|
||||
//Renvoyer string avec l'écran d'accueil
|
||||
std::string Menu::displayDefault(float temp,
|
||||
float press, int rad,
|
||||
int tap, int nbTortue) {
|
||||
std:: string message = "";
|
||||
message = "\nTemperature : " + std::to_string(temp) + " \n";
|
||||
message += "Pression : " + std::to_string(press) + " \n";
|
||||
message = "\nTemperature : " + std::to_string(temp) + " °C \n";
|
||||
message += "Pression : " + std::to_string(press) + " hPa\n";
|
||||
if (rad) message += "Etat du radiateur : ON \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;
|
||||
}
|
||||
|
||||
int Menu::getId() const {
|
||||
return id;
|
||||
}
|
||||
|
||||
int Menu::getChoice() const {
|
||||
return choice;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -8,6 +8,8 @@ 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(int thresholdHigh) {
|
||||
void TerrariumParameter::setThresholdHigh(float thresholdHigh) {
|
||||
if (thresholdHigh < thresholdLow){
|
||||
throw ThresholdExcep(1);
|
||||
} else {
|
||||
|
@ -27,7 +27,7 @@ void TerrariumParameter::setThresholdHigh(int thresholdHigh) {
|
|||
float TerrariumParameter::getThresholdLow() const {
|
||||
return thresholdLow;
|
||||
}
|
||||
void TerrariumParameter::setThresholdLow(int thresholdLow) {
|
||||
void TerrariumParameter::setThresholdLow(float thresholdLow) {
|
||||
if (thresholdLow > thresholdHigh){
|
||||
throw ThresholdExcep(2);
|
||||
} else {
|
||||
|
|
|
@ -40,12 +40,12 @@ std::string Tortue::getAge() const {
|
|||
timeinfo->tm_sec = s;
|
||||
|
||||
|
||||
long naiss =std::mktime(timeinfo);
|
||||
long double naiss =std::mktime(timeinfo);
|
||||
//std::cout << naiss << std::endl;
|
||||
|
||||
|
||||
std::time_t now = std::time(nullptr);
|
||||
long time = now - naiss;
|
||||
long double time = now - naiss;
|
||||
//std::cout << time <<std::endl;
|
||||
|
||||
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::time_t now = std::time(nullptr);
|
||||
long time = now - naiss;
|
||||
long double 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);
|
||||
//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("Clara","03/09/2008", "female")));
|
||||
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
|
||||
void Board::loop() {
|
||||
char buf[150];
|
||||
char inputBuf[150];
|
||||
char buf[150]; //buf utilisé en output
|
||||
char inputBuf[150]; //buf utilisé en input
|
||||
static int cpt = 0;
|
||||
static int bascule = 0;
|
||||
int i = 0;
|
||||
|
@ -59,22 +59,18 @@ void Board::loop() {
|
|||
|
||||
|
||||
for (i = 0; i < 10; i++) {
|
||||
TemperatureManagement();
|
||||
PressureManagement();
|
||||
cout << tortues->back() << endl;
|
||||
TemperatureManagement(); //Met à jour la valeur de temp
|
||||
PressureManagement(); // Met à jour la valeur de pression
|
||||
//cout << tortues->back() << endl;
|
||||
|
||||
if (menu->getId() == 0 && menu->displayDefault(temperature->getValue(),
|
||||
pressure->getValue(),
|
||||
terrarium->getRadState(),
|
||||
terrarium->getTapState(),
|
||||
0).c_str() != NULL) {
|
||||
if (menu->getId() == 0 ) { //Afficher écran d'accueil
|
||||
message = menu->displayDefault(temperature->getValue(),
|
||||
pressure->getValue(),
|
||||
terrarium->getRadState(),
|
||||
terrarium->getTapState(),
|
||||
Tortue::getNbTortue());
|
||||
|
||||
} else if (menu->getMessage().c_str() != NULL){
|
||||
} else { //Afficher le l'écran du ième menu
|
||||
message = menu->getMessage();
|
||||
}
|
||||
|
||||
|
@ -82,6 +78,7 @@ 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();
|
||||
|
@ -96,11 +93,9 @@ 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);
|
||||
|
@ -109,66 +104,69 @@ void Board::loop() {
|
|||
terrarium->setBackState(LOW);
|
||||
}
|
||||
|
||||
// cout << buf << endl;
|
||||
//sprintf(buf,"%s",menu.getMessage().c_str());
|
||||
|
||||
//sprintf(buf,"%f",temperature.getValue());
|
||||
|
||||
if (menu->getId() == 2){
|
||||
if (menu->getId() == 2){ //Lister les tortues
|
||||
iteratorT = tortues->begin();
|
||||
for (int j = 0; j < menu->getChoice(); ++j) {
|
||||
iteratorT++;
|
||||
}
|
||||
//cout << iteratorT->getInfo() << endl;
|
||||
message += iteratorT->getInfo();
|
||||
}
|
||||
if (cpt % 2 == 0) {
|
||||
|
||||
if (cpt % 2 == 0) { //Afficher sur écran un tr sur 2
|
||||
strcpy(buf, message.c_str());
|
||||
if (buf != NULL) bus.write(1, buf, 150);
|
||||
}
|
||||
|
||||
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){
|
||||
//Menus nécessitant une saisie au clavier
|
||||
if (menu->getId() >= 5 && menu->getId() <= 12){
|
||||
Keyboard::saisie = true ;
|
||||
sleep(4);
|
||||
if ( (&bus!=NULL)&&!(bus.isEmptyRegister(2))) {
|
||||
bus.requestFrom(2, inputBuf, 150);
|
||||
if (inputBuf[0] != '\0') {
|
||||
if (inputBuf[0] != '\0') { //Si utilisateur a saisie au clavier
|
||||
input = "";
|
||||
for (int j = 0; inputBuf[j] != '\0'; ++j) {
|
||||
input += inputBuf[j];
|
||||
}
|
||||
|
||||
switch (menu->getId()) {
|
||||
case 5 : {
|
||||
Tortue *newTortue = new Tortue();
|
||||
case 5 : { //Création de nouvelle tortue et ajout dans la liste
|
||||
Tortue *newTortue = new Tortue("default","01/01/1970","none");
|
||||
newTortue->setNom(input);
|
||||
tortues->push_back(*newTortue);
|
||||
menu->menuNext();
|
||||
break;
|
||||
}
|
||||
case 11 :
|
||||
case 11 : {//MàJ de la date de naissance de la nouvelle tortue
|
||||
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) {
|
||||
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";
|
||||
// 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: {
|
||||
}
|
||||
case 6: { //Supprimer la tortue ayant le nom input
|
||||
int length = tortues->size();
|
||||
iteratorT = tortues->begin();
|
||||
for (int j = 0; j < length; ++j) {
|
||||
|
@ -248,9 +246,8 @@ 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);
|
||||
|
@ -263,9 +260,7 @@ void Board::TemperatureManagement() {
|
|||
void Board::PressureManagement() {
|
||||
char buf[100];
|
||||
pressure->setValue(analogRead(5));
|
||||
//sprintf(buf, "pressure %f", pressure.getValue());
|
||||
//Serial.println(buf);
|
||||
|
||||
//Electrovanne ouverte si pression trop basse mais pas déjà ouverte
|
||||
if ((pressure->is2Low()) && (terrarium->getTapState() == LOW)) {
|
||||
digitalWrite(2, HIGH);
|
||||
terrarium->setTapState(HIGH);
|
||||
|
|
Loading…
Reference in a new issue