Menu 0 et 1 fonctionnels
This commit is contained in:
parent
ac143880d6
commit
2e71198459
6 changed files with 118 additions and 116 deletions
|
@ -11,14 +11,14 @@ ExternalDigitalSensorButton::ExternalDigitalSensorButton(int temps, std::string
|
|||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -6,45 +6,47 @@
|
|||
|
||||
|
||||
Menu::Menu() : id(0), choice(0), nbreChoices(1) {
|
||||
list.push_back(*(new std::pair<int,
|
||||
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")));
|
||||
listId.push_back(0);
|
||||
|
||||
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,
|
||||
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,
|
||||
std::string>(4,"Temperature max")));
|
||||
std::string>(3,"\n Ajouter tortue")));
|
||||
list.push_back(*(new std::pair<int,
|
||||
std::string>(4,"Temperature min")));
|
||||
list.push_back(*(new std::pair<int,
|
||||
std::string>(4,"Profondeur max")));
|
||||
list.push_back(*(new std::pair<int,
|
||||
std::string>(4,"Profondeur min")));
|
||||
std::string>(3,"\n supprimer tortue")));
|
||||
|
||||
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,
|
||||
std::string>(11,"Naissance")));
|
||||
std::string>(4,"\n Temperature min")));
|
||||
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,
|
||||
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,
|
||||
std::string>(7,"Temperature max")));
|
||||
std::string>(6,"\n Nom de la tortue a supprimer")));
|
||||
|
||||
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,
|
||||
std::string>(9,"Profondeur max")));
|
||||
std::string>(8,"\n Temperature min")));
|
||||
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() {
|
||||
|
@ -54,8 +56,8 @@ std::string Menu::getMessage() {
|
|||
std::list<std::pair<int,std::string>>::iterator it;
|
||||
for (it = list.begin(); it != list.end() ; it++) {
|
||||
if (it->first == id){
|
||||
if (it->first == choice){
|
||||
message += "->" + it->second;
|
||||
if (cpt == choice){
|
||||
message += it->second + "<--";
|
||||
} else {
|
||||
message += it->second;
|
||||
}
|
||||
|
@ -66,18 +68,14 @@ std::string Menu::getMessage() {
|
|||
}
|
||||
|
||||
void Menu::nextChoice() {
|
||||
choice = (choice + 1) % nbreChoices;
|
||||
choice = (choice + 1) % (nbreChoices);
|
||||
}
|
||||
|
||||
void Menu::previousChoice() {
|
||||
choice = (choice - 1) % nbreChoices;
|
||||
if (choice == 0) choice = nbreChoices;
|
||||
choice = (choice - 1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void Menu::menuBack() {
|
||||
if(listId.size() > 1){
|
||||
listId.pop_back();
|
||||
|
@ -92,7 +90,7 @@ void Menu::menuNext() {
|
|||
choice = 0;
|
||||
nbreChoices = 3;
|
||||
}
|
||||
if (id == 1){
|
||||
else if (id == 1){
|
||||
listId.push_back(id);
|
||||
switch (choice){
|
||||
case '0' :
|
||||
|
@ -117,7 +115,7 @@ void Menu::menuNext() {
|
|||
}
|
||||
|
||||
}
|
||||
if(id == 3){
|
||||
else if(id == 3){
|
||||
listId.push_back(id);
|
||||
switch (choice){
|
||||
case '0' :
|
||||
|
@ -137,7 +135,7 @@ void Menu::menuNext() {
|
|||
|
||||
}
|
||||
}
|
||||
if(id == 4){
|
||||
else if(id == 4){
|
||||
listId.push_back(id);
|
||||
switch (choice){
|
||||
case '0' :
|
||||
|
@ -166,11 +164,11 @@ void Menu::menuNext() {
|
|||
nbreChoices = 1;
|
||||
}
|
||||
}
|
||||
if(id == 5){
|
||||
else if(id == 5){
|
||||
listId.push_back(id);
|
||||
id = 11;
|
||||
}
|
||||
if (id == 11){
|
||||
else if (id == 11){
|
||||
listId.push_back(id);
|
||||
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 message = "";
|
||||
message = "Temperature : " + std::to_string(temp) + " \n ";
|
||||
message += " Pression : " + std::to_string(press) + " \n ";
|
||||
message += " Etat du radiateur : " + std::to_string(rad) + " \n ";
|
||||
message += " Etat du robinet : " + std::to_string(tap) + " \n ";
|
||||
message = "\n Temperature : " + std::to_string(temp) + " \n ";
|
||||
message += "Pression : " + std::to_string(press) + " \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 ";
|
||||
|
||||
return message;
|
||||
}
|
||||
|
||||
|
|
|
@ -11,10 +11,10 @@
|
|||
|
||||
int main(){
|
||||
//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 btnPrevPath;
|
||||
std::string btnOkPath;
|
||||
std::string btnBackPath;
|
||||
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";
|
||||
// creation d'une board
|
||||
Board esp8266;
|
||||
// achat des senseurs et actionneurs
|
||||
|
|
|
@ -99,8 +99,8 @@ Device::Device(){
|
|||
|
||||
void Device::run(){
|
||||
while(1){
|
||||
cout << "empty device\n";
|
||||
sleep(3);
|
||||
//cout << "empty device\n";
|
||||
sleep(4);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
0
on.txt
0
on.txt
134
sketch_ino.cpp
134
sketch_ino.cpp
|
@ -10,7 +10,7 @@ TerrariumParameter temperature(25, 20);
|
|||
TerrariumParameter pressure(3000,2990);
|
||||
TerrariumParameter ph(8,6);
|
||||
|
||||
Menu menu;
|
||||
Menu *menu = new Menu();
|
||||
|
||||
|
||||
|
||||
|
@ -35,83 +35,84 @@ void Board::setup(){
|
|||
}
|
||||
|
||||
// la boucle de controle arduino
|
||||
void Board::loop(){
|
||||
char buf[100];
|
||||
static int cpt=0;
|
||||
static int bascule=0;
|
||||
int i=0;
|
||||
std::string toDisplay;
|
||||
void Board::loop() {
|
||||
char buf[100];
|
||||
static int cpt = 0;
|
||||
static int bascule = 0;
|
||||
int i = 0;
|
||||
std::string toDisplay;
|
||||
|
||||
|
||||
for (i = 0; i < 10; i++) {
|
||||
TemperatureManagement();
|
||||
PressureManagement();
|
||||
|
||||
|
||||
//for(i=0;i<10;i++){
|
||||
TemperatureManagement();
|
||||
PressureManagement();
|
||||
if (i > 2 && menu->getId() == 0 && menu->displayDefault(temperature.getValue(),
|
||||
pressure.getValue(),
|
||||
terrarium.getRadState(),
|
||||
terrarium.getTapState(),
|
||||
0).c_str() != NULL) {
|
||||
strcpy(buf, menu->displayDefault(temperature.getValue(),
|
||||
pressure.getValue(),
|
||||
terrarium.getRadState(),
|
||||
terrarium.getTapState(),
|
||||
0).c_str());
|
||||
} else if (i > 2 && 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() {
|
||||
char buf[100];
|
||||
temperature.setValue(analogRead(1));
|
||||
sprintf(buf, "temperature %f", temperature.getValue());
|
||||
Serial.println(buf);
|
||||
//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)) {
|
||||
} else if ((temperature.is2High()) && (terrarium.getRadState() == HIGH)) {
|
||||
digitalWrite(0, LOW);
|
||||
terrarium.setRadState(LOW);
|
||||
}
|
||||
|
@ -120,14 +121,13 @@ void Board::TemperatureManagement() {
|
|||
void Board::PressureManagement() {
|
||||
char buf[100];
|
||||
pressure.setValue(analogRead(5));
|
||||
sprintf(buf, "pressure %f", pressure.getValue());
|
||||
Serial.println(buf);
|
||||
//sprintf(buf, "pressure %f", pressure.getValue());
|
||||
//Serial.println(buf);
|
||||
|
||||
if ((pressure.is2Low()) && (terrarium.getTapState() == LOW)) {
|
||||
digitalWrite(2, HIGH);
|
||||
terrarium.setTapState(HIGH);
|
||||
}
|
||||
else if ((pressure.is2High() ) && (terrarium.getTapState() == HIGH)) {
|
||||
} else if ((pressure.is2High()) && (terrarium.getTapState() == HIGH)) {
|
||||
digitalWrite(2, LOW);
|
||||
terrarium.setTapState(LOW);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue