Commit 94938f90 authored by João Lino's avatar João Lino

Migrated code for Pump

parent ed255e4e
......@@ -27,11 +27,12 @@ void runSettingsSelection();
#include "config.h"
#include "src/Temperature/Temperature.h"
#include "src/HeatingElement/HeatingElement.h"
#include "src/Pump/Pump.h"
#include "Melody.h"
#include "Display.h"
#include "Temperature.h"
#include "Profiles.h"
// ++++++++++++++++++++++++ FUNCTIONS +++++++++++++++++++++++++++++++++
......
This diff is collapsed.
......@@ -47,14 +47,10 @@
// ++++++++++++++++++++++++ Pump ++++++++++++++++++++++++
#define PUMP_PIN 6
#define PUMP_TEMPERATURE_MAX_OPERATION 90
#define PUMP_SPEED_STOP 0
#define PUMP_PRIMING_TIME_IN_SECONDS 10
#define PUMP_SPEED_STOP_MOSFET 255
#define PUMP_SPEED_SLOW 64
#define PUMP_SPEED_AVERAGE 128
#define PUMP_SPEED_FAST 192
#define PUMP_SPEED_MAX_MOSFET 0
#define PUMP_SPEED_MAX 255
#define PUMP_SPEED_DEFAULT 0
#define PUMP_SPEED_DEFAULT PUMP_SPEED_MAX_MOSFET
// ++++++++++++++++++++++++ Rotary Encoder ++++++++++++++++++++++++
#define ROTARY_ENCODER_INTERRUPT_NUMBER 1 // On Mega2560 boards, interrupt 1 is on pin 3
......
......@@ -35,8 +35,8 @@ class HeatingElement
double ulWattToWindowTime( double ulAppliedWatts );
int _iOutputPin;
int _uiOnValue;
int _uiOffValue;
int _uiOnValue;
boolean _bStatusElement;
int _iWindowSize; // Time frame to operate in
unsigned long _windowStartTime;
......
#include "Pump.h"
Pump::Pump( int iOutputPin, int iOffValue, int iMaxValue ) {
Pump(iOutputPin, iOffValue, iMaxValue, DEFAULT_PUMP_MAX_OPETATION_TEMPERARTURE, DEFAULT_PUMP_PRIMING_TIME_IN_SECONDS);
}
Pump::Pump( int iOutputPin, int iOffValue, int iMaxValue, int iMaxTemperature, int iPrimingTimeInSeconds ) {
_iOutputPin = iOutputPin;
_iOffValue = iOffValue;
_iMaxValue = iMaxValue;
_iMaxTemperature = iMaxTemperature;
_iPrimingTimeInSeconds = iPrimingTimeInSeconds;
_iActualPumpSpeed = _iOffValue; // Time frame to operate in
_iTargetPumpSpeed = _iOffValue;
_temperature = NULL;
_selfPrimingMode = false;
_hasBeenPrimedSinceStartup = false;
pinMode(_iOutputPin, OUTPUT); // sets the pin as output
analogWrite(_iOutputPin, _iOffValue); // analogWrite values from 0 to 255
}
void Pump::shutDown() {
_iActualPumpSpeed = _iOffValue; // Time frame to operate in
_iTargetPumpSpeed = _iOffValue;
_selfPrimingMode = false;
// Turn off gracefully
process();
}
bool Pump::process() {
if(_temperature != NULL) {
// Operate pump if its operating temperature is bellow the maximum operating temperature
float currentTemperature = _temperature->getCurrentTemperature();
if (currentTemperature <= _iMaxTemperature) {
// Self prime on first use
if(!_hasBeenPrimedSinceStartup && _iTargetPumpSpeed != _iOffValue) {
_hasBeenPrimedSinceStartup = true;
_selfPrimingMode = true;
_millisAtPrimingStart = millis();
}
// Process end of self priming mode
if(millis() - _millisAtPrimingStart > _iPrimingTimeInSeconds * 1000) {
_selfPrimingMode = false;
}
// Control speed for self priming mode of operation
if(_selfPrimingMode) {
// Alternate speed
if ( ((millis()/1000) % 2) == 0 ) {
_iActualPumpSpeed = _iMaxValue;
}
else {
_iActualPumpSpeed = _iOffValue;
}
}
// Set target speed in normal mode of operation
else {
_iActualPumpSpeed = _iTargetPumpSpeed;
}
}
// Turn pump off if its operating temperature exceeds the maximum operating temperature
else {
_iActualPumpSpeed = _iOffValue;
}
}
else {
// The pump will remain off until temperature feedback is provided
_iActualPumpSpeed = _iOffValue;
}
// Set pump speed
analogWrite(_iOutputPin, _iActualPumpSpeed); // analogWrite values from 0 to 255
return _iActualPumpSpeed;
}
bool Pump::process( int iTargetPumpSpeed ) {
setTargetPumpSpeed(iTargetPumpSpeed);
return process();
}
void Pump::forcePumpSelfPrime() {
_selfPrimingMode = true;
_millisAtPrimingStart = millis();
}
// Getter and setters
bool Pump::isPumpOn() {
return _iActualPumpSpeed != _iOffValue;
}
void Pump::setCheckTemperatureFunction( Temperature *temperature ) {
_temperature = temperature;
}
int Pump::getTargetPumpSpeed() {
return _iTargetPumpSpeed;
}
void Pump::setTargetPumpSpeed( int iTargetPumpSpeed ) {
_iTargetPumpSpeed = iTargetPumpSpeed;
}
// Power Increments
int Pump::getNullSpeed() {
return _iOffValue;
}
int Pump::getOneSixthSpeed() {
return calculateSpeedFraction(1.0/6.0);
}
int Pump::getOneThirdSpeed() {
return calculateSpeedFraction(1.0/3.0);
}
int Pump::getHalfSpeed() {
return calculateSpeedFraction(1.0/2.0);
}
int Pump::getTwoThirdSpeed() {
return calculateSpeedFraction(2.0/3.0);
}
int Pump::getMaxSpeed() {
return _iMaxValue;
}
// Private functions
int Pump::calculateSpeedFraction(double fraction) {
int ret;
if(_iMaxValue >= _iOffValue) {
ret = _iMaxValue * fraction;
}
else {
ret = _iOffValue * ((1.0 - fraction) * -1.0);
}
return ret;
}
\ No newline at end of file
#ifndef Pump_h
#define Pump_h
#include "Arduino.h"
#include "../Temperature/Temperature.h"
#define DEFAULT_PUMP_MAX_OPETATION_TEMPERARTURE 90
#define DEFAULT_PUMP_PRIMING_TIME_IN_SECONDS 10
//#define HEATING_ELEMENT_MAX_HEAT_PWM_INTEGER 5
//#define HEATING_ELEMENT_MAX_HEAT_PWM_FLOAT 5.0
class Pump
{
public:
Pump( int iOutputPin, int iOffValue, int iMaxValue, int iMaxTemperature, int iPrimingTimeInSeconds );
Pump( int iOutputPin, int iOffValue, int iMaxValue );
void shutDown();
void forcePumpSelfPrime();
bool process();
bool process( int iTargetPumpSpeed );
bool isPumpOn();
void setCheckTemperatureFunction( Temperature *temperature );
int getTargetPumpSpeed();
void setTargetPumpSpeed( int iTargetPumpSpeed );
int getNullSpeed();
int getOneSixthSpeed();
int getOneThirdSpeed();
int getHalfSpeed();
int getTwoThirdSpeed();
int getMaxSpeed();
private:
int _iOutputPin;
int _iOffValue;
int _iMaxValue;
boolean _selfPrimingMode;
boolean _hasBeenPrimedSinceStartup;
unsigned long _millisAtPrimingStart;
int _iPrimingTimeInSeconds;
int _iMaxTemperature;
int _iActualPumpSpeed; // Time frame to operate in
int _iTargetPumpSpeed;
Temperature *_temperature;
// Private functions
int calculateSpeedFraction(double fraction);
};
#endif
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment