mirror of
https://github.com/arwidcool/Solder-Plate.git
synced 2024-12-01 01:27:17 +01:00
Added timer to check execution time of codee
This commit is contained in:
parent
9b6040a98a
commit
c6a36fa771
23
src/main.cpp
23
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> reflowProcessState = WrappedState<ReflowProcessState>(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<ButtonKind, StateChangeEvent<ButtonState>> *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: ");
|
||||
|
@ -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);
|
||||
|
||||
|
49
src/tools/ExecutionTimer.h
Normal file
49
src/tools/ExecutionTimer.h
Normal file
@ -0,0 +1,49 @@
|
||||
#ifndef EXECUTIONTIMER_H
|
||||
#define EXECUTIONTIMER_H
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
|
||||
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
|
Loading…
Reference in New Issue
Block a user