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,68 +122,42 @@ 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
|| menu->getId() == 12 || menu->getId() == 6
|| menu->getId() == 7 || menu->getId() == 8
|| menu->getId() == 9 || menu->getId() == 10){
Keyboard::saisie = true ; Keyboard::saisie = true ;
sleep(4); sleep(4);
if ( (&bus!=NULL)&&!(bus.isEmptyRegister(2))) { if ( (&bus!=NULL)&&!(bus.isEmptyRegister(2))) {
bus.requestFrom(2, inputBuf, 150); bus.requestFrom(2, inputBuf, 150);
if (inputBuf[0] != '\0') { if (inputBuf[0] != '\0') {
input = ""; input = "";
Tortue *newTortue = new Tortue();
for (int j = 0; inputBuf[j] != '\0'; ++j) { for (int j = 0; inputBuf[j] != '\0'; ++j) {
input += inputBuf[j]; input += inputBuf[j];
} }
switch (menu->getId()) {
case 5 : {
Tortue *newTortue = new Tortue();
newTortue->setNom(input); newTortue->setNom(input);
tortues->push_back(*newTortue); tortues->push_back(*newTortue);
menu->menuNext(); menu->menuNext();
break; break;
} }
} case 11 :
} else if (menu->getId() == 11){
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().setNaissance(input); tortues->back().setNaissance(input);
menu->menuNext(); menu->menuNext();
break; break;
} case 12 :
}
} 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); tortues->back().setSexe(input);
menu->menuNext(); menu->menuNext();
} break;
} case 6: {
} 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(); int length = tortues->size();
iteratorT = tortues->begin(); iteratorT = tortues->begin();
for (int j = 0; j < length; ++j) { for (int j = 0; j < length; ++j) {
@ -198,78 +172,44 @@ void Board::loop() {
cout << "not in list" << endl; cout << "not in list" << endl;
menu->menuBack(); menu->menuBack();
} }
break;
} }
} case 7:
}else if (menu->getId() == 7){ //TODO vérifier que chiffres
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()){ if (stoi(input) >= temperature->getThresholdLow()){
temperature->setThresholdHigh(stoi(input)); temperature->setThresholdHigh(stoi(input));
menu->menuBack(); menu->menuBack();
} else { } else {
cout << "booooo" << endl; cout << "booooo" << endl;
} }
} break;
} case 8 :
}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()){ 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 :
}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()){ if (stoi(input) >= pressure->getThresholdLow()){
pressure->setThresholdHigh(stoi(input)); pressure->setThresholdHigh(stoi(input));
menu->menuBack(); menu->menuBack();
} else { } else {
cout << "booooo" << endl; cout << "booooo" << endl;
} }
} break;
} case 10 :
}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()){ if (stoi(input) <= pressure->getThresholdHigh()){
pressure->setThresholdLow(stoi(input)); pressure->setThresholdLow(stoi(input));
menu->menuBack(); menu->menuBack();
} else { } else {
cout << "booooo" << endl; cout << "booooo" << endl;
} }
default:
break;
}
} }
} }
} }