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

improoved logging

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