From 3f8004e81c07a86c8970e8da005d9f920c0d485c Mon Sep 17 00:00:00 2001 From: "Ben V. Brown" Date: Tue, 22 Nov 2022 18:07:34 +1100 Subject: [PATCH] Create checkUndervoltage.cpp --- .../utils/checkUndervoltage.cpp | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 source/Core/Threads/OperatingModes/utils/checkUndervoltage.cpp diff --git a/source/Core/Threads/OperatingModes/utils/checkUndervoltage.cpp b/source/Core/Threads/OperatingModes/utils/checkUndervoltage.cpp new file mode 100644 index 00000000..b95359f6 --- /dev/null +++ b/source/Core/Threads/OperatingModes/utils/checkUndervoltage.cpp @@ -0,0 +1,35 @@ + +#ifdef POW_DC +// returns true if undervoltage has occured +bool checkForUnderVoltage(void) { + if (!getIsPoweredByDCIN()) { + return false; + } + uint16_t v = getInputVoltageX10(getSettingValue(SettingsOptions::VoltageDiv), 0); + + // Dont check for first 2 seconds while the ADC stabilizes and the DMA fills + // the buffer + if (xTaskGetTickCount() > (TICKS_SECOND * 2)) { + if ((v < lookupVoltageLevel())) { + currentTempTargetDegC = 0; + OLED::clearScreen(); + OLED::setCursor(0, 0); + if (getSettingValue(SettingsOptions::DetailedSoldering)) { + OLED::print(translatedString(Tr->UndervoltageString), FontStyle::SMALL); + OLED::setCursor(0, 8); + OLED::print(translatedString(Tr->InputVoltageString), FontStyle::SMALL); + printVoltage(); + OLED::print(SymbolVolts, FontStyle::SMALL); + } else { + OLED::print(translatedString(Tr->UVLOWarningString), FontStyle::LARGE); + } + + OLED::refresh(); + GUIDelay(); + waitForButtonPress(); + return true; + } + } + return false; +} +#endif \ No newline at end of file