Skip to content

Commit d4028f0

Browse files
committed
clean function
1 parent 82b0fea commit d4028f0

File tree

4 files changed

+26
-38
lines changed

4 files changed

+26
-38
lines changed
0 Bytes
Binary file not shown.

Buffer.cpp

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44
Buffer::Buffer(int length, int init){
55
this->values = new int[length];
66
this->length = length;
7-
this->average = init;
87
this->init = init;
9-
this->fill(init);
8+
this->clean();
109
}
1110

1211

@@ -31,7 +30,7 @@ int Buffer::getAt(int position){
3130
}
3231

3332
bool Buffer::empty(){
34-
return this->average == this->init;
33+
return this->calcAverage() == this->init;
3534
}
3635

3736
int Buffer::size(){
@@ -48,19 +47,18 @@ void Buffer::fill(int value){
4847
}
4948

5049
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);
6664
}

Buffer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class Buffer {
1616
// Setters
1717
void fill(int);
1818
void insert(int);
19+
void clean();
1920

2021
private:
2122
int init;

keywords.txt

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,14 @@ Buffer KEYWORD1
1212
# Methods and Functions (KEYWORD2)
1313
#######################################
1414

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
2423

2524
#######################################
2625
# Instances (KEYWORD2)
@@ -29,14 +28,4 @@ toCelsius KEYWORD2
2928

3029
#######################################
3130
# 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+
#######################################

0 commit comments

Comments
 (0)