mirror of
https://github.com/arwidcool/Solder-Plate.git
synced 2025-02-17 19:09:23 +01:00
Refactor display handling and add debug profile
This commit is contained in:
commit
abce4ae4be
@ -37,7 +37,7 @@ void PidController::loop()
|
||||
{
|
||||
data->targetTemp = chosenReflowProfile.getTargetTemp();
|
||||
data->currentTemp = thermistor1.getTemperature();
|
||||
debug();
|
||||
// debug();
|
||||
compute();
|
||||
analogWrite(MOSTFET_PIN, data->setPoint);
|
||||
}
|
||||
|
@ -67,6 +67,11 @@ void OledDisplay::handleButtonStateChange(Pair<ButtonKind, StateChangeEvent<Butt
|
||||
curMenu->goNextItem();
|
||||
}
|
||||
}
|
||||
} else if (state == DONE) {
|
||||
// GO back to iniital state
|
||||
if (change.second.to == ButtonState::PRESSED) {
|
||||
reflowProcessState.set(USER_INPUT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -174,13 +179,30 @@ void OledDisplay::loop()
|
||||
{
|
||||
|
||||
ReflowProcessState state = reflowProcessState.get();
|
||||
if (state == USER_INPUT)
|
||||
if (state == ReflowProcessState::USER_INPUT)
|
||||
{
|
||||
handleUserInputState();
|
||||
}
|
||||
else if (state >= PREHEAT && state <= DONE)
|
||||
else if (state >= ReflowProcessState::PREHEAT && state < ReflowProcessState::DONE)
|
||||
{
|
||||
handleReflowState();
|
||||
} else if (state == ReflowProcessState::DONE) {
|
||||
// Traverse back to root menu
|
||||
while (curMenu->parent != NULL) {
|
||||
curMenu = curMenu->parent;
|
||||
}
|
||||
display.clearDisplay();
|
||||
display.setRotation(0);
|
||||
display.setTextSize(2);
|
||||
drawPositionedText("DONE :)", DisplayTextAlignment::CENTER, DisplayTextAlignment::START);
|
||||
uint8_t curTemp = thermistor1.getTemperature();
|
||||
display.setTextSize(1,2);
|
||||
drawPositionedText("Temperature", DisplayTextAlignment::START, DisplayTextAlignment::CENTER);
|
||||
drawPositionedText((String(curTemp)+" C").c_str(), DisplayTextAlignment::END, DisplayTextAlignment::CENTER);
|
||||
|
||||
display.display();
|
||||
|
||||
// This is not super efficient but it's fine for now
|
||||
}
|
||||
// Loop implementation
|
||||
}
|
||||
@ -215,7 +237,7 @@ void OledDisplay::displayIndicators()
|
||||
display.setCursor(SCREEN_HEIGHT - 14, SCREEN_WIDTH / 2 - 5);
|
||||
display.print(">");
|
||||
}
|
||||
void OledDisplay::centerText(const char *txt, DisplayTextAlignment horizontal, DisplayTextAlignment vertical)
|
||||
void OledDisplay::drawPositionedText(const char *txt, DisplayTextAlignment horizontal, DisplayTextAlignment vertical)
|
||||
{
|
||||
int16_t x1, y1;
|
||||
uint16_t w, h;
|
||||
@ -273,23 +295,29 @@ void OledDisplay::handleReflowState()
|
||||
display.setCursor(0, 0);
|
||||
display.setTextSize(2);
|
||||
ReflowProcessState state = reflowProcessState.get();
|
||||
centerText(STATE_STR(state), DisplayTextAlignment::CENTER, DisplayTextAlignment::START);
|
||||
|
||||
// Title topleft
|
||||
drawPositionedText(STATE_STR(state), DisplayTextAlignment::CENTER, DisplayTextAlignment::START);
|
||||
|
||||
display.setTextSize(1, 2);
|
||||
// SysV topright
|
||||
#ifdef DEBUG
|
||||
drawPositionedText((String(analogRef.calculateInputVoltage())+"V").c_str(), DisplayTextAlignment::END, DisplayTextAlignment::START);
|
||||
#endif
|
||||
|
||||
|
||||
// Remaining time center left + bottom left
|
||||
uint32_t elapsedStep = chosenReflowProfile.getCurrentStepRelativeTime();
|
||||
centerText("Remaining", DisplayTextAlignment::START, DisplayTextAlignment::CENTER);
|
||||
centerText((String(chosenReflowProfile.curReflowStep().duration - elapsedStep) + "s").c_str(), DisplayTextAlignment::START, DisplayTextAlignment::END);
|
||||
drawPositionedText("Remaining", DisplayTextAlignment::START, DisplayTextAlignment::CENTER);
|
||||
drawPositionedText((String(chosenReflowProfile.reflowStep().duration - elapsedStep) + "s").c_str(), DisplayTextAlignment::START, DisplayTextAlignment::END);
|
||||
|
||||
// Current temp center right + bottom right
|
||||
uint8_t curTemp = thermistor1.getTemperature();
|
||||
uint8_t targetTemp = pidControllerData.targetTemp;
|
||||
centerText(("Curr.: " + String(curTemp)).c_str(), DisplayTextAlignment::END, DisplayTextAlignment::CENTER);
|
||||
centerText(("Target: " + String(targetTemp)).c_str(), DisplayTextAlignment::END, DisplayTextAlignment::END);
|
||||
drawPositionedText(("Curr.: " + String(curTemp)).c_str(), DisplayTextAlignment::END, DisplayTextAlignment::CENTER);
|
||||
drawPositionedText(("Target: " + String(targetTemp)).c_str(), DisplayTextAlignment::END, DisplayTextAlignment::END);
|
||||
|
||||
display.setTextSize(1, 1);
|
||||
display.setCursor(15, 16);
|
||||
float systemVoltage = analogRef.calculateInputVoltage();
|
||||
display.println("In Voltage:"+String(systemVoltage));
|
||||
|
||||
// display.println("In Voltage:"+String(systemVoltage));
|
||||
|
||||
display.display();
|
||||
}
|
||||
|
@ -23,9 +23,9 @@ class OledDisplay {
|
||||
void handleUserInputState();
|
||||
void handleReflowState();
|
||||
void centerText(const char * text) {
|
||||
centerText(text, DisplayTextAlignment::CENTER, DisplayTextAlignment::CENTER);
|
||||
drawPositionedText(text, DisplayTextAlignment::CENTER, DisplayTextAlignment::CENTER);
|
||||
}
|
||||
void centerText(const char * text, DisplayTextAlignment horizontal, DisplayTextAlignment vertical);
|
||||
void drawPositionedText(const char * text, DisplayTextAlignment horizontal, DisplayTextAlignment vertical);
|
||||
void displayIndicators();
|
||||
void handleDrawThermistorMenu(OledMenuItem item);
|
||||
};
|
||||
|
@ -51,7 +51,7 @@ Thermistor thermistors[6] = {thermistor1, thermistor2, thermistor3, thermistor4,
|
||||
|
||||
// These are the reflow profiles that you can choose from, you can add more if you want (up to 5) but you will have to change the nReflowProfiles variable to the number of profiles you have
|
||||
|
||||
int nReflowProfiles = 2;
|
||||
int nReflowProfiles = 3;
|
||||
|
||||
ReflowProfile reflowProfiles[] = {
|
||||
// 138c profile Sn42Bi58
|
||||
@ -70,6 +70,13 @@ ReflowProfile reflowProfiles[] = {
|
||||
ReflowStep(ReflowProcessState::COOL, 30, 183),
|
||||
ReflowStep(ReflowProcessState::DONE, 0, 0)},
|
||||
"183C Sn63 Pb37 \0"),
|
||||
ReflowProfile(new ReflowStep[5]{
|
||||
ReflowStep(ReflowProcessState::PREHEAT, 5, 150),
|
||||
ReflowStep(ReflowProcessState::SOAK, 5, 180),
|
||||
ReflowStep(ReflowProcessState::REFLOW, 5, 220, EASE_IN_OUT),
|
||||
ReflowStep(ReflowProcessState::COOL, 5, 183),
|
||||
ReflowStep(ReflowProcessState::DONE, 0, 0)},
|
||||
"debug profi \0"),
|
||||
|
||||
|
||||
};
|
||||
|
@ -6,8 +6,8 @@
|
||||
|
||||
// If you didnt solder the LEDS in order, change the order here just change the pin numbers till it matches your board
|
||||
#define LEFT_LED_PIN 20 //Should be RED
|
||||
#define MID_LED_PIN 18 //Should be YELLOW
|
||||
#define RIGHT_LED_PIN 19 //Should be GREEN
|
||||
#define MID_LED_PIN 19 //Should be YELLOW
|
||||
#define RIGHT_LED_PIN 18 //Should be GREEN
|
||||
#define GREEN_LED_PIN RIGHT_LED_PIN
|
||||
|
||||
|
||||
|
30
src/main.cpp
30
src/main.cpp
@ -27,10 +27,12 @@ LEDS leds = LEDS();
|
||||
// Declare the PID
|
||||
ArduPID PID;
|
||||
OledDisplay oled = OledDisplay();
|
||||
TFT_Display tftDisplay ;
|
||||
|
||||
TemperatureController temperatureController ;
|
||||
|
||||
|
||||
|
||||
|
||||
TemperatureController temperatureController;
|
||||
|
||||
void setup()
|
||||
{
|
||||
@ -49,7 +51,7 @@ void setup()
|
||||
oled.setup();
|
||||
eepromDataManager.setup();
|
||||
|
||||
reflowProcessState.set(USER_INPUT);
|
||||
reflowProcessState.set(ReflowProcessState::USER_INPUT);
|
||||
|
||||
temperatureController.checkPluggedInThermistors();
|
||||
|
||||
@ -63,19 +65,21 @@ void loop()
|
||||
ReflowProcessState state = reflowProcessState.get();
|
||||
if (k != NULL)
|
||||
{
|
||||
if (state == USER_INPUT)
|
||||
if (state == ReflowProcessState::USER_INPUT)
|
||||
{
|
||||
leds.handleButtonStateChange(*k);
|
||||
oled.handleButtonStateChange(*k);
|
||||
}
|
||||
else if (state >= PREHEAT && state <= COOL)
|
||||
else if (state >= ReflowProcessState::PREHEAT && state <= ReflowProcessState::COOL)
|
||||
{
|
||||
if (k->first == ButtonKind::BACK && k->second.to == ButtonState::PRESSED)
|
||||
{
|
||||
// STOP REFLOW and restart
|
||||
reflowProcessState.set(USER_INPUT);
|
||||
reflowProcessState.set(ReflowProcessState::USER_INPUT);
|
||||
pidController.stop();
|
||||
}
|
||||
} else if (state == ReflowProcessState::DONE) {
|
||||
oled.handleButtonStateChange(*k);
|
||||
}
|
||||
}
|
||||
ReflowProcessState newState = reflowProcessState.get();
|
||||
@ -84,14 +88,7 @@ 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 == PREHEAT)
|
||||
{
|
||||
|
||||
// Initalize the TFT
|
||||
tftDisplay.init(&chosenReflowProfile);
|
||||
|
||||
|
||||
//Start the reflow profile after tft to make sure the timer is accurate
|
||||
if (newState == PREHEAT) {
|
||||
chosenReflowProfile.start();
|
||||
// Start the PID
|
||||
pidController.start();
|
||||
@ -102,10 +99,10 @@ void loop()
|
||||
leds.loop();
|
||||
oled.loop();
|
||||
|
||||
if (state >= PREHEAT && state <= COOL)
|
||||
if (state >= ReflowProcessState::PREHEAT && state <= ReflowProcessState::COOL)
|
||||
{
|
||||
pidController.loop();
|
||||
ReflowStep step = chosenReflowProfile.curReflowStep();
|
||||
ReflowStep step = chosenReflowProfile.reflowStep();
|
||||
|
||||
if (step.state != newState)
|
||||
{
|
||||
@ -119,6 +116,7 @@ void loop()
|
||||
pidController.stop();
|
||||
reflowProcessState.set(USER_INPUT);
|
||||
}
|
||||
|
||||
|
||||
// if (step.state == ReflowProcessState::DONE) {
|
||||
// profile.start();
|
||||
|
60
src/reflow.h
60
src/reflow.h
@ -75,8 +75,6 @@ public:
|
||||
class ReflowProfile
|
||||
{
|
||||
public:
|
||||
float percentage;
|
||||
|
||||
ReflowProfile(ReflowStep steps[5], char name[20])
|
||||
{
|
||||
for (int i = 0; i < 5; i++)
|
||||
@ -97,7 +95,7 @@ public:
|
||||
|
||||
void start()
|
||||
{
|
||||
timer = StopWatch(StopWatch::Resolution::SECONDS);
|
||||
timer = StopWatch(StopWatch::Resolution::MILLIS);
|
||||
timer.start();
|
||||
calculateTimes();
|
||||
}
|
||||
@ -117,15 +115,20 @@ public:
|
||||
startTimes[4] = endTimes[3];
|
||||
}
|
||||
|
||||
ReflowStep curReflowStep()
|
||||
ReflowStep reflowStep()
|
||||
{
|
||||
if (!timer.isRunning()) {
|
||||
if (!timer.isRunning())
|
||||
{
|
||||
return steps[0];
|
||||
}
|
||||
uint8_t elapsed = timer.elapsed();
|
||||
return reflowStep(timer.elapsed());
|
||||
}
|
||||
|
||||
ReflowStep reflowStep(uint32_t elapsedMS)
|
||||
{
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
if (elapsed >= startTimes[i] && elapsed < endTimes[i])
|
||||
if (elapsedMS >= startTimes[i] * 1000 && elapsedMS < endTimes[i] * 1000)
|
||||
{
|
||||
return steps[i];
|
||||
}
|
||||
@ -133,34 +136,57 @@ public:
|
||||
return steps[4]; // DONE by default
|
||||
}
|
||||
|
||||
float getPercentage() {
|
||||
return (float)timer.elapsed() / (float)(endTimes[4] * 1000);
|
||||
}
|
||||
|
||||
float getTargetTemp()
|
||||
{
|
||||
uint32_t elapsedTime = timer.elapsed();
|
||||
if (!timer.isRunning())
|
||||
{
|
||||
return 20;
|
||||
}
|
||||
return getTargetTemp(timer.elapsed());
|
||||
}
|
||||
float getTargetTemp(uint32_t elapsedMS) {
|
||||
uint8_t startTemp = 20; // always assume 20 degrees at the start
|
||||
|
||||
ReflowStep curStep = curReflowStep();
|
||||
ReflowStep curStep = reflowStep(elapsedMS);
|
||||
if (curStep.state > PREHEAT)
|
||||
{
|
||||
startTemp = steps[STEPINDEX(curStep) - 1].targetTempAtEnd;
|
||||
}
|
||||
|
||||
// startTemp => 20 or the targetTempAtEnd of the previous step
|
||||
|
||||
uint16_t startTime = startTimes[STEPINDEX(curStep)];
|
||||
|
||||
uint32_t relativeElapsedTime = elapsedTime - startTime;
|
||||
uint16_t startTimeMS = startTimes[STEPINDEX(curStep)] * 1000;
|
||||
|
||||
percentage = (float)relativeElapsedTime / (float)(curStep.duration);
|
||||
uint32_t relativeElapsedTime = elapsedMS - startTimeMS;
|
||||
|
||||
float percentage = (float)relativeElapsedTime / (float)(curStep.duration * 1000);
|
||||
|
||||
return curStep.calcTempAtPercentage(startTemp, percentage);
|
||||
}
|
||||
|
||||
|
||||
|
||||
uint8_t getCurrentStepRelativeTime() {
|
||||
uint32_t elapsedTime = timer.elapsed();
|
||||
uint16_t startTime = startTimes[STEPINDEX(curReflowStep())];
|
||||
return elapsedTime - startTime;
|
||||
/**
|
||||
* @brief Get the Target Temp At Process Percentage.
|
||||
* @param processPercentage a number between 0 and 1. 0 is the start of the process, 1 is the end of the process
|
||||
* @return float the target temperature at the given percentage of the full process
|
||||
*/
|
||||
float getTargetTempFromPercentage(double processPercentage)
|
||||
{
|
||||
uint16_t duration = endTimes[4];
|
||||
uint8_t startTemp = 20; // always assume 20 degrees at the start
|
||||
return getTargetTemp(duration * 1000 * processPercentage);
|
||||
}
|
||||
|
||||
uint8_t getCurrentStepRelativeTime()
|
||||
{
|
||||
uint32_t elapsedMS = timer.elapsed();
|
||||
uint16_t startTimeMS = startTimes[STEPINDEX(reflowStep())] * 1000;
|
||||
return (elapsedMS - startTimeMS) / 1000;
|
||||
}
|
||||
|
||||
void toBuffer(uint8_t *b)
|
||||
|
BIN
src/reflow.rar
BIN
src/reflow.rar
Binary file not shown.
BIN
src/reflow2.rar
BIN
src/reflow2.rar
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user