196 lines
5.5 KiB
C++
196 lines
5.5 KiB
C++
void printPhases() {
|
|
// oled.clear();
|
|
|
|
if (isComplete) {
|
|
// Show completion time and current temperature instead of the title
|
|
oled.setCursor(0, 0);
|
|
oled.invertText(true);
|
|
oled.print("Done!");
|
|
oled.invertText(false);
|
|
oled.print(" ");
|
|
formatTime((currentTime - finishTime) / 1000, timeBuffer); // Time since completion
|
|
oled.print(timeBuffer);
|
|
oled.print(" ");
|
|
oled.print(Input,0);
|
|
oled.print("c");
|
|
oled.print("->");
|
|
oled.print((int)Setpoint);
|
|
oled.print("c ");
|
|
} else {
|
|
oled.setCursor(0, 0);
|
|
oled.print(activeProfile.name);
|
|
oled.print(" ");
|
|
}
|
|
|
|
// Display the totals and current state on the OLED
|
|
oled.setCursor(0, 1);
|
|
oled.print(" ");
|
|
oled.setCursor(18, 1);
|
|
formatTime((long)totalElapsedTime, timeBuffer);
|
|
oled.print(timeBuffer);
|
|
oled.print(" / ");
|
|
formatTime((long)totalProcessTime, timeBuffer);
|
|
oled.print(timeBuffer);
|
|
oled.print(" ");
|
|
|
|
for (int i = 0; i < activeProfile.numPhases; i++) {
|
|
if (i == currentPhase) {
|
|
oled.invertText(true); // Invert text for the current phase
|
|
|
|
oled.setCursor(0, i + 2); // Set cursor to the row corresponding to the phase
|
|
long timeRemaining = ((long) activeProfile.phases[i].duration * 60) - ((currentTime - phaseStartTime) / 1000);
|
|
formatTime(timeRemaining, timeBuffer);
|
|
oled.print(i + 1);
|
|
oled.print(". ");
|
|
oled.print(Input, 1);
|
|
oled.print("c ");
|
|
if (fabs(Setpoint - round(Setpoint)) < 0.05) {
|
|
oled.print(Setpoint, 0); // Print without decimals
|
|
} else {
|
|
oled.print(Setpoint, 1); // Print with 1 decimal place
|
|
}
|
|
oled.print("c ");
|
|
if (!isInTransition) {
|
|
oled.print(timeBuffer);
|
|
}
|
|
oled.print(" ");
|
|
} else {
|
|
oled.invertText(false); // Normal text for other phases
|
|
|
|
oled.setCursor(0, i + 2); // Set cursor to the row corresponding to the phase
|
|
formatTime((long)activeProfile.phases[i].duration * 60, timeBuffer);
|
|
oled.print(i + 1);
|
|
oled.print(". ");
|
|
oled.print(activeProfile.phases[i].temperature);
|
|
oled.print("c ");
|
|
oled.print(timeBuffer);
|
|
oled.print(" ");
|
|
}
|
|
}
|
|
|
|
if (temperatureSensorError) {
|
|
oled.invertText(true);
|
|
oled.setCursor(0, 0);
|
|
oled.setScale(2);
|
|
oled.print("T = ");
|
|
oled.print(Input);
|
|
oled.print(" ");
|
|
oled.setScale(1);
|
|
digitalWrite(activeBuzzerPin, HIGH);
|
|
delay(5);
|
|
digitalWrite(activeBuzzerPin, LOW);
|
|
}
|
|
|
|
if (failedReadingCount) {
|
|
oled.setCursor(0, 7);
|
|
oled.print(failedReadingCount);
|
|
oled.print("!");
|
|
}
|
|
|
|
oled.invertText(false); // Ensure text inversion is off after the loop
|
|
|
|
HandlePwmHeaterDisplay();
|
|
// oled.setCursor(110,7);
|
|
// sprintf(timeBuffer, "%3d", (int)(Output*100));
|
|
// oled.print(timeBuffer);
|
|
// oled.update();
|
|
}
|
|
|
|
void displaySelection() {
|
|
// oled.clear();
|
|
// Display all profiles with the selected one highlighted
|
|
for (int i = 0; i < (int) (sizeof(profiles) / sizeof(profiles[0])); i++) {
|
|
if (i == selectedProfileIndex) {
|
|
oled.invertText(true); // Highlight the selected profile
|
|
}
|
|
|
|
oled.setCursor(0, i); // Set cursor to the correct row
|
|
oled.print(profiles[i].name);
|
|
|
|
oled.invertText(false); // Reset text inversion for other profiles
|
|
}
|
|
oled.update();
|
|
}
|
|
|
|
void formatTime(long seconds, char* buffer) {
|
|
long hours = seconds / 3600;
|
|
long mins = (seconds % 3600) / 60;
|
|
int secs = seconds % 60;
|
|
|
|
buffer[0] = '\0'; // Ensure the buffer is empty
|
|
|
|
if (hours > 0) {
|
|
sprintf(buffer + strlen(buffer), "%ldh", hours);
|
|
}
|
|
if (mins > 0) {
|
|
sprintf(buffer + strlen(buffer), "%ldm", mins);
|
|
}
|
|
if (secs > 0) {
|
|
sprintf(buffer + strlen(buffer), "%ds", secs);
|
|
}
|
|
}
|
|
|
|
|
|
#define graphItems 30
|
|
// LP_TIMER(1000, HandlePwmHeaterDisplay);
|
|
void HandlePwmHeaterDisplay() {
|
|
static byte graphStates[graphItems];
|
|
static byte currentGraphItemNumber = 0;
|
|
|
|
if (inSelectionMode) {
|
|
Setpoint = 0;
|
|
return;
|
|
}
|
|
|
|
currentGraphItemNumber++;
|
|
if (currentGraphItemNumber >= graphItems) {
|
|
currentGraphItemNumber = 0;
|
|
}
|
|
|
|
byte graphHeight = 7;
|
|
byte currentAmount = Output==0 ? 0 : (Output-1)/99.0 * (graphHeight) + 1;
|
|
|
|
graphStates[currentGraphItemNumber] = currentAmount;
|
|
|
|
byte rightMargin = 128;
|
|
byte topMargin = 63-graphHeight;
|
|
byte itemsDisplayed = 0;
|
|
|
|
while (itemsDisplayed < graphItems) {
|
|
int currentItemN = currentGraphItemNumber - itemsDisplayed;
|
|
if (currentItemN < 0) {
|
|
currentItemN += graphItems;
|
|
}
|
|
byte CurrentItemValue = graphStates[currentItemN];
|
|
oled.fastLineV(rightMargin - graphItems + itemsDisplayed, topMargin, topMargin+graphHeight-CurrentItemValue+1, 0);
|
|
if (CurrentItemValue) {
|
|
oled.fastLineV(rightMargin - graphItems + itemsDisplayed, topMargin+graphHeight-CurrentItemValue+1, topMargin+graphHeight, 1);
|
|
}
|
|
|
|
itemsDisplayed++;
|
|
}
|
|
|
|
byte leftPosition = rightMargin - graphItems - 3*6 - 1;
|
|
oled.setCursor(leftPosition, 7);
|
|
sprintf(timeBuffer, "%3d", (int)(Output));
|
|
oled.invertText(true);
|
|
oled.print(timeBuffer);
|
|
oled.invertText(false);
|
|
|
|
leftPosition -= 6*3+2;
|
|
oled.setCursor(leftPosition, 7);
|
|
sprintf(timeBuffer, "%3d", (int)(regulator.lastD));
|
|
oled.print(timeBuffer);
|
|
|
|
leftPosition -= 6*3+2;
|
|
oled.setCursor(leftPosition, 7);
|
|
sprintf(timeBuffer, "%3d", (int)(regulator.lastI));
|
|
oled.print(timeBuffer);
|
|
|
|
leftPosition -= 6*3+2;
|
|
oled.setCursor(leftPosition, 7);
|
|
sprintf(timeBuffer, "%3d", (int)(regulator.lastP));
|
|
oled.print(timeBuffer);
|
|
}
|
|
|