Skip to content

Commit

Permalink
Fix profile mode
Browse files Browse the repository at this point in the history
  • Loading branch information
ReimuHakurei committed Jul 17, 2024
1 parent db12683 commit 7d58d1c
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions source/Core/Threads/UI/logic/SolderingProfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,26 @@ OperatingMode gui_solderingProfileMode(const ButtonState buttons, guiContext *cx
if (cxt->scratch_state.state6 == 0) {
cxt->scratch_state.state6 = tipTemp;
// if this is hotter than the preheat temperature, we should fail
if (cxt->scratch_state.state6 >= 55) {
if (cxt->scratch_state.state6 >= cxt->scratch_state.state5) {
warnUser(translatedString(Tr->TooHotToStartProfileWarning), buttons);
return OperatingMode::HomeScreen;
}
}
uint16_t phaseElapsedSeconds = (xTaskGetTickCount() - cxt->scratch_state.state3) / TICKS_SECOND;

// have we finished this phase?
if (phaseElapsedSeconds >= cxt->scratch_state.state2 && tipTemp == cxt->scratch_state.state5) {
// Have we finished this phase?
// Check if we have hit our temperature target in either direction.
bool phaseTargetReached = false;
if (cxt->scratch_state.state6 < cxt->scratch_state.state5 && tipTemp >= cxt->scratch_state.state5) {
phaseTargetReached = true;
} else if (cxt->scratch_state.state6 > cxt->scratch_state.state5 && tipTemp <= cxt->scratch_state.state5) {
phaseTargetReached = true;
} else if (tipTemp == cxt->scratch_state.state5) {
phaseTargetReached = true;
}

// If we both hit the temperature target and enough time has passed, phase complete.
if (phaseElapsedSeconds >= cxt->scratch_state.state2 && phaseTargetReached) {
cxt->scratch_state.state1++;
cxt->scratch_state.state6 = cxt->scratch_state.state5;
cxt->scratch_state.state3 = xTaskGetTickCount();
Expand Down Expand Up @@ -115,13 +126,18 @@ OperatingMode gui_solderingProfileMode(const ButtonState buttons, guiContext *cx

// determine current target temp
if (cxt->scratch_state.state6 < cxt->scratch_state.state5) {
if (profileCurrentTargetTemp < cxt->scratch_state.state5) {
profileCurrentTargetTemp = cxt->scratch_state.state6 + ((xTaskGetTickCount() - cxt->viewEnterTime) / phaseTicksPerDegree);
}
} else {
profileCurrentTargetTemp = cxt->scratch_state.state6 + ((xTaskGetTickCount() - cxt->viewEnterTime) / phaseTicksPerDegree);
if (profileCurrentTargetTemp > cxt->scratch_state.state5) {
profileCurrentTargetTemp = cxt->scratch_state.state6 - ((xTaskGetTickCount() - cxt->viewEnterTime) / phaseTicksPerDegree);
profileCurrentTargetTemp = cxt->scratch_state.state5;
}
} else if (cxt->scratch_state.state6 > cxt->scratch_state.state5) {
profileCurrentTargetTemp = cxt->scratch_state.state6 - ((xTaskGetTickCount() - cxt->viewEnterTime) / phaseTicksPerDegree);
// Chance of an overflow when ramping up is basically zero, but chance of an underflow here is quite high. If the target underflowed, snap it back.
if (profileCurrentTargetTemp < cxt->scratch_state.state5 || profileCurrentTargetTemp > cxt->scratch_state.state6) {
profileCurrentTargetTemp = cxt->scratch_state.state5;
}
} else {
profileCurrentTargetTemp = cxt->scratch_state.state5;
}

// Draw in the screen details
Expand Down

0 comments on commit 7d58d1c

Please sign in to comment.