Compare commits

..

No commits in common. "f33e08f0d76179e23dae92a451874e9a845edc82" and "ac143880d656cb0332843dbd1a0ba850061be0ed" have entirely different histories.

6 changed files with 113 additions and 113 deletions

View file

@ -11,14 +11,14 @@ ExternalDigitalSensorButton::ExternalDigitalSensorButton(int temps, std::string
int ExternalDigitalSensorButton::getState(){ int ExternalDigitalSensorButton::getState(){
setState(); //determine if on.txt exists before getting state setState(); //determine if on.txt exists before getting state
return DigitalSensor::state; return state;
} }
void ExternalDigitalSensorButton::setState() { void ExternalDigitalSensorButton::setState() {
if (ifstream (PATH)){ if (ifstream (PATH)){
DigitalSensor::state = HIGH; state = HIGH;
} else { } else {
DigitalSensor::state = LOW; state = LOW;
} }
} }

View file

@ -7,44 +7,44 @@
Menu::Menu() : id(0), choice(0), nbreChoices(1) { Menu::Menu() : id(0), choice(0), nbreChoices(1) {
list.push_back(*(new std::pair<int, list.push_back(*(new std::pair<int,
std::string>(1,"\n Liste tortue "))); std::string>(1,"Liste tortue")));
list.push_back(*(new std::pair<int, list.push_back(*(new std::pair<int,
std::string>(1,"\n Management tortue "))); std::string>(1,"Management tortue")));
list.push_back(*(new std::pair<int, list.push_back(*(new std::pair<int,
std::string>(1,"\n Gestion terrarium "))); std::string>(1,"Gestion terrarium")));
list.push_back(*(new std::pair<int, list.push_back(*(new std::pair<int,
std::string>(3,"\n Ajouter tortue"))); std::string>(3,"Ajouter tortue")));
list.push_back(*(new std::pair<int, list.push_back(*(new std::pair<int,
std::string>(3,"\n supprimer tortue"))); std::string>(3,"supprimer tortue")));
list.push_back(*(new std::pair<int, list.push_back(*(new std::pair<int,
std::string>(4,"\n Temperature max"))); std::string>(4,"Temperature max")));
list.push_back(*(new std::pair<int, list.push_back(*(new std::pair<int,
std::string>(4,"\n Temperature min"))); std::string>(4,"Temperature min")));
list.push_back(*(new std::pair<int, list.push_back(*(new std::pair<int,
std::string>(4,"\n Profondeur max"))); std::string>(4,"Profondeur max")));
list.push_back(*(new std::pair<int, list.push_back(*(new std::pair<int,
std::string>(4,"\n Profondeur min"))); std::string>(4,"Profondeur min")));
list.push_back(*(new std::pair<int, list.push_back(*(new std::pair<int,
std::string>(5,"\n Nom de la tortue a ajouter"))); std::string>(5,"Nom de la tortue a ajouter")));
list.push_back(*(new std::pair<int, list.push_back(*(new std::pair<int,
std::string>(11,"\n Naissance"))); std::string>(11,"Naissance")));
list.push_back(*(new std::pair<int, list.push_back(*(new std::pair<int,
std::string>(12,"\n Sexe"))); std::string>(12,"Sexe")));
list.push_back(*(new std::pair<int, list.push_back(*(new std::pair<int,
std::string>(6,"\n Nom de la tortue a supprimer"))); std::string>(6,"Nom de la tortue a supprimer")));
list.push_back(*(new std::pair<int, list.push_back(*(new std::pair<int,
std::string>(7,"\n Temperature max"))); std::string>(7,"Temperature max")));
list.push_back(*(new std::pair<int, list.push_back(*(new std::pair<int,
std::string>(8,"\n Temperature min"))); std::string>(8,"Temperature min")));
list.push_back(*(new std::pair<int, list.push_back(*(new std::pair<int,
std::string>(9,"\n Profondeur max"))); std::string>(9,"Profondeur max")));
list.push_back(*(new std::pair<int, list.push_back(*(new std::pair<int,
std::string>(10,"\n Profondeur min"))); std::string>(10,"Profondeur min")));
} }
std::string Menu::getMessage() { std::string Menu::getMessage() {
@ -54,8 +54,8 @@ std::string Menu::getMessage() {
std::list<std::pair<int,std::string>>::iterator it; std::list<std::pair<int,std::string>>::iterator it;
for (it = list.begin(); it != list.end() ; it++) { for (it = list.begin(); it != list.end() ; it++) {
if (it->first == id){ if (it->first == id){
if (cpt == choice){ if (it->first == choice){
message += it->second + "<--"; message += "->" + it->second;
} else { } else {
message += it->second; message += it->second;
} }
@ -66,18 +66,22 @@ std::string Menu::getMessage() {
} }
void Menu::nextChoice() { void Menu::nextChoice() {
choice = (choice + 1) % (nbreChoices); choice = (choice + 1) % nbreChoices;
} }
void Menu::previousChoice() { void Menu::previousChoice() {
if (choice == 0) choice = nbreChoices; choice = (choice - 1) % nbreChoices;
choice = (choice - 1);
} }
void Menu::menuBack() { void Menu::menuBack() {
if(!listId.empty()){ if(listId.size() > 1){
id = listId.back();
listId.pop_back(); listId.pop_back();
id = *listId.end();
} }
} }
@ -88,7 +92,7 @@ void Menu::menuNext() {
choice = 0; choice = 0;
nbreChoices = 3; nbreChoices = 3;
} }
else if (id == 1){ if (id == 1){
listId.push_back(id); listId.push_back(id);
switch (choice){ switch (choice){
case '0' : case '0' :
@ -113,7 +117,7 @@ void Menu::menuNext() {
} }
} }
else if(id == 3){ if(id == 3){
listId.push_back(id); listId.push_back(id);
switch (choice){ switch (choice){
case '0' : case '0' :
@ -133,7 +137,7 @@ void Menu::menuNext() {
} }
} }
else if(id == 4){ if(id == 4){
listId.push_back(id); listId.push_back(id);
switch (choice){ switch (choice){
case '0' : case '0' :
@ -162,11 +166,11 @@ void Menu::menuNext() {
nbreChoices = 1; nbreChoices = 1;
} }
} }
else if(id == 5){ if(id == 5){
listId.push_back(id); listId.push_back(id);
id = 11; id = 11;
} }
else if (id == 11){ if (id == 11){
listId.push_back(id); listId.push_back(id);
id = 12; id = 12;
} }
@ -174,14 +178,10 @@ void Menu::menuNext() {
std::string Menu::displayDefault(float temp, float press, int rad, int tap, int nbTortue) { std::string Menu::displayDefault(float temp, float press, int rad, int tap, int nbTortue) {
std:: string message = ""; std:: string message = "";
message = "\n Temperature : " + std::to_string(temp) + " \n "; message = "Temperature : " + std::to_string(temp) + " \n ";
message += "Pression : " + std::to_string(press) + " \n "; message += " Pression : " + std::to_string(press) + " \n ";
if (rad) message += "Etat du radiateur : ON \n "; message += " Etat du radiateur : " + std::to_string(rad) + " \n ";
else message += "Etat du radiateur : OFF \n "; message += " Etat du robinet : " + std::to_string(tap) + " \n ";
if (tap) message += "Etat du robinet : ON \n ";
else message += "Etat du robinet : OFF ";
return message; return message;
} }

View file

@ -11,10 +11,10 @@
int main(){ int main(){
//std::string btnNextPath = "/Users/victorleroch/Documents/INSA/Année4/C++/Projet_VictorAvecUnK/on.txt"; //std::string btnNextPath = "/Users/victorleroch/Documents/INSA/Année4/C++/Projet_VictorAvecUnK/on.txt";
std::string btnNextPath = "D:\\Documents\\Etudes\\INSA\\4A\\BECpp\\Projet_VictorAvecUnK\\src\\next.txt"; std::string btnNextPath = "D:\\Documents\\Etudes\\INSA\\4A\\BECpp\\Projet_VictorAvecUnK\\src\\on.txt";
std::string btnPrevPath = "D:\\Documents\\Etudes\\INSA\\4A\\BECpp\\Projet_VictorAvecUnK\\src\\prev.txt"; std::string btnPrevPath;
std::string btnOkPath = "D:\\Documents\\Etudes\\INSA\\4A\\BECpp\\Projet_VictorAvecUnK\\src\\ok.txt"; std::string btnOkPath;
std::string btnBackPath = "D:\\Documents\\Etudes\\INSA\\4A\\BECpp\\Projet_VictorAvecUnK\\src\\back.txt"; std::string btnBackPath;
// creation d'une board // creation d'une board
Board esp8266; Board esp8266;
// achat des senseurs et actionneurs // achat des senseurs et actionneurs

View file

@ -99,8 +99,8 @@ Device::Device(){
void Device::run(){ void Device::run(){
while(1){ while(1){
//cout << "empty device\n"; cout << "empty device\n";
sleep(4); sleep(3);
} }
} }

0
on.txt Normal file
View file

View file

@ -10,7 +10,7 @@ TerrariumParameter temperature(25, 20);
TerrariumParameter pressure(3000,2990); TerrariumParameter pressure(3000,2990);
TerrariumParameter ph(8,6); TerrariumParameter ph(8,6);
Menu *menu = new Menu(); Menu menu;
@ -35,84 +35,83 @@ void Board::setup(){
} }
// la boucle de controle arduino // la boucle de controle arduino
void Board::loop() { void Board::loop(){
char buf[100]; char buf[100];
static int cpt = 0; static int cpt=0;
static int bascule = 0; static int bascule=0;
int i = 0; int i=0;
std::string toDisplay; std::string toDisplay;
for (i = 0; i < 10; i++) {
TemperatureManagement();
PressureManagement();
if (menu->getId() == 0 && menu->displayDefault(temperature.getValue(), //for(i=0;i<10;i++){
pressure.getValue(), TemperatureManagement();
terrarium.getRadState(), PressureManagement();
terrarium.getTapState(),
0).c_str() != NULL) {
strcpy(buf, menu->displayDefault(temperature.getValue(),
pressure.getValue(),
terrarium.getRadState(),
terrarium.getTapState(),
0).c_str());
} else if (menu->getMessage().c_str() != NULL){
strcpy(buf, menu->getMessage().c_str());
}
if (i % 2 == 0) {
if (analogRead(3) == HIGH && (terrarium.getPrevState() != analogRead(3))) {
terrarium.setPrevState(HIGH);
menu->previousChoice();
} else if (analogRead(3) == LOW && (terrarium.getPrevState() != analogRead(3))) {
terrarium.setPrevState(LOW);
}
if (analogRead(4) == HIGH && (terrarium.getNextState() != analogRead(4))) {
terrarium.setNextState(HIGH);
menu->nextChoice();
} else if (analogRead(4) == LOW && (terrarium.getNextState() != analogRead(4))) {
terrarium.setNextState(LOW);
}
if (analogRead(6) == HIGH && (terrarium.getOkState() != analogRead(6))) {
terrarium.setOkState(HIGH);
cout << "OK" << endl;
menu->menuNext();
} else if (analogRead(6) == LOW && (terrarium.getOkState() != analogRead(6))) {
terrarium.setOkState(LOW);
cout << "NOK" << endl;
}
if (analogRead(7) == HIGH && (terrarium.getBackState() != analogRead(7))) {
terrarium.setBackState(HIGH);
menu->menuBack();
} else if (analogRead(7) == LOW && (terrarium.getBackState() != analogRead(7))) {
terrarium.setBackState(LOW);
}
}
// cout << buf << endl;
//sprintf(buf,"%s",menu.getMessage().c_str());
//sprintf(buf,"%f",temperature.getValue());
if (cpt % 5 == 0) bus.write(1, buf, 100);
cpt++;
sleep(1);
} if(menu.getId() == 0){
strcpy(buf, menu.displayDefault(temperature.getValue(),
pressure.getValue(),
terrarium.getRadState(),
terrarium.getTapState(),
0).c_str());
} else {
strcpy(buf,menu.getMessage().c_str());
}
if(analogRead(3) && (terrarium.getPrevState() != analogRead(3)) ){
terrarium.setPrevState(HIGH);
menu.previousChoice();
} else if (!analogRead(3) && (terrarium.getPrevState() != analogRead(3))){
terrarium.setPrevState(LOW);
}
if(analogRead(4) && (terrarium.getNextState() != analogRead(4)) ){
terrarium.setNextState(HIGH);
menu.nextChoice();
}else if (!analogRead(4) && (terrarium.getNextState() != analogRead(4))){
terrarium.setNextState(LOW);
}
if(analogRead(6) && (terrarium.getOkState() != analogRead(6)) ){
terrarium.setOkState(HIGH);
menu.menuNext();
}else if (!analogRead(6) && (terrarium.getOkState() != analogRead(6))){
terrarium.setOkState(LOW);
}
if(analogRead(7) && (terrarium.getBackState() != analogRead(7)) ){
terrarium.setBackState(HIGH);
menu.menuBack();
}else if (!analogRead(7) && (terrarium.getBackState() != analogRead(7))){
terrarium.setBackState(LOW);
}
cout << buf << endl;
//sprintf(buf,"%s",menu.getMessage().c_str());
//sprintf(buf,"%f",temperature.getValue());
//bus.write(1,buf,100);
cpt++;
sleep(1);
} }
void Board::TemperatureManagement() { void Board::TemperatureManagement() {
char buf[100]; char buf[100];
temperature.setValue(analogRead(1)); temperature.setValue(analogRead(1));
//sprintf(buf, "temperature %f", temperature.getValue()); sprintf(buf, "temperature %f", temperature.getValue());
//Serial.println(buf); Serial.println(buf);
if ((temperature.is2Low()) && (terrarium.getRadState() == LOW)) { if ((temperature.is2Low()) && (terrarium.getRadState() == LOW)) {
digitalWrite(0, HIGH); digitalWrite(0, HIGH);
terrarium.setRadState(HIGH); terrarium.setRadState(HIGH);
} else if ((temperature.is2High()) && (terrarium.getRadState() == HIGH)) { }
else if ((temperature.is2High() ) && (terrarium.getRadState() == HIGH)) {
digitalWrite(0, LOW); digitalWrite(0, LOW);
terrarium.setRadState(LOW); terrarium.setRadState(LOW);
} }
@ -121,13 +120,14 @@ void Board::TemperatureManagement() {
void Board::PressureManagement() { void Board::PressureManagement() {
char buf[100]; char buf[100];
pressure.setValue(analogRead(5)); pressure.setValue(analogRead(5));
//sprintf(buf, "pressure %f", pressure.getValue()); sprintf(buf, "pressure %f", pressure.getValue());
//Serial.println(buf); Serial.println(buf);
if ((pressure.is2Low()) && (terrarium.getTapState() == LOW)) { if ((pressure.is2Low()) && (terrarium.getTapState() == LOW)) {
digitalWrite(2, HIGH); digitalWrite(2, HIGH);
terrarium.setTapState(HIGH); terrarium.setTapState(HIGH);
} else if ((pressure.is2High()) && (terrarium.getTapState() == HIGH)) { }
else if ((pressure.is2High() ) && (terrarium.getTapState() == HIGH)) {
digitalWrite(2, LOW); digitalWrite(2, LOW);
terrarium.setTapState(LOW); terrarium.setTapState(LOW);
} }