File tree Expand file tree Collapse file tree 4 files changed +26
-38
lines changed
.vscode/ipch/d5f06e6836b90039 Expand file tree Collapse file tree 4 files changed +26
-38
lines changed Original file line number Diff line number Diff line change 4
4
Buffer::Buffer (int length, int init){
5
5
this ->values = new int [length];
6
6
this ->length = length;
7
- this ->average = init;
8
7
this ->init = init;
9
- this ->fill (init );
8
+ this ->clean ( );
10
9
}
11
10
12
11
@@ -31,7 +30,7 @@ int Buffer::getAt(int position){
31
30
}
32
31
33
32
bool Buffer::empty (){
34
- return this ->average == this ->init ;
33
+ return this ->calcAverage () == this ->init ;
35
34
}
36
35
37
36
int Buffer::size (){
@@ -48,19 +47,18 @@ void Buffer::fill(int value){
48
47
}
49
48
50
49
void Buffer::insert (int value){
51
- if (!this ->empty ()){
52
- // Move array values
53
- for (int i = this ->length -1 ; i > 0 ; i--)
54
- this ->values [i] = this ->values [i - 1 ];
55
-
56
- // Insert new value
57
- this ->values [0 ] = value;
58
-
59
- // Update the average variable
60
- this ->calcAverage ();
61
- }
62
- // Insert the first value on array
63
- else {
64
- this ->fill (value);
65
- }
50
+ // Move array values
51
+ for (int i = this ->length -1 ; i > 0 ; i--)
52
+ this ->values [i] = this ->values [i - 1 ];
53
+
54
+ // Insert new value
55
+ this ->values [0 ] = value;
56
+
57
+ // Update the average variable
58
+ this ->calcAverage ();
59
+ }
60
+
61
+ void Buffer::clean (){
62
+ // Clean the Buffer and enable to fill on first insert
63
+ this ->fill (this ->init );
66
64
}
Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ class Buffer {
16
16
// Setters
17
17
void fill (int );
18
18
void insert (int );
19
+ void clean ();
19
20
20
21
private:
21
22
int init;
Original file line number Diff line number Diff line change @@ -12,15 +12,14 @@ Buffer KEYWORD1
12
12
# Methods and Functions (KEYWORD2)
13
13
#######################################
14
14
15
- setup KEYWORD2
16
- getTemperature KEYWORD2
17
- getHumidity KEYWORD2
18
- getStatus KEYWORD2
19
- getStatusString KEYWORD2
20
- getModel KEYWORD2
21
- getMinimumSamplingPeriod KEYWORD2
22
- toFahrenheit KEYWORD2
23
- toCelsius KEYWORD2
15
+ calcAverage KEYWORD2
16
+ getAverage KEYWORD2
17
+ getAt KEYWORD2
18
+ empty KEYWORD2
19
+ size KEYWORD2
20
+ fill KEYWORD2
21
+ insert KEYWORD2
22
+ clean KEYWORD2
24
23
25
24
#######################################
26
25
# Instances (KEYWORD2)
@@ -29,14 +28,4 @@ toCelsius KEYWORD2
29
28
30
29
#######################################
31
30
# Constants (LITERAL1)
32
- #######################################
33
-
34
- AUTO_DETECT LITERAL1
35
- DHT11 LITERAL1
36
- DHT22 LITERAL1
37
- AM2302 LITERAL1
38
- RHT03 LITERAL1
39
-
40
- ERROR_NONE LITERAL1
41
- ERROR_TIMEOUT LITERAL1
42
- ERROR_CHECKSUM LITERAL1
31
+ #######################################
You can’t perform that action at this time.
0 commit comments