Commit d5ea03fd authored by João Lino's avatar João Lino

menu system restructure - initial commit

menu system restructure
parent 9f46351c
...@@ -6,6 +6,8 @@ ...@@ -6,6 +6,8 @@
#ifndef CustomDataStructures_h #ifndef CustomDataStructures_h
#define CustomDataStructures_h #define CustomDataStructures_h
#define SYS_MAX_MENU_ELEMENTS 16
enum eRotaryEncoderMode { enum eRotaryEncoderMode {
eRotaryEncoderMode_Menu, eRotaryEncoderMode_Menu,
eRotaryEncoderMode_Time, eRotaryEncoderMode_Time,
...@@ -111,10 +113,10 @@ enum eBeerProfile { ...@@ -111,10 +113,10 @@ enum eBeerProfile {
}; };
typedef struct menuData_ { typedef struct menuData_ {
char *_title; const char *_title;
const char *_dialog[ SYS_MAX_MENU_ELEMENTS ];
int _position; int _position;
int _selection; int _selection;
char **_dialog;
bool _repaint; bool _repaint;
} MenuData; } MenuData;
......
#ifndef __BREW #ifndef __BREW
#define __BREW #define __BREW
// ++++++++++++++++++++++++ LiquidCrystal_I2C ++++++++++++++++++++++++
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>
// ++++++++++++++++++++++++ PT100 +++++++++++++++++++++++++++++++++
//#include <PT100.h>
// ++++++++++++++++++++++++ Defines +++++++++++++++++++++++++++++++++
#define NELEMS(x) (sizeof(x) / sizeof((x)[0]))
// ++++++++++++++++++++++++ OTHER +++++++++++++++++++++++++++++++++
#include "CustomDataStructures.h"
#include "debug.h"
#include "config.h"
#include "Melody.h"
#include "Display.h"
#include "Temperature.h"
#include "Profiles.h"
// ++++++++++++++++++++++++ FUNCTIONS +++++++++++++++++++++++++++++++++
void xSetupRotaryEncoder( eRotaryEncoderMode 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 );
// ######################### START ######################### // ######################### START #########################
......
...@@ -7,27 +7,6 @@ ...@@ -7,27 +7,6 @@
#define DEBUG #define DEBUG
// ######################### LIBRARIES ######################### // ######################### LIBRARIES #########################
// ++++++++++++++++++++++++ LiquidCrystal_I2C ++++++++++++++++++++++++
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>
// ++++++++++++++++++++++++ PT100 +++++++++++++++++++++++++++++++++
//#include <PT100.h>
// ++++++++++++++++++++++++ OTHER +++++++++++++++++++++++++++++++++
#include "debug.h"
#include "config.h"
#include "CustomDataStructures.h"
#include "Melody.h"
#include "Display.h"
#include "Temperature.h"
#include "Profiles.h"
#include "brew.h" #include "brew.h"
// ######################### VARIABLES ######################### // ######################### VARIABLES #########################
...@@ -39,15 +18,15 @@ eBeerProfile beerProfile; ...@@ -39,15 +18,15 @@ eBeerProfile beerProfile;
eMenuType eMenuType; eMenuType eMenuType;
MenuData mdMainMenu; MenuData mdMainMenu = { ._title = MENU_MAIN_TITLE, ._dialog = MENU_MAIN_DIALOG, ._position = MENU_MAIN_INIT_POSITION, ._selection = MENU_MAIN_INIT_SELECTION, ._repaint = MENU_MAIN_INIT_REPAINT };
MenuData mdStartFromStageMenu; MenuData mdStartFromStageMenu = { ._title = MENU_START_TITLE, ._dialog = MENU_START_DIALOG, ._position = MENU_START_INIT_POSITION, ._selection = MENU_START_INIT_SELECTION, ._repaint = MENU_START_INIT_REPAINT };
MenuData mdBeerProfileMenu; MenuData mdBeerProfileMenu = { ._title = MENU_PROFILE_TITLE, ._dialog = MENU_PROFILE_DIALOG, ._position = MENU_PROFILE_INIT_POSITION, ._selection = MENU_PROFILE_INIT_SELECTION, ._repaint = MENU_PROFILE_INIT_REPAINT };
MenuData mdStageMenu; MenuData mdStageMenu = { ._title = MENU_STAGE_TITLE, ._dialog = MENU_STAGE_DIALOG, ._position = MENU_STAGE_INIT_POSITION, ._selection = MENU_STAGE_INIT_SELECTION, ._repaint = MENU_STAGE_INIT_REPAINT };
MenuData mdMaltMenu; MenuData mdMaltMenu = { ._title = MENU_MALT_TITLE, ._dialog = MENU_MALT_DIALOG, ._position = MENU_MALT_INIT_POSITION, ._selection = MENU_MALT_INIT_SELECTION, ._repaint = MENU_MALT_INIT_REPAINT };
MenuData mdSettingsMenu; MenuData mdSettingsMenu = { ._title = MENU_SETTINGS_TITLE, ._dialog = MENU_SETTINGS_DIALOG, ._position = MENU_SETTINGS_INIT_POSITION, ._selection = MENU_SETTINGS_INIT_SELECTION, ._repaint = MENU_SETTINGS_INIT_REPAINT };
eMainMenuOptions eMainMenuPosition; //eMainMenuOptions eMainMenuPosition;
eMainMenuOptions eMainMenuSelection; //eMainMenuOptions eMainMenuSelection;
eStageMenuOptions eStartFromStageMenuPosition; eStageMenuOptions eStartFromStageMenuPosition;
eStageMenuOptions eStartFromStageMenuSelection; eStageMenuOptions eStartFromStageMenuSelection;
eBeerProfileMenuOptions eBeerProfileMenuPosition; eBeerProfileMenuOptions eBeerProfileMenuPosition;
...@@ -158,7 +137,7 @@ void isr () { // Interrupt service routine is executed when a HIGH to LOW tr ...@@ -158,7 +137,7 @@ void isr () { // Interrupt service routine is executed when a HIGH to LOW tr
if (diff > ROTARY_ENCODER_DEBOUNCE_TIME) { if (diff > ROTARY_ENCODER_DEBOUNCE_TIME) {
lastInterruptTime = interruptTime; lastInterruptTime = interruptTime;
switch(rotaryEncoderMode) { switch (rotaryEncoderMode) {
// Input of rotary encoder controling menus // Input of rotary encoder controling menus
case eRotaryEncoderMode_Menu: { case eRotaryEncoderMode_Menu: {
if (!digitalRead(ROTARY_ENCODER_DT_PIN)) { if (!digitalRead(ROTARY_ENCODER_DT_PIN)) {
...@@ -180,7 +159,7 @@ void isr () { // Interrupt service routine is executed when a HIGH to LOW tr ...@@ -180,7 +159,7 @@ void isr () { // Interrupt service routine is executed when a HIGH to LOW tr
// Input of rotary encoder controling time variables // Input of rotary encoder controling time variables
case eRotaryEncoderMode_Time: { case eRotaryEncoderMode_Time: {
if (!digitalRead(ROTARY_ENCODER_DT_PIN)) { if (!digitalRead(ROTARY_ENCODER_DT_PIN)) {
if(rotaryEncoderVirtualPosition >= 60) { if (rotaryEncoderVirtualPosition >= 60) {
rotaryEncoderVirtualPosition = (rotaryEncoderVirtualPosition + rotaryEncoderMultiStep); rotaryEncoderVirtualPosition = (rotaryEncoderVirtualPosition + rotaryEncoderMultiStep);
} }
else { else {
...@@ -188,11 +167,11 @@ void isr () { // Interrupt service routine is executed when a HIGH to LOW tr ...@@ -188,11 +167,11 @@ void isr () { // Interrupt service routine is executed when a HIGH to LOW tr
} }
} }
else { else {
if(rotaryEncoderVirtualPosition == rotaryEncoderMinPosition) { if (rotaryEncoderVirtualPosition == rotaryEncoderMinPosition) {
rotaryEncoderVirtualPosition = (rotaryEncoderVirtualPosition + 60); rotaryEncoderVirtualPosition = (rotaryEncoderVirtualPosition + 60);
} }
else { else {
if(rotaryEncoderVirtualPosition >= (60 + rotaryEncoderMultiStep)) { if (rotaryEncoderVirtualPosition >= (60 + rotaryEncoderMultiStep)) {
rotaryEncoderVirtualPosition = (rotaryEncoderVirtualPosition - rotaryEncoderMultiStep); rotaryEncoderVirtualPosition = (rotaryEncoderVirtualPosition - rotaryEncoderMultiStep);
} }
else { else {
...@@ -238,12 +217,12 @@ void isr () { // Interrupt service routine is executed when a HIGH to LOW tr ...@@ -238,12 +217,12 @@ void isr () { // Interrupt service routine is executed when a HIGH to LOW tr
} }
void xSetupRotaryEncoder( eRotaryEncoderMode 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;
if( newMinPosition >= 0 ) rotaryEncoderMinPosition = newMinPosition; if ( newMinPosition >= 0 ) rotaryEncoderMinPosition = newMinPosition;
if( newSingleStep >= 0 ) rotaryEncoderSingleStep = newSingleStep; if ( newSingleStep >= 0 ) rotaryEncoderSingleStep = newSingleStep;
if( newMultiStep >= 0 ) rotaryEncoderMultiStep = newMultiStep; if ( newMultiStep >= 0 ) rotaryEncoderMultiStep = newMultiStep;
} }
// ######################### START ######################### // ######################### START #########################
...@@ -276,9 +255,11 @@ void xWelcomeUser() { ...@@ -276,9 +255,11 @@ void xWelcomeUser() {
//#endif //#endif
} }
const char *_dialogs[] = {"", "b"};
void setup() { void setup() {
// ++++++++++++++++++++++++ Rotary Encoder ++++++++++++++++++++++++ // ++++++++++++++++++++++++ Rotary Encoder ++++++++++++++++++++++++
pinMode (ROTARY_ENCODER_CLK_PIN,INPUT); pinMode (ROTARY_ENCODER_CLK_PIN, INPUT);
pinMode (ROTARY_ENCODER_DT_PIN, INPUT); pinMode (ROTARY_ENCODER_DT_PIN, INPUT);
pinMode (ROTARY_ENCODER_SW_PIN, INPUT); pinMode (ROTARY_ENCODER_SW_PIN, INPUT);
attachInterrupt (ROTARY_ENCODER_INTERRUPT_NUMBER, isr, FALLING); attachInterrupt (ROTARY_ENCODER_INTERRUPT_NUMBER, isr, FALLING);
...@@ -307,8 +288,8 @@ void setup() { ...@@ -307,8 +288,8 @@ void setup() {
Serial.println (SETTING_SERIAL_MONITOR_WELCOME_MESSAGE); // print a start message to the terminal Serial.println (SETTING_SERIAL_MONITOR_WELCOME_MESSAGE); // print a start message to the terminal
// ++++++++++++++++++++++++ Library - LiquidCrystal_I2C ++++++++++++++++++++++++ // ++++++++++++++++++++++++ Library - LiquidCrystal_I2C ++++++++++++++++++++++++
lcd.begin (LCD_HORIZONTAL_RESOLUTION,LCD_VERTICAL_RESOLUTION); // <<----- My LCD was 16x2 lcd.begin (LCD_HORIZONTAL_RESOLUTION, LCD_VERTICAL_RESOLUTION); // <<----- My LCD was 16x2
lcd.setBacklightPin (LCD_BACKLIGHT_PIN,POSITIVE); // Setup backlight pin lcd.setBacklightPin (LCD_BACKLIGHT_PIN, POSITIVE); // Setup backlight pin
lcd.setBacklight (HIGH); // Switch on the backlight lcd.setBacklight (HIGH); // Switch on the backlight
// ######################### INITIALIZE ######################### // ######################### INITIALIZE #########################
...@@ -320,11 +301,8 @@ void setup() { ...@@ -320,11 +301,8 @@ void setup() {
// ++++++++++++++++++++++++ State Machine ++++++++++++++++++++++++ // ++++++++++++++++++++++++ State Machine ++++++++++++++++++++++++
eMenuType = eMenuType_Main; eMenuType = eMenuType_Main;
mdMainMenu._position = eMainMenu_GO; //eMainMenuPosition = MENU_MAIN_INIT_POSITION;
mdMainMenu._selection = eMainMenu_NULL; //eMainMenuSelection = MENU_MAIN_INIT_SELECTION;
eMainMenuPosition = eMainMenu_GO;
eMainMenuSelection = eMainMenu_NULL;
eBeerProfileMenuPosition = eBeerProfileMenu_Basic; eBeerProfileMenuPosition = eBeerProfileMenu_Basic;
eBeerProfileMenuSelection = eBeerProfileMenu_NULL; eBeerProfileMenuSelection = eBeerProfileMenu_NULL;
eStageMenuPosition = eStageMenu_Startpoint; eStageMenuPosition = eStageMenu_Startpoint;
...@@ -400,8 +378,8 @@ void setup() { ...@@ -400,8 +378,8 @@ void setup() {
void loop() { void loop() {
unsigned long inactivityTime = getInactivityTime(); unsigned long inactivityTime = getInactivityTime();
if( inactivityTime > SETTING_MAX_INACTIVITY_TIME ) { // Inactivity check if ( inactivityTime > SETTING_MAX_INACTIVITY_TIME ) { // Inactivity check
if(refresh) { if (refresh) {
repaint = true; repaint = true;
refresh = false; refresh = false;
} }
...@@ -417,24 +395,28 @@ void loop() { ...@@ -417,24 +395,28 @@ void loop() {
// ######################### FUNCTIONS ######################## // ######################### FUNCTIONS ########################
void runMenu() { void runMenu() {
#ifdef DEBUG_OFF #ifdef DEBUG_OFF
boolean debug_go = repaint; boolean debug_go = repaint;
if(debug_go) { if (debug_go) {
debugPrintFunction("runMenu"); debugPrintFunction("runMenu");
debugPrintVar("repaint", repaint); debugPrintVar("repaint", repaint);
debugPrintVar("eMenuType", eMenuType); debugPrintVar("eMenuType", eMenuType);
debugPrintVar("rotaryEncoderVirtualPosition", rotaryEncoderVirtualPosition); debugPrintVar("rotaryEncoderVirtualPosition", rotaryEncoderVirtualPosition);
} }
#endif #endif
switch(eMenuType) { switch (eMenuType) {
case eMenuType_Main: { case eMenuType_Main: {
eMainMenuPosition = static_cast<eMainMenuOptions>(rotaryEncoderVirtualPosition); //eMainMenuPosition = static_cast<eMainMenuOptions>(rotaryEncoderVirtualPosition);
mdMainMenu._position = rotaryEncoderVirtualPosition;
repaint = displayMainMenu( &lcd, eMainMenuPosition, repaint ); mdMainMenu._repaint = repaint;
repaint = displayGenericMenu( &lcd, &mdMainMenu );
//repaint = displayMainMenu( &lcd, eMainMenuPosition, repaint );
if ( gotButtonPress( ROTARY_ENCODER_SW_PIN ) ) { if ( gotButtonPress( ROTARY_ENCODER_SW_PIN ) ) {
eMainMenuSelection = eMainMenuPosition; mdMainMenu._selection = mdMainMenu._position;
//eMainMenuSelection = eMainMenuPosition;
} }
runMainMenuSelection(); runMainMenuSelection();
...@@ -508,18 +490,18 @@ void runMenu() { ...@@ -508,18 +490,18 @@ void runMenu() {
} }
} }
#ifdef DEBUG_OFF #ifdef DEBUG_OFF
if(debug_go) { if (debug_go) {
debugPrintVar("repaint", repaint); debugPrintVar("repaint", repaint);
} }
#endif #endif
} }
void runSettingsSelection() { void runSettingsSelection() {
switch(eSettingsMenuSelection) { switch (eSettingsMenuSelection) {
case eSettingsMenu_Pump: { case eSettingsMenu_Pump: {
// Stuff // Stuff
if( xSetGenericValue( iPumpSpeed?0:1, 0, 1, "pump", "bool" ) ) { if ( xSetGenericValue( iPumpSpeed ? 0 : 1, 0, 1, "pump", "bool" ) ) {
iPumpSpeed = PUMP_SPEED_MAX_MOSFET; iPumpSpeed = PUMP_SPEED_MAX_MOSFET;
} else { } else {
iPumpSpeed = PUMP_SPEED_STOP_MOSFET; iPumpSpeed = PUMP_SPEED_STOP_MOSFET;
...@@ -556,7 +538,8 @@ void runSettingsSelection() { ...@@ -556,7 +538,8 @@ void runSettingsSelection() {
repaint = true; repaint = true;
// reset operation state | INPUT : eRotaryEncoderMode 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, eMainMenuPosition, MENU_SIZE_MAIN_MENU - 1, 1, 1, 0 ); //xSetupRotaryEncoder( eRotaryEncoderMode_Menu, eMainMenuPosition, MENU_SIZE_MAIN_MENU - 1, 1, 1, 0 );
xSetupRotaryEncoder( eRotaryEncoderMode_Menu, mdMainMenu._position, MENU_SIZE_MAIN_MENU - 1, 1, 1, 0 );
break; break;
} }
...@@ -568,7 +551,7 @@ void runSettingsSelection() { ...@@ -568,7 +551,7 @@ void runSettingsSelection() {
} }
void runMaltSelection() { void runMaltSelection() {
switch(eMaltMenuSelection) { switch (eMaltMenuSelection) {
case eMaltMenu_CastleMalting_Chteau_Pilsen_2RS: { case eMaltMenu_CastleMalting_Chteau_Pilsen_2RS: {
// Stuff // Stuff
...@@ -588,7 +571,8 @@ void runMaltSelection() { ...@@ -588,7 +571,8 @@ void runMaltSelection() {
repaint = true; repaint = true;
// reset operation state | INPUT : eRotaryEncoderMode 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, eMainMenuPosition, MENU_SIZE_MAIN_MENU - 1, 1, 1, 0 ); //xSetupRotaryEncoder( eRotaryEncoderMode_Menu, eMainMenuPosition, MENU_SIZE_MAIN_MENU - 1, 1, 1, 0 );
xSetupRotaryEncoder( eRotaryEncoderMode_Menu, mdMainMenu._position, MENU_SIZE_MAIN_MENU - 1, 1, 1, 0 );
break; break;
} }
...@@ -600,7 +584,7 @@ void runMaltSelection() { ...@@ -600,7 +584,7 @@ void runMaltSelection() {
} }
void runStageSelection() { void runStageSelection() {
switch(eStageMenuSelection) { switch (eStageMenuSelection) {
case eStageMenu_Startpoint: { case eStageMenu_Startpoint: {
startpointTime = getTimer( startpointTime ); startpointTime = getTimer( startpointTime );
...@@ -705,7 +689,8 @@ void runStageSelection() { ...@@ -705,7 +689,8 @@ void runStageSelection() {
repaint = true; repaint = true;
// reset operation state | INPUT : eRotaryEncoderMode 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, eMainMenuPosition, MENU_SIZE_MAIN_MENU - 1, 1, 1, 0 ); //xSetupRotaryEncoder( eRotaryEncoderMode_Menu, eMainMenuPosition, MENU_SIZE_MAIN_MENU - 1, 1, 1, 0 );
xSetupRotaryEncoder( eRotaryEncoderMode_Menu, mdMainMenu._position, MENU_SIZE_MAIN_MENU - 1, 1, 1, 0 );
break; break;
} }
...@@ -717,7 +702,7 @@ void runStageSelection() { ...@@ -717,7 +702,7 @@ void runStageSelection() {
} }
void runBeerProfileSelection() { void runBeerProfileSelection() {
switch(eBeerProfileMenuSelection) { switch (eBeerProfileMenuSelection) {
case eBeerProfileMenu_Basic: { case eBeerProfileMenu_Basic: {
beerProfile = eBeerProfile_Basic; beerProfile = eBeerProfile_Basic;
...@@ -940,7 +925,8 @@ void runBeerProfileSelection() { ...@@ -940,7 +925,8 @@ void runBeerProfileSelection() {
repaint = true; repaint = true;
// reset operation state | INPUT : eRotaryEncoderMode 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, eMainMenuPosition, MENU_SIZE_MAIN_MENU - 1, 1, 1, 0 ); //xSetupRotaryEncoder( eRotaryEncoderMode_Menu, eMainMenuPosition, MENU_SIZE_MAIN_MENU - 1, 1, 1, 0 );
xSetupRotaryEncoder( eRotaryEncoderMode_Menu, mdMainMenu._position, MENU_SIZE_MAIN_MENU - 1, 1, 1, 0 );
break; break;
} }
...@@ -954,10 +940,18 @@ void runBeerProfileSelection() { ...@@ -954,10 +940,18 @@ void runBeerProfileSelection() {
void xStartStage( unsigned long *stageTime, int *stageTemperature, eCookingStages nextStage, bool bPurgePump, bool bSetFinalYield, bool bSetTime, bool bSetTemperature ) { void xStartStage( unsigned long *stageTime, int *stageTemperature, eCookingStages nextStage, bool bPurgePump, bool bSetFinalYield, bool bSetTime, bool bSetTemperature ) {
xSafeHardwarePowerOff(); // Stop anything that might be still going on xSafeHardwarePowerOff(); // Stop anything that might be still going on
if(bSetFinalYield) { finalYield = xSetFinalYield( finalYield ); } if (bSetFinalYield) {
if(bSetTime) { (*stageTime) = getTimer( clockCounter/1000, (*stageTime) ); } finalYield = xSetFinalYield( finalYield );
if(bSetTemperature) { (*stageTemperature) = xSetTemperature( (*stageTemperature) ); } }
if(bPurgePump) { xPurgePump(); } if (bSetTime) {
(*stageTime) = getTimer( clockCounter / 1000, (*stageTime) );
}
if (bSetTemperature) {
(*stageTemperature) = xSetTemperature( (*stageTemperature) );
}
if (bPurgePump) {
xPurgePump();
}
startBrewing(); startBrewing();
xSetupStage( nextStage ); xSetupStage( nextStage );
...@@ -973,7 +967,7 @@ void xStartStageInteractive( unsigned long *stageTime, int *stageTemperature, eC ...@@ -973,7 +967,7 @@ void xStartStageInteractive( unsigned long *stageTime, int *stageTemperature, eC
} }
void runStartFromStageSelection() { void runStartFromStageSelection() {
switch(eStartFromStageMenuSelection) { switch (eStartFromStageMenuSelection) {
case eStageMenu_Startpoint: { case eStageMenu_Startpoint: {
xStartStageInteractive( &startpointTime, &startpointTemperature, eCookingStage_Startpoint ); xStartStageInteractive( &startpointTime, &startpointTemperature, eCookingStage_Startpoint );
break; break;
...@@ -1029,7 +1023,8 @@ void runStartFromStageSelection() { ...@@ -1029,7 +1023,8 @@ void runStartFromStageSelection() {
} }
void runMainMenuSelection() { void runMainMenuSelection() {
switch(eMainMenuSelection) { switch (mdMainMenu._selection) {
//switch (eMainMenuSelection) {
case eMainMenu_GO: { case eMainMenu_GO: {
xStartStage( NULL, NULL, eCookingStage_Startpoint, true, true, false, false ); xStartStage( NULL, NULL, eCookingStage_Startpoint, true, true, false, false );
break; break;
...@@ -1093,7 +1088,8 @@ void runMainMenuSelection() { ...@@ -1093,7 +1088,8 @@ void runMainMenuSelection() {
default: { default: {
} }
} }
eMainMenuSelection = eMainMenu_NULL; mdMainMenu._selection = eMainMenu_NULL;
//eMainMenuSelection = eMainMenu_NULL;
} }
void xCountTheTime( int temperatureMarginRange, boolean bMaximumOfUpDown ) { void xCountTheTime( int temperatureMarginRange, boolean bMaximumOfUpDown ) {
...@@ -1101,10 +1097,10 @@ void xCountTheTime( int temperatureMarginRange, boolean bMaximumOfUpDown ) { ...@@ -1101,10 +1097,10 @@ void xCountTheTime( int temperatureMarginRange, boolean bMaximumOfUpDown ) {
// Get current maximum sensed temperaure // Get current maximum sensed temperaure
double temperatureCount = 0; double temperatureCount = 0;
if( bMaximumOfUpDown ) { if ( bMaximumOfUpDown ) {
float tup = upPT100.getCurrentTemperature(); float tup = upPT100.getCurrentTemperature();
float tdown = downPT100.getCurrentTemperature(); float tdown = downPT100.getCurrentTemperature();
if(tup > tdown) { if (tup > tdown) {
temperatureCount = tdown; temperatureCount = tdown;
} }
else { else {
...@@ -1116,7 +1112,7 @@ void xCountTheTime( int temperatureMarginRange, boolean bMaximumOfUpDown ) { ...@@ -1116,7 +1112,7 @@ void xCountTheTime( int temperatureMarginRange, boolean bMaximumOfUpDown ) {
// Ignote time ticks if temperature is not within the acceptable margin for this stage // Ignote time ticks if temperature is not within the acceptable margin for this stage
unsigned long elapsedTime = now - clockLastUpdate; unsigned long elapsedTime = now - clockLastUpdate;
if( temperatureCount < (cookTemperature - temperatureMarginRange) ) { if ( temperatureCount < (cookTemperature - temperatureMarginRange) ) {
clockIgnore += elapsedTime; clockIgnore += elapsedTime;
} }
...@@ -1130,18 +1126,18 @@ void xCountTheTime( int temperatureMarginRange, boolean bMaximumOfUpDown ) { ...@@ -1130,18 +1126,18 @@ void xCountTheTime( int temperatureMarginRange, boolean bMaximumOfUpDown ) {
clockLastUpdate = now; clockLastUpdate = now;
#ifdef DEBUG_OFF #ifdef DEBUG_OFF
debugPrintFunction("xCountTheTime"); debugPrintFunction("xCountTheTime");
debugPrintVar("millis()", now); debugPrintVar("millis()", now);
debugPrintVar("cookTime", cookTime); debugPrintVar("cookTime", cookTime);
debugPrintVar("clockStartTime", clockStartTime); debugPrintVar("clockStartTime", clockStartTime);
debugPrintVar("clockIgnore", clockIgnore); debugPrintVar("clockIgnore", clockIgnore);
debugPrintVar("clockCounter", clockCounter); debugPrintVar("clockCounter", clockCounter);
#endif #endif
} }
bool isTimeLeft() { bool isTimeLeft() {
if( clockCounter > 0 ) { if ( clockCounter > 0 ) {
return true; return true;
} }
return false; return false;
...@@ -1162,19 +1158,19 @@ bool xRegulateTemperature( boolean bMaximumOfUpDown ) { ...@@ -1162,19 +1158,19 @@ bool xRegulateTemperature( boolean bMaximumOfUpDown ) {
float tdown = downPT100.getCurrentTemperature(); float tdown = downPT100.getCurrentTemperature();
float tbase = basePT100.getCurrentTemperature(); float tbase = basePT100.getCurrentTemperature();
if( bMaximumOfUpDown ) { if ( bMaximumOfUpDown ) {
if(tup > tdown) { if (tup > tdown) {
difference = cookTemperature - tup; difference = cookTemperature - tup;
} }
else { else {
difference = cookTemperature - tdown; difference = cookTemperature - tdown;
} }
if(tbase > cookTemperature && (tbase >= (PUMP_TEMPERATURE_MAX_OPERATION - 2.0) || difference >= 5.0)) { if (tbase > cookTemperature && (tbase >= (PUMP_TEMPERATURE_MAX_OPERATION - 2.0) || difference >= 5.0)) {
difference = cookTemperature - tbase; difference = cookTemperature - tbase;
} }
if( (tbase < cookTemperature) && (difference < (cookTemperature - tbase)) ) { if ( (tbase < cookTemperature) && (difference < (cookTemperature - tbase)) ) {
difference = cookTemperature - tbase; difference = cookTemperature - tbase;
} }
} else { } else {
...@@ -1182,13 +1178,13 @@ bool xRegulateTemperature( boolean bMaximumOfUpDown ) { ...@@ -1182,13 +1178,13 @@ bool xRegulateTemperature( boolean bMaximumOfUpDown ) {
} }
// Deviation between the cook temperature set and the cook temperature measured // Deviation between the cook temperature set and the cook temperature measured
if( difference < 0.0 ) { if ( difference < 0.0 ) {
difference = difference * (-1.0); difference = difference * (-1.0);
overTemperature = true; overTemperature = true;
} }
// 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 // turn it off
wattage = 0.0; wattage = 0.0;
} else { } else {
...@@ -1196,13 +1192,13 @@ bool xRegulateTemperature( boolean bMaximumOfUpDown ) { ...@@ -1196,13 +1192,13 @@ bool xRegulateTemperature( boolean bMaximumOfUpDown ) {
// turn it off // turn it off
// wattage = 0.0; // wattage = 0.0;
//} else { //} else {
if(difference <= 0.5) { if (difference <= 0.5) {
// pulse lightly at 500 watt // pulse lightly at 500 watt
if(cookTemperature > 99.0) { if (cookTemperature > 99.0) {
wattage = 2000.0; wattage = 2000.0;
} }
else { else {
if(cookTemperature > 70.0) { if (cookTemperature > 70.0) {
wattage = 1000.0; wattage = 1000.0;
} }
else { else {
...@@ -1210,9 +1206,9 @@ bool xRegulateTemperature( boolean bMaximumOfUpDown ) { ...@@ -1210,9 +1206,9 @@ bool xRegulateTemperature( boolean bMaximumOfUpDown ) {
} }
} }
} else { } else {
if(difference <= 1.0) { if (difference <= 1.0) {
// pulse moderately at 1000 watt // pulse moderately at 1000 watt
if(cookTemperature > 99.0) { if (cookTemperature > 99.0) {
wattage = 2000.0; wattage = 2000.0;
} }
else { else {
...@@ -1220,7 +1216,7 @@ bool xRegulateTemperature( boolean bMaximumOfUpDown ) { ...@@ -1220,7 +1216,7 @@ bool xRegulateTemperature( boolean bMaximumOfUpDown ) {
} }
} else { } else {
if(difference <= 3.0) { if (difference <= 3.0) {
// pulse hardly at 2000 watt // pulse hardly at 2000 watt
wattage = 2000.0; wattage = 2000.0;
} else { } else {
...@@ -1233,20 +1229,20 @@ bool xRegulateTemperature( boolean bMaximumOfUpDown ) { ...@@ -1233,20 +1229,20 @@ bool xRegulateTemperature( boolean bMaximumOfUpDown ) {
} }
// 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) > iWindowSize) { // 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 += iWindowSize; windowStartTime += iWindowSize;
} }
// Apply wattage to the element at the right time // Apply wattage to the element at the right time
if( ulWattToWindowTime( wattage ) > (millis() - windowStartTime) ) { if ( ulWattToWindowTime( wattage ) > (millis() - windowStartTime) ) {
digitalWrite(HEATING_ELEMENT_OUTPUT_PIN,HIGH); digitalWrite(HEATING_ELEMENT_OUTPUT_PIN, HIGH);
bStatusElement = true; bStatusElement = true;
} else { } else {
digitalWrite(HEATING_ELEMENT_OUTPUT_PIN,LOW); digitalWrite(HEATING_ELEMENT_OUTPUT_PIN, LOW);
bStatusElement = false; bStatusElement = false;
} }
#ifdef DEBUG_OFF #ifdef DEBUG_OFF
//debugPrintFunction("xRegulateTemperature"); //debugPrintFunction("xRegulateTemperature");
debugPrintVar("difference", difference); debugPrintVar("difference", difference);
//debugPrintVar("overTemperature", overTemperature); //debugPrintVar("overTemperature", overTemperature);
...@@ -1255,11 +1251,11 @@ bool xRegulateTemperature( boolean bMaximumOfUpDown ) { ...@@ -1255,11 +1251,11 @@ bool xRegulateTemperature( boolean bMaximumOfUpDown ) {
//debugPrintVar("millis()", millis()); //debugPrintVar("millis()", millis());
//debugPrintVar("windowStartTime", windowStartTime); //debugPrintVar("windowStartTime", windowStartTime);
//debugPrintVar("test", ulWattToWindowTime( wattage ) > (millis() - windowStartTime) ); //debugPrintVar("test", ulWattToWindowTime( wattage ) > (millis() - windowStartTime) );
#endif #endif
} }
void xPurgePump() { void xPurgePump() {
for(int i = 0; i < 2; i++) { for (int i = 0; i < 2; i++) {
analogWrite(PUMP_PIN, PUMP_SPEED_MAX_MOSFET); // analogWrite values from 0 to 255 analogWrite(PUMP_PIN, PUMP_SPEED_MAX_MOSFET); // analogWrite values from 0 to 255
delay(1000); delay(1000);
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
...@@ -1270,7 +1266,7 @@ void xPurgePump() { ...@@ -1270,7 +1266,7 @@ void xPurgePump() {
bool xRegulatePumpSpeed() { bool xRegulatePumpSpeed() {
// 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
basePT100.setPumpStatus( false ); basePT100.setPumpStatus( false );
...@@ -1295,10 +1291,10 @@ void xWarnCookEnded() { ...@@ -1295,10 +1291,10 @@ void xWarnCookEnded() {
} }
void xPrepareForStage( int stageTime, int stageTemperature, int stagePumpSpeed, eCookingStages stage ) { void xPrepareForStage( int stageTime, int stageTemperature, int stagePumpSpeed, eCookingStages stage ) {
#ifdef DEBUG_OFF #ifdef DEBUG_OFF
debugPrintFunction("xPrepareForStage"); debugPrintFunction("xPrepareForStage");
debugPrintVar("cookingStage", stage); debugPrintVar("cookingStage", stage);
#endif #endif
// Reset the clock // Reset the clock
unsigned long now = millis(); unsigned long now = millis();
...@@ -1313,15 +1309,15 @@ void xPrepareForStage( int stageTime, int stageTemperature, int stagePumpSpeed, ...@@ -1313,15 +1309,15 @@ void xPrepareForStage( int stageTime, int stageTemperature, int stagePumpSpeed,
} }
void xSetupStage(eCookingStages nextStage) { void xSetupStage(eCookingStages nextStage) {
#ifdef DEBUG_OFF #ifdef DEBUG_OFF
debugPrintFunction("xSetupStage"); debugPrintFunction("xSetupStage");
debugPrintVar("cookingStage", nextStage); debugPrintVar("cookingStage", nextStage);
#endif #endif
// Operate the machine according to the current mode // Operate the machine according to the current mode
switch(nextStage) { switch (nextStage) {
case eCookingStage_Startpoint: { case eCookingStage_Startpoint: {
switch(beerProfile) { switch (beerProfile) {
case eBeerProfile_Trigo: { case eBeerProfile_Trigo: {
float wheatAmount = 0.05 * ((float) finalYield); float wheatAmount = 0.05 * ((float) finalYield);
float pilsnerAmount = 0.2 * ((float) finalYield); float pilsnerAmount = 0.2 * ((float) finalYield);
...@@ -1367,7 +1363,7 @@ void xSetupStage(eCookingStages nextStage) { ...@@ -1367,7 +1363,7 @@ void xSetupStage(eCookingStages nextStage) {
break; break;
} }
case eCookingStage_BetaGlucanase: { case eCookingStage_BetaGlucanase: {
switch(beerProfile) { switch (beerProfile) {
case eBeerProfile_Trigo: { case eBeerProfile_Trigo: {
float wheatAmount = 0.05 * ((float) finalYield); float wheatAmount = 0.05 * ((float) finalYield);
float pilsnerAmount = 0.2 * ((float) finalYield); float pilsnerAmount = 0.2 * ((float) finalYield);
...@@ -1438,7 +1434,7 @@ void xSetupStage(eCookingStages nextStage) { ...@@ -1438,7 +1434,7 @@ void xSetupStage(eCookingStages nextStage) {
break; break;
} }
case eCookingStage_Boil: { case eCookingStage_Boil: {
switch(beerProfile) { switch (beerProfile) {
case eBeerProfile_Trigo: { case eBeerProfile_Trigo: {
String say = "Get "; String say = "Get ";
...@@ -1532,13 +1528,13 @@ void xTransitionIntoStage(eCookingStages nextStage) { ...@@ -1532,13 +1528,13 @@ void xTransitionIntoStage(eCookingStages nextStage) {
void xBasicStageOperation( int iStageTime, int iStageTemperature, int iStageTemperatureRange, eCookingStages nextStage, boolean bMaximumOfUpDown ) { void xBasicStageOperation( int iStageTime, int iStageTemperature, int iStageTemperatureRange, eCookingStages nextStage, boolean bMaximumOfUpDown ) {
// Account for time spent at the target temperature | Input 1: range in ºC within which the target temperature is considered to be reached // Account for time spent at the target temperature | Input 1: range in ºC within which the target temperature is considered to be reached
#ifdef DEBUG_OFF #ifdef DEBUG_OFF
xCountTheTime( iStageTemperatureRange, false ); xCountTheTime( iStageTemperatureRange, false );
#else #else
xCountTheTime( iStageTemperatureRange, bMaximumOfUpDown ); xCountTheTime( iStageTemperatureRange, bMaximumOfUpDown );
#endif #endif
if( isTimeLeft() ) { if ( isTimeLeft() ) {
// Do temperature control // Do temperature control
xRegulateTemperature( bMaximumOfUpDown ); xRegulateTemperature( bMaximumOfUpDown );
...@@ -1546,10 +1542,10 @@ void xBasicStageOperation( int iStageTime, int iStageTemperature, int iStageTemp ...@@ -1546,10 +1542,10 @@ void xBasicStageOperation( int iStageTime, int iStageTemperature, int iStageTemp
xRegulatePumpSpeed(); xRegulatePumpSpeed();
} else { } else {
#ifdef DEBUG_OFF #ifdef DEBUG_OFF
debugPrintFunction("xBasicStageOperation"); debugPrintFunction("xBasicStageOperation");
debugPrintVar("clockCounter", clockCounter); debugPrintVar("clockCounter", clockCounter);
#endif #endif
// Continue to the next stage, there is nothing to do, in this stage // Continue to the next stage, there is nothing to do, in this stage
xTransitionIntoStage( nextStage ); xTransitionIntoStage( nextStage );
...@@ -1561,10 +1557,10 @@ void xBasicStageOperation( int iStageTime, int iStageTemperature, int iStageTemp ...@@ -1561,10 +1557,10 @@ void xBasicStageOperation( int iStageTime, int iStageTemperature, int iStageTemp
void xManageMachineSystems() { void xManageMachineSystems() {
#ifdef DEBUG #ifdef DEBUG
Serial.print(millis()); Serial.print(millis());
Serial.print(","); Serial.print(",");
if(cooking) { if (cooking) {
Serial.print("1"); Serial.print("1");
} }
else { else {
...@@ -1573,14 +1569,14 @@ void xManageMachineSystems() { ...@@ -1573,14 +1569,14 @@ void xManageMachineSystems() {
Serial.print(","); Serial.print(",");
Serial.print(cookTemperature); Serial.print(cookTemperature);
Serial.print(","); Serial.print(",");
if(bStatusElement) { if (bStatusElement) {
Serial.print("1"); Serial.print("1");
} }
else { else {
Serial.print("0"); Serial.print("0");
} }
Serial.print(","); Serial.print(",");
#endif #endif
// Measure temperature, for effect // Measure temperature, for effect
basePT100.measure(false); basePT100.measure(false);
...@@ -1588,14 +1584,14 @@ void xManageMachineSystems() { ...@@ -1588,14 +1584,14 @@ void xManageMachineSystems() {
downPT100.measure(true); downPT100.measure(true);
// If cooking is done, return (this is a nice place to double check safety and ensure the cooking parts aren't on. // If cooking is done, return (this is a nice place to double check safety and ensure the cooking parts aren't on.
if(!cooking) { if (!cooking) {
xSafeHardwarePowerOff(); xSafeHardwarePowerOff();
return; return;
} }
// Operate the machine according to the current mode // Operate the machine according to the current mode
switch(cookingStage) { switch (cookingStage) {
case eCookingStage_Startpoint: { case eCookingStage_Startpoint: {
// A basic operation for a basic stage // A basic operation for a basic stage
xBasicStageOperation( startpointTime, startpointTemperature, 0, eCookingStage_BetaGlucanase, false); xBasicStageOperation( startpointTime, startpointTemperature, 0, eCookingStage_BetaGlucanase, false);
...@@ -1707,12 +1703,13 @@ void stopBrewing() { ...@@ -1707,12 +1703,13 @@ void stopBrewing() {
void resetMenu( boolean requestRepaintPaint ) { void resetMenu( boolean requestRepaintPaint ) {
eMenuType = eMenuType_Main; eMenuType = eMenuType_Main;
if( requestRepaintPaint ) { if ( requestRepaintPaint ) {
repaint = true; repaint = true;
} }
// reset operation state | INPUT : eRotaryEncoderMode 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, eMainMenuPosition, MENU_SIZE_MAIN_MENU - 1, 1, 1, 0 ); //xSetupRotaryEncoder( eRotaryEncoderMode_Menu, eMainMenuPosition, MENU_SIZE_MAIN_MENU - 1, 1, 1, 0 );
xSetupRotaryEncoder( eRotaryEncoderMode_Menu, mdMainMenu._position, MENU_SIZE_MAIN_MENU - 1, 1, 1, 0 );
} }
void backToStatus() { void backToStatus() {
...@@ -1735,19 +1732,19 @@ int getTimer( int initialValue, int defaultValue ) { ...@@ -1735,19 +1732,19 @@ int getTimer( int initialValue, int defaultValue ) {
lcd.clear(); lcd.clear();
lcd.home(); lcd.home();
lcd.print("Set Time ("); lcd.print("Set Time (");
minutes = defaultValue/60; minutes = defaultValue / 60;
lcd.print(minutes); lcd.print(minutes);
seconds = defaultValue-minutes*60; seconds = defaultValue - minutes * 60;
lcd.print(":"); lcd.print(":");
if(seconds<10) { if (seconds < 10) {
lcd.print("0"); lcd.print("0");
} }
lcd.print(seconds); lcd.print(seconds);
lcd.print(")"); lcd.print(")");
lcd.setCursor (0,LCD_VERTICAL_RESOLUTION-1); lcd.setCursor (0, LCD_VERTICAL_RESOLUTION - 1);
lcd.print(" 0:00"); lcd.print(" 0:00");
while(true) { while (true) {
// Check if pushbutton is pressed // Check if pushbutton is pressed
if ((digitalRead(ROTARY_ENCODER_SW_PIN))) { if ((digitalRead(ROTARY_ENCODER_SW_PIN))) {
// Wait until switch is released // Wait until switch is released
...@@ -1766,21 +1763,21 @@ int getTimer( int initialValue, int defaultValue ) { ...@@ -1766,21 +1763,21 @@ int getTimer( int initialValue, int defaultValue ) {
// display current timer // display current timer
if (rotaryEncoderVirtualPosition != rotaryEncoderPreviousPosition) { if (rotaryEncoderVirtualPosition != rotaryEncoderPreviousPosition) {
rotaryEncoderPreviousPosition = rotaryEncoderVirtualPosition; rotaryEncoderPreviousPosition = rotaryEncoderVirtualPosition;
minutes = rotaryEncoderVirtualPosition/60; minutes = rotaryEncoderVirtualPosition / 60;
seconds = rotaryEncoderVirtualPosition-minutes*60; seconds = rotaryEncoderVirtualPosition - minutes * 60;
lcd.setCursor (0,LCD_VERTICAL_RESOLUTION-1); lcd.setCursor (0, LCD_VERTICAL_RESOLUTION - 1);
if(minutes<100) { if (minutes < 100) {
lcd.print(" "); lcd.print(" ");
} }
if(minutes<10) { if (minutes < 10) {
lcd.print(" "); lcd.print(" ");
} }
lcd.print(" "); lcd.print(" ");
lcd.print(minutes); lcd.print(minutes);
lcd.print(":"); lcd.print(":");
if(seconds<10) { if (seconds < 10) {
lcd.print("0"); lcd.print("0");
} }
lcd.print(seconds); lcd.print(seconds);
...@@ -1808,12 +1805,12 @@ int getTemperature(int initialValue) { ...@@ -1808,12 +1805,12 @@ int getTemperature(int initialValue) {
lcd.clear(); lcd.clear();
lcd.home(); lcd.home();
lcd.print("Set Temperature"); lcd.print("Set Temperature");
lcd.setCursor (0,LCD_VERTICAL_RESOLUTION-1); lcd.setCursor (0, LCD_VERTICAL_RESOLUTION - 1);
lcd.print(" 0 *C"); lcd.print(" 0 *C");
rotaryEncoderMaxPosition = TEMPERATURE_SETTING_MAX_VALUE; rotaryEncoderMaxPosition = TEMPERATURE_SETTING_MAX_VALUE;
while(true) { while (true) {
// Check if pushbutton is pressed // Check if pushbutton is pressed
if ((digitalRead(ROTARY_ENCODER_SW_PIN))) { if ((digitalRead(ROTARY_ENCODER_SW_PIN))) {
// Wait until switch is released // Wait until switch is released
...@@ -1833,13 +1830,13 @@ int getTemperature(int initialValue) { ...@@ -1833,13 +1830,13 @@ int getTemperature(int initialValue) {
if (rotaryEncoderVirtualPosition != rotaryEncoderPreviousPosition) { if (rotaryEncoderVirtualPosition != rotaryEncoderPreviousPosition) {
rotaryEncoderPreviousPosition = rotaryEncoderVirtualPosition; rotaryEncoderPreviousPosition = rotaryEncoderVirtualPosition;
lcd.setCursor (0,LCD_VERTICAL_RESOLUTION-1); lcd.setCursor (0, LCD_VERTICAL_RESOLUTION - 1);
lcd.print(" "); lcd.print(" ");
if(rotaryEncoderVirtualPosition<10) { if (rotaryEncoderVirtualPosition < 10) {
lcd.print(" "); lcd.print(" ");
} }
else { else {
if(rotaryEncoderVirtualPosition<100) { if (rotaryEncoderVirtualPosition < 100) {
lcd.print(" "); lcd.print(" ");
} }
} }
...@@ -1868,7 +1865,7 @@ int xSetGenericValue(int initialValue, int minimumValue, int maximumValue, const ...@@ -1868,7 +1865,7 @@ int xSetGenericValue(int initialValue, int minimumValue, int maximumValue, const
lcd.print( " 0 " ); lcd.print( " 0 " );
lcd.print( unit ); lcd.print( unit );
while(true) { while (true) {
// Check if pushbutton is pressed // Check if pushbutton is pressed
if ( digitalRead(ROTARY_ENCODER_SW_PIN) ) { if ( digitalRead(ROTARY_ENCODER_SW_PIN) ) {
// Wait until switch is released // Wait until switch is released
...@@ -1885,16 +1882,16 @@ int xSetGenericValue(int initialValue, int minimumValue, int maximumValue, const ...@@ -1885,16 +1882,16 @@ int xSetGenericValue(int initialValue, int minimumValue, int maximumValue, const
} }
// Check if there was an update by the rotary encoder // Check if there was an update by the rotary encoder
if( rotaryEncoderVirtualPosition != rotaryEncoderPreviousPosition ) { if ( rotaryEncoderVirtualPosition != rotaryEncoderPreviousPosition ) {
rotaryEncoderPreviousPosition = rotaryEncoderVirtualPosition; rotaryEncoderPreviousPosition = rotaryEncoderVirtualPosition;
lcd.setCursor( 0, LCD_VERTICAL_RESOLUTION - 1 ); lcd.setCursor( 0, LCD_VERTICAL_RESOLUTION - 1 );
lcd.print( " " ); lcd.print( " " );
if( rotaryEncoderVirtualPosition < 10 ) { if ( rotaryEncoderVirtualPosition < 10 ) {
lcd.print( " " ); lcd.print( " " );
} }
else { else {
if( rotaryEncoderVirtualPosition < 100 ) { if ( rotaryEncoderVirtualPosition < 100 ) {
lcd.print( " " ); lcd.print( " " );
} }
} }
...@@ -1920,9 +1917,9 @@ unsigned long getInactivityTime() { ...@@ -1920,9 +1917,9 @@ unsigned long getInactivityTime() {
unsigned long now = millis(); unsigned long now = millis();
unsigned long rotaryEncoderInactivityTime = now - lastInterruptTime; unsigned long rotaryEncoderInactivityTime = now - lastInterruptTime;
if(rotaryEncoderInactivityTime > SETTING_MAX_INACTIVITY_TIME) { if (rotaryEncoderInactivityTime > SETTING_MAX_INACTIVITY_TIME) {
if (digitalRead(ROTARY_ENCODER_SW_PIN)) { if (digitalRead(ROTARY_ENCODER_SW_PIN)) {
while(digitalRead(ROTARY_ENCODER_SW_PIN)) { while (digitalRead(ROTARY_ENCODER_SW_PIN)) {
delay(ROTARY_ENCODER_SW_DEBOUNCE_TIME); delay(ROTARY_ENCODER_SW_DEBOUNCE_TIME);
} }
...@@ -1942,7 +1939,7 @@ unsigned long getInactivityTime() { ...@@ -1942,7 +1939,7 @@ unsigned long getInactivityTime() {
// ###################### Set Variables ################################################## // ###################### Set Variables ##################################################
void xWaitForAction(String title, String message) { void xWaitForAction(String title, String message) {
while(true) { while (true) {
// Check if pushbutton is pressed // Check if pushbutton is pressed
if ( digitalRead(ROTARY_ENCODER_SW_PIN) ) { if ( digitalRead(ROTARY_ENCODER_SW_PIN) ) {
// Wait until switch is released // Wait until switch is released
...@@ -1957,7 +1954,7 @@ void xWaitForAction(String title, String message) { ...@@ -1957,7 +1954,7 @@ void xWaitForAction(String title, String message) {
sing(BUZZ_1, PIEZO_PIN); sing(BUZZ_1, PIEZO_PIN);
// Print the message // Print the message
if(! lcdPrint(&lcd, title, message)) { if (! lcdPrint(&lcd, title, message)) {
break; break;
} }
} }
......
...@@ -89,6 +89,43 @@ ...@@ -89,6 +89,43 @@
#define MENU_SIZE_MALT_MENU 4 #define MENU_SIZE_MALT_MENU 4
#define MENU_SIZE_SETTINGS_MENU 6 #define MENU_SIZE_SETTINGS_MENU 6
// ++++++++++++++++++++++++ Menus ++++++++++++++++++++++++
#define MENU_MAIN_TITLE "Brewery Menu"
#define MENU_MAIN_DIALOG { "", "-> GO ", "-> GO from stage", "-> STOP ", "-> SKIP ", "-> BeerProfile ", "-> Stages ", "-> Malt ", "-> Hops ", "-> Clean ", "-> Purge ", "-> Settings ", "-> Back " }
#define MENU_MAIN_INIT_POSITION eMainMenu_GO
#define MENU_MAIN_INIT_SELECTION eMainMenu_NULL
#define MENU_MAIN_INIT_REPAINT false
#define MENU_PROFILE_TITLE "Profile Menu"
#define MENU_PROFILE_DIALOG {"", "-> Basic ", "-> Trigo ", "-> IPA ", "-> Belga ", "-> Red ", "-> APA ", "-> Custom ", "-> Back " }
#define MENU_PROFILE_INIT_POSITION eBeerProfileMenu_Basic
#define MENU_PROFILE_INIT_SELECTION eBeerProfileMenu_NULL
#define MENU_PROFILE_INIT_REPAINT false
#define MENU_STAGE_TITLE "Stage Menu"
#define MENU_STAGE_DIALOG {"", "-> Startpoint ", "-> BetaGlucanase", "-> Debranching ", "-> Proteolytic ", "-> Beta Amylase ", "-> Alpha Amylase", "-> Mashout ", "-> Recirculation", "-> Sparge ", "-> Boil ", "-> Cooling ", "-> Back " }
#define MENU_STAGE_INIT_POSITION eStageMenu_Startpoint
#define MENU_STAGE_INIT_SELECTION eStageMenu_NULL
#define MENU_STAGE_INIT_REPAINT false
#define MENU_MALT_TITLE "Malt Menu"
#define MENU_MALT_DIALOG {"", "-> CM Ch. Pilsen", "-> CM Wheat Blan", "-> Back " }
#define MENU_MALT_INIT_POSITION eMaltMenu_CastleMalting_Chteau_Pilsen_2RS
#define MENU_MALT_INIT_SELECTION eMaltMenu_NULL
#define MENU_MALT_INIT_REPAINT false
#define MENU_SETTINGS_TITLE "Settings Menu"
#define MENU_SETTINGS_DIALOG {"", "-> PT100 Element", "-> PT100 Up ", "-> PT100 Down ", "-> Back " }
#define MENU_SETTINGS_INIT_POSITION eSettingsMenu_PT100_Element
#define MENU_SETTINGS_INIT_SELECTION eSettingsMenu_NULL
#define MENU_SETTINGS_INIT_REPAINT false
#define MENU_START_TITLE MENU_STAGE_TITLE
#define MENU_START_DIALOG MENU_STAGE_DIALOG
#define MENU_START_INIT_POSITION MENU_STAGE_INIT_POSITION
#define MENU_START_INIT_SELECTION MENU_STAGE_INIT_SELECTION
#define MENU_START_INIT_REPAINT MENU_STAGE_INIT_REPAINT
// ++++++++++++++++++++++++ Serial Monotor ++++++++++++++++++++++++ // ++++++++++++++++++++++++ Serial Monotor ++++++++++++++++++++++++
#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!"
......
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