Commit 65ccbff5 authored by João Lino's avatar João Lino

improoved logging

improoved logging
parent 3d27e28f
...@@ -4,7 +4,8 @@ ...@@ -4,7 +4,8 @@
Released into the public domain. Released into the public domain.
*/ */
#define DEBUG //#define DEBUG
#define INFO
// ######################### LIBRARIES ######################### // ######################### LIBRARIES #########################
#include "brew.h" #include "brew.h"
...@@ -71,6 +72,9 @@ boolean cancel; ...@@ -71,6 +72,9 @@ boolean cancel;
boolean bStatusElement; boolean bStatusElement;
unsigned long loggingTimeInterval;
// ++++++++++++++++++++++++ Interrupts ++++++++++++++++++++++++ // ++++++++++++++++++++++++ Interrupts ++++++++++++++++++++++++
static unsigned long lastInterruptTime; static unsigned long lastInterruptTime;
...@@ -335,6 +339,8 @@ void setup() { ...@@ -335,6 +339,8 @@ void setup() {
refresh = true; refresh = true;
repaint = true; repaint = true;
loggingTimeInterval = 0;
// ++++++++++++++++++++++++ Interrupts ++++++++++++++++++++++++ // ++++++++++++++++++++++++ Interrupts ++++++++++++++++++++++++
lastInterruptTime = 0; lastInterruptTime = 0;
...@@ -369,9 +375,6 @@ void loop() { ...@@ -369,9 +375,6 @@ void loop() {
// ######################### FUNCTIONS ######################## // ######################### FUNCTIONS ########################
void xCountTheTime( int temperatureMarginRange, boolean bMaximumOfUpDown ) { void xCountTheTime( int temperatureMarginRange, boolean bMaximumOfUpDown ) {
unsigned long now = millis(); unsigned long now = millis();
...@@ -465,47 +468,40 @@ bool xRegulateTemperature( boolean bMaximumOfUpDown ) { ...@@ -465,47 +468,40 @@ bool xRegulateTemperature( boolean bMaximumOfUpDown ) {
// Calculate applied wattage, based on the distance from the target temperature // Calculate applied wattage, based on the distance from the target temperature
if ( overTemperature ) { if ( overTemperature ) {
// turn it off wattage = 0.0; // turn it off
wattage = 0.0;
} else {
//if(difference <= 0.1) {
// turn it off
// wattage = 0.0;
//} else {
if (difference <= 0.5) {
// pulse lightly at 500 watt
if (cookTemperature > 99.0) {
wattage = 2000.0;
} }
else { else {
if (cookTemperature > 70.0) { if ( difference <= 0.5 ) {
wattage = 1000.0; if ( cookTemperature > 99.0 ) {
wattage = 2000.0; // pulse hardly at 2000 watt
} }
else { else {
wattage = 500.0; if ( cookTemperature > 70.0 ) {
wattage = 1000.0; // pulse moderately at 1000 watt
}
else {
wattage = 500.0; // pulse lightly at 500 watt
} }
} }
} else {
if (difference <= 1.0) {
// pulse moderately at 1000 watt
if (cookTemperature > 99.0) {
wattage = 2000.0;
} }
else { else {
wattage = 1000.0; if ( difference <= 1.0 ) {
if ( cookTemperature > 99.0 ) {
wattage = 2000.0; // pulse hardly at 2000 watt
} }
else {
} else { wattage = 1000.0; // pulse moderately at 1000 watt
if (difference <= 3.0) { }
// pulse hardly at 2000 watt }
wattage = 2000.0; else {
} else { if ( difference <= 3.0 ) {
//pulse constantly at HEATING_ELEMENT_MAX_WATTAGE watt wattage = 2000.0; // pulse hardly at 2000 watt
wattage = HEATING_ELEMENT_MAX_WATTAGE; }
else {
wattage = HEATING_ELEMENT_MAX_WATTAGE; // pulse constantly at HEATING_ELEMENT_MAX_WATTAGE watt
} }
} }
} }
//}
} }
// Update the recorded time for the begining of the window, if the previous window has passed // Update the recorded time for the begining of the window, if the previous window has passed
...@@ -836,28 +832,6 @@ void xBasicStageOperation( int iStageTime, int iStageTemperature, int iStageTemp ...@@ -836,28 +832,6 @@ void xBasicStageOperation( int iStageTime, int iStageTemperature, int iStageTemp
} }
void xManageMachineSystems() { void xManageMachineSystems() {
#ifdef DEBUG
Serial.print(millis());
Serial.print(",");
if (cooking) {
Serial.print("1");
}
else {
Serial.print("0");
}
Serial.print(",");
Serial.print(cookTemperature);
Serial.print(",");
if (bStatusElement) {
Serial.print("1");
}
else {
Serial.print("0");
}
Serial.print(",");
#endif
// Measure temperature, for effect // Measure temperature, for effect
basePT100.measure(false); basePT100.measure(false);
upPT100.measure(false); upPT100.measure(false);
...@@ -932,6 +906,41 @@ void xManageMachineSystems() { ...@@ -932,6 +906,41 @@ void xManageMachineSystems() {
break; break;
} }
} }
#ifdef INFO
unsigned long now = millis();
if( now - loggingTimeInterval > SETTING_MACHINE_LOGGING_INTERVAL ) {
loggingTimeInterval = now;
Serial.print(now);
Serial.print("|");
Serial.print(clockCounter);
Serial.print("|");
if (cooking) {
Serial.print("1");
}
else {
Serial.print("0");
}
Serial.print("|");
Serial.print(cookTemperature);
Serial.print("|");
Serial.print(basePT100.getCurrentTemperature());
Serial.print("|");
Serial.print(upPT100.getCurrentTemperature());
Serial.print("|");
Serial.print(downPT100.getCurrentTemperature());
Serial.print("|");
if (bStatusElement) {
Serial.print("1");
}
else {
Serial.print("0");
}
Serial.print("|");
}
#endif
} }
// ##################################################### Menus ################################################################### // ##################################################### Menus ###################################################################
...@@ -1375,7 +1384,7 @@ void runSettingsSelection() { ...@@ -1375,7 +1384,7 @@ void runSettingsSelection() {
switch (mdSettingsMenu._selection) { switch (mdSettingsMenu._selection) {
case eSettingsMenu_Pump: { case eSettingsMenu_Pump: {
bool bNewPumpStatus = xSetGenericValue( iPumpSpeed ? 0 : 1, PUMP_SPEED_DEFAULT, 0, 1, "pump", "bool" ); bool bNewPumpStatus = xSetGenericValue( iPumpSpeed ? 0 : 1, PUMP_SPEED_DEFAULT, 0, 1, "pump", "bool" );
if( cancel ) { if ( cancel ) {
cancel = false; cancel = false;
} }
else { else {
...@@ -1437,7 +1446,7 @@ void runMenuProcessor( MenuData *data ) { ...@@ -1437,7 +1446,7 @@ void runMenuProcessor( MenuData *data ) {
repaint = displayGenericMenu( &lcd, data ); // Display menu repaint = displayGenericMenu( &lcd, data ); // Display menu
if ( checkForEncoderSwitchPush( true ) ) { // Read selection if ( checkForEncoderSwitchPush( true ) ) { // Read selection
if( cancel ) { if ( cancel ) {
resetMenu( true ); resetMenu( true );
return; return;
} }
...@@ -1452,13 +1461,13 @@ void runStageSelection_Generic( unsigned long * selectedStageTime, int *selected ...@@ -1452,13 +1461,13 @@ void runStageSelection_Generic( unsigned long * selectedStageTime, int *selected
int selectedStageTemperatureStorage = *selectedStageTemperature; int selectedStageTemperatureStorage = *selectedStageTemperature;
*selectedStageTime = getTimer( *selectedStageTime ); *selectedStageTime = getTimer( *selectedStageTime );
if( cancel ) { if ( cancel ) {
*selectedStageTime = selectedStageTimeStorage; *selectedStageTime = selectedStageTimeStorage;
cancel = false; cancel = false;
} }
else { else {
*selectedStageTemperature = getTemperature( *selectedStageTemperature ); *selectedStageTemperature = getTemperature( *selectedStageTemperature );
if( cancel ) { if ( cancel ) {
*selectedStageTime = selectedStageTimeStorage; *selectedStageTime = selectedStageTimeStorage;
*selectedStageTemperature = selectedStageTemperatureStorage; *selectedStageTemperature = selectedStageTemperatureStorage;
cancel = false; cancel = false;
...@@ -1482,7 +1491,7 @@ void xStartStage( unsigned long *stageTime, int *stageTemperature, eCookingStage ...@@ -1482,7 +1491,7 @@ void xStartStage( unsigned long *stageTime, int *stageTemperature, eCookingStage
if (bSetFinalYield) { if (bSetFinalYield) {
finalYield = getFinalYield( finalYield, SETTING_MACHINE_YIELD_DEFAULT ); finalYield = getFinalYield( finalYield, SETTING_MACHINE_YIELD_DEFAULT );
if( cancel ) { if ( cancel ) {
finalYield = finalYieldStorage; finalYield = finalYieldStorage;
cancel = false; cancel = false;
...@@ -1492,7 +1501,7 @@ void xStartStage( unsigned long *stageTime, int *stageTemperature, eCookingStage ...@@ -1492,7 +1501,7 @@ void xStartStage( unsigned long *stageTime, int *stageTemperature, eCookingStage
} }
if (bSetTime) { if (bSetTime) {
(*stageTime) = getTimer( clockCounter / 1000, *stageTime ); (*stageTime) = getTimer( clockCounter / 1000, *stageTime );
if( cancel ) { if ( cancel ) {
finalYield = finalYieldStorage; finalYield = finalYieldStorage;
*stageTime = stageTimeStorage; *stageTime = stageTimeStorage;
...@@ -1503,7 +1512,7 @@ void xStartStage( unsigned long *stageTime, int *stageTemperature, eCookingStage ...@@ -1503,7 +1512,7 @@ void xStartStage( unsigned long *stageTime, int *stageTemperature, eCookingStage
} }
if (bSetTemperature) { if (bSetTemperature) {
(*stageTemperature) = getTemperature( cookTemperature, *stageTemperature ); (*stageTemperature) = getTemperature( cookTemperature, *stageTemperature );
if( cancel ) { if ( cancel ) {
finalYield = finalYieldStorage; finalYield = finalYieldStorage;
*stageTime = stageTimeStorage; *stageTime = stageTimeStorage;
*stageTemperature = stageTemperatureStorage; *stageTemperature = stageTemperatureStorage;
...@@ -1554,11 +1563,19 @@ void backToStatus() { ...@@ -1554,11 +1563,19 @@ void backToStatus() {
// #################################################### Set Variables ################################################################## // #################################################### Set Variables ##################################################################
int getTemperature(int initialValue ) { return getTemperature( initialValue, initialValue ); } int getTemperature(int initialValue ) {
int getTemperature(int initialValue, int defaultValue ) { return xSetGenericValue( initialValue, defaultValue, TEMPERATURE_MIN_VALUE, TEMPERATURE_MAX_VALUE, MENU_GLOBAL_STR_TEMPERATURE, MENU_GLOBAL_STR_CELSIUS ); } return getTemperature( initialValue, initialValue );
}
int getTemperature(int initialValue, int defaultValue ) {
return xSetGenericValue( initialValue, defaultValue, TEMPERATURE_MIN_VALUE, TEMPERATURE_MAX_VALUE, MENU_GLOBAL_STR_TEMPERATURE, MENU_GLOBAL_STR_CELSIUS );
}
int getFinalYield( int initialValue ) { return getFinalYield( initialValue, SETTING_MACHINE_YIELD_DEFAULT ); } int getFinalYield( int initialValue ) {
int getFinalYield( int initialValue, int defaultValue ) { return xSetGenericValue( initialValue, defaultValue, SETTING_MACHINE_YIELD_CAPACITY_MIN, SETTING_MACHINE_YIELD_CAPACITY_MAX, "Final Yield", "l" ); } return getFinalYield( initialValue, SETTING_MACHINE_YIELD_DEFAULT );
}
int getFinalYield( int initialValue, int defaultValue ) {
return xSetGenericValue( initialValue, defaultValue, SETTING_MACHINE_YIELD_CAPACITY_MIN, SETTING_MACHINE_YIELD_CAPACITY_MAX, "Final Yield", "l" );
}
int xSetGenericValue(int initialValue, int defaultValue, int minimumValue, int maximumValue, const char *valueName, const char *unit) { int xSetGenericValue(int initialValue, int defaultValue, int minimumValue, int maximumValue, const char *valueName, const char *unit) {
xSetupRotaryEncoder( eRotaryEncoderMode_Generic, initialValue, maximumValue, minimumValue, 1, 5 ); xSetupRotaryEncoder( eRotaryEncoderMode_Generic, initialValue, maximumValue, minimumValue, 1, 5 );
...@@ -1579,8 +1596,8 @@ int xSetGenericValue(int initialValue, int defaultValue, int minimumValue, int m ...@@ -1579,8 +1596,8 @@ int xSetGenericValue(int initialValue, int defaultValue, int minimumValue, int m
lcd.print( unit ); lcd.print( unit );
while (true) { while (true) {
if( checkForEncoderSwitchPush( true ) ) { // Check if pushbutton is pressed if ( checkForEncoderSwitchPush( true ) ) { // Check if pushbutton is pressed
if( cancel ) return rotaryEncoderVirtualPosition; if ( cancel ) return rotaryEncoderVirtualPosition;
break; break;
} }
else { else {
...@@ -1641,8 +1658,8 @@ int getTimer( int initialValue, int defaultValue ) { ...@@ -1641,8 +1658,8 @@ int getTimer( int initialValue, int defaultValue ) {
lcd.print(" 0:00"); lcd.print(" 0:00");
while (true) { while (true) {
if( checkForEncoderSwitchPush( true ) ) { if ( checkForEncoderSwitchPush( true ) ) {
if( cancel ) return rotaryEncoderVirtualPosition; if ( cancel ) return rotaryEncoderVirtualPosition;
break; break;
} }
else { else {
...@@ -1684,12 +1701,12 @@ boolean checkForEncoderSwitchPush( bool cancelable ) { ...@@ -1684,12 +1701,12 @@ boolean checkForEncoderSwitchPush( bool cancelable ) {
while (digitalRead(ROTARY_ENCODER_SW_PIN)) { // Wait until switch is released while (digitalRead(ROTARY_ENCODER_SW_PIN)) { // Wait until switch is released
delay(ROTARY_ENCODER_SW_DEBOUNCE_TIME); // debounce delay(ROTARY_ENCODER_SW_DEBOUNCE_TIME); // debounce
if( ((millis() - cancleTimer) >= SETTING_CANCEL_TIMER ) && cancelable ) { if ( ((millis() - cancleTimer) >= SETTING_CANCEL_TIMER ) && cancelable ) {
sing(BUZZ_1, PIEZO_PIN); sing(BUZZ_1, PIEZO_PIN);
} }
} }
if( ((millis() - cancleTimer) >= SETTING_CANCEL_TIMER) && cancelable ) { if ( ((millis() - cancleTimer) >= SETTING_CANCEL_TIMER) && cancelable ) {
cancel = true; cancel = true;
} }
} }
...@@ -1720,7 +1737,7 @@ unsigned long getInactivityTime() { ...@@ -1720,7 +1737,7 @@ unsigned long getInactivityTime() {
void xWaitForAction(String title, String message) { void xWaitForAction(String title, String message) {
while (true) { while (true) {
if( checkForEncoderSwitchPush( false ) ) { // Check if pushbutton is pressed if ( checkForEncoderSwitchPush( false ) ) { // Check if pushbutton is pressed
break; break;
} }
else { else {
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#define SETTING_MACHINE_YIELD_CAPACITY_MIN 0 #define SETTING_MACHINE_YIELD_CAPACITY_MIN 0
#define SETTING_MACHINE_YIELD_CAPACITY_MAX 50 #define SETTING_MACHINE_YIELD_CAPACITY_MAX 50
#define SETTING_MACHINE_YIELD_DEFAULT 25 #define SETTING_MACHINE_YIELD_DEFAULT 25
#define SETTING_MACHINE_LOGGING_INTERVAL 1000
// ++++++++++++++++++++++++ Heating Element Relay ++++++++++++++++++++++++ // ++++++++++++++++++++++++ Heating Element Relay ++++++++++++++++++++++++
#define HEATING_ELEMENT_DEFAULT_WINDOW_SIZE 1000 #define HEATING_ELEMENT_DEFAULT_WINDOW_SIZE 1000
......
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