Compare commits
No commits in common. "master" and "parameter" have entirely different histories.
34 changed files with 213 additions and 945 deletions
BIN
BECppRapport.pdf
BIN
BECppRapport.pdf
Binary file not shown.
|
@ -4,22 +4,18 @@
|
|||
|
||||
#include "../../../include/AnalogDevices/AnalogSensors/AnalogSensorManometre.h"
|
||||
|
||||
int AnalogSensorManometre::alea = -1;
|
||||
|
||||
AnalogSensorManometre::AnalogSensorManometre(int val, int temps):AnalogDevice(val,temps){
|
||||
AnalogSensorManometre::alea = -1;
|
||||
}
|
||||
|
||||
AnalogSensorManometre::AnalogSensorManometre(float val, int temps):AnalogSensor(val,temps){ alea = 1;}
|
||||
void AnalogSensorManometre::run(){
|
||||
int cpt = 0;
|
||||
while(1){
|
||||
if(ptrmem!=NULL) {
|
||||
*ptrmem = val + AnalogSensorManometre::alea;
|
||||
val = val + AnalogSensorManometre::alea;
|
||||
if(ptrmem!=NULL){
|
||||
if(cpt == 5){
|
||||
*ptrmem = val - alea;
|
||||
val = val - alea;
|
||||
cpt = 0;
|
||||
}
|
||||
}
|
||||
sleep(temps);
|
||||
sleep(temps);
|
||||
cpt++;
|
||||
}
|
||||
}
|
||||
|
||||
void AnalogSensorManometre::setAlea(int alea) {
|
||||
AnalogSensorManometre::alea = alea;
|
||||
}
|
||||
|
|
|
@ -18,7 +18,3 @@ void AnalogSensorPHmetre::run() {
|
|||
cpt ++;
|
||||
}
|
||||
}
|
||||
|
||||
void AnalogSensorPHmetre::setAlea(int alea) {
|
||||
AnalogSensorPHmetre::alea = alea;
|
||||
}
|
||||
|
|
|
@ -3,20 +3,3 @@
|
|||
//
|
||||
|
||||
#include "../../../include/DigitalDevices/DigitalActuators/DigitalActuatorElectrovanne.h"
|
||||
#include "../../../include/AnalogDevices/AnalogSensors/AnalogSensorManometre.h"
|
||||
|
||||
DigitalActuatorElectrovanne::DigitalActuatorElectrovanne(int temps) : DigitalActuator(temps){}
|
||||
|
||||
void DigitalActuatorElectrovanne::run() {
|
||||
int previousState = LOW;
|
||||
while (1){
|
||||
state = *ptrmem;
|
||||
if ((state != previousState)&&(state == HIGH)){
|
||||
AnalogSensorManometre::setAlea(5);
|
||||
previousState = HIGH;
|
||||
} else if((state != previousState)&&(state == LOW)) {
|
||||
AnalogSensorManometre::setAlea(-1);
|
||||
previousState = LOW;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,13 @@
|
|||
|
||||
#include "../../../include/DigitalDevices/DigitalActuators/DigitalActuatorRadiator.h"
|
||||
|
||||
DigitalActuatorRadiator::DigitalActuatorRadiator(int temps) : DigitalActuator(temps){}
|
||||
DigitalActuatorRadiator::DigitalActuatorRadiator(int temps, float thresholdHigh, float thresholdLow) : DigitalActuator(temps),
|
||||
thresholdHigh(thresholdHigh), thresholdLow(thresholdLow) {}
|
||||
|
||||
void DigitalActuatorRadiator::activate() {
|
||||
DigitalDevice::state = HIGH;
|
||||
}
|
||||
|
||||
void DigitalActuatorRadiator::run() {
|
||||
int previousState = LOW;
|
||||
while (1){
|
||||
|
@ -18,3 +24,19 @@ void DigitalActuatorRadiator::run() {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
float DigitalActuatorRadiator::getThresholdLow() const {
|
||||
return thresholdLow;
|
||||
}
|
||||
|
||||
void DigitalActuatorRadiator::setThresholdLow(float thresholdLow) {
|
||||
DigitalActuatorRadiator::thresholdLow = thresholdLow;
|
||||
}
|
||||
|
||||
float DigitalActuatorRadiator::getThresholdHigh() const {
|
||||
return thresholdHigh;
|
||||
}
|
||||
|
||||
void DigitalActuatorRadiator::setThresholdHigh(float threshold) {
|
||||
DigitalActuatorRadiator::thresholdHigh = threshold;
|
||||
}
|
||||
|
|
|
@ -2,23 +2,23 @@
|
|||
// Created by camer on 16/05/2020.
|
||||
//
|
||||
//#define PATH "D:\\Documents\\Etudes\\INSA\\4A\\BECpp\\Projet_VictorAvecUnK\\src\\on.txt"
|
||||
//#define PATH "/Users/victorleroch/Documents/INSA/Année4/C++/Projet_VictorAvecUnK/on.txt"
|
||||
#define PATH "/Users/victorleroch/Documents/INSA/Année4/C++/Projet_VictorAvecUnK/on.txt"
|
||||
#include "../../../include/DigitalDevices/DigitalSensors/ExternalDigitalSensorButton.h"
|
||||
|
||||
//ExternalDigDevice/////////////////////////
|
||||
|
||||
ExternalDigitalSensorButton::ExternalDigitalSensorButton(int temps, std::string PATH):DigitalSensor(temps), PATH(PATH){}
|
||||
ExternalDigitalSensorButton::ExternalDigitalSensorButton(int temps):DigitalSensor(temps) {}
|
||||
|
||||
int ExternalDigitalSensorButton::getState(){
|
||||
setState(); //determine if on.txt exists before getting state
|
||||
return DigitalSensor::state;
|
||||
return state;
|
||||
}
|
||||
|
||||
void ExternalDigitalSensorButton::setState() {
|
||||
if (ifstream (PATH)){
|
||||
DigitalSensor::state = HIGH;
|
||||
state = HIGH;
|
||||
} else {
|
||||
DigitalSensor::state = LOW;
|
||||
state = LOW;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,26 +0,0 @@
|
|||
//
|
||||
// Created by camer on 22/05/2020.
|
||||
//
|
||||
|
||||
#include "../../include/I2CDevices/Keyboard.h"
|
||||
|
||||
Keyboard::Keyboard(): Device() {}
|
||||
|
||||
//void Keyboard::run() {}
|
||||
bool Keyboard::saisie = false;
|
||||
|
||||
void Keyboard::run() {
|
||||
while (1) {
|
||||
if (saisie && i2cbus != NULL) {
|
||||
cin >> buf;
|
||||
while (!(i2cbus->isEmptyRegister(i2caddr))) {}
|
||||
Device::i2cbus->write(i2caddr, buf, I2C_BUFFER_SIZE);
|
||||
saisie = false;
|
||||
} else if (i2cbus != NULL){
|
||||
buf[0] = '\0';
|
||||
while (!(i2cbus->isEmptyRegister(i2caddr))) {}
|
||||
Device::i2cbus->write(i2caddr, buf, I2C_BUFFER_SIZE);
|
||||
}
|
||||
sleep(3);
|
||||
}
|
||||
}
|
|
@ -1,21 +0,0 @@
|
|||
//
|
||||
// Created by camer on 22/05/2020.
|
||||
//
|
||||
|
||||
#include "../../include/I2CDevices/Screen.h"
|
||||
using namespace std;
|
||||
|
||||
|
||||
|
||||
// classe I2CActuatorScreen
|
||||
Screen::Screen ():Device(){}
|
||||
|
||||
void Screen::run(){
|
||||
while(1){
|
||||
if ( (i2cbus!=NULL)&&!(i2cbus->isEmptyRegister(i2caddr))){
|
||||
Device::i2cbus->requestFrom(i2caddr, buf, I2C_BUFFER_SIZE);
|
||||
cout << "---screen :"<< buf << endl;
|
||||
}
|
||||
sleep(1);
|
||||
}
|
||||
}
|
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.
|
|
@ -1,35 +0,0 @@
|
|||
//
|
||||
// Created by camer on 22/05/2020.
|
||||
//
|
||||
|
||||
#ifndef PROJET_VICTORAVECUNK_MENU_H
|
||||
#define PROJET_VICTORAVECUNK_MENU_H
|
||||
#include <string>
|
||||
#include <list>
|
||||
#include "Tortue.h"
|
||||
|
||||
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
|
||||
public:
|
||||
Menu(); //Constructeur
|
||||
|
||||
//Getters
|
||||
int getId() const;
|
||||
int getChoice() const;
|
||||
|
||||
//Methods
|
||||
std::string getMessage();
|
||||
void nextChoice();
|
||||
void previousChoice();
|
||||
void menuBack();
|
||||
void menuNext();
|
||||
std::string displayDefault(float temp, float press, int rad, int tap, int nbTortue);
|
||||
};
|
||||
|
||||
|
||||
#endif //PROJET_VICTORAVECUNK_MENU_H
|
|
@ -11,27 +11,14 @@ private:
|
|||
int id;
|
||||
int radState;
|
||||
int tapState;
|
||||
|
||||
int NextState;
|
||||
int PrevState;
|
||||
int OKState;
|
||||
int BackState;
|
||||
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);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -8,24 +8,20 @@
|
|||
|
||||
class TerrariumParameter { //TODO add to diagram
|
||||
private:
|
||||
float value, thresholdHigh, thresholdLow;
|
||||
float value;
|
||||
int thresholdHigh;
|
||||
int thresholdLow;
|
||||
public:
|
||||
class ThresholdExcep {
|
||||
public:
|
||||
int id;
|
||||
ThresholdExcep(int id):id(id){};
|
||||
};
|
||||
TerrariumParameter(float thresholdHigh, float thresholdLow);
|
||||
TerrariumParameter(int thresholdHigh, int thresholdLow);
|
||||
|
||||
//getters setters
|
||||
float getValue() const;
|
||||
void setValue(float value);
|
||||
float getThresholdHigh() const;
|
||||
void setThresholdHigh(float thresholdHigh);
|
||||
float getThresholdLow() const;
|
||||
void setThresholdLow(float thresholdLow);
|
||||
int getThresholdHigh() const;
|
||||
void setThresholdHigh(int thresholdHigh);
|
||||
int getThresholdLow() const;
|
||||
void setThresholdLow(int thresholdLow);
|
||||
|
||||
//Methods
|
||||
bool is2High();
|
||||
bool is2Low();
|
||||
};
|
||||
|
|
|
@ -6,45 +6,21 @@
|
|||
#define BE_TORTUE_H
|
||||
|
||||
#include <string>
|
||||
#include <ostream>
|
||||
|
||||
class Tortue{
|
||||
private:
|
||||
std::string nom;
|
||||
std::string naissance;
|
||||
int naissance;
|
||||
std::string sexe;
|
||||
static int nbTortue;
|
||||
|
||||
|
||||
public:
|
||||
class ExceptionDate{
|
||||
public:
|
||||
int id;
|
||||
|
||||
ExceptionDate(int id);
|
||||
};
|
||||
Tortue();
|
||||
|
||||
Tortue(const std::string &nom, const std::string &naissance, const std::string &sexe);
|
||||
Tortue(const std::string &nom, const std::string &sexe);
|
||||
|
||||
const std::string &getNom() const;
|
||||
|
||||
void setNom(const std::string &nom);
|
||||
int getNaissance() const;
|
||||
int getAge() const;
|
||||
|
||||
void setNaissance(std::string naissance);
|
||||
|
||||
void setSexe(const std::string &sexe);
|
||||
|
||||
static int getNbTortue();
|
||||
std::string getNaissance() const;
|
||||
std::string getAge() const;
|
||||
const std::string &getSexe() const;
|
||||
|
||||
std::string getInfo();
|
||||
static void delete1();
|
||||
|
||||
friend std::ostream &operator<<(std::ostream &os, const Tortue &tortue);
|
||||
|
||||
};
|
||||
|
||||
#endif //BE_TORTUE_H
|
||||
|
|
225
app/src/Menu.cpp
225
app/src/Menu.cpp
|
@ -1,225 +0,0 @@
|
|||
//
|
||||
// Created by camer on 22/05/2020.
|
||||
//
|
||||
|
||||
#include "../include/Menu.h"
|
||||
|
||||
|
||||
Menu::Menu() : id(0), choice(0), nbreChoices(1) {
|
||||
list.push_back(*(new std::pair<int,
|
||||
std::string>(1,"\n Liste tortue ")));
|
||||
list.push_back(*(new std::pair<int,
|
||||
std::string>(1,"\n Management tortue ")));
|
||||
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,
|
||||
std::string>(3,"\n supprimer tortue")));
|
||||
|
||||
list.push_back(*(new std::pair<int,
|
||||
std::string>(4,"\n Temperature max")));
|
||||
list.push_back(*(new std::pair<int,
|
||||
std::string>(4,"\n Temperature min")));
|
||||
list.push_back(*(new std::pair<int,
|
||||
std::string>(4,"\n Profondeur max")));
|
||||
list.push_back(*(new std::pair<int,
|
||||
std::string>(4,"\n Profondeur min")));
|
||||
|
||||
list.push_back(*(new std::pair<int,
|
||||
std::string>(5,"\n Nom de la tortue a ajouter")));
|
||||
list.push_back(*(new std::pair<int,
|
||||
std::string>(11,"\n Naissance en utilisant le format jj/mm/yyyy")));
|
||||
list.push_back(*(new std::pair<int,
|
||||
std::string>(12,"\n Sexe")));
|
||||
|
||||
list.push_back(*(new std::pair<int,
|
||||
std::string>(6,"\n Nom de la tortue a supprimer")));
|
||||
|
||||
list.push_back(*(new std::pair<int,
|
||||
std::string>(7,"\n Temperature max")));
|
||||
list.push_back(*(new std::pair<int,
|
||||
std::string>(8,"\n Temperature min")));
|
||||
list.push_back(*(new std::pair<int,
|
||||
std::string>(9,"\n Profondeur max")));
|
||||
list.push_back(*(new std::pair<int,
|
||||
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;
|
||||
|
||||
std::string message = "";
|
||||
std::list<std::pair<int,std::string>>::iterator it;
|
||||
for (it = list.begin(); it != list.end() ; it++) {
|
||||
if (it->first == id){
|
||||
if (cpt == choice && id != 2){
|
||||
message += it->second + "<--";
|
||||
} else {
|
||||
message += it->second;
|
||||
}
|
||||
++cpt;
|
||||
}
|
||||
}
|
||||
return message;
|
||||
}
|
||||
|
||||
|
||||
void Menu::nextChoice() {
|
||||
choice = (choice + 1) % (nbreChoices);
|
||||
}
|
||||
|
||||
void Menu::previousChoice() {
|
||||
if (choice == 0) choice = nbreChoices;
|
||||
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;
|
||||
id = listId.back().first;
|
||||
nbreChoices = listId.back().second;
|
||||
listId.pop_back();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//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)));
|
||||
id = 1;
|
||||
choice = 0;
|
||||
nbreChoices = 3;
|
||||
}
|
||||
else if (id == 1){
|
||||
listId.push_back(*(new std::pair<int,int>(id,nbreChoices)));
|
||||
switch (choice){
|
||||
case 0 :
|
||||
id = 2;
|
||||
choice = 0;
|
||||
nbreChoices = Tortue::getNbTortue();
|
||||
break;
|
||||
case 1 :
|
||||
id = 3;
|
||||
choice = 0;
|
||||
nbreChoices = 2;
|
||||
break;
|
||||
case 2 :
|
||||
id = 4;
|
||||
choice = 0;
|
||||
nbreChoices = 4;
|
||||
break;
|
||||
default:
|
||||
id = 0;
|
||||
choice = 0;
|
||||
nbreChoices = 1;
|
||||
}
|
||||
|
||||
}
|
||||
else if(id == 3){
|
||||
listId.push_back(*(new std::pair<int,int>(id,nbreChoices)));
|
||||
switch (choice){
|
||||
case 0 :
|
||||
id = 5;
|
||||
choice = 0;
|
||||
nbreChoices = 1;
|
||||
break;
|
||||
case 1 :
|
||||
id = 6;
|
||||
choice = 0;
|
||||
nbreChoices = 1;
|
||||
break;
|
||||
default:
|
||||
id = 0;
|
||||
choice = 0;
|
||||
nbreChoices = 1;
|
||||
|
||||
}
|
||||
}
|
||||
else if(id == 4){
|
||||
listId.push_back(*(new std::pair<int,int>(id,nbreChoices)));
|
||||
switch (choice){
|
||||
case 0 :
|
||||
id = 7;
|
||||
choice = 0;
|
||||
nbreChoices = 1;
|
||||
break;
|
||||
case 1 :
|
||||
id = 8;
|
||||
choice = 0;
|
||||
nbreChoices = 1;
|
||||
break;
|
||||
case 2 :
|
||||
id = 9;
|
||||
choice = 0;
|
||||
nbreChoices = 1;
|
||||
break;
|
||||
case 3 :
|
||||
id = 10;
|
||||
choice = 0;
|
||||
nbreChoices = 1;
|
||||
break;
|
||||
default:
|
||||
id = 0;
|
||||
choice = 0;
|
||||
nbreChoices = 1;
|
||||
}
|
||||
}
|
||||
else if(id == 5){
|
||||
listId.push_back(*(new std::pair<int,int>(id,nbreChoices)));
|
||||
id = 11;
|
||||
choice = 2;
|
||||
}
|
||||
else if (id == 11){
|
||||
listId.push_back(*(new std::pair<int,int>(id,nbreChoices)));
|
||||
id = 12;
|
||||
choice = 2;
|
||||
}
|
||||
else if (id == 12 || id == 6){
|
||||
listId.clear();
|
||||
id = 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 message = "";
|
||||
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";
|
||||
|
||||
if (tap) message += "Etat du robinet : ON \n";
|
||||
else message += "Etat du robinet : OFF \n";
|
||||
|
||||
message += "Il y a "+std::to_string(nbTortue)+" Tortues \0";
|
||||
|
||||
return message;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -5,10 +5,7 @@
|
|||
#include "../include/Terrarium.h"
|
||||
#include "../../core_simulation.h"
|
||||
Terrarium::Terrarium(int id) : id(id),
|
||||
radState(LOW), tapState(LOW), NextState{LOW},
|
||||
PrevState(LOW), OKState(LOW), BackState(LOW){}
|
||||
|
||||
//Getters and Setters //
|
||||
radState(LOW), tapState(LOW){}
|
||||
|
||||
int Terrarium::getRadState() const {
|
||||
return radState;
|
||||
|
@ -26,35 +23,3 @@ void Terrarium::setTapState(int tapState) {
|
|||
Terrarium::tapState = tapState;
|
||||
}
|
||||
|
||||
int Terrarium::getNextState() const {
|
||||
return NextState;
|
||||
}
|
||||
|
||||
void Terrarium::setNextState(int nextState) {
|
||||
NextState = nextState;
|
||||
}
|
||||
|
||||
int Terrarium::getPrevState() const {
|
||||
return PrevState;
|
||||
}
|
||||
|
||||
void Terrarium::setPrevState(int prevState) {
|
||||
PrevState = prevState;
|
||||
}
|
||||
|
||||
int Terrarium::getOkState() const {
|
||||
return OKState;
|
||||
}
|
||||
|
||||
void Terrarium::setOkState(int okState) {
|
||||
OKState = okState;
|
||||
}
|
||||
|
||||
int Terrarium::getBackState() const {
|
||||
return BackState;
|
||||
}
|
||||
|
||||
void Terrarium::setBackState(int backState) {
|
||||
BackState = backState;
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
#include "../include/TerrariumParameter.h"
|
||||
//Constructor
|
||||
TerrariumParameter::TerrariumParameter(float thresholdHigh, float thresholdLow) : thresholdHigh(thresholdHigh),
|
||||
TerrariumParameter::TerrariumParameter(int thresholdHigh, int thresholdLow) : thresholdHigh(thresholdHigh),
|
||||
thresholdLow(thresholdLow){}
|
||||
|
||||
//Getters Setters
|
||||
|
@ -14,25 +14,17 @@ float TerrariumParameter::getValue() const {
|
|||
void TerrariumParameter::setValue(float value) {
|
||||
TerrariumParameter::value = value;
|
||||
}
|
||||
float TerrariumParameter::getThresholdHigh() const {
|
||||
int TerrariumParameter::getThresholdHigh() const {
|
||||
return thresholdHigh;
|
||||
}
|
||||
void TerrariumParameter::setThresholdHigh(float thresholdHigh) {
|
||||
if (thresholdHigh < thresholdLow){
|
||||
throw ThresholdExcep(1);
|
||||
} else {
|
||||
TerrariumParameter::thresholdHigh = thresholdHigh;
|
||||
}
|
||||
void TerrariumParameter::setThresholdHigh(int thresholdHigh) {
|
||||
TerrariumParameter::thresholdHigh = thresholdHigh;
|
||||
}
|
||||
float TerrariumParameter::getThresholdLow() const {
|
||||
int TerrariumParameter::getThresholdLow() const {
|
||||
return thresholdLow;
|
||||
}
|
||||
void TerrariumParameter::setThresholdLow(float thresholdLow) {
|
||||
if (thresholdLow > thresholdHigh){
|
||||
throw ThresholdExcep(2);
|
||||
} else {
|
||||
TerrariumParameter::thresholdLow = thresholdLow;
|
||||
}
|
||||
void TerrariumParameter::setThresholdLow(int thresholdLow) {
|
||||
TerrariumParameter::thresholdLow = thresholdLow;
|
||||
}
|
||||
|
||||
//Methods
|
||||
|
|
|
@ -6,62 +6,11 @@
|
|||
#include "../../core_simulation.h"
|
||||
//#include <string>
|
||||
|
||||
|
||||
Tortue::Tortue() {
|
||||
++nbTortue;
|
||||
}
|
||||
|
||||
Tortue::Tortue(const string &nom, const std::string &naissance, const string &sexe) : nom(nom), sexe(sexe), naissance(naissance) {
|
||||
nbTortue ++;
|
||||
}
|
||||
|
||||
std::string Tortue::getAge() const {
|
||||
|
||||
time_t rawtime;
|
||||
|
||||
struct tm * timeinfo ;
|
||||
std::string date = naissance;
|
||||
std::string message ="";
|
||||
|
||||
int annee = std::stoi(date.substr(6,9));
|
||||
int mois = std::stoi(date.substr(3,4));
|
||||
int jour = std::stoi(date.substr(0,2));
|
||||
int h = 0;
|
||||
int m = 0;
|
||||
int s = 0;
|
||||
|
||||
time(&rawtime);
|
||||
timeinfo = localtime(&rawtime);
|
||||
timeinfo->tm_year = annee - 1900;
|
||||
timeinfo->tm_mon= mois - 1;
|
||||
timeinfo->tm_mday = jour;
|
||||
timeinfo->tm_hour = h;
|
||||
timeinfo->tm_min = m;
|
||||
timeinfo->tm_sec = s;
|
||||
|
||||
|
||||
long double naiss =std::mktime(timeinfo);
|
||||
//std::cout << naiss << std::endl;
|
||||
|
||||
|
||||
std::time_t now = std::time(nullptr);
|
||||
long double time = now - naiss;
|
||||
//std::cout << time <<std::endl;
|
||||
|
||||
int agean = time / 31557600;
|
||||
time = time - (agean*31557600);
|
||||
int agemois = time / 2592000;
|
||||
|
||||
message = to_string(agean) + " ans et " + to_string(agemois) + " mois";
|
||||
return message;
|
||||
}
|
||||
int Tortue::nbTortue = 0;
|
||||
|
||||
const std::string &Tortue::getNom() const {
|
||||
return nom;
|
||||
}
|
||||
|
||||
string Tortue::getNaissance() const {
|
||||
int Tortue::getNaissance() const {
|
||||
return naissance;
|
||||
}
|
||||
|
||||
|
@ -69,80 +18,16 @@ const std::string &Tortue::getSexe() const {
|
|||
return sexe;
|
||||
}
|
||||
|
||||
int Tortue::getNbTortue() {
|
||||
return nbTortue;
|
||||
Tortue::Tortue(const string &nom, const string &sexe) : nom(nom), sexe(sexe) {
|
||||
naissance = std::time(nullptr);
|
||||
}
|
||||
|
||||
std::string Tortue::getInfo() {
|
||||
std::string message;
|
||||
message = "\nMy name is "+this->nom;
|
||||
message += "\n" + this->getAge();
|
||||
message += "\n"+this->sexe;
|
||||
return message;
|
||||
}
|
||||
|
||||
void Tortue::setNom(const string &nom) {
|
||||
Tortue::nom = nom;
|
||||
}
|
||||
|
||||
void Tortue::setNaissance(std::string naissance) {
|
||||
time_t rawtime;
|
||||
|
||||
struct tm * timeinfo ;
|
||||
std::string date = naissance;
|
||||
|
||||
if (date.size() != 10 || date[2] != '/'
|
||||
|| date[5] != '/'){
|
||||
throw ExceptionDate(2);
|
||||
}
|
||||
|
||||
int annee = std::stoi(date.substr(6,9));
|
||||
int mois = std::stoi(date.substr(3,4));
|
||||
int jour = std::stoi(date.substr(0,2));
|
||||
|
||||
if (annee < 1900) throw ExceptionDate(3);
|
||||
else if (mois > 12) throw ExceptionDate(4);
|
||||
else if (jour > 31) throw ExceptionDate(5);
|
||||
|
||||
int h = 0;
|
||||
int m = 0;
|
||||
int s = 0;
|
||||
|
||||
time(&rawtime);
|
||||
timeinfo = localtime(&rawtime);
|
||||
timeinfo->tm_year = annee - 1900;
|
||||
timeinfo->tm_mon= mois - 1;
|
||||
timeinfo->tm_mday = jour;
|
||||
timeinfo->tm_hour = h;
|
||||
timeinfo->tm_min = m;
|
||||
timeinfo->tm_sec = s;
|
||||
|
||||
|
||||
|
||||
long double naiss =std::mktime(timeinfo);
|
||||
//std::cout << naiss << std::endl;
|
||||
|
||||
|
||||
std::time_t now = std::time(nullptr);
|
||||
long double time = now - naiss;
|
||||
if (time < 0){
|
||||
throw ExceptionDate(1);
|
||||
}
|
||||
this->naissance = naissance;
|
||||
}
|
||||
|
||||
void Tortue::setSexe(const string &sexe) {
|
||||
Tortue::sexe = sexe;
|
||||
}
|
||||
|
||||
void Tortue::delete1() {
|
||||
--nbTortue;
|
||||
}
|
||||
|
||||
ostream &operator<<(ostream &os, const Tortue &tortue) {
|
||||
os << "nom: " << tortue.nom << " naissance: " << tortue.naissance << " sexe: " << tortue.sexe;
|
||||
return os;
|
||||
int Tortue::getAge() const {
|
||||
int ageSec = std::time(nullptr) - naissance;
|
||||
int ageHour = ageSec/(60*60);
|
||||
int ageDay = ageHour/24;
|
||||
int age = ageDay / 365.25;
|
||||
return age;
|
||||
}
|
||||
|
||||
|
||||
Tortue::ExceptionDate::ExceptionDate(int id) : id(id) {}
|
||||
|
|
45
board.cpp
45
board.cpp
|
@ -1,55 +1,34 @@
|
|||
#include "core_simulation.h"
|
||||
#include "mydevices.h"
|
||||
#include "include/AnalogDevices/AnalogSensors/AnalogSensorTemperature.h"
|
||||
#include "include/DigitalDevices/DigitalActuators/IntelligentDigitalActuatorLED.h"
|
||||
#include "include/AnalogDevices/AnalogSensors/AnalogSensorLuminosity.h"
|
||||
#include "include/DigitalDevices/DigitalSensors/ExternalDigitalSensorButton.h"
|
||||
#include "include/AnalogDevices/AnalogSensors/AnalogSensorManometre.h"
|
||||
#include "include/DigitalDevices/DigitalActuators/DigitalActuatorRadiator.h"
|
||||
#include "include/DigitalDevices/DigitalActuators/DigitalActuatorElectrovanne.h"
|
||||
#include "include/I2CDevices/Screen.h"
|
||||
#include "include/I2CDevices/Keyboard.h"
|
||||
|
||||
int main(){
|
||||
|
||||
#if __APPLE__
|
||||
std::string btnNextPath = "/Users/victorleroch/Desktop/boutons/next.txt";
|
||||
std::string btnPrevPath = "/Users/victorleroch/Desktop/boutons/prev.txt";
|
||||
std::string btnOkPath = "/Users/victorleroch/Desktop/boutons/ok.txt";
|
||||
std::string btnBackPath = "/Users/victorleroch/Desktop/boutons/back.txt";
|
||||
#else //!___unix___
|
||||
std::string btnNextPath = "D:\\Documents\\Etudes\\INSA\\4A\\BECpp\\Projet_VictorAvecUnK\\src\\next.txt";
|
||||
std::string btnPrevPath = "D:\\Documents\\Etudes\\INSA\\4A\\BECpp\\Projet_VictorAvecUnK\\src\\prev.txt";
|
||||
std::string btnOkPath = "D:\\Documents\\Etudes\\INSA\\4A\\BECpp\\Projet_VictorAvecUnK\\src\\ok.txt";
|
||||
std::string btnBackPath = "D:\\Documents\\Etudes\\INSA\\4A\\BECpp\\Projet_VictorAvecUnK\\src\\back.txt";
|
||||
#endif
|
||||
// creation d'une board
|
||||
Board esp8266;
|
||||
// achat des senseurs et actionneurs
|
||||
AnalogSensorTemperature temperature(TEMP,DELAY);
|
||||
Screen screen;
|
||||
Keyboard keyboard;
|
||||
ExternalDigitalSensorButton buttonNext(DELAY - 2, btnNextPath);
|
||||
ExternalDigitalSensorButton buttonPrev(DELAY - 2, btnPrevPath);
|
||||
ExternalDigitalSensorButton buttonOK(DELAY - 2, btnOkPath);
|
||||
ExternalDigitalSensorButton buttonBack(DELAY - 2, btnBackPath);
|
||||
AnalogSensorManometre manometre(PRESSURE,DELAY);
|
||||
DigitalActuatorRadiator radiator(DELAY);
|
||||
DigitalActuatorElectrovanne electrovanne(DELAY);
|
||||
//DigitalActuatorLED led1(DELAY);
|
||||
IntelligentDigitalActuatorLED led1(DELAY);
|
||||
I2CActuatorScreen screen;
|
||||
AnalogSensorLuminosity luminosite(DELAY);
|
||||
ExternalDigitalSensorButton button(DELAY);
|
||||
AnalogSensorManometre manometre(4,DELAY);
|
||||
DigitalActuatorRadiator radiator(DELAY, THRESHOLDHIGH, THRESHOLDLOW);
|
||||
|
||||
|
||||
// branchement des capteurs actionneurs
|
||||
esp8266.pin(0, radiator);
|
||||
esp8266.pin(1,temperature);
|
||||
//esp8266.pin(0,led1);
|
||||
esp8266.pin(2, electrovanne);
|
||||
esp8266.pin(3, buttonPrev);
|
||||
esp8266.pin(4, buttonNext);
|
||||
esp8266.pin(5, manometre);
|
||||
esp8266.pin(6, buttonOK);
|
||||
esp8266.pin(7, buttonBack);
|
||||
|
||||
esp8266.pin(2, luminosite);
|
||||
esp8266.i2c(1,screen);
|
||||
esp8266.i2c(2,keyboard);
|
||||
esp8266.pin(4, button);
|
||||
esp8266.pin(5, manometre);
|
||||
esp8266.pin(0, radiator);
|
||||
|
||||
// allumage de la carte
|
||||
esp8266.run();
|
||||
|
|
|
@ -99,8 +99,8 @@ Device::Device(){
|
|||
|
||||
void Device::run(){
|
||||
while(1){
|
||||
//cout << "empty device\n";
|
||||
sleep(4);
|
||||
cout << "empty device\n";
|
||||
sleep(3);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -174,5 +174,3 @@ void Board::i2c(int addr,Device& dev){
|
|||
tabthreadbus[addr]=new thread(&Device::run,&dev);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -8,12 +8,13 @@
|
|||
|
||||
#define DELAY 3
|
||||
#define TEMP 17
|
||||
#define PRESSURE 2995
|
||||
#define HIGH 1
|
||||
#define LOW 0
|
||||
#define MAX_I2C_DEVICES 4
|
||||
#define I2C_BUFFER_SIZE 1024
|
||||
#define MAX_IO_PIN 10
|
||||
#define MAX_IO_PIN 6
|
||||
#define THRESHOLDHIGH 25
|
||||
#define THRESHOLDLOW 20
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
@ -126,8 +127,6 @@ public:
|
|||
void setup();
|
||||
// fonction arduino : boucle de controle de la carte arduino
|
||||
void loop();
|
||||
void TemperatureManagement();
|
||||
void PressureManagement();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -2,10 +2,7 @@
|
|||
// Created by camer on 16/05/2020.
|
||||
//
|
||||
#include "../../core_simulation.h"
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
#include <fstream>
|
||||
#include "../../mydevices.h"
|
||||
|
||||
#ifndef PROJET_VICTORAVECUNK_ANALOGDEVICE_H
|
||||
#define PROJET_VICTORAVECUNK_ANALOGDEVICE_H
|
||||
|
|
|
@ -11,15 +11,11 @@
|
|||
//#include <fstream>
|
||||
#include "../AnalogDevice.h"
|
||||
|
||||
class AnalogSensorManometre: public AnalogDevice {
|
||||
class AnalogSensorManometre : public AnalogSensor{
|
||||
private:
|
||||
static int alea;
|
||||
int alea;
|
||||
public:
|
||||
// fait osciller la valeur du cpateur de 1
|
||||
//constructeur ne pas oublier d'initialiser la classe mere
|
||||
AnalogSensorManometre(int d,int t);
|
||||
static void setAlea(int alea);
|
||||
// thread representant le capteur et permettant de fonctionner independamment de la board
|
||||
AnalogSensorManometre(float val, int t); //
|
||||
virtual void run();
|
||||
};
|
||||
|
||||
|
|
|
@ -8,10 +8,9 @@
|
|||
#include "../AnalogDevice.h"
|
||||
|
||||
class AnalogSensorPHmetre : public AnalogSensor {
|
||||
private:
|
||||
static int alea;
|
||||
public:
|
||||
static void setAlea(int alea);
|
||||
static int alea;
|
||||
|
||||
AnalogSensorPHmetre(float val, int temps);
|
||||
virtual void run();
|
||||
};
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
|
||||
// exemple de capteur analogique de temperature, ne pas oublier d'heriter de Device
|
||||
class AnalogSensorTemperature: public AnalogDevice {
|
||||
private:
|
||||
public:
|
||||
static int alea;
|
||||
public:
|
||||
// fait osciller la valeur du cpateur de 1
|
||||
|
|
|
@ -6,12 +6,8 @@
|
|||
#define PROJET_VICTORAVECUNK_DIGITALACTUATORELECTROVANNE_H
|
||||
|
||||
|
||||
#include "../DigitalDevice.h"
|
||||
class DigitalActuatorElectrovanne {
|
||||
|
||||
class DigitalActuatorElectrovanne : public DigitalActuator{
|
||||
public:
|
||||
DigitalActuatorElectrovanne(int temps);
|
||||
void run();
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -10,8 +10,20 @@
|
|||
#include "../../../include/AnalogDevices/AnalogSensors/AnalogSensorTemperature.h"
|
||||
|
||||
class DigitalActuatorRadiator : public DigitalActuator {
|
||||
private:
|
||||
float thresholdHigh, thresholdLow;
|
||||
|
||||
public:
|
||||
DigitalActuatorRadiator(int temps);
|
||||
DigitalActuatorRadiator(int temps, float threshold, float thresholdLow);
|
||||
|
||||
float getThresholdHigh() const;
|
||||
void setThresholdHigh(float threshold);
|
||||
|
||||
float getThresholdLow() const;
|
||||
|
||||
void setThresholdLow(float thresholdLow);
|
||||
|
||||
void activate();
|
||||
void run();
|
||||
};
|
||||
|
||||
|
|
|
@ -7,10 +7,7 @@
|
|||
|
||||
|
||||
#include "../../core_simulation.h"
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
#include <fstream>
|
||||
#include "../../mydevices.h"
|
||||
|
||||
class DigitalDevice : public Device {
|
||||
protected:
|
||||
|
|
|
@ -9,10 +9,8 @@
|
|||
#include "../DigitalDevice.h"
|
||||
|
||||
class ExternalDigitalSensorButton : public DigitalSensor{
|
||||
private:
|
||||
std::string PATH;
|
||||
public:
|
||||
ExternalDigitalSensorButton(int temps, std::string PATH);
|
||||
ExternalDigitalSensorButton(int temps);
|
||||
|
||||
int getState();
|
||||
void setState();
|
||||
|
|
|
@ -1,22 +0,0 @@
|
|||
//
|
||||
// Created by camer on 22/05/2020.
|
||||
//
|
||||
|
||||
#ifndef PROJET_VICTORAVECUNK_KEYBOARD_H
|
||||
#define PROJET_VICTORAVECUNK_KEYBOARD_H
|
||||
|
||||
#include "../../core_simulation.h"
|
||||
#include <unistd.h>
|
||||
|
||||
class Keyboard : public Device{
|
||||
protected:
|
||||
char buf[I2C_BUFFER_SIZE];
|
||||
public:
|
||||
static bool saisie;
|
||||
Keyboard();
|
||||
virtual void run();
|
||||
//void saisie();
|
||||
};
|
||||
|
||||
|
||||
#endif //PROJET_VICTORAVECUNK_KEYBOARD_H
|
|
@ -1,25 +0,0 @@
|
|||
//
|
||||
// Created by camer on 22/05/2020.
|
||||
//
|
||||
|
||||
#ifndef PROJET_VICTORAVECUNK_SCREEN_H
|
||||
#define PROJET_VICTORAVECUNK_SCREEN_H
|
||||
|
||||
|
||||
#include "../../core_simulation.h"
|
||||
#include <unistd.h>
|
||||
|
||||
class Screen : public Device{
|
||||
protected:
|
||||
// memorise l'affichage de l'ecran
|
||||
char buf[I2C_BUFFER_SIZE];
|
||||
|
||||
public:
|
||||
// constructeur
|
||||
Screen ();
|
||||
// thread representant le capteur et permettant de fonctionner independamment de la board
|
||||
virtual void run();
|
||||
};
|
||||
|
||||
|
||||
#endif //PROJET_VICTORAVECUNK_SCREEN_H
|
35
mydevices.cpp
Normal file
35
mydevices.cpp
Normal file
|
@ -0,0 +1,35 @@
|
|||
|
||||
#include "mydevices.h"
|
||||
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
|
||||
// classe I2CActuatorScreen
|
||||
I2CActuatorScreen::I2CActuatorScreen ():Device(){}
|
||||
|
||||
void I2CActuatorScreen::run(){
|
||||
while(1){
|
||||
if ( (i2cbus!=NULL)&&!(i2cbus->isEmptyRegister(i2caddr))){
|
||||
Device::i2cbus->requestFrom(i2caddr, buf, I2C_BUFFER_SIZE);
|
||||
cout << "---screen :"<< buf << endl;
|
||||
}
|
||||
sleep(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//TODO Capteur de temperature a revoir avec conditions
|
||||
//TODO Electrovanne / moteur (a voir food)
|
||||
//TODO Radiateur rechauffer terrarium
|
||||
//TODO PHmetre pour qualite de l'eau
|
||||
//TODO regarder les manometre
|
||||
//TODO Electrovanne pour remplir la piscine
|
||||
|
||||
//TODO Ecran d'affichage avec infos de temps, derniere bouffe, infos sur tortues
|
||||
//TODO Bouton pour sauter prochaine bouffe (I2C)
|
||||
|
||||
|
||||
|
||||
|
24
mydevices.h
Normal file
24
mydevices.h
Normal file
|
@ -0,0 +1,24 @@
|
|||
#ifndef MYDEVICES_H
|
||||
#define MYDEVICES_H
|
||||
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <fstream>
|
||||
#include "core_simulation.h"
|
||||
|
||||
// exemple d'actionneur sur le bus I2C permettant d'echanger des tableaux de caracteres : un ecran, ne pas oublier d'heriter de Device
|
||||
class I2CActuatorScreen : public Device{
|
||||
protected:
|
||||
// memorise l'affichage de l'ecran
|
||||
char buf[I2C_BUFFER_SIZE];
|
||||
|
||||
public:
|
||||
// constructeur
|
||||
I2CActuatorScreen ();
|
||||
// thread representant le capteur et permettant de fonctionner independamment de la board
|
||||
virtual void run();
|
||||
};
|
||||
//class ExternalDigitalSensorButton: public Device
|
||||
#endif
|
0
on.txt
Normal file
0
on.txt
Normal file
283
sketch_ino.cpp
283
sketch_ino.cpp
|
@ -2,25 +2,12 @@
|
|||
#include "core_simulation.h"
|
||||
#include "app/include/Terrarium.h"
|
||||
#include "app/include/TerrariumParameter.h"
|
||||
#include "app/include/Menu.h"
|
||||
#include "app/include/Tortue.h"
|
||||
#include "include/I2CDevices/Keyboard.h"
|
||||
|
||||
|
||||
Terrarium *terrarium = new Terrarium(1);
|
||||
TerrariumParameter *temperature = new TerrariumParameter(25,
|
||||
20);
|
||||
TerrariumParameter *pressure = new TerrariumParameter(3000,
|
||||
2990);
|
||||
|
||||
Menu *menu = new Menu();
|
||||
|
||||
list<Tortue> * tortues = new list<Tortue>;
|
||||
list<Tortue>::iterator iteratorT;
|
||||
|
||||
string message = "";
|
||||
string input = "";
|
||||
|
||||
Terrarium terrarium(1);
|
||||
TerrariumParameter temperature(25, 20);
|
||||
TerrariumParameter pressure(3000,2990);
|
||||
TerrariumParameter ph(8,6);
|
||||
|
||||
|
||||
|
||||
|
@ -30,242 +17,62 @@ void Board::setup(){
|
|||
Serial.begin(9600);
|
||||
// on fixe les pin en entree et en sorite en fonction des capteurs/actionneurs mis sur la carte
|
||||
pinMode(1, INPUT);
|
||||
pinMode(0, OUTPUT);
|
||||
pinMode(2, INPUT);
|
||||
pinMode(4, INPUT);
|
||||
pinMode(5, INPUT);
|
||||
pinMode(3, INPUT);
|
||||
pinMode(6, INPUT);
|
||||
pinMode(7, INPUT);
|
||||
|
||||
pinMode(0, OUTPUT);
|
||||
pinMode(2, OUTPUT);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
digitalWrite(0,LOW);
|
||||
//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/1971", "female")));
|
||||
|
||||
//pinMode(6, OUTPUT);
|
||||
}
|
||||
|
||||
// la boucle de controle arduino
|
||||
void Board::loop() {
|
||||
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;
|
||||
std::string toDisplay;
|
||||
void Board::loop(){
|
||||
char buf[100];
|
||||
int val;
|
||||
int val1;
|
||||
static int cpt=0;
|
||||
static int bascule=0;
|
||||
int i=0;
|
||||
//for(i=0;i<10;i++){
|
||||
// if (i%3==0) {
|
||||
// lecture sur la pin 1 : capteur de temperature
|
||||
temperature.setValue(analogRead(1));
|
||||
sprintf(buf, "temperature %f", temperature.getValue());
|
||||
Serial.println(buf);
|
||||
|
||||
if ((temperature.is2Low()) && (terrarium.getRadState() == LOW)) {
|
||||
digitalWrite(0, HIGH);
|
||||
terrarium.setRadState(HIGH);
|
||||
}
|
||||
else if ((temperature.is2High() ) && (terrarium.getRadState() == HIGH)) {
|
||||
digitalWrite(0, LOW);
|
||||
terrarium.setRadState(LOW);
|
||||
}
|
||||
|
||||
|
||||
for (i = 0; i < 10; i++) {
|
||||
TemperatureManagement(); //Met à jour la valeur de temp
|
||||
PressureManagement(); // Met à jour la valeur de pression
|
||||
//cout << tortues->back() << endl;
|
||||
// lecture sur la pin 2 : capteur de temperature
|
||||
val = analogRead(2);
|
||||
sprintf(buf, "luminosite %d", val);
|
||||
Serial.println(buf);
|
||||
// }
|
||||
|
||||
if (menu->getId() == 0 ) { //Afficher écran d'accueil
|
||||
message = menu->displayDefault(temperature->getValue(),
|
||||
pressure->getValue(),
|
||||
terrarium->getRadState(),
|
||||
terrarium->getTapState(),
|
||||
Tortue::getNbTortue());
|
||||
|
||||
} else { //Afficher le l'écran du ième menu
|
||||
message = menu->getMessage();
|
||||
}
|
||||
|
||||
int a3 = analogRead(3);
|
||||
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();
|
||||
} else if (a3 == LOW && (terrarium->getPrevState() != a3)) {
|
||||
terrarium->setPrevState(LOW);
|
||||
}
|
||||
else if (a4 == HIGH && (terrarium->getNextState() != a4)) {
|
||||
terrarium->setNextState(HIGH);
|
||||
menu->nextChoice();
|
||||
} else if (a4 == LOW && (terrarium->getNextState() != a4)) {
|
||||
terrarium->setNextState(LOW);
|
||||
}
|
||||
else if (a6 == HIGH && (terrarium->getOkState() != a6)) {
|
||||
terrarium->setOkState(HIGH);
|
||||
menu->menuNext();
|
||||
} else if (a6 == LOW && (terrarium->getOkState() != a6)) {
|
||||
terrarium->setOkState(LOW);
|
||||
}
|
||||
else if (a7 == HIGH && (terrarium->getBackState() != a7)) {
|
||||
terrarium->setBackState(HIGH);
|
||||
menu->menuBack();
|
||||
} else if (a7 == LOW && (terrarium->getBackState() != a7)) {
|
||||
terrarium->setBackState(LOW);
|
||||
}
|
||||
// if(cpt%5==0){
|
||||
// tous les 5 fois on affiche sur l ecran la temperature
|
||||
sprintf(buf,"%d",val1);
|
||||
bus.write(1,buf,100);
|
||||
|
||||
|
||||
if (menu->getId() == 2){ //Lister les tortues
|
||||
iteratorT = tortues->begin();
|
||||
for (int j = 0; j < menu->getChoice(); ++j) {
|
||||
iteratorT++;
|
||||
}
|
||||
message += iteratorT->getInfo();
|
||||
}
|
||||
|
||||
if (cpt % 2 == 0) { //Afficher sur écran un tr sur 2
|
||||
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){
|
||||
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
|
||||
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");
|
||||
newTortue->setNom(input);
|
||||
tortues->push_back(*newTortue);
|
||||
menu->menuNext();
|
||||
break;
|
||||
}
|
||||
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) {
|
||||
// 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 : {
|
||||
tortues->back().setSexe(input);
|
||||
menu->menuNext();
|
||||
break;
|
||||
}
|
||||
case 6: { //Supprimer la tortue ayant le nom input
|
||||
int length = tortues->size();
|
||||
iteratorT = tortues->begin();
|
||||
for (int j = 0; j < length; ++j) {
|
||||
if (iteratorT->getNom() == input) {
|
||||
tortues->erase(iteratorT);
|
||||
Tortue::delete1();
|
||||
menu->menuNext();
|
||||
}
|
||||
++iteratorT;
|
||||
}
|
||||
if (iteratorT == tortues->end()) {
|
||||
cout << "not in list" << endl;
|
||||
menu->menuBack();
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 7:
|
||||
try {
|
||||
temperature->setThresholdHigh(stoi(input));
|
||||
menu->menuBack();
|
||||
}
|
||||
catch (TerrariumParameter::ThresholdExcep excep) {
|
||||
if (excep.id == 1) cout << "value is under the minimum value";
|
||||
}
|
||||
catch (std::invalid_argument excep) {
|
||||
cout << "Not a value" << endl;
|
||||
}
|
||||
break;
|
||||
case 8 :
|
||||
try {
|
||||
temperature->setThresholdLow(stoi(input));
|
||||
menu->menuBack();
|
||||
}catch (TerrariumParameter::ThresholdExcep excep) {
|
||||
if (excep.id == 2) cout << "value is over the maximum value";
|
||||
}
|
||||
catch (std::invalid_argument excep) {
|
||||
cout << "Not a value" << endl;
|
||||
}
|
||||
break;
|
||||
case 9 :
|
||||
try {
|
||||
pressure->setThresholdHigh(stoi(input));
|
||||
menu->menuBack();
|
||||
}catch (TerrariumParameter::ThresholdExcep excep) {
|
||||
if (excep.id == 1) cout << "value is under the minimum value";
|
||||
}
|
||||
catch (std::invalid_argument excep) {
|
||||
cout << "Not a value" << endl;
|
||||
}
|
||||
break;
|
||||
case 10 :
|
||||
try {
|
||||
pressure->setThresholdLow(stoi(input));
|
||||
menu->menuBack();
|
||||
}catch (TerrariumParameter::ThresholdExcep excep) {
|
||||
if (excep.id == 2) cout << "value is over the maximum value";
|
||||
}
|
||||
catch (std::invalid_argument excep) {
|
||||
cout << "Not a value" << endl;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// }
|
||||
cpt++;
|
||||
sleep(1);
|
||||
|
||||
|
||||
}
|
||||
//}
|
||||
|
||||
}
|
||||
|
||||
void Board::TemperatureManagement() {
|
||||
char buf[100];
|
||||
temperature->setValue(analogRead(1));
|
||||
|
||||
//Rad allume si temp trop basse mais pas déjà allumé
|
||||
if ((temperature->is2Low()) && (terrarium->getRadState() == LOW)) {
|
||||
digitalWrite(0, HIGH);
|
||||
terrarium->setRadState(HIGH);
|
||||
} else if ((temperature->is2High()) && (terrarium->getRadState() == HIGH)) {
|
||||
digitalWrite(0, LOW);
|
||||
terrarium->setRadState(LOW);
|
||||
}
|
||||
}
|
||||
|
||||
void Board::PressureManagement() {
|
||||
char buf[100];
|
||||
pressure->setValue(analogRead(5));
|
||||
//Electrovanne ouverte si pression trop basse mais pas déjà ouverte
|
||||
if ((pressure->is2Low()) && (terrarium->getTapState() == LOW)) {
|
||||
digitalWrite(2, HIGH);
|
||||
terrarium->setTapState(HIGH);
|
||||
} else if ((pressure->is2High()) && (terrarium->getTapState() == HIGH)) {
|
||||
digitalWrite(2, LOW);
|
||||
terrarium->setTapState(LOW);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue