From 1432fc0dc39e514bf56b7c7ca5153ea34be8a808 Mon Sep 17 00:00:00 2001 From: "Ben V. Brown" Date: Tue, 22 Nov 2022 18:07:46 +1100 Subject: [PATCH] Create CJC.cpp --- source/Core/Threads/OperatingModes/CJC.cpp | 39 ++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 source/Core/Threads/OperatingModes/CJC.cpp diff --git a/source/Core/Threads/OperatingModes/CJC.cpp b/source/Core/Threads/OperatingModes/CJC.cpp new file mode 100644 index 00000000..d17e6f41 --- /dev/null +++ b/source/Core/Threads/OperatingModes/CJC.cpp @@ -0,0 +1,39 @@ + + +#include "OperatingModes.h" +void performCJCC(void) { + // Calibrate Cold Junction Compensation directly at boot, before internal components get warm. + OLED::refresh(); + osDelay(50); + if (!isTipDisconnected() && (TipThermoModel::getTipInC() - getHandleTemperature(0) / 10) < 10) { + uint16_t setoffset = 0; + // If the thermo-couple at the end of the tip, and the handle are at + // equilibrium, then the output should be zero, as there is no temperature + // differential. + while (setoffset == 0) { + uint32_t offset = 0; + for (uint8_t i = 0; i < 16; i++) { + offset += getTipRawTemp(1); + // cycle through the filter a fair bit to ensure we're stable. + OLED::clearScreen(); + OLED::setCursor(0, 0); + OLED::print(SymbolDot, FontStyle::LARGE); + for (uint8_t x = 0; x < (i / 4); x++) + OLED::print(SymbolDot, FontStyle::LARGE); + OLED::refresh(); + osDelay(100); + } + setoffset = TipThermoModel::convertTipRawADCTouV(offset / 16, true); + } + setSettingValue(SettingsOptions::CalibrationOffset, setoffset); + OLED::clearScreen(); + OLED::setCursor(0, 0); + OLED::drawCheckbox(true); + OLED::printNumber(setoffset, 5, FontStyle::LARGE); + OLED::refresh(); + osDelay(1200); + // Preventing to repeat calibration at boot automatically (only one shot). + setSettingValue(SettingsOptions::CalibrateCJC, 0); + saveSettings(); + } +}