Project

General

Profile

Statistics
| Branch: | Revision:

pse-2015-16-grupo-3 / tpf / mainTest.c @ 6d70682c

History | View | Annotate | Download (10.4 KB)

1
#include "tempo.h"
2
#include "display.h"
3
#include "config.h"
4
#include "io.h"
5
#include <stdio.h>
6
#include <stdlib.h>
7

    
8
#define testing
9
#define testing_display
10

    
11
#ifdef testing
12

    
13
#include <lcd.h>
14
#include <wiringPi.h>
15

    
16
#endif
17

    
18

    
19
int timeSet = 0;        //Apenas quando estas duas variáveis
20
int powerSet = 0;        //estiverem a 1 é que se pode dar Start
21

    
22
// Power Settings
23
uint16_t powerSettings[] = {150, 350, 500, 750};
24
uint16_t currentPower; //vai indice do array com o tempo atual de power
25

    
26
//1 enquanto estiver a funcionar(start), 0 se estiver parado(stop);
27
int isRunning = 0;
28

    
29
//Classe q vai controlar o display
30
//Display disp;
31

    
32
//Ciclo de vida do sistema
33
int main()
34
{
35
    
36
#ifndef testing
37
        pse_time_t tempo;
38
        tempo.segundos = 0;
39
        tempo.minutos = 0;
40
        tempo.horas = 0;
41
        setTime(tempo);
42
        char c;
43
        
44

    
45
        while(1)
46
        {
47
            
48
                
49
                printf("t-Escolher tempo\n p-Escolher power\n s-Start/Stop\n");
50
                c = '0';
51
                do{c=getchar();}while(isspace(c));
52
                if(c == 't')
53
                {
54
                        c = '0';
55
                        printf("Escolha de tempo\n");
56
                        while(c != 't') //Enquanto não pressionar o botão Time novamente, fica na janela de regulação do tempo
57
                        {
58
                                //disp.setDisplay(time.getTime());        //Mostra o tempo atualmente escolhido no visor
59
                                printf("t-Sair de escolha de tempo\n +Aumentar tempo\n -Diminuir tempo\n");
60
                                pse_time_t atual;
61
                                getTime(&atual);
62
                                printf("Tempo atual = %d:%d:%d\n", atual.horas, atual.minutos, atual.segundos);
63
                                c = '0';
64
                                do{c=getchar();}while(isspace(c));
65
                                if(c == '+')
66
                                {
67
                                        //if(time.increase());        //Se o botão "+" for pressionado é chamada a função para incrementar o tempo
68
                                        increase();
69
                                        printf("Tempo Aumentado\n");
70
                                        pse_time_t atual;
71
                                        getTime(&atual);
72
                                }
73
                                if(c == '-')
74
                                {
75
                                        //if(time.decrease());        //Se o botão "-" for pressionado é chamada a função para decrementar o tempo
76
                                        decrease();
77
                                        printf("Tempo Decrementado\n");
78
                                        pse_time_t atual;
79
                                        getTime(&atual);
80
                                }
81
                                
82
                        }
83
                        timeSet = 1;        
84
                }
85
                else if(c == 'p')
86
                {
87
                        c='0';
88
                        printf("Modo de escolha de power\n");
89
                        
90
                        
91
                        //Caso o microondas esteja a funcionar, apenas mostra o valor do power durante 2 segundos
92
                        if(isRunning)
93
                                printf("Microondas em execucao\n");
94
                                //disp.setDisplay(powerSettings[currentPower]);        //mostrar isto durante 2 segundos
95
                        
96
                        //Caso não esteja a funcionar, permite ao utilizador escolher o power pretendido
97
                        else
98
                        {
99
                                printf("p-Sair de escolha de power\n +Aumentar power\n -Diminuir power\n");
100
                                while(c != 'p')
101
                                {
102
                                        
103
                                        printf("Power atual:%d \n",powerSettings[currentPower]);
104
                                        c = '0';
105
                                        do{c=getchar();}while(isspace(c));
106
                                        //disp.setDisplay(powerSettings[currentPower]);
107
                                        if(c == '+')
108
                                        {
109
                                                if(currentPower < 3)
110
                                                currentPower++;
111
                                        }
112
                                        if(c == '-')
113
                                        {
114
                                                if(currentPower > 0)
115
                                                currentPower--;
116
                                        }
117
                                }
118
                                powerSet = 1;        
119
                        }
120
                }
121
                else if(c == 's')
122
                {
123
                        if(!isRunning)
124
                        {
125
                                //Verifica se as condicoes estao definidas
126
                                if(powerSet && timeSet)
127
                                {        
128
                                        printf("MICROONDAS LIGADO\n");
129
                                        isRunning = 1;
130
                                        //Liga o microondas com o tempo e potencia configuradas
131
                                        /*powerOven(time.getTime(),powerSettings[currentPower];
132
                                        switchLight(ON);
133
                                        switchTurnMotor(ON);*/
134
                                }
135
                                else printf("Tempo ou Power não definido\n");
136
                        }
137
                        else printf("MICROONDAS DESLIGADO\n");                        
138
                        
139
                }
140
        }
141
        
142
#endif
143
#ifdef testing
144
        
145
        
146
        initBoard();
147
        /*
148
        //char c;
149
        uint8_t btnPressed;
150
        uint8_t lastStateBtnPressed=0;
151
        uint8_t state=0;
152
        uint16_t btnCounter = 0;
153
        uint8_t tim=0;
154
        
155
        
156
        while(1)
157
        {
158
            
159
            (uint8_t) getMinusButton(&btnPressed);
160
            
161
            if(btnPressed == 1 && lastStateBtnPressed==0)
162
            {
163
                
164
                if (state == 0) {
165
                    (u_int8_t) turnOnLight();
166
                    (u_int8_t) turnOnMegatron();
167
                    state = 1;
168
                } 
169
                else {
170
                    (u_int8_t) turnOffLight();
171
                    (u_int8_t) turnOffMegatron();
172
                    state = 0;
173
                }
174
                lastStateBtnPressed = 1;
175
                
176
                
177
               
178
            }
179
            else if(btnPressed == 0 && lastStateBtnPressed==1)
180
            {
181
                lastStateBtnPressed = 0;
182
                btnCounter=0;
183
            }
184
            
185
            
186
        }
187
        */
188
        
189
#ifndef testing_display
190
        
191
        int lcdHandler;
192
        uint8_t btnPressed=0;
193
        
194
        (uint8_t) turnOffLight();
195
        (uint8_t) turnOffMegatron();
196
        
197
        (uint8_t) getLCDHandler(&lcdHandler);
198
        
199
        
200
        // start btn test
201
        lcdPosition (lcdHandler, 0, 0) ; lcdPuts (lcdHandler, "Press Start btn.") ;
202
        lcdPosition (lcdHandler, 0, 1) ; lcdPuts (lcdHandler, "                ") ;
203
        
204
        while (btnPressed == 0)
205
        {
206
            (uint8_t) getStartStop(&btnPressed);
207
        }
208
        
209
        lcdPosition (lcdHandler, 0, 0) ; lcdPuts (lcdHandler, "   WELL DONE!   ") ;
210
        lcdPosition (lcdHandler, 0, 1) ; lcdPuts (lcdHandler, "                ") ;
211
        delay(3000);
212
        
213
        //Plus btn test
214
        btnPressed = 0;
215
        lcdPosition (lcdHandler, 0, 0) ; lcdPuts (lcdHandler, "                ") ;
216
        lcdPosition (lcdHandler, 0, 1) ; lcdPuts (lcdHandler, "Press plus  btn.") ;
217
        
218
        while (btnPressed == 0)
219
        {
220
            (uint8_t) getPlusButton(&btnPressed);
221
        }
222
        
223
        lcdPosition (lcdHandler, 0, 0) ; lcdPuts (lcdHandler, "   WELL DONE!   ") ;
224
        lcdPosition (lcdHandler, 0, 1) ; lcdPuts (lcdHandler, "                ") ;
225
        delay(3000);
226
        
227
        
228
        //Minus btn test
229
        btnPressed = 0;
230
        lcdPosition (lcdHandler, 0, 0) ; lcdPuts (lcdHandler, "                ") ;
231
        lcdPosition (lcdHandler, 0, 1) ; lcdPuts (lcdHandler, "Press minus btn.") ;
232
        
233
        while (btnPressed == 0)
234
        {
235
            (uint8_t) getMinusButton(&btnPressed);
236
        }
237
        
238
        lcdPosition (lcdHandler, 0, 0) ; lcdPuts (lcdHandler, "   WELL DONE!   ") ;
239
        lcdPosition (lcdHandler, 0, 1) ; lcdPuts (lcdHandler, "                ") ;
240
        delay(3000);
241
        
242
        
243
        //Power btn test
244
        btnPressed = 0;
245
        lcdPosition (lcdHandler, 0, 0) ; lcdPuts (lcdHandler, "                ") ;
246
        lcdPosition (lcdHandler, 0, 1) ; lcdPuts (lcdHandler, "Press power btn.") ;
247
        
248
        while (btnPressed == 0)
249
        {
250
            (uint8_t) getPowerButton(&btnPressed);
251
        }
252
        
253
        lcdPosition (lcdHandler, 0, 0) ; lcdPuts (lcdHandler, "   WELL DONE!   ") ;
254
        lcdPosition (lcdHandler, 0, 1) ; lcdPuts (lcdHandler, "                ") ;
255
        delay(3000);
256
        
257
        
258
        //Time btn test
259
        btnPressed = 0;
260
        lcdPosition (lcdHandler, 0, 0) ; lcdPuts (lcdHandler, "                ") ;
261
        lcdPosition (lcdHandler, 0, 1) ; lcdPuts (lcdHandler, "Press time btn.") ;
262
        
263
        while (btnPressed == 0)
264
        {
265
            (uint8_t) getTimeButton(&btnPressed);
266
        }
267
        
268
        lcdPosition (lcdHandler, 0, 0) ; lcdPuts (lcdHandler, "   WELL DONE!   ") ;
269
        lcdPosition (lcdHandler, 0, 1) ; lcdPuts (lcdHandler, "                ") ;
270
        delay(3000);
271
        
272
        
273
        //door sw test
274
        btnPressed = 0;
275
        lcdPosition (lcdHandler, 0, 0) ; lcdPuts (lcdHandler, "                ") ;
276
        lcdPosition (lcdHandler, 0, 1) ; lcdPuts (lcdHandler, " open the door. ") ;
277
        
278
        while (btnPressed == 0)
279
        {
280
            (uint8_t) IsDoorOpen(&btnPressed);
281
        }
282
        
283
        lcdPosition (lcdHandler, 0, 0) ; lcdPuts (lcdHandler, "   WELL DONE!   ") ;
284
        lcdPosition (lcdHandler, 0, 1) ; lcdPuts (lcdHandler, "                ") ;
285
        delay(3000);
286
        
287
        
288
        //on off test
289
        btnPressed = 0;
290
        lcdPosition (lcdHandler, 0, 0) ; lcdPuts (lcdHandler, "                ") ;
291
        lcdPosition (lcdHandler, 0, 1) ; lcdPuts (lcdHandler, " turn power on. ") ;
292
        
293
        while (btnPressed == 0)
294
        {
295
            (uint8_t) getONOFFSwitch(&btnPressed);
296
        }
297
        
298
        lcdPosition (lcdHandler, 0, 0) ; lcdPuts (lcdHandler, "   WELL DONE!   ") ;
299
        lcdPosition (lcdHandler, 0, 1) ; lcdPuts (lcdHandler, "                ") ;
300
        delay(3000);
301
        
302
        
303
        //temperature sw test
304
        btnPressed = 0;
305
        lcdPosition (lcdHandler, 0, 0) ; lcdPuts (lcdHandler, "                ") ;
306
        lcdPosition (lcdHandler, 0, 1) ; lcdPuts (lcdHandler, "    heat up.    ") ;
307
        
308
        while (btnPressed == 0)
309
        {
310
            (uint8_t) getTemperatureSwitch(&btnPressed);
311
        }
312
        
313
        lcdPosition (lcdHandler, 0, 0) ; lcdPuts (lcdHandler, "   WELL DONE!   ") ;
314
        lcdPosition (lcdHandler, 0, 1) ; lcdPuts (lcdHandler, "                ") ;
315
        delay(3000);
316
        
317
        
318
        //inside light check
319
        lcdPosition (lcdHandler, 0, 0) ; lcdPuts (lcdHandler, "                ") ;
320
        lcdPosition (lcdHandler, 0, 1) ; lcdPuts (lcdHandler, "check insid lamp") ;
321
        (uint8_t) turnOnLight();
322
        delay(5000);
323
        (uint8_t) turnOffLight();
324
        
325
        
326
        lcdPosition (lcdHandler, 0, 0) ; lcdPuts (lcdHandler, "   WELL DONE!   ") ;
327
        lcdPosition (lcdHandler, 0, 1) ; lcdPuts (lcdHandler, "                ") ;
328
        delay(3000);
329
        
330
        //megatron light check
331
        lcdPosition (lcdHandler, 0, 0) ; lcdPuts (lcdHandler, "                ") ;
332
        lcdPosition (lcdHandler, 0, 1) ; lcdPuts (lcdHandler, " check MEGATRON ") ;
333
        (uint8_t) turnOnMegatron();
334
        delay(5000);
335
        (uint8_t) turnOffMegatron();
336
        
337
        
338
        
339
        lcdPosition (lcdHandler, 0, 0) ; lcdPuts (lcdHandler, "   WELL DONE!   ") ;
340
        lcdPosition (lcdHandler, 0, 1) ; lcdPuts (lcdHandler, "                ") ;
341
        delay(3000);
342
        
343
        
344
        //tests finished
345
        
346
        lcdPosition (lcdHandler, 0, 0) ; lcdPuts (lcdHandler, "      THANK     ") ;
347
        lcdPosition (lcdHandler, 0, 1) ; lcdPuts (lcdHandler, "       YOU      ") ;
348
        
349
#endif
350
        
351
#ifdef testing_display
352
        
353
        pse_time_t tempo;
354
        tempo.horas=0;
355
        tempo.minutos=20;
356
        tempo.segundos=20;
357
        //char abc[16] = "jogos";
358
        uint16_t power = powerSettings[0];
359
        
360
        initDisplay();
361
        setDisplayPower(power);
362
        setDisplayTime(tempo);
363
        showDisplay();
364
        
365
        
366
        
367
#endif
368
        
369
#endif
370

    
371
}