-
Notifications
You must be signed in to change notification settings - Fork 148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Display Menu (Buttons & Rotary Input) #498
Open
chris-dot-exe
wants to merge
12
commits into
rancilio-pid:master
Choose a base branch
from
chris-dot-exe:monoMenu
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+270
−4
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
91c1597
WIP - adjustments for MonoMenu
chris-dot-exe 9618496
WIP - adjustments for MonoMenu
chris-dot-exe 32e9082
Save functions; added more items; exit standby with display buttons; …
chris-dot-exe 4ca71b2
Updated to latest master of clever coffee.
chris-dot-exe a5a5cc8
code formatting
chris-dot-exe ab59aaa
corrected order of pidSettings Brew Pid and Back item.
chris-dot-exe d9edfb9
Readded usage of FEATURE_MENU
chris-dot-exe 6ac26a8
Added menu defines to userConfig_sample.h
chris-dot-exe 790aa5e
Adding rotary encoder
chris-dot-exe 53d3720
Removed unused variables
chris-dot-exe a547f98
Inverted triggered events on rotary rotation.
chris-dot-exe 15a2e2f
fix Brewcontrol check in display menu
LoQue90 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,3 +55,7 @@ void GPIOPin::setType(Type pinType) { | |
break; | ||
} | ||
} | ||
|
||
int GPIOPin::getPinNumber() const { | ||
return pin; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,219 @@ | ||
|
||
#pragma once | ||
|
||
#include <ESP32Encoder.h> | ||
#include <Menu.h> | ||
#include <button.h> | ||
#include <hardware/pinmapping.h> | ||
#include <icons/menuIcons.h> | ||
|
||
enum MENUINPUT { | ||
BUTTONS, | ||
ROTARY, | ||
}; | ||
|
||
Menu* menu; | ||
GPIOPin* menuEnterPin; | ||
GPIOPin* menuUpPin; | ||
GPIOPin* menuDownPin; | ||
ESP32Encoder encoder; | ||
QueueHandle_t button_events; | ||
button_event_t ev; | ||
|
||
int last = 0; | ||
|
||
void saveBrewTemp() { | ||
sysParaBrewSetpoint.setStorage(true); | ||
} | ||
|
||
void saveSteamTemp() { | ||
sysParaSteamSetpoint.setStorage(true); | ||
} | ||
|
||
void savePIDOn() { | ||
sysParaPidOn.setStorage(true); | ||
} | ||
|
||
void saveStandby() { | ||
sysParaStandbyModeOn.setStorage(true); | ||
} | ||
|
||
void saveStandbyTime() { | ||
sysParaStandbyModeTime.setStorage(true); | ||
} | ||
|
||
bool hasBrewControl() { | ||
return FEATURE_BREWCONTROL > 0; | ||
} | ||
|
||
bool hasScale() { | ||
return FEATURE_SCALE > 0; | ||
} | ||
|
||
bool hasSoftwareDetection() { | ||
return BREWDETECTION_TYPE == 1; | ||
} | ||
|
||
void menuInputInit() { | ||
switch (MENU_INPUT) { | ||
case MENUINPUT::BUTTONS: | ||
menuEnterPin = new GPIOPin(PIN_MENU_ENTER, GPIOPin::IN_PULLUP); | ||
menuUpPin = new GPIOPin(PIN_MENU_OUT_A, GPIOPin::IN_PULLUP); | ||
menuDownPin = new GPIOPin(PIN_MENU_OUT_B, GPIOPin::IN_PULLUP); | ||
|
||
button_events = pulled_button_init(PIN_BIT(menuEnterPin->getPinNumber()) | PIN_BIT(menuUpPin->getPinNumber()) | PIN_BIT(menuDownPin->getPinNumber()), GPIO_PULLUP_ONLY); | ||
break; | ||
case MENUINPUT::ROTARY: | ||
menuEnterPin = new GPIOPin(PIN_MENU_ENTER, GPIOPin::IN_PULLUP); | ||
menuUpPin = new GPIOPin(PIN_MENU_OUT_A, GPIOPin::IN_PULLUP); | ||
menuDownPin = new GPIOPin(PIN_MENU_OUT_B, GPIOPin::IN_PULLUP); | ||
|
||
button_events = pulled_button_init(PIN_BIT(menuEnterPin->getPinNumber()), GPIO_PULLUP_ONLY); | ||
|
||
encoder.useInternalWeakPullResistors = puType::up; | ||
encoder.attachFullQuad(PIN_MENU_OUT_A, PIN_MENU_OUT_B); | ||
encoder.setCount(0); | ||
|
||
break; | ||
default: | ||
break; | ||
} | ||
} | ||
|
||
void initMenu(U8G2& display) { | ||
menu = new Menu(display); | ||
|
||
menuInputInit(); | ||
|
||
/* Main Menu */ | ||
menu->AddInputItem("Brew Temp.", "Brew Temperature", "", "°C", BREW_SETPOINT_MIN, BREW_SETPOINT_MAX, saveBrewTemp, brewSetpoint, bitmap_icon_temp, 0.1, 0.5); | ||
menu->AddInputItem("Steam Temp.", "Steam Temperature", "", "°C", STEAM_SETPOINT_MIN, STEAM_SETPOINT_MAX, saveSteamTemp, steamSetpoint, bitmap_icon_steam, 0.1, 0.5); | ||
|
||
menu->AddToggleItem("PID", savePIDOn, reinterpret_cast<bool&>(pidON), bitmap_icon_pid); | ||
|
||
menu->SetEventHandler([&]() { | ||
if (xQueueReceive(button_events, &ev, 1 / portTICK_PERIOD_MS)) { | ||
if (ev.pin == menuEnterPin->getPinNumber()) { | ||
if (standbyModeRemainingTimeMillis == 0) { | ||
resetStandbyTimer(); | ||
display.setPowerSave(0); | ||
pidON = 1; | ||
if (steamON) { | ||
machineState = kSteam; | ||
} | ||
else if (isBrewDetected) { | ||
machineState = kBrew; | ||
} | ||
else { | ||
machineState = kPidDisabled; | ||
} | ||
return; | ||
} | ||
if (ev.event == EventState::STATE_DOWN) { | ||
resetStandbyTimer(); | ||
} | ||
menu->Event(EVENT_ENTER, EventState(ev.event)); | ||
} | ||
else { | ||
if (MENU_INPUT == MENUINPUT::BUTTONS) { | ||
if (ev.pin == menuUpPin->getPinNumber()) { | ||
resetStandbyTimer(); | ||
menu->Event(EVENT_UP, EventState(ev.event)); | ||
} | ||
else if (ev.pin == menuDownPin->getPinNumber()) { | ||
resetStandbyTimer(); | ||
menu->Event(EVENT_DOWN, EventState(ev.event)); | ||
} | ||
} | ||
} | ||
} | ||
if (MENU_INPUT == MENUINPUT::ROTARY) { | ||
int32_t pos = encoder.getCount() / ENCODER_CLICKS_PER_NOTCH; | ||
if (pos > last) { | ||
menu->Event(EVENT_UP, EventState(EventState::STATE_DOWN)); | ||
LOG(DEBUG, "Menu: Up\n"); | ||
menu->Event(EVENT_UP, EventState(EventState::STATE_UP)); | ||
} | ||
else if (pos < last) { | ||
menu->Event(EVENT_DOWN, EventState(EventState::STATE_DOWN)); | ||
LOG(DEBUG, "Menu: Down\n"); | ||
menu->Event(EVENT_DOWN, EventState(EventState::STATE_UP)); | ||
} | ||
|
||
last = pos; | ||
} | ||
}); | ||
|
||
/* Brew Weight & Time */ | ||
Menu* weightNTime = new Menu(display); | ||
weightNTime->AddInputItem("Brew by Time", "Brew Time", "", " s", BREW_TIME_MIN, BREW_TIME_MAX, []() { sysParaBrewTime.setStorage(true); }, brewTime, bitmap_icon_clock); | ||
weightNTime->AddInputItem("Brew by Weight", "Brew Weight", "", "g", WEIGHTSETPOINT_MIN, WEIGHTSETPOINT_MAX, []() { sysParaWeightSetpoint.setStorage(true); }, weightSetpoint, bitmap_icon_scale, hasScale()); | ||
weightNTime->AddBackItem("Back", bitmap_icon_back); | ||
menu->AddSubMenu("Brew Time & Weight", *weightNTime, hasBrewControl()); | ||
|
||
/* Preinfusion */ | ||
Menu* preInfusion = new Menu(display); | ||
preInfusion->AddInputItem("Preinfusion Pause", "Pause", "", "s", PRE_INFUSION_PAUSE_MIN, PRE_INFUSION_PAUSE_MAX, []() { sysParaPreInfPause.setStorage(true); }, preinfusionPause, 1.0, 2.0, true); | ||
preInfusion->AddInputItem("Preinfusion", "Time", "", "s", PRE_INFUSION_TIME_MIN, PRE_INFUSION_TIME_MAX, []() { sysParaPreInfTime.setStorage(true); }, preinfusion, 1.0, 2.0, true); | ||
preInfusion->AddBackItem("Back", bitmap_icon_back); | ||
menu->AddSubMenu("Preinfusion", *preInfusion, hasBrewControl()); | ||
/* | ||
* Maintenance Menu | ||
* */ | ||
Menu* maintenanceMenu = new Menu(display); | ||
maintenanceMenu->AddToggleItem("Backflush", reinterpret_cast<bool&>(backflushOn), bitmap_icon_refresh); | ||
maintenanceMenu->AddBackItem("Back", bitmap_icon_back); | ||
|
||
menu->AddSubMenu("Maintenance", *maintenanceMenu, bitmap_icon_tools, hasBrewControl()); | ||
|
||
/* | ||
* Advanced Menu | ||
*/ | ||
|
||
Menu* advancedMenu = new Menu(display); | ||
advancedMenu->AddInputItem("Brew Temp. Offset", "Brew temp. offset", "", "°C", BREW_TEMP_OFFSET_MIN, BREW_TEMP_OFFSET_MAX, []() { sysParaTempOffset.setStorage(true); }, brewTempOffset, bitmap_icon_temp); | ||
/* | ||
* Standby Menu | ||
*/ | ||
Menu* standbyMenu = new Menu(display); | ||
standbyMenu->AddToggleItem("Standby", saveStandby, reinterpret_cast<bool&>(standbyModeOn), true); | ||
standbyMenu->AddInputItem("Standby Time", "Standby Time", "", " m", STANDBY_MODE_TIME_MIN, STANDBY_MODE_TIME_MAX, saveStandbyTime, standbyModeTime, bitmap_icon_clock, 1.0, 2.0, true); | ||
|
||
standbyMenu->AddBackItem("Back", bitmap_icon_back); | ||
advancedMenu->AddSubMenu("Standby", *standbyMenu, bitmap_icon_sleep_mode); | ||
|
||
/* PID Settings */ | ||
Menu* pidSettings = new Menu(display); | ||
pidSettings->AddToggleItem("Enable PonM", []() { sysParaUsePonM.setStorage(true); }, reinterpret_cast<bool&>(usePonM)); | ||
pidSettings->AddInputItem("Start Kp", "Start Kp", "", "", PID_KP_START_MIN, PID_KP_START_MAX, []() { (sysParaPidKpStart.setStorage(true)); }, startKp); | ||
pidSettings->AddInputItem("Start Tn", "Start Tn", "", "", PID_TN_START_MIN, PID_TN_START_MAX, []() { sysParaPidTnStart.setStorage(true); }, startTn); | ||
pidSettings->AddInputItem("Kp", "Kp", "", "", PID_KP_REGULAR_MIN, PID_KP_REGULAR_MAX, []() { sysParaPidKpReg.setStorage(true); }, aggKp); | ||
pidSettings->AddInputItem("Tn", "Tn (=Kp/Ki)", "", "", PID_TN_REGULAR_MIN, PID_TN_REGULAR_MAX, []() { sysParaPidTnReg.setStorage(true); }, aggTn); | ||
pidSettings->AddInputItem("Tv", "Tv (=Kd/Kp)", "", "", PID_TV_REGULAR_MIN, PID_TV_REGULAR_MAX, []() { sysParaPidTvReg.setStorage(true); }, aggTv); | ||
pidSettings->AddInputItem("Integrator Max", "Integrator Max", "", "", PID_I_MAX_REGULAR_MIN, PID_I_MAX_REGULAR_MAX, []() { sysParaPidIMaxReg.setStorage(true); }, aggIMax); | ||
pidSettings->AddInputItem("Steam Kp", "Steam Kp", "", "", PID_KP_STEAM_MIN, PID_KP_STEAM_MAX, []() { sysParaPidKpSteam.setStorage(true); }, steamKp); | ||
|
||
/* Brew PID Settings */ | ||
Menu* brewPidSettings = new Menu(display); | ||
brewPidSettings->AddToggleItem("Enable Brew PID", []() { sysParaUsePonM.setStorage(true); }, reinterpret_cast<bool&>(useBDPID)); | ||
brewPidSettings->AddInputItem("BD Kp", "BD Kp", "", "", PID_KP_BD_MIN, PID_KP_BD_MAX, []() { sysParaPidKpBd.setStorage(true); }, aggbKp); | ||
brewPidSettings->AddInputItem("BD Tn", "BD Tn (=Kp/Ki)", "", "", PID_TN_BD_MIN, PID_TN_BD_MAX, []() { sysParaPidTnBd.setStorage(true); }, aggbTn); | ||
brewPidSettings->AddInputItem("BD Tv", "BD Tv (=Kd/Kp)", "", "", PID_TV_BD_MIN, PID_TV_BD_MAX, []() { sysParaPidTvBd.setStorage(true); }, aggbTv); | ||
brewPidSettings->AddInputItem("PID BD Time", "PID BD Time", "", "s", BREW_SW_TIME_MIN, BREW_SW_TIME_MAX, []() { sysParaBrewSwTime.setStorage(true); }, brewtimesoftware, hasSoftwareDetection()); | ||
brewPidSettings->AddInputItem("PID BD Sensitivity", "Sensitivity", "", "", BD_THRESHOLD_MIN, BD_THRESHOLD_MAX, []() { sysParaBrewThresh.setStorage(true); }, brewSensitivity, hasSoftwareDetection()); | ||
brewPidSettings->AddBackItem("Back", bitmap_icon_back); | ||
|
||
pidSettings->AddSubMenu("Brew PID", *brewPidSettings); | ||
pidSettings->AddBackItem("Back", bitmap_icon_back); | ||
|
||
advancedMenu->AddSubMenu("PID Settings", *pidSettings, bitmap_icon_pid); | ||
advancedMenu->AddBackItem("Back", bitmap_icon_back); | ||
menu->AddSubMenu("Advanced", *advancedMenu, bitmap_icon_settings); | ||
|
||
menu->AddBackItem("Close Menu", bitmap_icon_back); | ||
menu->Init(); | ||
} | ||
|
||
void menuLoop() { | ||
menu->Loop(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe you could be more specific with the naming:
-> FEATURE_DISPLAY_MENU
-> displayMenuHandler