Commit 4fab6c8e authored by João Lino's avatar João Lino

fixed all the syntax errors - code now compiles. datastuctures sent to a header file.

parent 6eecd9b6
/*
CustomDataStructures.h - Data structures helper for the brew project.
Created by João Lino, August 11, 2015.
Released into the public domain.
*/
#ifndef CustomDataStructures_h
enum eRotaryEncoderMode {
eRotaryEncoderMode_Menu,
eRotaryEncoderMode_Time,
eRotaryEncoderMode_Generic,
eRotaryEncoderMode_Disabled
};
// menu
enum eMainMenuOptions {
eMainMenu_GO,
eMainMenu_Presets,
eMainMenu_Malt,
eMainMenu_Startpoint,
eMainMenu_BetaGlucanase,
eMainMenu_Debranching,
eMainMenu_Proteolytic,
eMainMenu_BetaAmylase,
eMainMenu_AlphaAmylase,
eMainMenu_Mashout,
eMainMenu_Recirculation,
eMainMenu_Sparge,
eMainMenu_Boil,
eMainMenu_Hops,
eMainMenu_Cooling,
eMainMenu_Settings,
eMainMenu_Back
};
enum ePresetsMenuOptions {
ePresetsMenu_Trigo,
ePresetsMenu_IPA,
ePresetsMenu_Belga,
ePresetsMenu_Red,
ePresetsMenu_APA,
ePresetsMenu_Back
};
enum eMaltMenuOptions {
eMaltMenu_CastleMalting_Chteau_Pilsen_2RS,
eMaltMenu_CastleMalting_Wheat_Blanc,
eMaltMenu_Back
};
enum eSettingsMenuOptions {
eSettingsMenu_PT100_Element,
eSettingsMenu_PT100_Up,
eSettingsMenu_PT100_Down,
eSettingsMenu_Back
};
// cooking
enum eCookingStages {
eCookingStage_Startpoint,
eCookingStage_BetaGlucanase,
eCookingStage_Debranching,
eCookingStage_Proteolytic,
eCookingStage_BetaAmylase,
eCookingStage_AlphaAmylase,
eCookingStage_Mashout,
eCookingStage_Recirculation,
eCookingStage_Sparge,
eCookingStage_Boil,
eCookingStage_Cooling,
eCookingStage_Done
};
#endif
\ No newline at end of file
...@@ -54,7 +54,7 @@ ...@@ -54,7 +54,7 @@
#define SETTING_MAX_INACTIVITY_TIME 3000 #define SETTING_MAX_INACTIVITY_TIME 3000
#define MENU_MAX_DEPTH 10 #define MENU_MAX_DEPTH 10
#define MENU_INIT_VALUES -1,-1,-1,-1,-1,-1,-1,-1,-1,-1 #define MENU_INIT_VALUES -1,-1,-1,-1,-1,-1,-1,-1,-1,-1
#define MENU_SIZE_MAIN_MENU 16 #define MENU_SIZE_MAIN_MENU 17
#define SETTING_SERIAL_MONITOR_BAUD_RATE 9600 #define SETTING_SERIAL_MONITOR_BAUD_RATE 9600
#define SETTING_SERIAL_MONITOR_WELCOME_MESSAGE "Let's start Brewing!" #define SETTING_SERIAL_MONITOR_WELCOME_MESSAGE "Let's start Brewing!"
...@@ -79,93 +79,21 @@ ...@@ -79,93 +79,21 @@
// ++++++++++++++++++++++++ PT100 +++++++++++++++++++++++++++++++++ // ++++++++++++++++++++++++ PT100 +++++++++++++++++++++++++++++++++
#include <PT100.h> #include <PT100.h>
// ######################### VARIABLES ######################### // ++++++++++++++++++++++++ ENUM +++++++++++++++++++++++++++++++++
// ++++++++++++++++++++++++ Rotary Encoder ++++++++++++++++++++++++ #include "CustomDataStructures.h"
volatile int rotaryEncoderVirtualPosition;
volatile int rotaryEncoderMaxPosition;
volatile int rotaryEncoderMinPosition;
volatile int rotaryEncoderSingleStep;
volatile int rotaryEncoderMultiStep;
// ++++++++++++++++++++++++ Heating Element Relay ++++++++++++++++++++++++
int WindowSize; // Time frame to operate in
unsigned long windowStartTime;
unsigned long dWattPerPulse;
// ######################### VARIABLES #########################
// ++++++++++++++++++++++++ State Machine ++++++++++++++++++++++++ // ++++++++++++++++++++++++ State Machine ++++++++++++++++++++++++
// global eRotaryEncoderMode rotaryEncoderMode;
enum TRotaryEncoderMode { eMainMenuOptions mainMenuOption;
eRotaryEncoderMode_Menu, ePresetsMenuOptions presetsMenuOption;
eRotaryEncoderMode_Time, eMaltMenuOptions maltMenuOption;
eRotaryEncoderMode_Generic, eSettingsMenuOptions settingsMenuOption;
eRotaryEncoderMode_Disabled eCookingStages cookingStage;
};
TRotaryEncoderMode rotaryEncoderMode;
// menu
enum eMainMenuOptions {
eMainMenu_GO,
eMainMenu_Presets,
eMainMenu_Malt,
eMainMenu_Startpoint,
eMainMenu_BetaGlucanase,
eMainMenu_Debranching,
eMainMenu_Proteolytic,
eMainMenu_BetaAmylase,
eMainMenu_AlphaAmylase,
eMainMenu_Mashout,
eMainMenu_Recirculation,
eMainMenu_Sparge,
eMainMenu_Boil,
eMainMenu_Hops,
eMainMenu_Cooling,
eMainMenu_Settings
};
eMainMenuOptions mainMenuOption;
enum ePresetsMenuOptions {
ePresetsMenu_Trigo,
ePresetsMenu_IPA,
ePresetsMenu_Belga,
ePresetsMenu_Red,
ePresetsMenu_APA,
ePresetsMenu_Back,
};
ePresetsMenuOptions presetsMenuOption;
enum eMaltMenuOptions {
eMaltMenu_CastleMalting_Chteau_Pilsen_2RS,
eMaltMenu_CastleMalting_Wheat_Blanc,
eMaltMenu_Back,
};
eMaltMenuOptions maltMenuOption;
enum eSettingsMenuOptions {
eSettingsMenu_PT100_Element,
eSettingsMenu_PT100_Up,
eSettingsMenu_PT100_Down,
eSettingsMenu_Back,
};
eSettingsMenuOptions settingsMenuOption;
// cooking
enum eCookingStages {
eCookingStage_Startpoint,
eCookingStage_BetaGlucanase,
eCookingStage_Debranching,
eCookingStage_Proteolytic,
eCookingStage_BetaAmylase,
eCookingStage_AlphaAmylase,
eCookingStage_Mashout,
eCookingStage_Recirculation,
eCookingStage_Sparge,
eCookingStage_Boil,
eCookingStage_Cooling,
eCookingStage_Done
};
eCookingStages cookingStage;
// ++++++++++++++++++++++++ Global Variables ++++++++++++++++++++++++ // ++++++++++++++++++++++++ Global Variables ++++++++++++++++++++++++
boolean cooking; boolean cooking;
boolean bStageFirstRun;
int clockStartTime; int clockStartTime;
int clockCounter; int clockCounter;
...@@ -212,6 +140,18 @@ boolean repaint; ...@@ -212,6 +140,18 @@ boolean repaint;
// ++++++++++++++++++++++++ Interrupts ++++++++++++++++++++++++ // ++++++++++++++++++++++++ Interrupts ++++++++++++++++++++++++
static unsigned long lastInterruptTime; static unsigned long lastInterruptTime;
// ++++++++++++++++++++++++ Rotary Encoder ++++++++++++++++++++++++
volatile int rotaryEncoderVirtualPosition = 0;
volatile int rotaryEncoderMaxPosition = 1;
volatile int rotaryEncoderMinPosition = 0;
volatile int rotaryEncoderSingleStep = 1;
volatile int rotaryEncoderMultiStep = 1;
// ++++++++++++++++++++++++ Heating Element Relay ++++++++++++++++++++++++
int iWindowSize; // Time frame to operate in
unsigned long windowStartTime;
double dWattPerPulse;
// ######################### INITIALIZE ######################### // ######################### INITIALIZE #########################
// ++++++++++++++++++++++++ Library - LiquidCrystal_I2C ++++++++++++++++++++++++ // ++++++++++++++++++++++++ Library - LiquidCrystal_I2C ++++++++++++++++++++++++
LiquidCrystal_I2C lcd(LCD_I2C_ADDR, LCD_EN_PIN, LCD_RW_PIN, LCD_RS_PIN, LCD_D4_PIN, LCD_D5_PIN, LCD_D6_PIN, LCD_D7_PIN); LiquidCrystal_I2C lcd(LCD_I2C_ADDR, LCD_EN_PIN, LCD_RW_PIN, LCD_RS_PIN, LCD_D4_PIN, LCD_D5_PIN, LCD_D6_PIN, LCD_D7_PIN);
...@@ -222,7 +162,7 @@ PT100 upPT100(PT100_UP_OUTPUT_PIN, PT100_UP_INPUT_PIN, PT100_UP_TIME_BETWEEN_REA ...@@ -222,7 +162,7 @@ PT100 upPT100(PT100_UP_OUTPUT_PIN, PT100_UP_INPUT_PIN, PT100_UP_TIME_BETWEEN_REA
PT100 downPT100(PT100_DOWN_OUTPUT_PIN, PT100_DOWN_INPUT_PIN, PT100_DOWN_TIME_BETWEEN_READINGS, PT100_DOWN_DEFAULT_ADC_VMAX, PT100_DOWN_DEFAULT_VS, PT100_DOWN_DEFAULT_R1_RESISTENCE, PT100_DOWN_DEFAULT_LINE_RESISTENCE, PT100_DOWN_DEFAULT_OPERATION_RESISTENCE); PT100 downPT100(PT100_DOWN_OUTPUT_PIN, PT100_DOWN_INPUT_PIN, PT100_DOWN_TIME_BETWEEN_READINGS, PT100_DOWN_DEFAULT_ADC_VMAX, PT100_DOWN_DEFAULT_VS, PT100_DOWN_DEFAULT_R1_RESISTENCE, PT100_DOWN_DEFAULT_LINE_RESISTENCE, PT100_DOWN_DEFAULT_OPERATION_RESISTENCE);
// ######################### INTERRUPTS ######################### // ######################### INTERRUPTS #########################
void xSetupRotaryEncoder( TRotaryEncoderMode newMode, int newPosition, int newMaxPosition, int newMinPosition, int newSingleStep, int newMultiStep ) { void xSetupRotaryEncoder( eRotaryEncoderMode newMode, int newPosition, int newMaxPosition, int newMinPosition, int newSingleStep, int newMultiStep ) {
if( newMode >= 0 ) rotaryEncoderMode = newMode; if( newMode >= 0 ) rotaryEncoderMode = newMode;
if( newPosition >= 0 ) rotaryEncoderVirtualPosition = newPosition; if( newPosition >= 0 ) rotaryEncoderVirtualPosition = newPosition;
if( newMaxPosition >= 0 ) rotaryEncoderMaxPosition = newMaxPosition; if( newMaxPosition >= 0 ) rotaryEncoderMaxPosition = newMaxPosition;
...@@ -260,9 +200,7 @@ void isr () { // Interrupt service routine is executed when a HIGH to LOW tran ...@@ -260,9 +200,7 @@ void isr () { // Interrupt service routine is executed when a HIGH to LOW tran
// Input of rotary encoder controling time variables // Input of rotary encoder controling time variables
case eRotaryEncoderMode_Time: { case eRotaryEncoderMode_Time: {
xDecodeRotaryEncoder(); if (!digitalRead(ROTARY_ENCODER_DT_PIN)) {
if (!digitalRead(ROTARY_ENCODER_DT_PIN)) {
if(rotaryEncoderVirtualPosition >= 60) { if(rotaryEncoderVirtualPosition >= 60) {
rotaryEncoderVirtualPosition = (rotaryEncoderVirtualPosition + rotaryEncoderMultiStep); rotaryEncoderVirtualPosition = (rotaryEncoderVirtualPosition + rotaryEncoderMultiStep);
} }
...@@ -354,9 +292,6 @@ void setup() { ...@@ -354,9 +292,6 @@ void setup() {
windowStartTime = millis(); windowStartTime = millis();
dWattPerPulse = HEATING_ELEMENT_MAX_WATTAGE / HEATING_ELEMENT_AC_FREQUENCY_HZ; dWattPerPulse = HEATING_ELEMENT_MAX_WATTAGE / HEATING_ELEMENT_AC_FREQUENCY_HZ;
myPID.SetOutputLimits (0, WindowSize); // tell the PID to range between 0 and the full window size
myPID.SetMode (AUTOMATIC); // turn the PID on
// ++++++++++++++++++++++++ Mixer ++++++++++++++++++++++++ // ++++++++++++++++++++++++ Mixer ++++++++++++++++++++++++
// pinMode (MIXER_PIN, OUTPUT); // pinMode (MIXER_PIN, OUTPUT);
// analogWrite (MIXER_PIN, 0); // analogWrite (MIXER_PIN, 0);
...@@ -379,7 +314,7 @@ void setup() { ...@@ -379,7 +314,7 @@ void setup() {
// ######################### INITIALIZE ######################### // ######################### INITIALIZE #########################
// ++++++++++++++++++++++++ Rotary Encoder ++++++++++++++++++++++++ // ++++++++++++++++++++++++ Rotary Encoder ++++++++++++++++++++++++
// set operation state | INPUT : TRotaryEncoderMode newMode, int newPosition, int newMaxPosition, int newMinPosition, int newSingleStep, int newMultiStep // set operation state | INPUT : eRotaryEncoderMode newMode, int newPosition, int newMaxPosition, int newMinPosition, int newSingleStep, int newMultiStep
xSetupRotaryEncoder( eRotaryEncoderMode_Disabled, 0, 0, 0, 0, 0 ); xSetupRotaryEncoder( eRotaryEncoderMode_Disabled, 0, 0, 0, 0, 0 );
// ++++++++++++++++++++++++ State Machine ++++++++++++++++++++++++ // ++++++++++++++++++++++++ State Machine ++++++++++++++++++++++++
...@@ -389,6 +324,7 @@ void setup() { ...@@ -389,6 +324,7 @@ void setup() {
cookingStage = eCookingStage_Startpoint; cookingStage = eCookingStage_Startpoint;
// ++++++++++++++++++++++++ Global Variables ++++++++++++++++++++++++ // ++++++++++++++++++++++++ Global Variables ++++++++++++++++++++++++
cooking = false; cooking = false;
bStageFirstRun = true;
clockStartTime = 0; clockStartTime = 0;
clockCounter = 0; clockCounter = 0;
...@@ -433,7 +369,7 @@ void setup() { ...@@ -433,7 +369,7 @@ void setup() {
lastInterruptTime = 0; lastInterruptTime = 0;
// ++++++++++++++++++++++++ PID ++++++++++++++++++++++++ // ++++++++++++++++++++++++ PID ++++++++++++++++++++++++
WindowSize = HEATING_ELEMENT_DEFAULT_WINDOW_SIZE; // Time frame to operate in iWindowSize = HEATING_ELEMENT_DEFAULT_WINDOW_SIZE; // Time frame to operate in
// ######################### Code - Run Once ######################### // ######################### Code - Run Once #########################
xSafeHardwarePowerOff(); xSafeHardwarePowerOff();
...@@ -552,7 +488,7 @@ void displayMainMenu() { ...@@ -552,7 +488,7 @@ void displayMainMenu() {
menu_position[0] = -1; menu_position[0] = -1;
// reset operation state | INPUT : TRotaryEncoderMode newMode, int newPosition, int newMaxPosition, int newMinPosition, int newSingleStep, int newMultiStep // reset operation state | INPUT : eRotaryEncoderMode newMode, int newPosition, int newMaxPosition, int newMinPosition, int newSingleStep, int newMultiStep
xSetupRotaryEncoder( eRotaryEncoderMode_Menu, eMainMenu_GO, MENU_SIZE_MAIN_MENU - 1, 0, 1, 1 ); xSetupRotaryEncoder( eRotaryEncoderMode_Menu, eMainMenu_GO, MENU_SIZE_MAIN_MENU - 1, 0, 1, 1 );
break; break;
...@@ -562,7 +498,7 @@ void displayMainMenu() { ...@@ -562,7 +498,7 @@ void displayMainMenu() {
menu_position[0] = -1; menu_position[0] = -1;
// reset operation state | INPUT : TRotaryEncoderMode newMode, int newPosition, int newMaxPosition, int newMinPosition, int newSingleStep, int newMultiStep // reset operation state | INPUT : eRotaryEncoderMode newMode, int newPosition, int newMaxPosition, int newMinPosition, int newSingleStep, int newMultiStep
xSetupRotaryEncoder( eRotaryEncoderMode_Menu, eMainMenu_Presets, MENU_SIZE_MAIN_MENU - 1, 0, 1, 1 ); xSetupRotaryEncoder( eRotaryEncoderMode_Menu, eMainMenu_Presets, MENU_SIZE_MAIN_MENU - 1, 0, 1, 1 );
break; break;
...@@ -572,7 +508,7 @@ void displayMainMenu() { ...@@ -572,7 +508,7 @@ void displayMainMenu() {
menu_position[0] = -1; menu_position[0] = -1;
// reset operation state | INPUT : TRotaryEncoderMode newMode, int newPosition, int newMaxPosition, int newMinPosition, int newSingleStep, int newMultiStep // reset operation state | INPUT : eRotaryEncoderMode newMode, int newPosition, int newMaxPosition, int newMinPosition, int newSingleStep, int newMultiStep
xSetupRotaryEncoder( eRotaryEncoderMode_Menu, eMainMenu_Malt, MENU_SIZE_MAIN_MENU - 1, 0, 1, 1 ); xSetupRotaryEncoder( eRotaryEncoderMode_Menu, eMainMenu_Malt, MENU_SIZE_MAIN_MENU - 1, 0, 1, 1 );
break; break;
...@@ -582,7 +518,7 @@ void displayMainMenu() { ...@@ -582,7 +518,7 @@ void displayMainMenu() {
menu_position[0] = -1; menu_position[0] = -1;
// reset operation state | INPUT : TRotaryEncoderMode newMode, int newPosition, int newMaxPosition, int newMinPosition, int newSingleStep, int newMultiStep // reset operation state | INPUT : eRotaryEncoderMode newMode, int newPosition, int newMaxPosition, int newMinPosition, int newSingleStep, int newMultiStep
xSetupRotaryEncoder( eRotaryEncoderMode_Menu, eMainMenu_Startpoint, MENU_SIZE_MAIN_MENU - 1, 0, 1, 1 ); xSetupRotaryEncoder( eRotaryEncoderMode_Menu, eMainMenu_Startpoint, MENU_SIZE_MAIN_MENU - 1, 0, 1, 1 );
break; break;
...@@ -592,7 +528,7 @@ void displayMainMenu() { ...@@ -592,7 +528,7 @@ void displayMainMenu() {
menu_position[0] = -1; menu_position[0] = -1;
// reset operation state | INPUT : TRotaryEncoderMode newMode, int newPosition, int newMaxPosition, int newMinPosition, int newSingleStep, int newMultiStep // reset operation state | INPUT : eRotaryEncoderMode newMode, int newPosition, int newMaxPosition, int newMinPosition, int newSingleStep, int newMultiStep
xSetupRotaryEncoder( eRotaryEncoderMode_Menu, eMainMenu_BetaGlucanase, MENU_SIZE_MAIN_MENU - 1, 0, 1, 1 ); xSetupRotaryEncoder( eRotaryEncoderMode_Menu, eMainMenu_BetaGlucanase, MENU_SIZE_MAIN_MENU - 1, 0, 1, 1 );
break; break;
...@@ -602,7 +538,7 @@ void displayMainMenu() { ...@@ -602,7 +538,7 @@ void displayMainMenu() {
menu_position[0] = -1; menu_position[0] = -1;
// reset operation state | INPUT : TRotaryEncoderMode newMode, int newPosition, int newMaxPosition, int newMinPosition, int newSingleStep, int newMultiStep // reset operation state | INPUT : eRotaryEncoderMode newMode, int newPosition, int newMaxPosition, int newMinPosition, int newSingleStep, int newMultiStep
xSetupRotaryEncoder( eRotaryEncoderMode_Menu, eMainMenu_Settings, MENU_SIZE_MAIN_MENU - 1, 0, 1, 1 ); xSetupRotaryEncoder( eRotaryEncoderMode_Menu, eMainMenu_Settings, MENU_SIZE_MAIN_MENU - 1, 0, 1, 1 );
break; break;
...@@ -612,7 +548,7 @@ void displayMainMenu() { ...@@ -612,7 +548,7 @@ void displayMainMenu() {
menu_position[0] = -1; menu_position[0] = -1;
// reset operation state | INPUT : TRotaryEncoderMode newMode, int newPosition, int newMaxPosition, int newMinPosition, int newSingleStep, int newMultiStep // reset operation state | INPUT : eRotaryEncoderMode newMode, int newPosition, int newMaxPosition, int newMinPosition, int newSingleStep, int newMultiStep
xSetupRotaryEncoder( eRotaryEncoderMode_Menu, eMainMenu_Proteolytic, MENU_SIZE_MAIN_MENU - 1, 0, 1, 1 ); xSetupRotaryEncoder( eRotaryEncoderMode_Menu, eMainMenu_Proteolytic, MENU_SIZE_MAIN_MENU - 1, 0, 1, 1 );
break; break;
...@@ -622,7 +558,7 @@ void displayMainMenu() { ...@@ -622,7 +558,7 @@ void displayMainMenu() {
menu_position[0] = -1; menu_position[0] = -1;
// reset operation state | INPUT : TRotaryEncoderMode newMode, int newPosition, int newMaxPosition, int newMinPosition, int newSingleStep, int newMultiStep // reset operation state | INPUT : eRotaryEncoderMode newMode, int newPosition, int newMaxPosition, int newMinPosition, int newSingleStep, int newMultiStep
xSetupRotaryEncoder( eRotaryEncoderMode_Menu, eMainMenu_BetaAmylase, MENU_SIZE_MAIN_MENU - 1, 0, 1, 1 ); xSetupRotaryEncoder( eRotaryEncoderMode_Menu, eMainMenu_BetaAmylase, MENU_SIZE_MAIN_MENU - 1, 0, 1, 1 );
break; break;
...@@ -632,7 +568,7 @@ void displayMainMenu() { ...@@ -632,7 +568,7 @@ void displayMainMenu() {
menu_position[0] = -1; menu_position[0] = -1;
// reset operation state | INPUT : TRotaryEncoderMode newMode, int newPosition, int newMaxPosition, int newMinPosition, int newSingleStep, int newMultiStep // reset operation state | INPUT : eRotaryEncoderMode newMode, int newPosition, int newMaxPosition, int newMinPosition, int newSingleStep, int newMultiStep
xSetupRotaryEncoder( eRotaryEncoderMode_Menu, eMainMenu_AlphaAmylase, MENU_SIZE_MAIN_MENU - 1, 0, 1, 1 ); xSetupRotaryEncoder( eRotaryEncoderMode_Menu, eMainMenu_AlphaAmylase, MENU_SIZE_MAIN_MENU - 1, 0, 1, 1 );
break; break;
...@@ -642,7 +578,7 @@ void displayMainMenu() { ...@@ -642,7 +578,7 @@ void displayMainMenu() {
menu_position[0] = -1; menu_position[0] = -1;
// reset operation state | INPUT : TRotaryEncoderMode newMode, int newPosition, int newMaxPosition, int newMinPosition, int newSingleStep, int newMultiStep // reset operation state | INPUT : eRotaryEncoderMode newMode, int newPosition, int newMaxPosition, int newMinPosition, int newSingleStep, int newMultiStep
xSetupRotaryEncoder( eRotaryEncoderMode_Menu, eMainMenu_Mashout, MENU_SIZE_MAIN_MENU - 1, 0, 1, 1 ); xSetupRotaryEncoder( eRotaryEncoderMode_Menu, eMainMenu_Mashout, MENU_SIZE_MAIN_MENU - 1, 0, 1, 1 );
break; break;
...@@ -652,7 +588,7 @@ void displayMainMenu() { ...@@ -652,7 +588,7 @@ void displayMainMenu() {
menu_position[0] = -1; menu_position[0] = -1;
// reset operation state | INPUT : TRotaryEncoderMode newMode, int newPosition, int newMaxPosition, int newMinPosition, int newSingleStep, int newMultiStep // reset operation state | INPUT : eRotaryEncoderMode newMode, int newPosition, int newMaxPosition, int newMinPosition, int newSingleStep, int newMultiStep
xSetupRotaryEncoder( eRotaryEncoderMode_Menu, eMainMenu_Recirculation, MENU_SIZE_MAIN_MENU - 1, 0, 1, 1 ); xSetupRotaryEncoder( eRotaryEncoderMode_Menu, eMainMenu_Recirculation, MENU_SIZE_MAIN_MENU - 1, 0, 1, 1 );
break; break;
...@@ -662,7 +598,7 @@ void displayMainMenu() { ...@@ -662,7 +598,7 @@ void displayMainMenu() {
menu_position[0] = -1; menu_position[0] = -1;
// reset operation state | INPUT : TRotaryEncoderMode newMode, int newPosition, int newMaxPosition, int newMinPosition, int newSingleStep, int newMultiStep // reset operation state | INPUT : eRotaryEncoderMode newMode, int newPosition, int newMaxPosition, int newMinPosition, int newSingleStep, int newMultiStep
xSetupRotaryEncoder( eRotaryEncoderMode_Menu, eMainMenu_Sparge, MENU_SIZE_MAIN_MENU - 1, 0, 1, 1 ); xSetupRotaryEncoder( eRotaryEncoderMode_Menu, eMainMenu_Sparge, MENU_SIZE_MAIN_MENU - 1, 0, 1, 1 );
break; break;
...@@ -672,7 +608,7 @@ void displayMainMenu() { ...@@ -672,7 +608,7 @@ void displayMainMenu() {
menu_position[0] = -1; menu_position[0] = -1;
// reset operation state | INPUT : TRotaryEncoderMode newMode, int newPosition, int newMaxPosition, int newMinPosition, int newSingleStep, int newMultiStep // reset operation state | INPUT : eRotaryEncoderMode newMode, int newPosition, int newMaxPosition, int newMinPosition, int newSingleStep, int newMultiStep
xSetupRotaryEncoder( eRotaryEncoderMode_Menu, eMainMenu_Boil, MENU_SIZE_MAIN_MENU - 1, 0, 1, 1 ); xSetupRotaryEncoder( eRotaryEncoderMode_Menu, eMainMenu_Boil, MENU_SIZE_MAIN_MENU - 1, 0, 1, 1 );
break; break;
...@@ -682,7 +618,7 @@ void displayMainMenu() { ...@@ -682,7 +618,7 @@ void displayMainMenu() {
menu_position[0] = -1; menu_position[0] = -1;
// reset operation state | INPUT : TRotaryEncoderMode newMode, int newPosition, int newMaxPosition, int newMinPosition, int newSingleStep, int newMultiStep // reset operation state | INPUT : eRotaryEncoderMode newMode, int newPosition, int newMaxPosition, int newMinPosition, int newSingleStep, int newMultiStep
xSetupRotaryEncoder( eRotaryEncoderMode_Menu, eMainMenu_Hops, MENU_SIZE_MAIN_MENU - 1, 0, 1, 1 ); xSetupRotaryEncoder( eRotaryEncoderMode_Menu, eMainMenu_Hops, MENU_SIZE_MAIN_MENU - 1, 0, 1, 1 );
break; break;
...@@ -692,7 +628,7 @@ void displayMainMenu() { ...@@ -692,7 +628,7 @@ void displayMainMenu() {
menu_position[0] = -1; menu_position[0] = -1;
// reset operation state | INPUT : TRotaryEncoderMode newMode, int newPosition, int newMaxPosition, int newMinPosition, int newSingleStep, int newMultiStep // reset operation state | INPUT : eRotaryEncoderMode newMode, int newPosition, int newMaxPosition, int newMinPosition, int newSingleStep, int newMultiStep
xSetupRotaryEncoder( eRotaryEncoderMode_Menu, eMainMenu_Cooling, MENU_SIZE_MAIN_MENU - 1, 0, 1, 1 ); xSetupRotaryEncoder( eRotaryEncoderMode_Menu, eMainMenu_Cooling, MENU_SIZE_MAIN_MENU - 1, 0, 1, 1 );
break; break;
...@@ -701,9 +637,19 @@ void displayMainMenu() { ...@@ -701,9 +637,19 @@ void displayMainMenu() {
MainMenu_Settings(); MainMenu_Settings();
menu_position[0] = -1; menu_position[0] = -1;
// reset operation state | INPUT : TRotaryEncoderMode newMode, int newPosition, int newMaxPosition, int newMinPosition, int newSingleStep, int newMultiStep // reset operation state | INPUT : eRotaryEncoderMode newMode, int newPosition, int newMaxPosition, int newMinPosition, int newSingleStep, int newMultiStep
xSetupRotaryEncoder( eRotaryEncoderMode_Menu, eMainMenu_Settings, MENU_SIZE_MAIN_MENU - 1, 0, 1, 1 ); xSetupRotaryEncoder( eRotaryEncoderMode_Menu, eMainMenu_Settings, MENU_SIZE_MAIN_MENU - 1, 0, 1, 1 );
break;
}
case eMainMenu_Back: {
MainMenu_Back();
menu_position[0] = -1;
// reset operation state | INPUT : eRotaryEncoderMode newMode, int newPosition, int newMaxPosition, int newMinPosition, int newSingleStep, int newMultiStep
xSetupRotaryEncoder( eRotaryEncoderMode_Menu, eMainMenu_Settings, MENU_SIZE_MAIN_MENU - 1, 0, 1, 1 );
break; break;
} }
...@@ -796,8 +742,13 @@ void displayMainMenu() { ...@@ -796,8 +742,13 @@ void displayMainMenu() {
lcd.print("-> Settings "); lcd.print("-> Settings ");
break; break;
} }
case eMainMenu_Back: {
lcd.setCursor (0,1); // go to start of 2nd line
lcd.print("-> Back ");
break;
}
default: { default: {
// reset operation state | INPUT : TRotaryEncoderMode newMode, int newPosition, int newMaxPosition, int newMinPosition, int newSingleStep, int newMultiStep // reset operation state | INPUT : eRotaryEncoderMode newMode, int newPosition, int newMaxPosition, int newMinPosition, int newSingleStep, int newMultiStep
xSetupRotaryEncoder( eRotaryEncoderMode_Menu, eMainMenu_GO, MENU_SIZE_MAIN_MENU - 1, 0, 1, 1 ); xSetupRotaryEncoder( eRotaryEncoderMode_Menu, eMainMenu_GO, MENU_SIZE_MAIN_MENU - 1, 0, 1, 1 );
} }
} }
...@@ -822,10 +773,14 @@ void MainMenu_GO() { ...@@ -822,10 +773,14 @@ void MainMenu_GO() {
} }
void MainMenu_Presets() { void MainMenu_Presets() {
backToStatus();
} }
void MainMenu_Malt() { void MainMenu_Malt() {
backToStatus();
} }
...@@ -833,76 +788,105 @@ void MainMenu_Startpoint() { ...@@ -833,76 +788,105 @@ void MainMenu_Startpoint() {
startpointTime = getTimer( startpointTime ); startpointTime = getTimer( startpointTime );
startpointTemperature = xSetGenericValue( startpointTemperature, 0, 120, "temperature", "*C" ); startpointTemperature = xSetGenericValue( startpointTemperature, 0, 120, "temperature", "*C" );
backToStatus();
} }
void MainMenu_BetaGlucanase() { void MainMenu_BetaGlucanase() {
betaGlucanaseTime = getTimer( betaGlucanaseTime ); betaGlucanaseTime = getTimer( betaGlucanaseTime );
betaGlucanaseTemperature = xSetGenericValue( betaGlucanaseTemperature, 0, 120, "temperature", "*C" ); betaGlucanaseTemperature = xSetGenericValue( betaGlucanaseTemperature, 0, 120, "temperature", "*C" );
backToStatus();
} }
void MainMenu_Debranching() { void MainMenu_Debranching() {
debranchingTime = getTimer( debranchingTime ); debranchingTime = getTimer( debranchingTime );
debranchingTemperature = xSetGenericValue( debranchingTemperature, 0, 120, "temperature", "*C" ); debranchingTemperature = xSetGenericValue( debranchingTemperature, 0, 120, "temperature", "*C" );
backToStatus();
} }
void MainMenu_Proteolytic() { void MainMenu_Proteolytic() {
proteolyticTime = getTimer( proteolyticTime ); proteolyticTime = getTimer( proteolyticTime );
proteolyticTemperature = xSetGenericValue( proteolyticTemperature, 0, 120, "temperature", "*C" ); proteolyticTemperature = xSetGenericValue( proteolyticTemperature, 0, 120, "temperature", "*C" );
backToStatus();
} }
void MainMenu_BetaAmylase() { void MainMenu_BetaAmylase() {
betaAmylaseTime = getTimer( betaAmylaseTime ); betaAmylaseTime = getTimer( betaAmylaseTime );
betaAmylaseTemperature = xSetGenericValue( betaAmylaseTemperature, 0, 120, "temperature", "*C" ); betaAmylaseTemperature = xSetGenericValue( betaAmylaseTemperature, 0, 120, "temperature", "*C" );
backToStatus();
} }
void MainMenu_AlphaAmylase() { void MainMenu_AlphaAmylase() {
alphaAmylaseTime = getTimer( alphaAmylaseTime ); alphaAmylaseTime = getTimer( alphaAmylaseTime );
alphaAmylaseTemperature = xSetGenericValue( alphaAmylaseTemperature, 0, 120, "temperature", "*C" ); alphaAmylaseTemperature = xSetGenericValue( alphaAmylaseTemperature, 0, 120, "temperature", "*C" );
backToStatus();
} }
void MainMenu_Mashout() { void MainMenu_Mashout() {
mashoutTime = getTimer( mashoutTime ); mashoutTime = getTimer( mashoutTime );
mashoutTemperature = xSetGenericValue( mashoutTemperature, 0, 120, "temperature", "*C" ); mashoutTemperature = xSetGenericValue( mashoutTemperature, 0, 120, "temperature", "*C" );
backToStatus();
} }
void MainMenu_Recirculation() { void MainMenu_Recirculation() {
recirculationTime = getTimer( recirculationTime ); recirculationTime = getTimer( recirculationTime );
recirculationTemperature = xSetGenericValue( recirculationTemperature, 0, 120, "temperature", "*C" ); recirculationTemperature = xSetGenericValue( recirculationTemperature, 0, 120, "temperature", "*C" );
backToStatus();
} }
void MainMenu_Sparge() { void MainMenu_Sparge() {
spargeTime = getTimer( spargeTime ); spargeTime = getTimer( spargeTime );
spargeTemperature = xSetGenericValue( spargeTemperature, 0, 120, "temperature", "*C" ); spargeTemperature = xSetGenericValue( spargeTemperature, 0, 120, "temperature", "*C" );
backToStatus();
} }
void MainMenu_Boil() { void MainMenu_Boil() {
boilTime = getTimer( boilTime ); boilTime = getTimer( boilTime );
boilTemperature = xSetGenericValue( boilTemperature, 0, 120, "temperature", "*C" ); boilTemperature = xSetGenericValue( boilTemperature, 0, 120, "temperature", "*C" );
backToStatus();
} }
void MainMenu_Hops() { void MainMenu_Hops() {
backToStatus();
} }
void MainMenu_Coooling() { void MainMenu_Cooling() {
coolingTime = getTimer( coolingTime ); coolingTime = getTimer( coolingTime );
coolingTemperature = xSetGenericValue( coolingTemperature, 0, 120, "temperature", "*C" ); coolingTemperature = xSetGenericValue( coolingTemperature, 0, 120, "temperature", "*C" );
backToStatus();
} }
void MainMenu_Settings() { void MainMenu_Settings() {
backToStatus();
} }
void MainMenu_Back() {
backToStatus();
}
void xCountTheTime( int temperatureRange ) { void xCountTheTime( int temperatureRange ) {
// Check if the machine is in the right temperature range, for the current mode, // Check if the machine is in the right temperature range, for the current mode,
...@@ -921,19 +905,19 @@ bool isTimeLeft() { ...@@ -921,19 +905,19 @@ bool isTimeLeft() {
return true; return true;
} }
unsigned long ulWattToWindowTime( unsigned long appliedWatts ) { double ulWattToWindowTime( double ulAppliedWatts ) {
unsigned long ulPulsesRequired = ulAppliedWatts / dWattPerPulse; double ulPulsesRequired = ulAppliedWatts / dWattPerPulse;
return windowSize / 1000.0 * ulPulsesRequired; return (double)iWindowSize / 1000.0 * ulPulsesRequired;
} }
bool xRegulateTemperature() { bool xRegulateTemperature() {
double diference = basePT100.getCurrentTemperature() - cookTemperature; double difference = basePT100.getCurrentTemperature() - cookTemperature;
bool overTemperature = false; bool overTemperature = false;
unsigned long wattage = 0.0; double wattage = 0.0;
// Deviation between the cook temperature set and the cook temperature measured // Deviation between the cook temperature set and the cook temperature measured
if( diference < 0.0 ) { if( difference < 0.0 ) {
diference = diference * (-1.0); difference = difference * (-1.0);
overTemperature = true; overTemperature = true;
} }
...@@ -942,19 +926,19 @@ bool xRegulateTemperature() { ...@@ -942,19 +926,19 @@ bool xRegulateTemperature() {
// turn it off // turn it off
wattage = 0.0; wattage = 0.0;
} else { } else {
if(diffrence <= 1) { if(difference <= 1) {
// turn it off // turn it off
wattage = 0.0; wattage = 0.0;
} else { } else {
if(diffrence <= 3) { if(difference <= 3) {
// pulse lightly at 500 watt // pulse lightly at 500 watt
wattage = 500.0; wattage = 500.0;
} else { } else {
if(diffrence <= 6) { if(difference <= 6) {
// pulse moderately at 1000 watt // pulse moderately at 1000 watt
wattage = 1000.0; wattage = 1000.0;
} else { } else {
if(diffrence <= 9) { if(difference <= 9) {
// pulse hardly at 2000 watt // pulse hardly at 2000 watt
wattage = 2000.0; wattage = 2000.0;
} else { } else {
...@@ -967,8 +951,8 @@ bool xRegulateTemperature() { ...@@ -967,8 +951,8 @@ bool xRegulateTemperature() {
} }
// 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
while((millis() - windowStartTime) > WindowSize) { // Check if it's time to vary the pulse width modulation and if so do it by shifting the "Relay in ON" Window while((millis() - windowStartTime) > iWindowSize) { // Check if it's time to vary the pulse width modulation and if so do it by shifting the "Relay in ON" Window
windowStartTime += WindowSize; windowStartTime += iWindowSize;
} }
// Apply wattage to the element at the right time // Apply wattage to the element at the right time
...@@ -997,7 +981,7 @@ void xStageFirstRun( int stageTime, int stageTemperature ) { ...@@ -997,7 +981,7 @@ void xStageFirstRun( int stageTime, int stageTemperature ) {
void xTransitionIntoStage_GlobalVariables(eCookingStages nextStage) { void xTransitionIntoStage_GlobalVariables(eCookingStages nextStage) {
// Reset global stage variables // Reset global stage variables
stageFirstRun = true; bStageFirstRun = true;
cookingStage = nextStage; cookingStage = nextStage;
} }
...@@ -1014,9 +998,9 @@ void xTransitionIntoStage(eCookingStages nextStage) { ...@@ -1014,9 +998,9 @@ void xTransitionIntoStage(eCookingStages nextStage) {
} }
void xBasicStageOperation( int iStageTime, int iStageTemperature, int iStageTemperatureRange, eCookingStages nextStage ) { void xBasicStageOperation( int iStageTime, int iStageTemperature, int iStageTemperatureRange, eCookingStages nextStage ) {
if(stageFirstRun) { if(bStageFirstRun) {
// Don't run this again // Don't run this again
stageFirstRun = false; bStageFirstRun = false;
// When the stage should be skipped // When the stage should be skipped
if( iStageTime == 0) { if( iStageTime == 0) {
...@@ -1053,7 +1037,6 @@ void xWarnCookEnded() { ...@@ -1053,7 +1037,6 @@ void xWarnCookEnded() {
/// TODO /// TODO
} }
bool stageFirstRun = true;
void operateMachine() { void operateMachine() {
// Measure temperature, for effect // Measure temperature, for effect
...@@ -1174,7 +1157,7 @@ void backToStatus() { ...@@ -1174,7 +1157,7 @@ void backToStatus() {
// #################################################### Set Variables ################################################################## // #################################################### Set Variables ##################################################################
int getTimer(int init) { int getTimer(int init) {
// set operation state | INPUT : TRotaryEncoderMode newMode, int newPosition, int newMaxPosition, int newMinPosition, int newSingleStep, int newMultiStep // set operation state | INPUT : eRotaryEncoderMode newMode, int newPosition, int newMaxPosition, int newMinPosition, int newSingleStep, int newMultiStep
xSetupRotaryEncoder( eRotaryEncoderMode_Time, init, 7200, 0, 1, 30 ); xSetupRotaryEncoder( eRotaryEncoderMode_Time, init, 7200, 0, 1, 30 );
// initialize variables // initialize variables
...@@ -1223,13 +1206,10 @@ int getTimer(int init) { ...@@ -1223,13 +1206,10 @@ int getTimer(int init) {
} }
} }
backToStatus();
rotaryEncoderMode = initialState;
return rotaryEncoderVirtualPosition; return rotaryEncoderVirtualPosition;
} }
int getTemperature(int init) { int getTemperature(int init) {
TRotaryEncoderMode initialState = rotaryEncoderMode;
// set operation state // set operation state
rotaryEncoderMode = eRotaryEncoderMode_Generic; rotaryEncoderMode = eRotaryEncoderMode_Generic;
...@@ -1283,13 +1263,11 @@ int getTemperature(int init) { ...@@ -1283,13 +1263,11 @@ int getTemperature(int init) {
} }
} }
backToStatus();
rotaryEncoderMode = initialState;
return rotaryEncoderVirtualPosition; return rotaryEncoderVirtualPosition;
} }
int xSetGenericValue(int init, int min, int max, char *valueName, char *unit) { int xSetGenericValue(int init, int min, int max, char *valueName, char *unit) {
// set operation state | INPUT : TRotaryEncoderMode newMode, int newPosition, int newMaxPosition, int newMinPosition, int newSingleStep, int newMultiStep // set operation state | INPUT : eRotaryEncoderMode newMode, int newPosition, int newMaxPosition, int newMinPosition, int newSingleStep, int newMultiStep
xSetupRotaryEncoder( eRotaryEncoderMode_Generic, init, max, min, 1, 5 ); xSetupRotaryEncoder( eRotaryEncoderMode_Generic, init, max, min, 1, 5 );
// initialize variables // initialize variables
......
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