Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/ECSensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,11 @@ uint32_t ECSensor::readSensor() {

uint32_t averageCycles;
if (timeout) {
sensorStatus = EC_FAIL;
averageCycles = 0;
}
else {
sensorStatus = EC_SUCCESS;
averageCycles = (totalCycles >> oversamplingRate);
}
EIMSK &= ~(1 << INT0); // Disable INT0.
Expand Down Expand Up @@ -313,9 +315,11 @@ uint32_t ECSensor::readSensor() {
delayMicroseconds(DISCHARGEDELAY);
}
if (timeout) {
sensorStatus = EC_FAIL;
dischargeCycles = 0;
}
else {
sensorStatus = EC_SUCCESS;
dischargeCycles = (totalCycles >> oversamplingRate);
}
yield(); // For the ESP8266: allow for background processes to run.
Expand Down Expand Up @@ -360,6 +364,7 @@ void ECSensor::begin() {
uint32_t ECSensor::readSensor() {
uint32_t totalCycles = 0;
bool timeout = false;
sensorStatus = EC_SUCCESS;
for (uint8_t i = 0; i < (1 << oversamplingRate); i++) {

///////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -399,6 +404,7 @@ uint32_t ECSensor::readSensor() {
totalCycles += dischargeCycles;
PCMSK &= ~(1 << INTERRUPT); // Clear the pin change interrupt on CAPPOS.
if (timeout) { // A timeout here means the sensor is not measuring anything.
sensorStatus = EC_FAIL;
break;
}

Expand Down Expand Up @@ -697,9 +703,11 @@ uint32_t ECSensor::readSensor() {
EIMSK &= ~(1 << INT4); // Disable INT4
uint32_t averageCycles;
if (timeout) {
sensorStatus = EC_FAIL;
averageCycles = 0;
}
else {
sensorStatus = EC_SUCCESS;
averageCycles = (totalCycles >> oversamplingRate);
}
return averageCycles;
Expand Down
2 changes: 1 addition & 1 deletion src/ECSensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class ECSensor {
#if defined(__AVR__)
void begin(void);
#elif defined(ESP8266)
void begin(uint8_t, uint8_t, uint8_t);
void begin(uint8_t cp, uint8_t cn, uint8_t ec);
#endif

uint32_t readSensor(void);
Expand Down