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);
Screen screen;
Keyboard keyboard;
ExternalDigitalSensorButton buttonNext(DELAY + 2, btnNextPath);
ExternalDigitalSensorButton buttonPrev(DELAY + 2, btnPrevPath);
ExternalDigitalSensorButton buttonOK(DELAY + 2, btnOkPath);
ExternalDigitalSensorButton buttonBack(DELAY + 2, btnBackPath);
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);

View file

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