From 589d8ea8f2397913f7f50002f899f7223e22166e Mon Sep 17 00:00:00 2001 From: Aleksander Belov Date: Sat, 31 Aug 2024 01:46:02 +0700 Subject: [PATCH] polishing --- README.md | 3 --- hot_fermentation.ino | 19 ++++++++++++------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 06a908d..1a6dd8b 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,4 @@ ## TODO -* check the ai suggestion -* time after completion is not displayed * eeprom saving every 5 minutes and resuming -* profile selection diff --git a/hot_fermentation.ino b/hot_fermentation.ino index 5ff607e..1097351 100644 --- a/hot_fermentation.ino +++ b/hot_fermentation.ino @@ -65,6 +65,7 @@ unsigned long ssrLastSwitchTime; unsigned long totalElapsedTime; unsigned long totalProcessTime; unsigned long finishTime = 0; +unsigned long currentTime = 0; bool isComplete = false; const int ssrSwitchInterval = 1000; // SSR switching interval in milliseconds @@ -85,12 +86,15 @@ void loop() { if (inSelectionMode) { handleProfileSelection(); // Handle profile selection mode } else { - unsigned long currentTime = millis(); + currentTime = millis(); totalElapsedTime = (currentTime - totalStartTime) / 1000; // Total elapsed time in seconds getPhaseAndTemperature(totalElapsedTime); - Input = (int) thermocouple.readCelsius(); // Cast to integer for display and control + Input = thermocouple.readCelsius(); + if (isnan(Input)) { + Input = 0; + } myPID.Compute(); // Switch SSR based on PID output and interval control @@ -99,12 +103,12 @@ void loop() { ssrLastSwitchTime = currentTime; } - if (isComplete && currentPhase >= activeProfile.numPhases) { + if (isComplete && currentPhase >= activeProfile.numPhases && !finishTime) { finishTime = currentTime; } // Display all phases and highlight the current one - printPhases(currentPhase, currentTime - phaseStartTime, currentTime); + printPhases(); oled.update(); @@ -213,7 +217,7 @@ void getPhaseAndTemperature(unsigned long elapsedSeconds) { isComplete = true; // Mark the process as complete } -void printPhases(int currentPhase, unsigned long phaseElapsedTime, unsigned long currentTime) { +void printPhases() { oled.clear(); if (isComplete) { @@ -241,16 +245,17 @@ void printPhases(int currentPhase, unsigned long phaseElapsedTime, unsigned long formatTime(totalProcessTime, timeBuffer); oled.print(timeBuffer); + for (int i = 0; i < activeProfile.numPhases; i++) { if (i == currentPhase && !isComplete) { oled.invertText(true); // Invert text for the current phase oled.setCursor(0, i + 2); // Set cursor to the row corresponding to the phase - unsigned long timeRemaining = (activeProfile.phases[i].duration * 60) - (phaseElapsedTime / 1000); + unsigned long timeRemaining = (activeProfile.phases[i].duration * 60) - ((currentTime - phaseStartTime) / 1000); formatTime(timeRemaining, timeBuffer); oled.print(i + 1); oled.print(". "); - oled.print((int)Input); + oled.print(Input, 1); oled.print("c "); if (fabs(Setpoint - round(Setpoint)) < 0.05) { oled.print((int)Setpoint); // Print without decimals