Project

General

Profile

Revision 87a830c5

ID87a830c59f978b8cf0423c76f6a0d8f87b8075f3
Parent d838fe06
Child 87c22974

Added by RicardoSilva91 almost 7 years ago

main tests

View differences:

tpf/mainTest.c
2 2
#include "display.h"
3 3
#include "config.h"
4 4
#include "io.h"
5
#include"power.h"
5 6
#include <stdio.h>
6 7
#include <stdlib.h>
8
#include <wiringPi.h>
7 9

  
8
#define testing
10
//#define testing
11
#define release
9 12

  
10 13
#ifdef testing
11 14

  
......
15 18

  
16 19
#endif
17 20

  
18

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

  
23 21
//switches / plugs / doors
24 22

  
25 23
//state of the on/off plug (switch) (1-> on; 0->off)
......
51 49
uint8_t minusBtnPressedLast=0;
52 50
//start/stop button
53 51
uint8_t startBtnPressed=0;
54
uint8_t ptartBtnPressedLast=0;
52
uint8_t startBtnPressedLast=0;
55 53

  
54
//internal states
56 55

  
57 56
//internal state of the hoven (0-> disabled; 1->running)
58 57
uint8_t runState=0;
58
//internal state to define which value is being configured (0-> power; 1-> time)
59
uint8_t powerOrTime=0;
59 60

  
60 61

  
61 62
//Ciclo de vida do sistema
62 63
int main()
63 64
{
65
#ifndef testing
66
#ifdef release
67
    
68
    pse_time_t temp;
69
    uint8_t flag=0;
64 70
    
71
    initBoard();
72
    initDisplay();
73
    
74
    while(1)
75
    {
76
        (uint8_t) getONOFFSwitch(&onOffState);
77
        
78
        if(onOffState==1)
79
        {
80
            //check pressed buttons
81
            
82
            //if user is already defining power settings, program only listens to pressing of the time button
83
            if(powerOrTime==0)
84
            {
85
                (uint8_t) getTimeButton(&timeBtnPressed);
86

  
87
                if (timeBtnPressed == 1 && timeBtnPressedLast == 0) 
88
                {
89
                    timeBtnPressedLast = 1;
90
                    powerOrTime=1;
91
                } 
92
                else if (timeBtnPressed == 0 && timeBtnPressedLast == 1) 
93
                {
94
                    timeBtnPressedLast = 0;
95
                }
96
                
97
                
98
                //read plus button
99
                (uint8_t) getPlusButton(&plusBtnPressed);
100

  
101
                if (plusBtnPressed == 1 && plusBtnPressedLast == 0) 
102
                {
103
                    plusBtnPressedLast = 1;
104
                    
105
                    nextPowerSetting();
106
                    
107
                } 
108
                else if (plusBtnPressed == 0 && plusBtnPressedLast == 1) 
109
                {
110
                    plusBtnPressedLast = 0;
111
                }
112
                
113
                
114
                //read minus button
115
                (uint8_t) getMinusButton(&minusBtnPressed);
116

  
117
                if (minusBtnPressed == 1 && minusBtnPressedLast == 0) 
118
                {
119
                    minusBtnPressedLast = 1;
120
                    
121
                    previousPowerSetting();
122
                    
123
                } 
124
                else if (minusBtnPressed == 0 && minusBtnPressedLast == 1) 
125
                {
126
                    minusBtnPressedLast = 0;
127
                }
128
                
129
                
130
            }
131
            //if user is already defining time settings, program only listens to pressing of the power button
132
            else
133
            {
134
                (uint8_t) getPowerButton(&powerBtnPressed);
135

  
136
                if (powerBtnPressed == 1 && powerBtnPressedLast == 0) 
137
                {
138
                    timeBtnPressedLast = 1;
139
                    powerOrTime=0;
140
                } 
141
                else if (powerBtnPressed == 0 && powerBtnPressedLast == 1) 
142
                {
143
                    powerBtnPressedLast = 0;
144
                }
145
                
146
                
147
                //read plus button
148
                (uint8_t) getPlusButton(&plusBtnPressed);
149

  
150
                if (plusBtnPressed == 1 && plusBtnPressedLast == 0) 
151
                {
152
                    plusBtnPressedLast = 1;
153
                    
154
                    increase();
155
                    
156
                } 
157
                else if (plusBtnPressed == 0 && plusBtnPressedLast == 1) 
158
                {
159
                    plusBtnPressedLast = 0;
160
                }
161
                
162
                
163
                //read minus button
164
                (uint8_t) getMinusButton(&minusBtnPressed);
165

  
166
                if (minusBtnPressed == 1 && minusBtnPressedLast == 0) 
167
                {
168
                    minusBtnPressedLast = 1;
169
                    
170
                    decrease();
171
                    
172
                } 
173
                else if (minusBtnPressed == 0 && minusBtnPressedLast == 1) 
174
                {
175
                    minusBtnPressedLast = 0;
176
                }
177
                
178
                
179
            }
180
            
181
            
182
            
183
            (uint8_t) IsDoorOpen(&doorState);
184
            
185
            if(doorState==0)
186
            {
187
                //read start/stop button
188
                (uint8_t) getStartStop(&startBtnPressed);
189

  
190
                if (startBtnPressed == 1 && startBtnPressedLast == 0) 
191
                {
192
                    startBtnPressedLast = 1;
193
                    
194
                    if(runState==0)
195
                    {
196
                        runState=1;
197
                    }
198
                    else
199
                    {
200
                        runState=0;
201
                    }
202
                    
203
                } 
204
                else if (startBtnPressed == 0 && startBtnPressedLast == 1) 
205
                {
206
                    startBtnPressedLast = 0;
207
                }
208
                
209
                
210
                //machine is Running
211
                if(runState==1)
212
                {
213
                    while(flag==0)
214
                    {
215
                        delay(1000);
216
                        decrease();
217
                        getTime(&temp);
218
                        if(temp.segundos==0)
219
                        {
220
                            flag=1;
221
                            runState=0;
222
                        }
223
                        showDisplay();
224
                    }
225
                    flag=0;
226
                }
227
                    
228
                
229
                
230
            }
231
            
232
            showDisplay();
233
        }
234
        
235
    }
236
    
237
    
238
    
239
#endif
240
#endif
241
    
242
#ifndef release
65 243
#ifndef testing
66 244
	pse_time_t tempo;
67 245
	tempo.segundos = 0;
......
372 550
#endif
373 551
        
374 552
#endif
553
        
554
#endif
375 555

  
376 556
}

Also available in: Unified diff