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