From 7903df36e57befa0d600ab5c66fca4249db774b6 Mon Sep 17 00:00:00 2001 From: "Ben V. Brown" Date: Sat, 1 May 2021 16:44:50 +1000 Subject: [PATCH] Create isTipDisconnected function --- source/Core/BSP/BSP.h | 2 ++ source/Core/BSP/MHP30/BSP.cpp | 8 ++++++++ source/Core/BSP/MHP30/ThermoModel.cpp | 10 ++++++++-- source/Core/BSP/Miniware/BSP.cpp | 8 ++++++++ source/Core/BSP/Miniware/ThermoModel.cpp | 4 +--- source/Core/BSP/Pine64/BSP.cpp | 8 ++++++++ source/Core/BSP/Pine64/ThermoModel.cpp | 4 +--- source/Core/Drivers/TipThermoModel.cpp | 2 -- source/Core/Inc/configuration.h | 8 ++++---- source/Core/Threads/GUIThread.cpp | 11 ++++++----- 10 files changed, 46 insertions(+), 19 deletions(-) diff --git a/source/Core/BSP/BSP.h b/source/Core/BSP/BSP.h index 08ead36a..1ed0507c 100644 --- a/source/Core/BSP/BSP.h +++ b/source/Core/BSP/BSP.h @@ -74,6 +74,8 @@ bool getIsPoweredByDCIN(); // Logs the system state to a debug interface if supported void log_system_state(int32_t PWMWattsx10); +// Returns true if the tip is disconnected +bool isTipDisconnected(); #ifdef __cplusplus } #endif diff --git a/source/Core/BSP/MHP30/BSP.cpp b/source/Core/BSP/MHP30/BSP.cpp index 7b09ed3e..7abfccb7 100644 --- a/source/Core/BSP/MHP30/BSP.cpp +++ b/source/Core/BSP/MHP30/BSP.cpp @@ -5,6 +5,7 @@ #include "Model_Config.h" #include "Pins.h" #include "Setup.h" +#include "TipThermoModel.h" #include "Utils.h" #include "history.hpp" #include "main.hpp" @@ -180,3 +181,10 @@ void BSPInit(void) {} void reboot() { NVIC_SystemReset(); } void delay_ms(uint16_t count) { HAL_Delay(count); } + +bool isTipDisconnected() { + + uint16_t tipDisconnectedThres = TipThermoModel::getTipMaxInC() - 5; + uint32_t tipTemp = TipThermoModel::getTipInC(); + return tipTemp > tipDisconnectedThres; +} diff --git a/source/Core/BSP/MHP30/ThermoModel.cpp b/source/Core/BSP/MHP30/ThermoModel.cpp index 887f32c9..d7f5b643 100644 --- a/source/Core/BSP/MHP30/ThermoModel.cpp +++ b/source/Core/BSP/MHP30/ThermoModel.cpp @@ -5,8 +5,8 @@ * Author: Ralim */ #include "TipThermoModel.h" -#include "configuration.h" #include "Utils.h" +#include "configuration.h" #ifdef TEMP_uV_LOOKUP_MHP30 const uint16_t uVtoDegC[] = { @@ -47,5 +47,11 @@ const uint16_t uVtoDegC[] = { const int uVtoDegCItems = sizeof(uVtoDegC) / (2 * sizeof(uint16_t)); +uint32_t TipThermoModel::convertuVToDegC(uint32_t tipuVDelta) { + // For the MHP30, we are mimicing the original code and using the resistor fitted to the base of the heater head + // As such, we need to use the ADC and some pin toggling to measure this resistor + // We want to cache the value as it takes time to measure, but we also need to re-measure when the tip is inserted / removed + // We can detect the tip being inserted / removed by using the reading of that channel, as if its reporting max (0xFFFF) then the heater is not connected -uint32_t TipThermoModel::convertuVToDegC(uint32_t tipuVDelta) { return Utils::InterpolateLookupTable(uVtoDegC, uVtoDegCItems, tipuVDelta); } + return Utils::InterpolateLookupTable(uVtoDegC, uVtoDegCItems, tipuVDelta); +} diff --git a/source/Core/BSP/Miniware/BSP.cpp b/source/Core/BSP/Miniware/BSP.cpp index a40c9000..2de98bf2 100644 --- a/source/Core/BSP/Miniware/BSP.cpp +++ b/source/Core/BSP/Miniware/BSP.cpp @@ -5,6 +5,7 @@ #include "Model_Config.h" #include "Pins.h" #include "Setup.h" +#include "TipThermoModel.h" #include "history.hpp" #include "main.hpp" #include @@ -338,3 +339,10 @@ void BSPInit(void) { switchToFastPWM(); } void reboot() { NVIC_SystemReset(); } void delay_ms(uint16_t count) { HAL_Delay(count); } + +bool isTipDisconnected() { + + uint16_t tipDisconnectedThres = TipThermoModel::getTipMaxInC() - 5; + uint32_t tipTemp = TipThermoModel::getTipInC(); + return tipTemp > tipDisconnectedThres; +} diff --git a/source/Core/BSP/Miniware/ThermoModel.cpp b/source/Core/BSP/Miniware/ThermoModel.cpp index ea54927f..ae74d49c 100644 --- a/source/Core/BSP/Miniware/ThermoModel.cpp +++ b/source/Core/BSP/Miniware/ThermoModel.cpp @@ -5,10 +5,8 @@ * Author: Ralim */ #include "TipThermoModel.h" -#include "configuration.h" #include "Utils.h" - - +#include "configuration.h" #ifdef TEMP_uV_LOOKUP_HAKKO const uint16_t uVtoDegC[] = { diff --git a/source/Core/BSP/Pine64/BSP.cpp b/source/Core/BSP/Pine64/BSP.cpp index e29abea2..70cc04f1 100644 --- a/source/Core/BSP/Pine64/BSP.cpp +++ b/source/Core/BSP/Pine64/BSP.cpp @@ -4,6 +4,7 @@ #include "I2C_Wrapper.hpp" #include "Pins.h" #include "Setup.h" +#include "TipThermoModel.h" #include "gd32vf103_timer.h" #include "history.hpp" #include "main.hpp" @@ -120,3 +121,10 @@ void delay_ms(uint16_t count) { delay_1ms(count); } uint32_t __get_IPSR(void) { return 0; // To shut-up CMSIS } + +bool isTipDisconnected() { + + uint16_t tipDisconnectedThres = TipThermoModel::getTipMaxInC() - 5; + uint32_t tipTemp = TipThermoModel::getTipInC(); + return tipTemp > tipDisconnectedThres; +} diff --git a/source/Core/BSP/Pine64/ThermoModel.cpp b/source/Core/BSP/Pine64/ThermoModel.cpp index efdfc207..a8efdcb0 100644 --- a/source/Core/BSP/Pine64/ThermoModel.cpp +++ b/source/Core/BSP/Pine64/ThermoModel.cpp @@ -5,9 +5,8 @@ * Author: Ralim */ #include "TipThermoModel.h" -#include "configuration.h" #include "Utils.h" - +#include "configuration.h" #ifdef TEMP_uV_LOOKUP_HAKKO const uint16_t uVtoDegC[] = { @@ -70,5 +69,4 @@ const uint16_t uVtoDegC[] = { const int uVtoDegCItems = sizeof(uVtoDegC) / (2 * sizeof(uint16_t)); - uint32_t TipThermoModel::convertuVToDegC(uint32_t tipuVDelta) { return Utils::InterpolateLookupTable(uVtoDegC, uVtoDegCItems, tipuVDelta); } diff --git a/source/Core/Drivers/TipThermoModel.cpp b/source/Core/Drivers/TipThermoModel.cpp index eab52333..643d2b4e 100644 --- a/source/Core/Drivers/TipThermoModel.cpp +++ b/source/Core/Drivers/TipThermoModel.cpp @@ -55,8 +55,6 @@ uint32_t TipThermoModel::convertTipRawADCTouV(uint16_t rawADC, bool ski uint32_t TipThermoModel::convertTipRawADCToDegC(uint16_t rawADC) { return convertuVToDegC(convertTipRawADCTouV(rawADC)); } uint32_t TipThermoModel::convertTipRawADCToDegF(uint16_t rawADC) { return convertuVToDegF(convertTipRawADCTouV(rawADC)); } - - uint32_t TipThermoModel::convertuVToDegF(uint32_t tipuVDelta) { return convertCtoF(convertuVToDegC(tipuVDelta)); } uint32_t TipThermoModel::convertCtoF(uint32_t degC) { diff --git a/source/Core/Inc/configuration.h b/source/Core/Inc/configuration.h index f8eccd12..9524c57c 100644 --- a/source/Core/Inc/configuration.h +++ b/source/Core/Inc/configuration.h @@ -111,8 +111,8 @@ #define OP_AMP_GAIN_STAGE_TS80 (1 + (OP_AMP_Rf_TS80 / OP_AMP_Rin_TS80)) -#define OP_AMP_Rf_MHP30 268500 // 268.5 Kilo-ohms -> Measured -#define OP_AMP_Rin_MHP30 1600 // 1.6 Kilo-ohms -> Measured +#define OP_AMP_Rf_MHP30 268500 // 268.5 Kilo-ohms -> Measured +#define OP_AMP_Rin_MHP30 1600 // 1.6 Kilo-ohms -> Measured #define OP_AMP_GAIN_STAGE_MHP30 (1 + (OP_AMP_Rf_MHP30 / OP_AMP_Rin_MHP30)) // Deriving the Voltage div: @@ -200,6 +200,6 @@ const uint8_t tipResistance = 45; // x10 ohms, 4.5 typical for ts80 tips #endif #ifdef MODEL_MHP30 -const uint32_t tipMass = 100; // TODO -const uint8_t tipResistance = 75; // x10 ohms, ~6 typical +const uint32_t tipMass = 100; // TODO +const uint8_t tipResistance = 75; // x10 ohms, ~6 typical #endif diff --git a/source/Core/Threads/GUIThread.cpp b/source/Core/Threads/GUIThread.cpp index 795820f6..4753fba6 100644 --- a/source/Core/Threads/GUIThread.cpp +++ b/source/Core/Threads/GUIThread.cpp @@ -840,8 +840,10 @@ void startGUITask(void const *argument __unused) { saveSettings(); break; case BUTTON_F_SHORT: - gui_solderingMode(0); // enter soldering mode - buttonLockout = true; + if (!isTipDisconnected()) { + gui_solderingMode(0); // enter soldering mode + buttonLockout = true; + } break; case BUTTON_B_SHORT: enterSettingsMenu(); // enter the settings menu @@ -865,12 +867,11 @@ void startGUITask(void const *argument __unused) { if ((tipTemp < 50) && systemSettings.sensitivity && (((xTaskGetTickCount() - lastMovementTime) > MOVEMENT_INACTIVITY_TIME) && ((xTaskGetTickCount() - lastButtonTime) > BUTTON_INACTIVITY_TIME))) { OLED::setDisplayState(OLED::DisplayState::OFF); } - uint16_t tipDisconnectedThres = TipThermoModel::getTipMaxInC() - 5; // Clear the lcd buffer OLED::clearScreen(); OLED::setCursor(0, 0); if (systemSettings.detailedIDLE) { - if (tipTemp > tipDisconnectedThres) { + if (isTipDisconnected()) { OLED::print(translatedString(Tr->TipDisconnectedString), FontStyle::SMALL); } else { OLED::print(translatedString(Tr->IdleTipString), FontStyle::SMALL); @@ -903,7 +904,7 @@ void startGUITask(void const *argument __unused) { tempOnDisplay = true; else if (tipTemp < 45) tempOnDisplay = false; - if (tipTemp > tipDisconnectedThres) { + if (isTipDisconnected()) { tempOnDisplay = false; tipDisconnectedDisplay = true; }