Commit 90ab15b9 authored by João Lino's avatar João Lino

Moved more code to libraries

addet test function
parent 94938f90
#ifndef MELODY_h
#define MELODY_h
#define NOTE_B0 31
#define NOTE_C1 33
#define NOTE_CS1 35
#define NOTE_D1 37
#define NOTE_DS1 39
#define NOTE_E1 41
#define NOTE_F1 44
#define NOTE_FS1 46
#define NOTE_G1 49
#define NOTE_GS1 52
#define NOTE_A1 55
#define NOTE_AS1 58
#define NOTE_B1 62
#define NOTE_C2 65
#define NOTE_CS2 69
#define NOTE_D2 73
#define NOTE_DS2 78
#define NOTE_E2 82
#define NOTE_F2 87
#define NOTE_FS2 93
#define NOTE_G2 98
#define NOTE_GS2 104
#define NOTE_A2 110
#define NOTE_AS2 117
#define NOTE_B2 123
#define NOTE_C3 131
#define NOTE_CS3 139
#define NOTE_D3 147
#define NOTE_DS3 156
#define NOTE_E3 165
#define NOTE_F3 175
#define NOTE_FS3 185
#define NOTE_G3 196
#define NOTE_GS3 208
#define NOTE_A3 220
#define NOTE_AS3 233
#define NOTE_B3 247
#define NOTE_C4 262
#define NOTE_CS4 277
#define NOTE_D4 294
#define NOTE_DS4 311
#define NOTE_E4 330
#define NOTE_F4 349
#define NOTE_FS4 370
#define NOTE_G4 392
#define NOTE_GS4 415
#define NOTE_A4 440
#define NOTE_AS4 466
#define NOTE_B4 494
#define NOTE_C5 523
#define NOTE_CS5 554
#define NOTE_D5 587
#define NOTE_DS5 622
#define NOTE_E5 659
#define NOTE_F5 698
#define NOTE_FS5 740
#define NOTE_G5 784
#define NOTE_GS5 831
#define NOTE_A5 880
#define NOTE_AS5 932
#define NOTE_B5 988
#define NOTE_C6 1047
#define NOTE_CS6 1109
#define NOTE_D6 1175
#define NOTE_DS6 1245
#define NOTE_E6 1319
#define NOTE_F6 1397
#define NOTE_FS6 1480
#define NOTE_G6 1568
#define NOTE_GS6 1661
#define NOTE_A6 1760
#define NOTE_AS6 1865
#define NOTE_B6 1976
#define NOTE_C7 2093
#define NOTE_CS7 2217
#define NOTE_D7 2349
#define NOTE_DS7 2489
#define NOTE_E7 2637
#define NOTE_F7 2794
#define NOTE_FS7 2960
#define NOTE_G7 3136
#define NOTE_GS7 3322
#define NOTE_A7 3520
#define NOTE_AS7 3729
#define NOTE_B7 3951
#define NOTE_C8 4186
#define NOTE_CS8 4435
#define NOTE_D8 4699
#define NOTE_DS8 4978
// Start by defining the relationship between note, period, & frequency.
#define _c 3830 // 261 Hz
#define _d 3400 // 294 Hz
#define _e 3038 // 329 Hz
#define _f 2864 // 349 Hz
#define _g 2550 // 392 Hz
#define _a 2272 // 440 Hz
#define _b 2028 // 493 Hz
#define _C 1912 // 523 Hz
// Define a special note, 'R', to represent a rest
#define _R 0
#define MELODY_SUPER_MARIO 1
#define MELODY_UNDERWORLD 2
#define MELODY_SUPER_MARIO_START 3
// melody[] is an array of notes, accompanied by beats[],
// which sets each note's relative length (higher #, longer note)
void buzz(int targetPin, long frequency, long length);
void sing(int s, int pin);
#endif
\ No newline at end of file
/*
Temperature.cpp - Library for measuring temperature with a Temperature.
Created by João Lino, December 22, 2015.
Released into the public domain.
*/
#include "Arduino.h"
#include "Temperature.h"
Temperature::Temperature(char *name,
int OutputPin_SensorPower,
int InputPin_TemperatureReading,
int TimeBetweenReadings) {
_name = name;
_OutputPin_SensorPower = OutputPin_SensorPower;
_InputPin_TemperatureReading = InputPin_TemperatureReading;
_TimeBetweenReadings = TimeBetweenReadings;
_ADCVmax = ADCVmax;
_temperatureAverage = 24.0;
_measuredTemperature = 24.0;
_lastTemperatureRead = 0;
_VoutAnalogSample = -1;
_VoutPreviousAnalogSample = -1.0;
_temperatureMeasurementsMarker = 0;
_rTemperatureMeasurementsMarker = 0;
_rLineMeasurementsMarker = 0;
_measuredTemperatureDeviation = 0.0;
_sampleDeviation = 0.0;
analogReference(INTERNAL1V1); // EXTERNAL && INTERNAL2V56 && INTERNAL1V1
pinMode(_OutputPin_SensorPower, OUTPUT); // setup temperature sensor input pin
digitalWrite(_OutputPin_SensorPower, LOW); // initialize sensor on
}
void Temperature::safeHardwarePowerOff() {
digitalWrite(_OutputPin_SensorPower, LOW); // Turn temperature sensor OFF for safety
digitalWrite(_OutputPin_ThirdLinePower, LOW); // Turn temperature sensor OFF for safety
}
void Temperature::measure1(boolean ln, boolean rline) {
if(millis() - _lastTemperatureRead >= _TimeBetweenReadings) { //time to measure temperature
/** measure Vout analog sample */
digitalWrite(_OutputPin_SensorPower, HIGH); // initialize sensor on
digitalWrite(_OutputPin_ThirdLinePower, HIGH); // initialize sensor on
delay(10);
_VoutAnalogSample = analogRead(_InputPin_TemperatureReading) + _sampleDeviation; // Get a reading
_VoutRAnalogSample = analogRead(_InputPin_ThirdLineReading) + _sampleDeviation; // Get a reading
digitalWrite(_OutputPin_SensorPower, LOW); // initialize sensor on
digitalWrite(_OutputPin_ThirdLinePower, LOW); // initialize sensor on
_lastTemperatureRead = millis(); // Mark time of temperature reading
_rTemperatureMeasurementsMarker++; // Position reading buffer marker at the last updated position
if(_rTemperatureMeasurementsMarker >= TEMPERATURE_AVERAGE_VALUE_I) _rTemperatureMeasurementsMarker = 0; // Check that it has not gone out of the buffer range
_rTemperatureMeasurements[_rTemperatureMeasurementsMarker] = _VoutAnalogSample;
float Vout = GetMedian(_rTemperatureMeasurements) * _ADCVmax / CONSTANT_ADC_STEP_COUNT;
float Rx = _R1 / ( _Vs / Vout - 1.0);
if(rline) {
_rLineMeasurementsMarker++; // Position reading buffer marker at the last updated position
if(_rLineMeasurementsMarker >= TEMPERATURE_AVERAGE_VALUE_I) _rLineMeasurementsMarker = 0; // Check that it has not gone out of the buffer range
_rLineMeasurements[_rLineMeasurementsMarker] = _VoutRAnalogSample;
/** Calculate temperature value */
float VoutR = GetMedian(_rLineMeasurements) * _ADCVmax / CONSTANT_ADC_STEP_COUNT;
float Rline = _R2 / ( _Vs / VoutR - 1.0);
_measuredTemperature = 1.08271 * pow(10.0, -13.0) * (3.12508 * pow(10.0, 16.0) - 5.65566 * pow(10.0, 6.0) * sqrt(3.51501 * pow(10.0, 19.0) - 4.61805 * pow(10.0, 16.0) * (Rx - Rline)));
}
else {
/** Calculate temperature value */
_measuredTemperature = 1.08271 * pow(10.0, -13.0) * (3.12508 * pow(10.0, 16.0) - 5.65566 * pow(10.0, 6.0) * sqrt(3.51501 * pow(10.0, 19.0) - 4.61805 * pow(10.0, 16.0) * Rx));
}
//xFilterNoise(_temperatureMeasurementsMarker);
/*
Serial.print("Temperature : [");
Serial.print(_name);
Serial.print("]\tVoutSample: [");
Serial.print(_VoutAnalogSample);
// Serial.print("]\tVout[");
// Serial.print(Vout,6);
// Serial.print("]\tRx[");
// Serial.print(Rx,6);
Serial.print("]\tTNow[");
Serial.print(measuredTemperatureNow,6);
Serial.print("]\tTCalc[");
Serial.print(_measuredTemperature,6);
Serial.println("] ");
*/
//Serial.print("Temperature : [");
#ifdef DEBUG
Serial.print(_name);
Serial.print(",");
Serial.print(_VoutAnalogSample);
Serial.print(",");
//Serial.print(_VoutRAnalogSample);
//Serial.print(",");
/*Serial.print(test);
Serial.print(",");
Serial.print(Rtest);
Serial.print(",");*/
/*Serial.print(Vout,6);
Serial.print(",");
Serial.print(Rx,6);
Serial.print(",");
Serial.print(measuredTemperatureNow,6);
Serial.print(",");
Serial.print(_measuredTemperature,6);
Serial.print(",");*/
if(ln) Serial.println("");
#endif
}
}
float Temperature::GetMedian(int array[]){
int sorted[TEMPERATURE_AVERAGE_VALUE_I];
float value = 0.0;
for(int x = 0; x < TEMPERATURE_AVERAGE_VALUE_I; x++) {
sorted[x] = array[x];
}
//ARRANGE VALUES
for(int x = 0; x < TEMPERATURE_AVERAGE_VALUE_I; x++){
for(int y = 0; y < TEMPERATURE_AVERAGE_VALUE_I - 1; y++){
if(sorted[y]>sorted[y+1]){
int temp = sorted[y+1];
sorted[y+1] = sorted[y];
sorted[y] = temp;
}
}
}
//CALCULATE THE MEDIAN (middle number)
if(TEMPERATURE_AVERAGE_VALUE_I % 2 != 0){// is the # of elements odd?
int temp = ((TEMPERATURE_AVERAGE_VALUE_I+1)/2)-1;
value = (float) sorted[temp];
}
else{// then it's even! :)
value = ((float) ( sorted[(TEMPERATURE_AVERAGE_VALUE_I/2)-1] + sorted[TEMPERATURE_AVERAGE_VALUE_I/2] )) / 2.0;
}
return value;
}
float Temperature::getCurrentTemperature() {
return _measuredTemperature + _measuredTemperatureDeviation;
}
float Temperature::getMeasuredTemperatureDeviation() {
return _measuredTemperatureDeviation;
}
float Temperature::setMeasuredTemperatureDeviation( float measuredTemperatureDeviation) {
if( _measuredTemperatureDeviation != measuredTemperatureDeviation ) {
_measuredTemperatureDeviation = measuredTemperatureDeviation;
for( int i = 0; i < TEMPERATURE_AVERAGE_VALUE_I; i++ ) {
_temperatureMeasurements[i] = _temperatureMeasurements[i] + ( _measuredTemperatureDeviation * -1 );
}
}
return _measuredTemperatureDeviation;
}
float Temperature::setSampleDeviation( float sampleDeviation) {
_sampleDeviation = sampleDeviation;
return _sampleDeviation;
}
\ No newline at end of file
/*
Temperature.h - Library for measuring temperature with a Temperature.
Created by João Lino, December 22, 2015.
Released into the public domain.
*/
#ifndef TEMPERATURE_h
#define TEMPERATURE_h
#include "Arduino.h"
#define DEBUG
#define CONSTANT_ADC_STEP_COUNT 1024.0
#define TEMPERATURE_AVERAGE_VALUE_I 50
#define TEMPERATURE_AVERAGE_VALUE_F 50.0
//#define TEMPERATURE_AVERATE_INIT_VALUES 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0
#define TEMPERATURE_AVERATE_INIT_VALUES 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0
#define TEMPERATURE_AVERATE_INIT_VALUES_I 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
#define TEMPERATURE_SETTING_MAX_VALUE 120
class Temperature
{
public:
// Temperature(Temperature_OUTPUT_PIN, Temperature_INPUT_PIN, Temperature_TIME_BETWEEN_READINGS, Temperature_DEFAULT_ADC_VMAX, Temperature_DEFAULT_VS, Temperature_DEFAULT_R1_RESISTENCE, Temperature_DEFAULT_LINE_RESISTENCE, Temperature_DEFAULT_OPERATION_RESISTENCE);
Temperature(char *name,
int OutputPin_SensorPower,
int InputPin_TemperatureReading,
int TimeBetweenReadings = 100);
void measure(boolean ln);
void measure1(boolean ln, boolean rline);
void safeHardwarePowerOff();
float getCurrentTemperature();
float getMeasuredTemperatureDeviation();
float setMeasuredTemperatureDeviation( float measuredTemperatureDeviation);
float setSampleDeviation( float sampleDeviation);
private:
char *_name;
int _OutputPin_SensorPower;
int _OutputPin_ThirdLinePower;
int _InputPin_TemperatureReading;
int _InputPin_ThirdLineReading;
int _TimeBetweenReadings;
float _ADCVmax;
float _Vs;
float _R1;
float _R2;
float __m;
float __b;
float _temperatureAverage;
float _measuredTemperature;
float _measuredTemperatureDeviation;
float _sampleDeviation;
unsigned long _lastTemperatureRead;
int _VoutAnalogSample;
int _VoutRAnalogSample;
float _VoutPreviousAnalogSample;
int _temperatureMeasurementsMarker;
int _rTemperatureMeasurementsMarker;
int _rLineMeasurementsMarker;
float _temperatureMeasurements[TEMPERATURE_AVERAGE_VALUE_I] = {TEMPERATURE_AVERATE_INIT_VALUES};
int _rTemperatureMeasurements[TEMPERATURE_AVERAGE_VALUE_I] = {TEMPERATURE_AVERATE_INIT_VALUES_I};
int _rLineMeasurements[TEMPERATURE_AVERAGE_VALUE_I] = {TEMPERATURE_AVERATE_INIT_VALUES_I};
float GetMedian(int array[]);
};
#endif
\ No newline at end of file
...@@ -30,9 +30,9 @@ void runSettingsSelection(); ...@@ -30,9 +30,9 @@ void runSettingsSelection();
#include "src/Temperature/Temperature.h" #include "src/Temperature/Temperature.h"
#include "src/HeatingElement/HeatingElement.h" #include "src/HeatingElement/HeatingElement.h"
#include "src/Pump/Pump.h" #include "src/Pump/Pump.h"
#include "src/Melody/Melody.h"
#include "src/Display/Display.h"
#include "Melody.h"
#include "Display.h"
#include "Profiles.h" #include "Profiles.h"
// ++++++++++++++++++++++++ FUNCTIONS +++++++++++++++++++++++++++++++++ // ++++++++++++++++++++++++ FUNCTIONS +++++++++++++++++++++++++++++++++
......
...@@ -92,11 +92,7 @@ volatile boolean onISR = false; ...@@ -92,11 +92,7 @@ volatile boolean onISR = false;
unsigned long rotarySwDetectTime; unsigned long rotarySwDetectTime;
// ++++++++++++++++++++++++ Heating Element Relay ++++++++++++++++++++++++ // ++++++++++++++++++++++++ Heating Element Relay ++++++++++++++++++++++++
#ifdef HEATING_ELEMENT_ALWAYS_OFF
HeatingElement heatingElement(HEATING_ELEMENT_OUTPUT_PIN, LOW, LOW);
#else
HeatingElement heatingElement(HEATING_ELEMENT_OUTPUT_PIN, LOW, HIGH); HeatingElement heatingElement(HEATING_ELEMENT_OUTPUT_PIN, LOW, HIGH);
#endif
/* /*
int iWindowSize; // Time frame to operate in int iWindowSize; // Time frame to operate in
unsigned long windowStartTime; unsigned long windowStartTime;
...@@ -105,11 +101,7 @@ double dWattage; ...@@ -105,11 +101,7 @@ double dWattage;
*/ */
// ++++++++++++++++++++++++ Pump ++++++++++++++++++++++++ // ++++++++++++++++++++++++ Pump ++++++++++++++++++++++++
#ifdef PUMP_ALWAYS_OFF
Pump pump(PUMP_PIN, PUMP_SPEED_STOP_MOSFET, PUMP_SPEED_MAX_MOSFET, PUMP_TEMPERATURE_MAX_OPERATION, PUMP_PRIMING_TIME_IN_SECONDS); Pump pump(PUMP_PIN, PUMP_SPEED_STOP_MOSFET, PUMP_SPEED_MAX_MOSFET, PUMP_TEMPERATURE_MAX_OPERATION, PUMP_PRIMING_TIME_IN_SECONDS);
#else
Pump pump(PUMP_PIN, PUMP_SPEED_STOP_MOSFET, PUMP_SPEED_MAX_MOSFET, PUMP_TEMPERATURE_MAX_OPERATION, PUMP_PRIMING_TIME_IN_SECONDS);
#endif
//int iPumpSpeed; // Time frame to operate in //int iPumpSpeed; // Time frame to operate in
// ######################### INITIALIZE ######################### // ######################### INITIALIZE #########################
...@@ -282,12 +274,19 @@ void setup() { ...@@ -282,12 +274,19 @@ void setup() {
dWattPerPulse = HEATING_ELEMENT_MAX_WATTAGE / HEATING_ELEMENT_AC_FREQUENCY_HZ; dWattPerPulse = HEATING_ELEMENT_MAX_WATTAGE / HEATING_ELEMENT_AC_FREQUENCY_HZ;
dWattage = 0.0; dWattage = 0.0;
*/ */
#ifdef HEATING_ELEMENT_ALWAYS_OFF
heatingElement.setTesting(true);
#endif
// ++++++++++++++++++++++++ Mixer ++++++++++++++++++++++++ // ++++++++++++++++++++++++ Mixer ++++++++++++++++++++++++
// ++++++++++++++++++++++++ Pump ++++++++++++++++++++++++ // ++++++++++++++++++++++++ Pump ++++++++++++++++++++++++
//float (Temperature::*xCheckTemperature)(); //float (Temperature::*xCheckTemperature)();
//xCheckTemperature = &(basePT100.getCurrentTemperature); //xCheckTemperature = &(basePT100.getCurrentTemperature);
#ifdef PUMP_ALWAYS_OFF
pump.setTesting(true);
#endif
pump.setCheckTemperatureFunction(&basePT100); pump.setCheckTemperatureFunction(&basePT100);
/* /*
pinMode(PUMP_PIN, OUTPUT); // sets the pin as output pinMode(PUMP_PIN, OUTPUT); // sets the pin as output
...@@ -590,6 +589,14 @@ void xPurgePump() { ...@@ -590,6 +589,14 @@ void xPurgePump() {
} }
bool xRegulatePumpSpeed() { bool xRegulatePumpSpeed() {
pump.process();
bool isPumpOn = pump.isPumpOn();
basePT100.setPumpStatus( isPumpOn );
upPT100.setPumpStatus( isPumpOn );
downPT100.setPumpStatus( isPumpOn );
/*
if(pump.process()) { if(pump.process()) {
basePT100.setPumpStatus( true ); basePT100.setPumpStatus( true );
upPT100.setPumpStatus( true ); upPT100.setPumpStatus( true );
...@@ -601,7 +608,6 @@ bool xRegulatePumpSpeed() { ...@@ -601,7 +608,6 @@ bool xRegulatePumpSpeed() {
downPT100.setPumpStatus( false ); downPT100.setPumpStatus( false );
} }
/*
// analogWrite(PUMP_PIN, iPumpSpeed); // analogWrite values from 0 to 255 // analogWrite(PUMP_PIN, iPumpSpeed); // analogWrite values from 0 to 255
if (basePT100.getCurrentTemperature() > PUMP_TEMPERATURE_MAX_OPERATION) { if (basePT100.getCurrentTemperature() > PUMP_TEMPERATURE_MAX_OPERATION) {
analogWrite(PUMP_PIN, PUMP_SPEED_STOP_MOSFET); // analogWrite values from 0 to 255 analogWrite(PUMP_PIN, PUMP_SPEED_STOP_MOSFET); // analogWrite values from 0 to 255
......
...@@ -18,11 +18,6 @@ ...@@ -18,11 +18,6 @@
// ++++++++++++++++++++++++ Heating Element Relay ++++++++++++++++++++++++ // ++++++++++++++++++++++++ Heating Element Relay ++++++++++++++++++++++++
#define HEATING_ELEMENT_OUTPUT_PIN 24 #define HEATING_ELEMENT_OUTPUT_PIN 24
//#define HEATING_ELEMENT_DEFAULT_WINDOW_SIZE 1000
//#define HEATING_ELEMENT_MAX_HEAT_PWM_INTEGER 5
//#define HEATING_ELEMENT_MAX_HEAT_PWM_FLOAT 5.0
//#define HEATING_ELEMENT_MAX_WATTAGE 3000.0 // Minimum = 2000.0
//#define HEATING_ELEMENT_AC_FREQUENCY_HZ 50.0
// ++++++++++++++++++++++++ Temperature ++++++++++++++++++++++++ // ++++++++++++++++++++++++ Temperature ++++++++++++++++++++++++
#define TEMPERATURE_MIN_VALUE 0 #define TEMPERATURE_MIN_VALUE 0
...@@ -57,8 +52,8 @@ ...@@ -57,8 +52,8 @@
#define ROTARY_ENCODER_CLK_PIN 3 // Used for generating interrupts using CLK signal #define ROTARY_ENCODER_CLK_PIN 3 // Used for generating interrupts using CLK signal
#define ROTARY_ENCODER_DT_PIN 22 // Used for reading DT signal #define ROTARY_ENCODER_DT_PIN 22 // Used for reading DT signal
#define ROTARY_ENCODER_SW_PIN 23 // Used for the push button switch #define ROTARY_ENCODER_SW_PIN 23 // Used for the push button switch
#define ROTARY_ENCODER_DEBOUNCE_TIME 50 //20 // Number of miliseconds to ignore new signals a signal is received #define ROTARY_ENCODER_DEBOUNCE_TIME 100 //50 //20 // Number of miliseconds to ignore new signals a signal is received
#define ROTARY_ENCODER_SW_DEBOUNCE_TIME 10 //20 // Number of miliseconds to ignore new signals a signal is received #define ROTARY_ENCODER_SW_DEBOUNCE_TIME 50 //10 //20 // Number of miliseconds to ignore new signals a signal is received
// ++++++++++++++++++++++++ State Machine ++++++++++++++++++++++++ // ++++++++++++++++++++++++ State Machine ++++++++++++++++++++++++
#define SETTING_WELCOME_TIMEOUT 100 #define SETTING_WELCOME_TIMEOUT 100
......
...@@ -13,8 +13,8 @@ ...@@ -13,8 +13,8 @@
#include <LCD.h> #include <LCD.h>
#include <LiquidCrystal_I2C.h> #include <LiquidCrystal_I2C.h>
#include "config.h" #include "../../config.h"
#include "CustomDataStructures.h" #include "../../CustomDataStructures.h"
boolean lcdPrint(LiquidCrystal_I2C *lcd, String title, String message); boolean lcdPrint(LiquidCrystal_I2C *lcd, String title, String message);
......
#include "HeatingElement.h" #include "HeatingElement.h"
HeatingElement::HeatingElement( int iOutputPin, int uiOffValue, int uiOnValue ) { HeatingElement::HeatingElement( int iOutputPin, int iOffValue, int iOnValue ) {
_iOutputPin = iOutputPin; _iOutputPin = iOutputPin;
_uiOffValue = uiOffValue; _iOffValue = iOffValue;
_uiOnValue = uiOnValue; _iOnValue = iOnValue;
pinMode(_iOutputPin, OUTPUT);
digitalWrite(_iOutputPin, _uiOffValue);
_testing = false;
_bStatusElement = false; _bStatusElement = false;
_iWindowSize = HEATING_ELEMENT_DEFAULT_WINDOW_SIZE; // Time frame to operate in _iWindowSize = HEATING_ELEMENT_DEFAULT_WINDOW_SIZE; // Time frame to operate in
_windowStartTime = millis(); _windowStartTime = millis();
_dWattPerPulse = HEATING_ELEMENT_MAX_WATTAGE / HEATING_ELEMENT_AC_FREQUENCY_HZ; _dWattPerPulse = HEATING_ELEMENT_MAX_WATTAGE / HEATING_ELEMENT_AC_FREQUENCY_HZ;
_dWattage = 0.0; _dWattage = 0.0;
pinMode(_iOutputPin, OUTPUT);
modeSet( _iOffValue );
} }
void HeatingElement::shutDown() { void HeatingElement::shutDown() {
digitalWrite(_iOutputPin, _uiOffValue); // Turn heading element OFF for safety modeSet( _iOffValue ); // Turn heading element OFF for safety
_bStatusElement = false; _bStatusElement = false;
} }
...@@ -33,10 +34,10 @@ double HeatingElement::process() { ...@@ -33,10 +34,10 @@ double HeatingElement::process() {
// Apply wattage to the element at the right time // Apply wattage to the element at the right time
if ( ulWattToWindowTime( _dWattage ) > (millis() - _windowStartTime) ) { if ( ulWattToWindowTime( _dWattage ) > (millis() - _windowStartTime) ) {
digitalWrite(_iOutputPin, _uiOnValue); modeSet( _iOnValue );
_bStatusElement = true; _bStatusElement = true;
} else { } else {
digitalWrite(_iOutputPin, _uiOffValue); modeSet( _iOffValue );
_bStatusElement = false; _bStatusElement = false;
} }
...@@ -57,6 +58,10 @@ void HeatingElement::setWattage( double dWattage ) { ...@@ -57,6 +58,10 @@ void HeatingElement::setWattage( double dWattage ) {
_dWattage = dWattage; _dWattage = dWattage;
} }
bool HeatingElement::setTesting( bool testing ) {
_testing = testing;
}
// Private functions // Private functions
double HeatingElement::ulWattToWindowTime( double ulAppliedWatts ) { double HeatingElement::ulWattToWindowTime( double ulAppliedWatts ) {
...@@ -64,6 +69,18 @@ double HeatingElement::ulWattToWindowTime( double ulAppliedWatts ) { ...@@ -64,6 +69,18 @@ double HeatingElement::ulWattToWindowTime( double ulAppliedWatts ) {
return (double)_iWindowSize / 1000.0 * ulPulsesRequired * 1000.0 / HEATING_ELEMENT_AC_FREQUENCY_HZ; return (double)_iWindowSize / 1000.0 * ulPulsesRequired * 1000.0 / HEATING_ELEMENT_AC_FREQUENCY_HZ;
} }
int HeatingElement::modeSet( int value ) {
int valueSet = _iOffValue;
if( !_testing ) {
valueSet = value;
}
digitalWrite(_iOutputPin, valueSet);
return valueSet;
}
// Power Increments // Power Increments
double HeatingElement::getNullWattage() { double HeatingElement::getNullWattage() {
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
class HeatingElement class HeatingElement
{ {
public: public:
HeatingElement( int iOutputPin, int uiOffValue, int uiOnValue ); HeatingElement( int iOutputPin, int iOffValue, int iOnValue );
void shutDown(); void shutDown();
double process(); double process();
...@@ -30,18 +30,21 @@ class HeatingElement ...@@ -30,18 +30,21 @@ class HeatingElement
double getTwoThirdWattage(); double getTwoThirdWattage();
double getMaxWattage(); double getMaxWattage();
private: bool setTesting( bool testing );
double ulWattToWindowTime( double ulAppliedWatts );
private:
int _iOutputPin; int _iOutputPin;
int _uiOffValue; int _iOffValue;
int _uiOnValue; int _iOnValue;
int _testing;
boolean _bStatusElement; boolean _bStatusElement;
int _iWindowSize; // Time frame to operate in int _iWindowSize; // Time frame to operate in
unsigned long _windowStartTime; unsigned long _windowStartTime;
double _dWattPerPulse; double _dWattPerPulse;
double _dWattage; double _dWattage;
double ulWattToWindowTime( double ulAppliedWatts );
int modeSet( int value );
}; };
#endif #endif
\ No newline at end of file
...@@ -11,6 +11,7 @@ Pump::Pump( int iOutputPin, int iOffValue, int iMaxValue, int iMaxTemperature, i ...@@ -11,6 +11,7 @@ Pump::Pump( int iOutputPin, int iOffValue, int iMaxValue, int iMaxTemperature, i
_iMaxTemperature = iMaxTemperature; _iMaxTemperature = iMaxTemperature;
_iPrimingTimeInSeconds = iPrimingTimeInSeconds; _iPrimingTimeInSeconds = iPrimingTimeInSeconds;
_testing = false;
_iActualPumpSpeed = _iOffValue; // Time frame to operate in _iActualPumpSpeed = _iOffValue; // Time frame to operate in
_iTargetPumpSpeed = _iOffValue; _iTargetPumpSpeed = _iOffValue;
_temperature = NULL; _temperature = NULL;
...@@ -19,7 +20,7 @@ Pump::Pump( int iOutputPin, int iOffValue, int iMaxValue, int iMaxTemperature, i ...@@ -19,7 +20,7 @@ Pump::Pump( int iOutputPin, int iOffValue, int iMaxValue, int iMaxTemperature, i
_hasBeenPrimedSinceStartup = false; _hasBeenPrimedSinceStartup = false;
pinMode(_iOutputPin, OUTPUT); // sets the pin as output pinMode(_iOutputPin, OUTPUT); // sets the pin as output
analogWrite(_iOutputPin, _iOffValue); // analogWrite values from 0 to 255 modeSet( _iOffValue ); // turn off element
} }
void Pump::shutDown() { void Pump::shutDown() {
...@@ -38,6 +39,7 @@ bool Pump::process() { ...@@ -38,6 +39,7 @@ bool Pump::process() {
// Operate pump if its operating temperature is bellow the maximum operating temperature // Operate pump if its operating temperature is bellow the maximum operating temperature
float currentTemperature = _temperature->getCurrentTemperature(); float currentTemperature = _temperature->getCurrentTemperature();
if (currentTemperature <= _iMaxTemperature) { if (currentTemperature <= _iMaxTemperature) {
// Self prime on first use // Self prime on first use
if(!_hasBeenPrimedSinceStartup && _iTargetPumpSpeed != _iOffValue) { if(!_hasBeenPrimedSinceStartup && _iTargetPumpSpeed != _iOffValue) {
_hasBeenPrimedSinceStartup = true; _hasBeenPrimedSinceStartup = true;
...@@ -80,7 +82,7 @@ bool Pump::process() { ...@@ -80,7 +82,7 @@ bool Pump::process() {
} }
// Set pump speed // Set pump speed
analogWrite(_iOutputPin, _iActualPumpSpeed); // analogWrite values from 0 to 255 modeSet( _iActualPumpSpeed ); // operate element values from 0 to 255
return _iActualPumpSpeed; return _iActualPumpSpeed;
} }
...@@ -101,18 +103,22 @@ bool Pump::isPumpOn() { ...@@ -101,18 +103,22 @@ bool Pump::isPumpOn() {
return _iActualPumpSpeed != _iOffValue; return _iActualPumpSpeed != _iOffValue;
} }
void Pump::setCheckTemperatureFunction( Temperature *temperature ) {
_temperature = temperature;
}
int Pump::getTargetPumpSpeed() { int Pump::getTargetPumpSpeed() {
return _iTargetPumpSpeed; return _iTargetPumpSpeed;
} }
void Pump::setCheckTemperatureFunction( Temperature *temperature ) {
_temperature = temperature;
}
void Pump::setTargetPumpSpeed( int iTargetPumpSpeed ) { void Pump::setTargetPumpSpeed( int iTargetPumpSpeed ) {
_iTargetPumpSpeed = iTargetPumpSpeed; _iTargetPumpSpeed = iTargetPumpSpeed;
} }
bool Pump::setTesting( bool testing ) {
_testing = testing;
}
// Power Increments // Power Increments
int Pump::getNullSpeed() { int Pump::getNullSpeed() {
return _iOffValue; return _iOffValue;
...@@ -146,3 +152,19 @@ int Pump::calculateSpeedFraction(double fraction) { ...@@ -146,3 +152,19 @@ int Pump::calculateSpeedFraction(double fraction) {
return ret; return ret;
} }
int Pump::modeSet( int value ) {
int valueSet = _iOffValue;
if( !_testing ) {
valueSet = value;
_iActualPumpSpeed = valueSet;
}
else {
_iActualPumpSpeed = _iOffValue;
}
analogWrite(_iOutputPin, valueSet); // analogWrite values from 0 to 255
return valueSet;
}
\ No newline at end of file
...@@ -33,12 +33,13 @@ class Pump ...@@ -33,12 +33,13 @@ class Pump
int getTwoThirdSpeed(); int getTwoThirdSpeed();
int getMaxSpeed(); int getMaxSpeed();
bool setTesting( bool testing );
private: private:
int _iOutputPin; int _iOutputPin;
int _iOffValue; int _iOffValue;
int _iMaxValue; int _iMaxValue;
int _testing;
boolean _selfPrimingMode; boolean _selfPrimingMode;
boolean _hasBeenPrimedSinceStartup; boolean _hasBeenPrimedSinceStartup;
unsigned long _millisAtPrimingStart; unsigned long _millisAtPrimingStart;
...@@ -49,7 +50,8 @@ class Pump ...@@ -49,7 +50,8 @@ class Pump
Temperature *_temperature; Temperature *_temperature;
// Private functions // Private functions
int calculateSpeedFraction(double fraction); int calculateSpeedFraction( double fraction );
int modeSet( int value );
}; };
#endif #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