88 lines
1.8 KiB
C++
88 lines
1.8 KiB
C++
#include "pump.h"
|
|
|
|
Pump::Pump(uint8_t pumpPin, uint8_t pressurePin, uint8_t flowPin, uint8_t errorLedPin) {
|
|
this->pumpPin = pumpPin;
|
|
this->pressurePin = pressurePin;
|
|
this->flowPin = flowPin;
|
|
this->errorLedPin = errorLedPin;
|
|
|
|
pinMode(this->pumpPin, OUTPUT);
|
|
pinMode(this->errorLedPin, OUTPUT);
|
|
pinMode(this->pressurePin, INPUT);
|
|
// Hall flow sensor?
|
|
|
|
digitalWrite(this->pumpPin, LOW);
|
|
digitalWrite(this->errorLedPin, LOW);
|
|
}
|
|
|
|
void Pump::loop() {
|
|
switch (this->state) {
|
|
case State::Off :
|
|
|
|
break;
|
|
|
|
case State::On :
|
|
|
|
break;
|
|
|
|
case State::Timer :
|
|
|
|
break;
|
|
|
|
case State::Standby :
|
|
|
|
break;
|
|
|
|
case State::Error :
|
|
if (millis() - this->startTime > Pump::blinkTime) {
|
|
this->startTime = millis();
|
|
if (this->ledState) {
|
|
this->ledState = false;
|
|
digitalWrite(this->errorLedPin, LOW);
|
|
} else {
|
|
this->ledState = true;
|
|
digitalWrite(this->errorLedPin, HIGH);
|
|
}
|
|
}
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
void Pump::activate(uint32_t duration) {
|
|
this->startTime = millis();
|
|
if (duration) {
|
|
this->state = State::Timer;
|
|
this->duration = duration;
|
|
} else {
|
|
this->state = State::On;
|
|
}
|
|
}
|
|
|
|
void Pump::stop() {
|
|
if (this->state != State::Error)
|
|
this->state = State::Off;
|
|
}
|
|
|
|
void Pump::clearError() {
|
|
if (this->state == State::Error)
|
|
this->state = State::Off;
|
|
}
|
|
|
|
uint16_t Pump::getPressure() {
|
|
return 0;
|
|
}
|
|
|
|
uint32_t Pump::getRunningTime() {
|
|
return millis() -this->startTime;
|
|
}
|
|
|
|
uint16_t Pump::getFlow() {
|
|
return 0;
|
|
}
|
|
|
|
void Pump::checkSensors() {
|
|
|
|
} |