hot-fermentation/t_encoder.ino

57 lines
1.2 KiB
C++

LP_TIMER(2, checkEncoder);
void checkEncoder() {
enc1.tick();
isLeft = enc1.isLeft();
isRight = enc1.isRight();
isClick = enc1.isClick();
if (!isLeft && !isRight && !isClick) {
return;
}
if (inSelectionMode) {
handleProfileSelection();
}
else {
handleExecutionSelection();
}
}
void handleExecutionSelection() {
if (isClick) {
activeProfileIndex = 100;
activeProfile = profiles[activeProfileIndex];
inSelectionMode = true;
Output = 0;
writeEEPROM();
oled.clear();
displaySelection();
return;
}
}
void handleProfileSelection() {
if (Setpoint > 0) {
Setpoint = 0;
}
if (!isClick && !isLeft && !isRight) {
return;
}
// Handle encoder input for selecting the profile
if (isRight) {
selectedProfileIndex = (selectedProfileIndex + 1) % (sizeof(profiles) / sizeof(profiles[0]));
} else if (isLeft) {
selectedProfileIndex = (selectedProfileIndex - 1 + (sizeof(profiles) / sizeof(profiles[0]))) % (sizeof(profiles) / sizeof(profiles[0]));
}
displaySelection();
// Start the selected profile on button press
if (isClick) {
activeProfileIndex = selectedProfileIndex;
startExecution();
}
}