Compare commits

...

26 commits

Author SHA1 Message Date
00c761d383 Petite modif ReadMe (nom des boutons) 2020-05-30 15:28:38 +02:00
65106128ed final with readme 2020-05-30 15:21:17 +02:00
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
5c3d503b30 beta 1.0 + operator 2020-05-27 09:59:21 +02:00
e8096b9681 beta 1.0 2020-05-27 01:35:03 +02:00
958bfa9038 threshold sans exceptions lave (switch) 2020-05-27 00:42:57 +02:00
fddb04eab5 threshold sans exceptions 2020-05-27 00:06:40 +02:00
bcf9514dd1 supprimer fonctionne 2020-05-26 23:54:30 +02:00
eea602662f Ajout tortue fonctionne 2020-05-26 23:08:53 +02:00
0856b5762c if apple else windows 2020-05-26 17:38:24 +02:00
9dd4721d1d Ajout getAge tortue 2020-05-26 17:14:38 +02:00
585f568930 Lister tortues fonctionne, debut ajouter tortue 2.0 2020-05-26 17:10:31 +02:00
df8d16ef4c Lister tortues fonctionne, debut ajouter tortue 2020-05-26 15:58:07 +02:00
8e999d0e59 Menu 0 et 1 fonctionnels 3.0 2020-05-25 21:23:32 +02:00
f33e08f0d7 Menu 0 et 1 fonctionnels 2.0 2020-05-25 21:18:47 +02:00
2e71198459 Menu 0 et 1 fonctionnels 2020-05-25 20:57:23 +02:00
ac143880d6 Avancement menu, probleme avec le bus.write 2020-05-25 16:49:27 +02:00
ca90d0487b Boutons 2.0 2020-05-25 14:12:48 +02:00
acb5c35fe1 Menu.cpp v0 2020-05-22 17:27:40 +02:00
8600c09ba2 I2C reorganisation delete devices.cpp on est des genies 2020-05-22 15:43:33 +02:00
a38774d31f Electrovanne terminee et fonctionelle 2.0 2020-05-20 11:55:18 +02:00
3b04428c7f Electrovanne terminee et fonctionelle 2020-05-20 11:44:55 +02:00
f99ea9a83d electrovanne declaré, je pense ca marche 2020-05-20 11:05:57 +02:00
9527f1004b manometre declaré, je pense ca marche 2020-05-20 10:57:02 +02:00
34 changed files with 946 additions and 214 deletions

BIN
BECppRapport.pdf Normal file

Binary file not shown.

View file

@ -4,18 +4,22 @@
#include "../../../include/AnalogDevices/AnalogSensors/AnalogSensorManometre.h"
AnalogSensorManometre::AnalogSensorManometre(float val, int temps):AnalogSensor(val,temps){ alea = 1;}
int AnalogSensorManometre::alea = -1;
AnalogSensorManometre::AnalogSensorManometre(int val, int temps):AnalogDevice(val,temps){
AnalogSensorManometre::alea = -1;
}
void AnalogSensorManometre::run(){
int cpt = 0;
while(1){
if(ptrmem!=NULL){
if(cpt == 5){
*ptrmem = val - alea;
val = val - alea;
cpt = 0;
}
if(ptrmem!=NULL) {
*ptrmem = val + AnalogSensorManometre::alea;
val = val + AnalogSensorManometre::alea;
}
sleep(temps);
cpt++;
sleep(temps);
}
}
void AnalogSensorManometre::setAlea(int alea) {
AnalogSensorManometre::alea = alea;
}

View file

@ -18,3 +18,7 @@ void AnalogSensorPHmetre::run() {
cpt ++;
}
}
void AnalogSensorPHmetre::setAlea(int alea) {
AnalogSensorPHmetre::alea = alea;
}

View file

@ -3,3 +3,20 @@
//
#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;
}
}
}

View file

@ -4,13 +4,7 @@
#include "../../../include/DigitalDevices/DigitalActuators/DigitalActuatorRadiator.h"
DigitalActuatorRadiator::DigitalActuatorRadiator(int temps, float thresholdHigh, float thresholdLow) : DigitalActuator(temps),
thresholdHigh(thresholdHigh), thresholdLow(thresholdLow) {}
void DigitalActuatorRadiator::activate() {
DigitalDevice::state = HIGH;
}
DigitalActuatorRadiator::DigitalActuatorRadiator(int temps) : DigitalActuator(temps){}
void DigitalActuatorRadiator::run() {
int previousState = LOW;
while (1){
@ -24,19 +18,3 @@ 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;
}

View file

@ -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):DigitalSensor(temps) {}
ExternalDigitalSensorButton::ExternalDigitalSensorButton(int temps, std::string PATH):DigitalSensor(temps), PATH(PATH){}
int ExternalDigitalSensorButton::getState(){
setState(); //determine if on.txt exists before getting state
return state;
return DigitalSensor::state;
}
void ExternalDigitalSensorButton::setState() {
if (ifstream (PATH)){
state = HIGH;
DigitalSensor::state = HIGH;
} else {
state = LOW;
DigitalSensor::state = LOW;
}
}

View file

@ -0,0 +1,26 @@
//
// 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);
}
}

View file

@ -0,0 +1,21 @@
//
// 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 Normal file
View file

@ -0,0 +1,13 @@
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.

35
app/include/Menu.h Normal file
View file

@ -0,0 +1,35 @@
//
// 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

View file

@ -11,14 +11,27 @@ private:
int id;
int radState;
int tapState;
public:
Terrarium(int id);
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);
};

View file

@ -8,20 +8,24 @@
class TerrariumParameter { //TODO add to diagram
private:
float value;
int thresholdHigh;
int thresholdLow;
float value, thresholdHigh, thresholdLow;
public:
TerrariumParameter(int thresholdHigh, int thresholdLow);
class ThresholdExcep {
public:
int id;
ThresholdExcep(int id):id(id){};
};
TerrariumParameter(float thresholdHigh, float thresholdLow);
//getters setters
float getValue() const;
void setValue(float value);
int getThresholdHigh() const;
void setThresholdHigh(int thresholdHigh);
int getThresholdLow() const;
void setThresholdLow(int thresholdLow);
float getThresholdHigh() const;
void setThresholdHigh(float thresholdHigh);
float getThresholdLow() const;
void setThresholdLow(float thresholdLow);
//Methods
bool is2High();
bool is2Low();
};

View file

@ -6,21 +6,45 @@
#define BE_TORTUE_H
#include <string>
#include <ostream>
class Tortue{
private:
std::string nom;
int naissance;
std::string naissance;
std::string sexe;
static int nbTortue;
public:
Tortue(const std::string &nom, const std::string &sexe);
class ExceptionDate{
public:
int id;
ExceptionDate(int id);
};
Tortue();
Tortue(const std::string &nom, const std::string &naissance, const std::string &sexe);
const std::string &getNom() const;
int getNaissance() const;
int getAge() const;
void setNom(const std::string &nom);
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 Normal file
View file

@ -0,0 +1,225 @@
//
// 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;
}

View file

@ -5,7 +5,10 @@
#include "../include/Terrarium.h"
#include "../../core_simulation.h"
Terrarium::Terrarium(int id) : id(id),
radState(LOW), tapState(LOW){}
radState(LOW), tapState(LOW), NextState{LOW},
PrevState(LOW), OKState(LOW), BackState(LOW){}
//Getters and Setters //
int Terrarium::getRadState() const {
return radState;
@ -23,3 +26,35 @@ 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;
}

View file

@ -4,7 +4,7 @@
#include "../include/TerrariumParameter.h"
//Constructor
TerrariumParameter::TerrariumParameter(int thresholdHigh, int thresholdLow) : thresholdHigh(thresholdHigh),
TerrariumParameter::TerrariumParameter(float thresholdHigh, float thresholdLow) : thresholdHigh(thresholdHigh),
thresholdLow(thresholdLow){}
//Getters Setters
@ -14,17 +14,25 @@ float TerrariumParameter::getValue() const {
void TerrariumParameter::setValue(float value) {
TerrariumParameter::value = value;
}
int TerrariumParameter::getThresholdHigh() const {
float TerrariumParameter::getThresholdHigh() const {
return thresholdHigh;
}
void TerrariumParameter::setThresholdHigh(int thresholdHigh) {
TerrariumParameter::thresholdHigh = thresholdHigh;
void TerrariumParameter::setThresholdHigh(float thresholdHigh) {
if (thresholdHigh < thresholdLow){
throw ThresholdExcep(1);
} else {
TerrariumParameter::thresholdHigh = thresholdHigh;
}
}
int TerrariumParameter::getThresholdLow() const {
float TerrariumParameter::getThresholdLow() const {
return thresholdLow;
}
void TerrariumParameter::setThresholdLow(int thresholdLow) {
TerrariumParameter::thresholdLow = thresholdLow;
void TerrariumParameter::setThresholdLow(float thresholdLow) {
if (thresholdLow > thresholdHigh){
throw ThresholdExcep(2);
} else {
TerrariumParameter::thresholdLow = thresholdLow;
}
}
//Methods

View file

@ -6,11 +6,62 @@
#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;
}
int Tortue::getNaissance() const {
string Tortue::getNaissance() const {
return naissance;
}
@ -18,16 +69,80 @@ const std::string &Tortue::getSexe() const {
return sexe;
}
Tortue::Tortue(const string &nom, const string &sexe) : nom(nom), sexe(sexe) {
naissance = std::time(nullptr);
int Tortue::getNbTortue() {
return nbTortue;
}
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;
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;
}
Tortue::ExceptionDate::ExceptionDate(int id) : id(id) {}

View file

@ -1,34 +1,55 @@
#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);
//DigitalActuatorLED led1(DELAY);
IntelligentDigitalActuatorLED led1(DELAY);
I2CActuatorScreen screen;
AnalogSensorLuminosity luminosite(DELAY);
ExternalDigitalSensorButton button(DELAY);
AnalogSensorManometre manometre(4,DELAY);
DigitalActuatorRadiator radiator(DELAY, THRESHOLDHIGH, THRESHOLDLOW);
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);
// branchement des capteurs actionneurs
esp8266.pin(0, radiator);
esp8266.pin(1,temperature);
//esp8266.pin(0,led1);
esp8266.pin(2, luminosite);
esp8266.i2c(1,screen);
esp8266.pin(4, button);
esp8266.pin(2, electrovanne);
esp8266.pin(3, buttonPrev);
esp8266.pin(4, buttonNext);
esp8266.pin(5, manometre);
esp8266.pin(0, radiator);
esp8266.pin(6, buttonOK);
esp8266.pin(7, buttonBack);
esp8266.i2c(1,screen);
esp8266.i2c(2,keyboard);
// allumage de la carte
esp8266.run();

View file

@ -99,8 +99,8 @@ Device::Device(){
void Device::run(){
while(1){
cout << "empty device\n";
sleep(3);
//cout << "empty device\n";
sleep(4);
}
}
@ -174,3 +174,5 @@ void Board::i2c(int addr,Device& dev){
tabthreadbus[addr]=new thread(&Device::run,&dev);
}

View file

@ -8,13 +8,12 @@
#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 6
#define THRESHOLDHIGH 25
#define THRESHOLDLOW 20
#define MAX_IO_PIN 10
using namespace std;
@ -127,6 +126,8 @@ public:
void setup();
// fonction arduino : boucle de controle de la carte arduino
void loop();
void TemperatureManagement();
void PressureManagement();
};
#endif

View file

@ -2,7 +2,10 @@
// Created by camer on 16/05/2020.
//
#include "../../core_simulation.h"
#include "../../mydevices.h"
#include <unistd.h>
#include <iostream>
#include <thread>
#include <fstream>
#ifndef PROJET_VICTORAVECUNK_ANALOGDEVICE_H
#define PROJET_VICTORAVECUNK_ANALOGDEVICE_H

View file

@ -11,11 +11,15 @@
//#include <fstream>
#include "../AnalogDevice.h"
class AnalogSensorManometre : public AnalogSensor{
class AnalogSensorManometre: public AnalogDevice {
private:
int alea;
static int alea;
public:
AnalogSensorManometre(float val, int t); //
// 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
virtual void run();
};

View file

@ -8,9 +8,10 @@
#include "../AnalogDevice.h"
class AnalogSensorPHmetre : public AnalogSensor {
public:
private:
static int alea;
public:
static void setAlea(int alea);
AnalogSensorPHmetre(float val, int temps);
virtual void run();
};

View file

@ -15,7 +15,7 @@
// exemple de capteur analogique de temperature, ne pas oublier d'heriter de Device
class AnalogSensorTemperature: public AnalogDevice {
public:
private:
static int alea;
public:
// fait osciller la valeur du cpateur de 1

View file

@ -6,8 +6,12 @@
#define PROJET_VICTORAVECUNK_DIGITALACTUATORELECTROVANNE_H
class DigitalActuatorElectrovanne {
#include "../DigitalDevice.h"
class DigitalActuatorElectrovanne : public DigitalActuator{
public:
DigitalActuatorElectrovanne(int temps);
void run();
};

View file

@ -10,20 +10,8 @@
#include "../../../include/AnalogDevices/AnalogSensors/AnalogSensorTemperature.h"
class DigitalActuatorRadiator : public DigitalActuator {
private:
float thresholdHigh, thresholdLow;
public:
DigitalActuatorRadiator(int temps, float threshold, float thresholdLow);
float getThresholdHigh() const;
void setThresholdHigh(float threshold);
float getThresholdLow() const;
void setThresholdLow(float thresholdLow);
void activate();
DigitalActuatorRadiator(int temps);
void run();
};

View file

@ -7,7 +7,10 @@
#include "../../core_simulation.h"
#include "../../mydevices.h"
#include <unistd.h>
#include <iostream>
#include <thread>
#include <fstream>
class DigitalDevice : public Device {
protected:

View file

@ -9,8 +9,10 @@
#include "../DigitalDevice.h"
class ExternalDigitalSensorButton : public DigitalSensor{
private:
std::string PATH;
public:
ExternalDigitalSensorButton(int temps);
ExternalDigitalSensorButton(int temps, std::string PATH);
int getState();
void setState();

View file

@ -0,0 +1,22 @@
//
// 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

View file

@ -0,0 +1,25 @@
//
// 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

View file

@ -1,35 +0,0 @@
#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)

View file

@ -1,24 +0,0 @@
#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
View file

View file

@ -2,12 +2,25 @@
#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(1);
TerrariumParameter temperature(25, 20);
TerrariumParameter pressure(3000,2990);
TerrariumParameter ph(8,6);
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 = "";
@ -17,62 +30,242 @@ 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);
//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/1971", "female")));
}
// la boucle de controle arduino
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);
}
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;
// lecture sur la pin 2 : capteur de temperature
val = analogRead(2);
sprintf(buf, "luminosite %d", val);
Serial.println(buf);
// }
for (i = 0; i < 10; i++) {
TemperatureManagement(); //Met à jour la valeur de temp
PressureManagement(); // Met à jour la valeur de pression
//cout << tortues->back() << endl;
// 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() == 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 (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);
}
}