threshold sans exceptions lave (switch)

This commit is contained in:
Cameron Bray 2020-05-27 00:42:57 +02:00
parent fddb04eab5
commit 958bfa9038
2 changed files with 75 additions and 135 deletions

View file

@ -28,10 +28,10 @@ int main(){
AnalogSensorTemperature temperature(TEMP,DELAY); AnalogSensorTemperature temperature(TEMP,DELAY);
Screen screen; Screen screen;
Keyboard keyboard; Keyboard keyboard;
ExternalDigitalSensorButton buttonNext(DELAY + 2, btnNextPath); ExternalDigitalSensorButton buttonNext(DELAY - 2, btnNextPath);
ExternalDigitalSensorButton buttonPrev(DELAY + 2, btnPrevPath); ExternalDigitalSensorButton buttonPrev(DELAY - 2, btnPrevPath);
ExternalDigitalSensorButton buttonOK(DELAY + 2, btnOkPath); ExternalDigitalSensorButton buttonOK(DELAY - 2, btnOkPath);
ExternalDigitalSensorButton buttonBack(DELAY + 2, btnBackPath); ExternalDigitalSensorButton buttonBack(DELAY - 2, btnBackPath);
AnalogSensorManometre manometre(PRESSURE,DELAY); AnalogSensorManometre manometre(PRESSURE,DELAY);
DigitalActuatorRadiator radiator(DELAY); DigitalActuatorRadiator radiator(DELAY);
DigitalActuatorElectrovanne electrovanne(DELAY); DigitalActuatorElectrovanne electrovanne(DELAY);

View file

@ -122,29 +122,15 @@ void Board::loop() {
//cout << iteratorT->getInfo() << endl; //cout << iteratorT->getInfo() << endl;
message += iteratorT->getInfo(); message += iteratorT->getInfo();
} }
if (cpt % 3 == 0) { if (cpt % 2 == 0) {
strcpy(buf, message.c_str()); strcpy(buf, message.c_str());
if (buf != NULL) bus.write(1, buf, 150); if (buf != NULL) bus.write(1, buf, 150);
} }
if (menu->getId() == 5){ if (menu->getId() == 5 || menu->getId() == 11
Keyboard::saisie = true ; || menu->getId() == 12 || menu->getId() == 6
sleep(4); || menu->getId() == 7 || menu->getId() == 8
if ( (&bus!=NULL)&&!(bus.isEmptyRegister(2))) { || menu->getId() == 9 || menu->getId() == 10){
bus.requestFrom(2, inputBuf, 150);
if (inputBuf[0] != '\0') {
input = "";
Tortue *newTortue = new Tortue();
for (int j = 0; inputBuf[j] != '\0'; ++j) {
input += inputBuf[j];
}
newTortue->setNom(input);
tortues->push_back(*newTortue);
menu->menuNext();
break;
}
}
} else if (menu->getId() == 11){
Keyboard::saisie = true ; Keyboard::saisie = true ;
sleep(4); sleep(4);
if ( (&bus!=NULL)&&!(bus.isEmptyRegister(2))) { if ( (&bus!=NULL)&&!(bus.isEmptyRegister(2))) {
@ -154,122 +140,76 @@ void Board::loop() {
for (int j = 0; inputBuf[j] != '\0'; ++j) { for (int j = 0; inputBuf[j] != '\0'; ++j) {
input += inputBuf[j]; input += inputBuf[j];
} }
tortues->back().setNaissance(input);
menu->menuNext();
break;
}
}
} else if (menu->getId() == 12){
Keyboard::saisie = true ;
sleep(4);
if ( (&bus!=NULL)&&!(bus.isEmptyRegister(2))) {
bus.requestFrom(2, inputBuf, 150);
if (inputBuf[0] != '\0') {
input = "";
for (int j = 0; inputBuf[j] != '\0'; ++j) {
input += inputBuf[j];
}
tortues->back().setSexe(input);
menu->menuNext();
}
}
} else if (menu->getId() == 6){
Keyboard::saisie = true ;
sleep(4);
if ( (&bus!=NULL)&&!(bus.isEmptyRegister(2))) {
bus.requestFrom(2, inputBuf, 150);
if (inputBuf[0] != '\0') { switch (menu->getId()) {
input = ""; case 5 : {
for (int j = 0; inputBuf[j] != '\0'; ++j) { Tortue *newTortue = new Tortue();
input += inputBuf[j]; newTortue->setNom(input);
} tortues->push_back(*newTortue);
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(); menu->menuNext();
break;
} }
++iteratorT; case 11 :
} tortues->back().setNaissance(input);
if (iteratorT == tortues->end()) { menu->menuNext();
cout << "not in list" << endl; break;
menu->menuBack(); case 12 :
} tortues->back().setSexe(input);
} menu->menuNext();
} break;
}else if (menu->getId() == 7){ case 6: {
Keyboard::saisie = true ; int length = tortues->size();
sleep(4); iteratorT = tortues->begin();
if ( (&bus!=NULL)&&!(bus.isEmptyRegister(2))) { for (int j = 0; j < length; ++j) {
bus.requestFrom(2, inputBuf, 150); if (iteratorT->getNom() == input) {
if (inputBuf[0] != '\0') { tortues->erase(iteratorT);
input = ""; Tortue::delete1();
for (int j = 0; inputBuf[j] != '\0'; ++j) { menu->menuNext();
input += inputBuf[j]; }
} //TODO vérifier que chiffres ++iteratorT;
if (stoi(input) >= temperature->getThresholdLow()){ }
temperature->setThresholdHigh(stoi(input)); if (iteratorT == tortues->end()) {
menu->menuBack(); cout << "not in list" << endl;
} else { menu->menuBack();
cout << "booooo" << endl; }
} break;
} }
} case 7:
}else if (menu->getId() == 8){ //TODO vérifier que chiffres
Keyboard::saisie = true ; if (stoi(input) >= temperature->getThresholdLow()){
sleep(4); temperature->setThresholdHigh(stoi(input));
if ( (&bus!=NULL)&&!(bus.isEmptyRegister(2))) { menu->menuBack();
bus.requestFrom(2, inputBuf, 150); } else {
if (inputBuf[0] != '\0') { cout << "booooo" << endl;
input = ""; }
for (int j = 0; inputBuf[j] != '\0'; ++j) { break;
input += inputBuf[j]; case 8 :
} if (stoi(input) <= temperature->getThresholdHigh()){
if (stoi(input) <= temperature->getThresholdHigh()){ temperature->setThresholdLow(stoi(input));
temperature->setThresholdLow(stoi(input)); menu->menuBack();
menu->menuBack(); } else {
} else { cout << "booooo" << endl;
cout << "booooo" << endl; }
} break;
} case 9 :
} if (stoi(input) >= pressure->getThresholdLow()){
}else if (menu->getId() == 9){ pressure->setThresholdHigh(stoi(input));
Keyboard::saisie = true ; menu->menuBack();
sleep(4); } else {
if ( (&bus!=NULL)&&!(bus.isEmptyRegister(2))) { cout << "booooo" << endl;
bus.requestFrom(2, inputBuf, 150); }
if (inputBuf[0] != '\0') { break;
input = ""; case 10 :
for (int j = 0; inputBuf[j] != '\0'; ++j) { if (stoi(input) <= pressure->getThresholdHigh()){
input += inputBuf[j]; pressure->setThresholdLow(stoi(input));
} menu->menuBack();
if (stoi(input) >= pressure->getThresholdLow()){ } else {
pressure->setThresholdHigh(stoi(input)); cout << "booooo" << endl;
menu->menuBack(); }
} else { default:
cout << "booooo" << endl; break;
}
}
}
}else if (menu->getId() == 10){
Keyboard::saisie = true ;
sleep(4);
if ( (&bus!=NULL)&&!(bus.isEmptyRegister(2))) {
bus.requestFrom(2, inputBuf, 150);
if (inputBuf[0] != '\0') {
input = "";
for (int j = 0; inputBuf[j] != '\0'; ++j) {
input += inputBuf[j];
}
if (stoi(input) <= pressure->getThresholdHigh()){
pressure->setThresholdLow(stoi(input));
menu->menuBack();
} else {
cout << "booooo" << endl;
} }
} }
} }
} }