Menu 0 et 1 fonctionnels

This commit is contained in:
Cameron Bray 2020-05-25 20:57:23 +02:00
parent ac143880d6
commit 2e71198459
6 changed files with 118 additions and 116 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 state; return DigitalSensor::state;
} }
void ExternalDigitalSensorButton::setState() { void ExternalDigitalSensorButton::setState() {
if (ifstream (PATH)){ if (ifstream (PATH)){
state = HIGH; DigitalSensor::state = HIGH;
} else { } else {
state = LOW; DigitalSensor::state = LOW;
} }
} }

View file

@ -6,45 +6,47 @@
Menu::Menu() : id(0), choice(0), nbreChoices(1) { Menu::Menu() : id(0), choice(0), nbreChoices(1) {
list.push_back(*(new std::pair<int, listId.push_back(0);
std::string>(1,"Liste tortue")));
list.push_back(*(new std::pair<int,
std::string>(1,"Management tortue")));
list.push_back(*(new std::pair<int,
std::string>(1,"Gestion terrarium")));
list.push_back(*(new std::pair<int, list.push_back(*(new std::pair<int,
std::string>(3,"Ajouter tortue"))); std::string>(1,"\n Liste tortue ")));
list.push_back(*(new std::pair<int, list.push_back(*(new std::pair<int,
std::string>(3,"supprimer tortue"))); 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, list.push_back(*(new std::pair<int,
std::string>(4,"Temperature max"))); std::string>(3,"\n Ajouter tortue")));
list.push_back(*(new std::pair<int, list.push_back(*(new std::pair<int,
std::string>(4,"Temperature min"))); std::string>(3,"\n supprimer tortue")));
list.push_back(*(new std::pair<int,
std::string>(4,"Profondeur max")));
list.push_back(*(new std::pair<int,
std::string>(4,"Profondeur min")));
list.push_back(*(new std::pair<int, list.push_back(*(new std::pair<int,
std::string>(5,"Nom de la tortue a ajouter"))); std::string>(4,"\n Temperature max")));
list.push_back(*(new std::pair<int, list.push_back(*(new std::pair<int,
std::string>(11,"Naissance"))); std::string>(4,"\n Temperature min")));
list.push_back(*(new std::pair<int, list.push_back(*(new std::pair<int,
std::string>(12,"Sexe"))); 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, list.push_back(*(new std::pair<int,
std::string>(6,"Nom de la tortue a supprimer"))); std::string>(5,"\n Nom de la tortue a ajouter")));
list.push_back(*(new std::pair<int,
std::string>(11,"\n Naissance")));
list.push_back(*(new std::pair<int,
std::string>(12,"\n Sexe")));
list.push_back(*(new std::pair<int, list.push_back(*(new std::pair<int,
std::string>(7,"Temperature max"))); std::string>(6,"\n Nom de la tortue a supprimer")));
list.push_back(*(new std::pair<int, list.push_back(*(new std::pair<int,
std::string>(8,"Temperature min"))); std::string>(7,"\n Temperature max")));
list.push_back(*(new std::pair<int, list.push_back(*(new std::pair<int,
std::string>(9,"Profondeur max"))); std::string>(8,"\n Temperature min")));
list.push_back(*(new std::pair<int, list.push_back(*(new std::pair<int,
std::string>(10,"Profondeur min"))); std::string>(9,"\n Profondeur max")));
list.push_back(*(new std::pair<int,
std::string>(10,"\n Profondeur min")));
} }
std::string Menu::getMessage() { std::string Menu::getMessage() {
@ -54,8 +56,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 (it->first == choice){ if (cpt == choice){
message += "->" + it->second; message += it->second + "<--";
} else { } else {
message += it->second; message += it->second;
} }
@ -66,18 +68,14 @@ std::string Menu::getMessage() {
} }
void Menu::nextChoice() { void Menu::nextChoice() {
choice = (choice + 1) % nbreChoices; choice = (choice + 1) % (nbreChoices);
} }
void Menu::previousChoice() { void Menu::previousChoice() {
choice = (choice - 1) % nbreChoices; if (choice == 0) choice = nbreChoices;
choice = (choice - 1);
} }
void Menu::menuBack() { void Menu::menuBack() {
if(listId.size() > 1){ if(listId.size() > 1){
listId.pop_back(); listId.pop_back();
@ -92,7 +90,7 @@ void Menu::menuNext() {
choice = 0; choice = 0;
nbreChoices = 3; nbreChoices = 3;
} }
if (id == 1){ else if (id == 1){
listId.push_back(id); listId.push_back(id);
switch (choice){ switch (choice){
case '0' : case '0' :
@ -117,7 +115,7 @@ void Menu::menuNext() {
} }
} }
if(id == 3){ else if(id == 3){
listId.push_back(id); listId.push_back(id);
switch (choice){ switch (choice){
case '0' : case '0' :
@ -137,7 +135,7 @@ void Menu::menuNext() {
} }
} }
if(id == 4){ else if(id == 4){
listId.push_back(id); listId.push_back(id);
switch (choice){ switch (choice){
case '0' : case '0' :
@ -166,11 +164,11 @@ void Menu::menuNext() {
nbreChoices = 1; nbreChoices = 1;
} }
} }
if(id == 5){ else if(id == 5){
listId.push_back(id); listId.push_back(id);
id = 11; id = 11;
} }
if (id == 11){ else if (id == 11){
listId.push_back(id); listId.push_back(id);
id = 12; id = 12;
} }
@ -178,10 +176,14 @@ 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 = "Temperature : " + std::to_string(temp) + " \n "; message = "\n Temperature : " + std::to_string(temp) + " \n ";
message += " Pression : " + std::to_string(press) + " \n "; message += "Pression : " + std::to_string(press) + " \n ";
message += " Etat du radiateur : " + std::to_string(rad) + " \n "; if (rad) message += "Etat du radiateur : ON \n ";
message += " Etat du robinet : " + std::to_string(tap) + " \n "; else message += "Etat du radiateur : OFF \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\\on.txt"; std::string btnNextPath = "D:\\Documents\\Etudes\\INSA\\4A\\BECpp\\Projet_VictorAvecUnK\\src\\next.txt";
std::string btnPrevPath; std::string btnPrevPath = "D:\\Documents\\Etudes\\INSA\\4A\\BECpp\\Projet_VictorAvecUnK\\src\\prev.txt";
std::string btnOkPath; std::string btnOkPath = "D:\\Documents\\Etudes\\INSA\\4A\\BECpp\\Projet_VictorAvecUnK\\src\\ok.txt";
std::string btnBackPath; std::string btnBackPath = "D:\\Documents\\Etudes\\INSA\\4A\\BECpp\\Projet_VictorAvecUnK\\src\\back.txt";
// 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(3); sleep(4);
} }
} }

0
on.txt
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; Menu *menu = new Menu();
@ -35,83 +35,84 @@ 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();
//for(i=0;i<10;i++){ if (i > 2 && menu->getId() == 0 && menu->displayDefault(temperature.getValue(),
TemperatureManagement(); pressure.getValue(),
PressureManagement(); terrarium.getRadState(),
terrarium.getTapState(),
0).c_str() != NULL) {
if(menu.getId() == 0){ strcpy(buf, menu->displayDefault(temperature.getValue(),
strcpy(buf, menu.displayDefault(temperature.getValue(), pressure.getValue(),
pressure.getValue(), terrarium.getRadState(),
terrarium.getRadState(), terrarium.getTapState(),
terrarium.getTapState(), 0).c_str());
0).c_str()); } else if (i > 2 && menu->getMessage().c_str() != NULL){
} else { strcpy(buf, menu->getMessage().c_str());
strcpy(buf,menu.getMessage().c_str()); }
}
if (i % 2 == 0) {
if (analogRead(3) == HIGH && (terrarium.getPrevState() != analogRead(3))) {
terrarium.setPrevState(HIGH);
if(analogRead(3) && (terrarium.getPrevState() != analogRead(3)) ){ menu->previousChoice();
terrarium.setPrevState(HIGH); } else if (analogRead(3) == LOW && (terrarium.getPrevState() != analogRead(3))) {
menu.previousChoice(); terrarium.setPrevState(LOW);
} else if (!analogRead(3) && (terrarium.getPrevState() != analogRead(3))){ }
terrarium.setPrevState(LOW); if (analogRead(4) == HIGH && (terrarium.getNextState() != analogRead(4))) {
} terrarium.setNextState(HIGH);
if(analogRead(4) && (terrarium.getNextState() != analogRead(4)) ){ menu->nextChoice();
terrarium.setNextState(HIGH); } else if (analogRead(4) == LOW && (terrarium.getNextState() != analogRead(4))) {
menu.nextChoice(); terrarium.setNextState(LOW);
}else if (!analogRead(4) && (terrarium.getNextState() != analogRead(4))){ }
terrarium.setNextState(LOW); if (analogRead(6) == HIGH && (terrarium.getOkState() != analogRead(6))) {
} terrarium.setOkState(HIGH);
if(analogRead(6) && (terrarium.getOkState() != analogRead(6)) ){ cout << "OK" << endl;
terrarium.setOkState(HIGH); menu->menuNext();
menu.menuNext(); } else if (analogRead(6) == LOW && (terrarium.getOkState() != analogRead(6))) {
}else if (!analogRead(6) && (terrarium.getOkState() != analogRead(6))){ terrarium.setOkState(LOW);
terrarium.setOkState(LOW); cout << "NOK" << endl;
} }
if(analogRead(7) && (terrarium.getBackState() != analogRead(7)) ){ if (analogRead(7) == HIGH && (terrarium.getBackState() != analogRead(7))) {
terrarium.setBackState(HIGH); terrarium.setBackState(HIGH);
menu.menuBack(); menu->menuBack();
}else if (!analogRead(7) && (terrarium.getBackState() != analogRead(7))){ } else if (analogRead(7) == LOW && (terrarium.getBackState() != analogRead(7))) {
terrarium.setBackState(LOW); terrarium.setBackState(LOW);
} }
}
cout << buf << endl;
//sprintf(buf,"%s",menu.getMessage().c_str()); // cout << buf << endl;
//sprintf(buf,"%s",menu.getMessage().c_str());
//sprintf(buf,"%f",temperature.getValue());
//bus.write(1,buf,100); //sprintf(buf,"%f",temperature.getValue());
if (cpt % 5 == 0) bus.write(1, buf, 100);
cpt++; cpt++;
sleep(1);
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);
} }
@ -120,14 +121,13 @@ 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);
} }