Browse Source

threshold sans exceptions lave (switch)

Cameron Bray 3 years ago
parent
commit
958bfa9038
2 changed files with 75 additions and 135 deletions
  1. 4
    4
      board.cpp
  2. 71
    131
      sketch_ino.cpp

+ 4
- 4
board.cpp View File

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

+ 71
- 131
sketch_ino.cpp View File

@@ -122,154 +122,94 @@ void Board::loop() {
122 122
             //cout << iteratorT->getInfo() << endl;
123 123
             message += iteratorT->getInfo();
124 124
         }
125
-        if (cpt % 3 == 0) {
125
+        if (cpt % 2 == 0) {
126 126
             strcpy(buf, message.c_str());
127 127
             if (buf != NULL) bus.write(1, buf, 150);
128 128
         }
129 129
 
130
-        if (menu->getId() == 5){
130
+        if (menu->getId() == 5 || menu->getId() == 11
131
+            || menu->getId() == 12 || menu->getId() == 6
132
+            || menu->getId() == 7 || menu->getId() == 8
133
+            || menu->getId() == 9 || menu->getId() == 10){
131 134
             Keyboard::saisie = true ;
132 135
             sleep(4);
133 136
             if ( (&bus!=NULL)&&!(bus.isEmptyRegister(2))) {
134 137
                 bus.requestFrom(2, inputBuf, 150);
135 138
                 if (inputBuf[0] != '\0') {
136 139
                     input = "";
137
-                    Tortue *newTortue = new Tortue();
138 140
                     for (int j = 0; inputBuf[j] != '\0'; ++j) {
139 141
                         input += inputBuf[j];
140 142
                     }
141
-                    newTortue->setNom(input);
142
-                    tortues->push_back(*newTortue);
143
-                    menu->menuNext();
144
-                    break;
145
-                }
146
-            }
147
-        } else if (menu->getId() == 11){
148
-            Keyboard::saisie = true ;
149
-            sleep(4);
150
-            if ( (&bus!=NULL)&&!(bus.isEmptyRegister(2))) {
151
-                bus.requestFrom(2, inputBuf, 150);
152
-                if (inputBuf[0] != '\0') {
153
-                    input = "";
154
-                    for (int j = 0; inputBuf[j] != '\0'; ++j) {
155
-                        input += inputBuf[j];
156
-                    }
157
-                    tortues->back().setNaissance(input);
158
-                    menu->menuNext();
159
-                    break;
160
-                }
161
-            }
162
-        } else if (menu->getId() == 12){
163
-            Keyboard::saisie = true ;
164
-            sleep(4);
165
-            if ( (&bus!=NULL)&&!(bus.isEmptyRegister(2))) {
166
-                bus.requestFrom(2, inputBuf, 150);
167
-                if (inputBuf[0] != '\0') {
168
-                    input = "";
169
-                    for (int j = 0; inputBuf[j] != '\0'; ++j) {
170
-                        input += inputBuf[j];
171
-                    }
172
-                    tortues->back().setSexe(input);
173
-                    menu->menuNext();
174
-                }
175
-            }
176
-        } else if (menu->getId() == 6){
177
-            Keyboard::saisie = true ;
178
-            sleep(4);
179
-            if ( (&bus!=NULL)&&!(bus.isEmptyRegister(2))) {
180
-                bus.requestFrom(2, inputBuf, 150);
181 143
 
182
-                if (inputBuf[0] != '\0') {
183
-                    input = "";
184
-                    for (int j = 0; inputBuf[j] != '\0'; ++j) {
185
-                        input += inputBuf[j];
186
-                    }
187
-                    int length = tortues->size();
188
-                    iteratorT = tortues->begin();
189
-                    for (int j = 0; j < length; ++j) {
190
-                        if (iteratorT->getNom() == input) {
191
-                            tortues->erase(iteratorT);
192
-                            Tortue::delete1();
144
+                    switch (menu->getId()) {
145
+                        case 5 : {
146
+                            Tortue *newTortue = new Tortue();
147
+                            newTortue->setNom(input);
148
+                            tortues->push_back(*newTortue);
193 149
                             menu->menuNext();
150
+                            break;
194 151
                         }
195
-                        ++iteratorT;
196
-                    }
197
-                    if (iteratorT == tortues->end()) {
198
-                        cout << "not in list" << endl;
199
-                        menu->menuBack();
200
-                    }
201
-                }
202
-            }
203
-        }else if (menu->getId() == 7){
204
-            Keyboard::saisie = true ;
205
-            sleep(4);
206
-            if ( (&bus!=NULL)&&!(bus.isEmptyRegister(2))) {
207
-                bus.requestFrom(2, inputBuf, 150);
208
-                if (inputBuf[0] != '\0') {
209
-                    input = "";
210
-                    for (int j = 0; inputBuf[j] != '\0'; ++j) {
211
-                        input += inputBuf[j];
212
-                    } //TODO vérifier que chiffres
213
-                    if (stoi(input) >= temperature->getThresholdLow()){
214
-                        temperature->setThresholdHigh(stoi(input));
215
-                        menu->menuBack();
216
-                    } else {
217
-                        cout << "booooo" << endl;
218
-                    }
219
-                }
220
-            }
221
-        }else if (menu->getId() == 8){
222
-            Keyboard::saisie = true ;
223
-            sleep(4);
224
-            if ( (&bus!=NULL)&&!(bus.isEmptyRegister(2))) {
225
-                bus.requestFrom(2, inputBuf, 150);
226
-                if (inputBuf[0] != '\0') {
227
-                    input = "";
228
-                    for (int j = 0; inputBuf[j] != '\0'; ++j) {
229
-                        input += inputBuf[j];
230
-                    }
231
-                    if (stoi(input) <= temperature->getThresholdHigh()){
232
-                        temperature->setThresholdLow(stoi(input));
233
-                        menu->menuBack();
234
-                    } else {
235
-                        cout << "booooo" << endl;
236
-                    }
237
-                }
238
-            }
239
-        }else if (menu->getId() == 9){
240
-            Keyboard::saisie = true ;
241
-            sleep(4);
242
-            if ( (&bus!=NULL)&&!(bus.isEmptyRegister(2))) {
243
-                bus.requestFrom(2, inputBuf, 150);
244
-                if (inputBuf[0] != '\0') {
245
-                    input = "";
246
-                    for (int j = 0; inputBuf[j] != '\0'; ++j) {
247
-                        input += inputBuf[j];
248
-                    }
249
-                    if (stoi(input) >= pressure->getThresholdLow()){
250
-                        pressure->setThresholdHigh(stoi(input));
251
-                        menu->menuBack();
252
-                    } else {
253
-                        cout << "booooo" << endl;
254
-                    }
255
-                }
256
-            }
257
-        }else if (menu->getId() == 10){
258
-            Keyboard::saisie = true ;
259
-            sleep(4);
260
-            if ( (&bus!=NULL)&&!(bus.isEmptyRegister(2))) {
261
-                bus.requestFrom(2, inputBuf, 150);
262
-                if (inputBuf[0] != '\0') {
263
-                    input = "";
264
-                    for (int j = 0; inputBuf[j] != '\0'; ++j) {
265
-                        input += inputBuf[j];
266
-                    }
267
-                    if (stoi(input) <= pressure->getThresholdHigh()){
268
-                        pressure->setThresholdLow(stoi(input));
269
-                        menu->menuBack();
270
-                    } else {
271
-                        cout << "booooo" << endl;
152
+                        case 11 :
153
+                            tortues->back().setNaissance(input);
154
+                            menu->menuNext();
155
+                            break;
156
+                        case 12 :
157
+                            tortues->back().setSexe(input);
158
+                            menu->menuNext();
159
+                            break;
160
+                        case 6: {
161
+                            int length = tortues->size();
162
+                            iteratorT = tortues->begin();
163
+                            for (int j = 0; j < length; ++j) {
164
+                                if (iteratorT->getNom() == input) {
165
+                                    tortues->erase(iteratorT);
166
+                                    Tortue::delete1();
167
+                                    menu->menuNext();
168
+                                }
169
+                                ++iteratorT;
170
+                            }
171
+                            if (iteratorT == tortues->end()) {
172
+                                cout << "not in list" << endl;
173
+                                menu->menuBack();
174
+                            }
175
+                            break;
176
+                        }
177
+                        case 7:
178
+                            //TODO vérifier que chiffres
179
+                            if (stoi(input) >= temperature->getThresholdLow()){
180
+                                temperature->setThresholdHigh(stoi(input));
181
+                                menu->menuBack();
182
+                            } else {
183
+                                cout << "booooo" << endl;
184
+                            }
185
+                            break;
186
+                        case 8 :
187
+                            if (stoi(input) <= temperature->getThresholdHigh()){
188
+                                temperature->setThresholdLow(stoi(input));
189
+                                menu->menuBack();
190
+                            } else {
191
+                                cout << "booooo" << endl;
192
+                            }
193
+                            break;
194
+                        case 9 :
195
+                            if (stoi(input) >= pressure->getThresholdLow()){
196
+                                pressure->setThresholdHigh(stoi(input));
197
+                                menu->menuBack();
198
+                            } else {
199
+                                cout << "booooo" << endl;
200
+                            }
201
+                            break;
202
+                        case 10 :
203
+                            if (stoi(input) <= pressure->getThresholdHigh()){
204
+                                pressure->setThresholdLow(stoi(input));
205
+                                menu->menuBack();
206
+                            } else {
207
+                                cout << "booooo" << endl;
208
+                            }
209
+                        default:
210
+                            break;
272 211
                     }
212
+
273 213
                 }
274 214
             }
275 215
         }

Loading…
Cancel
Save