diff --git a/src/PID/PidController.cpp b/src/PID/PidController.cpp index cf8e93c..c317068 100644 --- a/src/PID/PidController.cpp +++ b/src/PID/PidController.cpp @@ -57,3 +57,8 @@ void PidController::start() controller.start(); } + +double* PidController::getInput() +{ + return controller.input; +} diff --git a/src/PID/PidController.h b/src/PID/PidController.h index 194ab0f..8636447 100644 --- a/src/PID/PidController.h +++ b/src/PID/PidController.h @@ -20,6 +20,8 @@ public: void loop(); void start(); + double* getInput(); + boolean started = false; private: diff --git a/src/displays/oled.cpp b/src/displays/oled.cpp index 5d37575..12938a6 100644 --- a/src/displays/oled.cpp +++ b/src/displays/oled.cpp @@ -300,9 +300,10 @@ void OledDisplay::handleReflowState() display.setTextSize(1, 2); // SysV topright - #ifdef DEBUG + // #ifdef DEBUG + drawPositionedText((String(analogRef.calculateInputVoltage())+"V").c_str(), DisplayTextAlignment::END, DisplayTextAlignment::START); - #endif + // #endif // Remaining time center left + bottom left diff --git a/src/displays/tft.cpp b/src/displays/tft.cpp index 778d7a6..06e27b1 100644 --- a/src/displays/tft.cpp +++ b/src/displays/tft.cpp @@ -39,9 +39,56 @@ void TFT_Display::init(ReflowProfile *profile) this->profile = profile; + drawTimer.reset(); + + drawTimer.setResolution(StopWatch::MILLIS); + drawTimer.start(); + drawGraph(); } +void TFT_Display::drawRealTemp(double *temp, float time) +{ + + uint32_t timeSinceLastDraw = drawTimer.elapsed(); + + // Serial.print("Time since last draw:"); + // Serial.println(timeSinceLastDraw); + + if (timeSinceLastDraw >= 930) + { + float timeElapsed = time; + + float temperature = static_cast(*temp); + + time = time / 1000; + // Serial.print("Time:"); + // Serial.print(time); + // Serial.print(" Temp:"); + // Serial.println(temperature); + + uint16_t eplased = drawTimer.elapsed(); + + // Get the xy and y pixel of the temp + + uint16_t x = timeXonGraph(time); + uint16_t y = tempYonGraph(temperature); + // Draw the pixel + + //tft.drawPixel(x, y, ST77XX_RED); + + tft.drawLine(prevousTempXY.x, prevousTempXY.y, x, y, ST77XX_RED); + + prevousTempXY.x = x; + prevousTempXY.y = y; + drawTimer.reset(); + drawTimer.start(); + } + else + { + }; +} + void TFT_Display::clear() { tft.fillScreen(ST77XX_BLACK); @@ -304,7 +351,7 @@ void TFT_Display::drawGraphReflowStagesBackground() uint16_t x = graphXY.x + 1; uint16_t previopusWidth; // Draw the background for the reflow stages - for (int i = 0; i < 5; i++) + for (int i = 0; i < 4; i++) { Serial.println("Time x"); @@ -345,7 +392,6 @@ void TFT_Display::drawGraphReflowStagesBackground() break; default: - break; } } @@ -370,31 +416,31 @@ void TFT_Display::drawReflowTargetTempLine() uint16_t endX = timeXonGraph(endTime); uint16_t endY = tempYonGraph(endTemp); - Serial.print("State:"); - Serial.println(String(STATE_STR(profile->steps[i].state))); - Serial.print("Start x:"); - Serial.println(String(startX)); - Serial.print("Start y:"); - Serial.println(String(startY)); - Serial.print("End x:"); - Serial.println(String(endX)); - Serial.print("End y:"); - Serial.println(String(endY)); - Serial.print("Start temp:"); - Serial.println(String(startTemp)); - Serial.print("End temp:"); - Serial.println(String(endTemp)); - Serial.print("Start time:"); - Serial.println(String(startTime)); - Serial.print("End time:"); - Serial.println(String(endTime)); - Serial.println(" "); + // Serial.print("State:"); + // Serial.println(String(STATE_STR(profile->steps[i].state))); + // Serial.print("Start x:"); + // Serial.println(String(startX)); + // Serial.print("Start y:"); + // Serial.println(String(startY)); + // Serial.print("End x:"); + // Serial.println(String(endX)); + // Serial.print("End y:"); + // Serial.println(String(endY)); + // Serial.print("Start temp:"); + // Serial.println(String(startTemp)); + // Serial.print("End temp:"); + // Serial.println(String(endTemp)); + // Serial.print("Start time:"); + // Serial.println(String(startTime)); + // Serial.print("End time:"); + // Serial.println(String(endTime)); + // Serial.println(" "); - - if(profile->steps[i].flagged) { - // tft.drawCircle(startX, startY, 5, ST77XX_RED); - startTemp = profile->steps[i-2].targetTempAtEnd; - + // Check for the half sine function flag if its flagged draw the line using the ending temp of the step 2 before the current step + if (profile->steps[i].flagged) + { + // tft.drawCircle(startX, startY, 5, ST77XX_RED); + startTemp = profile->steps[i - 2].targetTempAtEnd; } // Draw the line pixel by pixel @@ -416,12 +462,6 @@ void TFT_Display::drawReflowTargetTempLine() float temp = startTemp + (endTemp - startTemp) * -(cos(percentage * PI) - 1) / (double)2; - Serial.print("Temp:"); - Serial.println(temp); - - Serial.print("Percentage:"); - Serial.println(percentage); - float time = startTime + (duration * percentage); // Calculate the x and y position of the temp on the graph @@ -445,12 +485,6 @@ void TFT_Display::drawReflowTargetTempLine() float temp = startTemp + (endTemp - startTemp) * (1 - cos(percentage * PI / (double)2)); - Serial.print("Temp:"); - Serial.println(temp); - - Serial.print("Percentage:"); - Serial.println(percentage); - // Calculate the x and y position of the temp on the graph uint16_t y = tempYonGraph(temp); @@ -468,16 +502,8 @@ void TFT_Display::drawReflowTargetTempLine() // calculate the temp at the current percentage of the line - - float temp = startTemp + (endTemp - startTemp) * (sin(percentage * PI / (double)2)); - Serial.print("Temp:"); - Serial.println(temp); - - Serial.print("Percentage:"); - Serial.println(percentage); - // Calculate the x and y position of the temp on the graph uint16_t y = tempYonGraph(temp); @@ -496,15 +522,8 @@ void TFT_Display::drawReflowTargetTempLine() float percentage = i / 100.0; // calculate the temp at the current percentage of the line - float temp = startTemp + (endTemp - startTemp) * (sin(percentage * PI)); - Serial.print("Temp:"); - Serial.println(temp); - - Serial.print("Percentage:"); - Serial.println(percentage); - // Calculate the x and y position of the temp on the graph uint16_t y = tempYonGraph(temp); @@ -543,6 +562,13 @@ uint16_t TFT_Display::tempYonGraph(float temp) return y; } +uint16_t TFT_Display::tempYonGraph(float *temp) +{ + + float y = graphXY.y - (graphHeight * ((*temp - minTemp) / (maxTemp - minTemp))); + return y; +} + uint16_t TFT_Display::timeXonGraph(float time) { // Calculate the x position of the time on the graph based on the min and max times and the min and max x of the graph diff --git a/src/displays/tft.h b/src/displays/tft.h index 09d6cf0..cef85ff 100644 --- a/src/displays/tft.h +++ b/src/displays/tft.h @@ -5,6 +5,7 @@ #include // Include the ST7789 library #include #include +#include struct TFT_XY { @@ -21,10 +22,15 @@ public: void start(); // Add your class methods here void init(ReflowProfile *profile); + void drawRealTemp(double *temp, float time); void clear(); private: + TFT_XY prevousTempXY = {32, 220}; + + StopWatch drawTimer; + ReflowProfile *profile; uint8_t tickMarkLength = 5; @@ -37,7 +43,7 @@ private: void getTotalTimeFromProfile(ReflowProfile *profile); uint16_t graphHeight = 180; - uint16_t graphWidth = 256; + uint16_t graphWidth = 255; TFT_XY graphXY = {32, 220}; uint16_t maxTemp = 0; uint16_t totalTIme =0; @@ -54,6 +60,7 @@ private: void drawReflowTargetTempLine(); uint16_t tempYonGraph(float temp); + uint16_t tempYonGraph(float *temp); uint16_t timeXonGraph(float time); template diff --git a/src/globals.cpp b/src/globals.cpp index 841469a..82e1b88 100644 --- a/src/globals.cpp +++ b/src/globals.cpp @@ -61,7 +61,7 @@ int nReflowProfiles = 3; ReflowProfile reflowProfiles[] = { // 138c profile Sn42Bi58 ReflowProfile(new ReflowStep[5]{ - ReflowStep(ReflowProcessState::PREHEAT, 90, 100, EASE_OUT), + ReflowStep(ReflowProcessState::PREHEAT, 100, 100, EASE_OUT), ReflowStep(ReflowProcessState::SOAK, 90, 155,EASE_IN_OUT), ReflowStep(ReflowProcessState::REFLOW, 90, 185, HALF_SINE), ReflowStep(ReflowProcessState::COOL, 50, 85, EASE_IN), diff --git a/src/main.cpp b/src/main.cpp index ad0763f..7b8a441 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -13,9 +13,7 @@ #include "globals.h" #include "EEPROMDataManager.h" #include "thermistors/TemperatureController.h" - - - +#include "tools/ExecutionTimer.h" #define MOSTFET_PIN 17 @@ -23,19 +21,17 @@ double currentTemp = 0; double targetTemp = 60; double pwmValue = 255; +ExecutionTimer executionTimer; + Buttons buttons = Buttons(); LEDS leds = LEDS(); // Declare the PID ArduPID PID; OledDisplay oled = OledDisplay(); -TFT_Display tftDisplay ; +TFT_Display tftDisplay; TemperatureController temperatureController; - - - - void setup() { @@ -62,6 +58,8 @@ void setup() void loop() { +// executionTimer.start(); + // Return the button that changed state Pair> *k = buttons.handleButtons(); ReflowProcessState state = reflowProcessState.get(); @@ -80,11 +78,11 @@ void loop() reflowProcessState.set(ReflowProcessState::USER_INPUT); pidController.stop(); leds.reset(); - } - } else if (state == ReflowProcessState::DONE) { + } + else if (state == ReflowProcessState::DONE) + { oled.handleButtonStateChange(*k); - } } ReflowProcessState newState = reflowProcessState.get(); @@ -93,14 +91,14 @@ void loop() { Serial.println("State changed from " + String(STATE_STR(state)) + " to " + String(STATE_STR(newState))); // State changed from state to newState (user input or wifi input needs to be above here) - if (newState == ReflowProcessState::PREHEAT) { + if (newState == ReflowProcessState::PREHEAT) + { tftDisplay.init(&chosenReflowProfile); - + chosenReflowProfile.start(); // Start the PID pidController.start(); - } } state = newState; @@ -111,9 +109,9 @@ void loop() if (state >= ReflowProcessState::PREHEAT && state <= ReflowProcessState::COOL) { - pidController.loop(); - //pidController.debug(); + pidController.debug(); + tftDisplay.drawRealTemp(pidController.getInput(), chosenReflowProfile.getCurrentTime()); ReflowStep step = chosenReflowProfile.reflowStep(); // Here we draw the actual temp vs time to the display @@ -123,10 +121,9 @@ void loop() if (step.state == ReflowProcessState::DONE) { pidController.stop(); - } } } - +// executionTimer.stop(); } diff --git a/src/reflow.h b/src/reflow.h index cc06173..6e81c7f 100644 --- a/src/reflow.h +++ b/src/reflow.h @@ -243,6 +243,11 @@ public: return (elapsedMS - startTimeMS) / 1000; } + uint32_t getCurrentTime() + { + return timer.elapsed(); + } + void toBuffer(uint8_t *b) { memset(b, 0, PROFILE_SERIALIZED_SIZE);