diff --git a/src/main.cpp b/src/main.cpp index 36c7313..018c90d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -12,7 +12,9 @@ #include "globals.h" #include "PID/PidController.h" #include "reflow.h" +#include "tools/ExecutionTimer.h" +ExecutionTimer timer = ExecutionTimer(); WrappedState reflowProcessState = WrappedState(INITIALIZING); @@ -54,14 +56,12 @@ Buttons buttons = Buttons(); LEDS leds = LEDS(); // Declare the PID - - ReflowProfile profile = ReflowProfile(new ReflowStep[5]{ - ReflowStep(ReflowProcessState::PREHEAT, 2, 50), - ReflowStep(ReflowProcessState::SOAK, 2, 70), - ReflowStep(ReflowProcessState::REFLOW, 2, 85), - ReflowStep(ReflowProcessState::COOL, 2, 20), - ReflowStep(ReflowProcessState::DONE, 0, 0)}, + ReflowStep(ReflowProcessState::PREHEAT, 2, 50), + ReflowStep(ReflowProcessState::SOAK, 2, 70), + ReflowStep(ReflowProcessState::REFLOW, 2, 85), + ReflowStep(ReflowProcessState::COOL, 2, 20), + ReflowStep(ReflowProcessState::DONE, 0, 0)}, "meow\0"); // Reflowprofile profile = Reflowprofile(new ReflowStep[5]{ @@ -114,7 +114,7 @@ void setup() void loop() { - + timer.start(); // Return the button that changed state Pair> *k = buttons.handleButtons(); @@ -160,6 +160,7 @@ void loop() else { + // targetTemp = profile.getTargetTemp(); targetTemp = profile.getTargetTemp(); currentTemp = thermistor1.getTemperature(); @@ -172,11 +173,9 @@ void loop() char myCharArray[50]; // Ensure this array is large enough to hold the string plus the null terminator String(STATE_STR(step.state)).toCharArray(myCharArray, sizeof(myCharArray)); + - controller.debug2(myCharArray); - - ; - // Serial.print(String(STATE_STR(step.state)) + " " + String(step.duration) + " " + String(step.targetTempAtEnd) + " " + String(profile.timer.elapsed()) + " Step Time " + String(profile.getCurrentStepRelativeTime()) + " Target Temp:" + String(profile.targetTempReflow) + " % " + String(profile.percentage) + "\r"); + // controller.debug2(myCharArray); }; // Serial.print("Targt temp: "); diff --git a/src/reflow.h b/src/reflow.h index 404e9c5..209a292 100644 --- a/src/reflow.h +++ b/src/reflow.h @@ -204,7 +204,9 @@ public: float getTargetTemp() { uint32_t elapsedTime = timer.elapsed(); - uint8_t startTemp = 20; // always assume 20 degrees at the start + // uint8_t startTemp = 20; // always assume 20 degrees at the start + uint8_t startTemp=thermistor1.getTemperature(); + ReflowStep curStep = curReflowStep(); ReflowStep prevStep = getPreviousSetep(curStep); diff --git a/src/tools/ExecutionTimer.h b/src/tools/ExecutionTimer.h new file mode 100644 index 0000000..ea32ef5 --- /dev/null +++ b/src/tools/ExecutionTimer.h @@ -0,0 +1,49 @@ +#ifndef EXECUTIONTIMER_H +#define EXECUTIONTIMER_H + +#include + + +class ExecutionTimer { +private: + unsigned long startTime; + unsigned long endTime; + bool isRunning; + +public: + ExecutionTimer() { + startTime = 0; + endTime = 0; + isRunning = false; + } + + void start() { + startTime = millis(); // Use micros() for microsecond precision + isRunning = true; + } + + unsigned long stop() { + if (isRunning) { + endTime = millis(); // Use micros() for microsecond precision + isRunning = false; + + Serial.print("Execution time: "); + Serial.print(endTime - startTime); + Serial.println(" ms"); + return endTime - startTime; + } else { + return 0; // or retain the last execution time + } + } + + // Optional: Function to get the elapsed time without stopping + unsigned long elapsed() const { + if (isRunning) { + return millis() - startTime; // Use micros() for microsecond precision + } else { + return endTime - startTime; + } + } +}; + +#endif // EXECUTIONTIMER_H \ No newline at end of file