hot-fermentation/t_encoder.ino

57 lines
1.2 KiB
Arduino
Raw Permalink Normal View History

2025-01-17 01:16:01 +07:00
LP_TIMER(2, checkEncoder);
2025-01-14 12:43:13 +07:00
void checkEncoder() {
2024-10-06 22:21:02 +07:00
enc1.tick();
isLeft = enc1.isLeft();
isRight = enc1.isRight();
isClick = enc1.isClick();
if (!isLeft && !isRight && !isClick) {
return;
}
if (inSelectionMode) {
handleProfileSelection();
}
else {
handleExecutionSelection();
}
2025-01-14 12:43:13 +07:00
}
2024-10-06 22:21:02 +07:00
void handleExecutionSelection() {
if (isClick) {
activeProfileIndex = 100;
activeProfile = profiles[activeProfileIndex];
inSelectionMode = true;
2025-01-17 01:16:01 +07:00
Output = 0;
2024-10-06 22:21:02 +07:00
writeEEPROM();
oled.clear();
displaySelection();
return;
}
}
void handleProfileSelection() {
2024-12-19 23:20:33 +07:00
if (Setpoint > 0) {
Setpoint = 0;
}
2024-10-06 22:21:02 +07:00
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();
}
}