mirror of
https://github.com/Ralim/IronOS.git
synced 2025-02-26 07:53:55 +00:00
Move to new folder
This commit is contained in:
15
source/Core/Threads/UI/logic/utils/DrawTipTemperature.cpp
Normal file
15
source/Core/Threads/UI/logic/utils/DrawTipTemperature.cpp
Normal file
@@ -0,0 +1,15 @@
|
||||
#include "OperatingModeUtilities.h"
|
||||
#include "OperatingModes.h"
|
||||
#include "SolderingCommon.h"
|
||||
#include "TipThermoModel.h"
|
||||
|
||||
void gui_drawTipTemp(bool symbol, const FontStyle font) {
|
||||
// Draw tip temp handling unit conversion & tolerance near setpoint
|
||||
TemperatureType_t Temp = getTipTemp();
|
||||
|
||||
OLED::printNumber(Temp, 3, font); // Draw the tip temp out
|
||||
if (symbol) {
|
||||
// For big font, can draw nice symbols, otherwise fall back to chars
|
||||
OLED::printSymbolDeg(font == FontStyle::LARGE ? FontStyle::EXTRAS : font);
|
||||
}
|
||||
}
|
||||
10
source/Core/Threads/UI/logic/utils/GUIDelay.cpp
Normal file
10
source/Core/Threads/UI/logic/utils/GUIDelay.cpp
Normal file
@@ -0,0 +1,10 @@
|
||||
|
||||
#include "OperatingModeUtilities.h"
|
||||
|
||||
void GUIDelay() {
|
||||
// Called in all UI looping tasks,
|
||||
// This limits the re-draw rate to the LCD and also lets the DMA run
|
||||
// As the gui task can very easily fill this bus with transactions, which will
|
||||
// prevent the movement detection from running
|
||||
vTaskDelay(5 * TICKS_10MS);
|
||||
}
|
||||
19
source/Core/Threads/UI/logic/utils/OperatingModeUtilities.h
Normal file
19
source/Core/Threads/UI/logic/utils/OperatingModeUtilities.h
Normal file
@@ -0,0 +1,19 @@
|
||||
#ifndef OPERATING_MODE_UTILITIES_H_
|
||||
#define OPERATING_MODE_UTILITIES_H_
|
||||
#include "Buttons.hpp"
|
||||
#include "OLED.hpp"
|
||||
#include <stdbool.h>
|
||||
|
||||
void GUIDelay(); //
|
||||
bool checkForUnderVoltage(void); //
|
||||
uint32_t getSleepTimeout(void); //
|
||||
bool shouldBeSleeping(); //
|
||||
bool shouldShutdown(void); //
|
||||
void gui_drawTipTemp(bool symbol, const FontStyle font); //
|
||||
void printVoltage(void); //
|
||||
bool warnUser(const char *warning, const ButtonState buttons); //
|
||||
void gui_drawBatteryIcon(void); //
|
||||
bool checkForUnderVoltage(void); //
|
||||
uint16_t min(uint16_t a, uint16_t b); //
|
||||
void printCountdownUntilSleep(int sleepThres); //
|
||||
#endif
|
||||
8
source/Core/Threads/UI/logic/utils/PrintVoltage.cpp
Normal file
8
source/Core/Threads/UI/logic/utils/PrintVoltage.cpp
Normal file
@@ -0,0 +1,8 @@
|
||||
#include "OperatingModeUtilities.h"
|
||||
|
||||
void printVoltage(void) {
|
||||
uint32_t volt = getInputVoltageX10(getSettingValue(SettingsOptions::VoltageDiv), 0);
|
||||
OLED::printNumber(volt / 10, 2, FontStyle::SMALL);
|
||||
OLED::print(SmallSymbolDot, FontStyle::SMALL);
|
||||
OLED::printNumber(volt % 10, 1, FontStyle::SMALL);
|
||||
}
|
||||
12
source/Core/Threads/UI/logic/utils/ShowWarning.cpp
Normal file
12
source/Core/Threads/UI/logic/utils/ShowWarning.cpp
Normal file
@@ -0,0 +1,12 @@
|
||||
#include "Buttons.hpp"
|
||||
#include "OperatingModeUtilities.h"
|
||||
#include "OperatingModes.h"
|
||||
bool warnUser(const char *warning, const ButtonState buttons) {
|
||||
OLED::clearScreen();
|
||||
OLED::printWholeScreen(warning);
|
||||
// Also timeout after 5 seconds
|
||||
if ((xTaskGetTickCount() - lastButtonTime) > TICKS_SECOND * 5) {
|
||||
return true;
|
||||
}
|
||||
return buttons != BUTTON_NONE;
|
||||
}
|
||||
160
source/Core/Threads/UI/logic/utils/SolderingCommon.cpp
Normal file
160
source/Core/Threads/UI/logic/utils/SolderingCommon.cpp
Normal file
@@ -0,0 +1,160 @@
|
||||
//
|
||||
// Created by laura on 24.04.23.
|
||||
//
|
||||
|
||||
#include "SolderingCommon.h"
|
||||
#include "OperatingModes.h"
|
||||
#include "Types.h"
|
||||
#include "configuration.h"
|
||||
#include "history.hpp"
|
||||
|
||||
extern bool heaterThermalRunaway;
|
||||
|
||||
void detailedPowerStatus() {
|
||||
if (OLED::getRotation()) {
|
||||
OLED::setCursor(0, 0);
|
||||
} else {
|
||||
OLED::setCursor(67, 0);
|
||||
}
|
||||
// Print wattage
|
||||
{
|
||||
uint32_t x10Watt = x10WattHistory.average();
|
||||
if (x10Watt > 999) {
|
||||
// If we exceed 99.9W we drop the decimal place to keep it all fitting
|
||||
OLED::print(SmallSymbolSpace, FontStyle::SMALL);
|
||||
OLED::printNumber(x10WattHistory.average() / 10, 3, FontStyle::SMALL);
|
||||
} else {
|
||||
OLED::printNumber(x10WattHistory.average() / 10, 2, FontStyle::SMALL);
|
||||
OLED::print(SmallSymbolDot, FontStyle::SMALL);
|
||||
OLED::printNumber(x10WattHistory.average() % 10, 1, FontStyle::SMALL);
|
||||
}
|
||||
OLED::print(SmallSymbolWatts, FontStyle::SMALL);
|
||||
}
|
||||
|
||||
if (OLED::getRotation()) {
|
||||
OLED::setCursor(0, 8);
|
||||
} else {
|
||||
OLED::setCursor(67, 8);
|
||||
}
|
||||
printVoltage();
|
||||
OLED::print(SmallSymbolVolts, FontStyle::SMALL);
|
||||
}
|
||||
|
||||
void basicSolderingStatus(bool boostModeOn) {
|
||||
OLED::setCursor(0, 0);
|
||||
// We switch the layout direction depending on the orientation of the oled
|
||||
if (OLED::getRotation()) {
|
||||
// battery
|
||||
gui_drawBatteryIcon();
|
||||
// Space out gap between battery <-> temp
|
||||
OLED::print(LargeSymbolSpace, FontStyle::LARGE);
|
||||
// Draw current tip temp
|
||||
gui_drawTipTemp(true, FontStyle::LARGE);
|
||||
|
||||
// We draw boost arrow if boosting,
|
||||
// or else gap temp <-> heat indicator
|
||||
if (boostModeOn) {
|
||||
OLED::drawSymbol(2);
|
||||
} else {
|
||||
OLED::print(LargeSymbolSpace, FontStyle::LARGE);
|
||||
}
|
||||
|
||||
// Draw heating/cooling symbols
|
||||
OLED::drawHeatSymbol(X10WattsToPWM(x10WattHistory.average()));
|
||||
} else {
|
||||
// Draw heating/cooling symbols
|
||||
OLED::drawHeatSymbol(X10WattsToPWM(x10WattHistory.average()));
|
||||
// We draw boost arrow if boosting,
|
||||
// or else gap temp <-> heat indicator
|
||||
if (boostModeOn) {
|
||||
OLED::drawSymbol(2);
|
||||
} else {
|
||||
OLED::print(LargeSymbolSpace, FontStyle::LARGE);
|
||||
}
|
||||
// Draw current tip temp
|
||||
gui_drawTipTemp(true, FontStyle::LARGE);
|
||||
// Space out gap between battery <-> temp
|
||||
OLED::print(LargeSymbolSpace, FontStyle::LARGE);
|
||||
|
||||
gui_drawBatteryIcon();
|
||||
}
|
||||
}
|
||||
|
||||
bool checkExitSoldering(void) {
|
||||
#ifdef POW_DC
|
||||
// Undervoltage test
|
||||
if (checkForUnderVoltage()) {
|
||||
lastButtonTime = xTaskGetTickCount();
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef ACCEL_EXITS_ON_MOVEMENT
|
||||
// If the accel works in reverse where movement will cause exiting the soldering mode
|
||||
if (getSettingValue(Sensitivity)) {
|
||||
if (lastMovementTime) {
|
||||
if (lastMovementTime > TICKS_SECOND * 10) {
|
||||
// If we have moved recently; in the last second
|
||||
// Then exit soldering mode
|
||||
|
||||
// Movement occurred in last update
|
||||
if (((TickType_t)(xTaskGetTickCount() - lastMovementTime)) < (TickType_t)(TICKS_SECOND / 5)) {
|
||||
currentTempTargetDegC = 0;
|
||||
lastMovementTime = 0;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// If we have tripped thermal runaway, turn off heater and show warning
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
int8_t getPowerSourceNumber(void) {
|
||||
int8_t sourceNumber = 0;
|
||||
if (getIsPoweredByDCIN()) {
|
||||
sourceNumber = 0;
|
||||
} else {
|
||||
// We are not powered via DC, so want to display the appropriate state for PD or QC
|
||||
bool poweredbyPD = false;
|
||||
bool pdHasVBUSConnected = false;
|
||||
#ifdef POW_PD
|
||||
if (USBPowerDelivery::fusbPresent()) {
|
||||
// We are PD capable
|
||||
if (USBPowerDelivery::negotiationComplete()) {
|
||||
// We are powered via PD
|
||||
poweredbyPD = true;
|
||||
#ifdef VBUS_MOD_TEST
|
||||
pdHasVBUSConnected = USBPowerDelivery::isVBUSConnected();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if (poweredbyPD) {
|
||||
if (pdHasVBUSConnected) {
|
||||
sourceNumber = 2;
|
||||
} else {
|
||||
sourceNumber = 3;
|
||||
}
|
||||
} else {
|
||||
sourceNumber = 1;
|
||||
}
|
||||
}
|
||||
return sourceNumber;
|
||||
}
|
||||
|
||||
// Returns temperature of the tip in *C/*F (based on user settings)
|
||||
TemperatureType_t getTipTemp(void) {
|
||||
#ifdef FILTER_DISPLAYED_TIP_TEMP
|
||||
static history<TemperatureType_t, FILTER_DISPLAYED_TIP_TEMP> Filter_Temp;
|
||||
TemperatureType_t reading = getSettingValue(SettingsOptions::TemperatureInF) ? TipThermoModel::getTipInF() : TipThermoModel::getTipInC();
|
||||
Filter_Temp.update(reading);
|
||||
return Filter_Temp.average();
|
||||
|
||||
#else
|
||||
return getSettingValue(SettingsOptions::TemperatureInF) ? TipThermoModel::getTipInF() : TipThermoModel::getTipInC();
|
||||
#endif
|
||||
}
|
||||
11
source/Core/Threads/UI/logic/utils/SolderingCommon.h
Normal file
11
source/Core/Threads/UI/logic/utils/SolderingCommon.h
Normal file
@@ -0,0 +1,11 @@
|
||||
#include "Types.h"
|
||||
#include <stdint.h>
|
||||
#ifndef SOLDERING_COMMON_H_
|
||||
#define SOLDERING_COMMON_H_
|
||||
|
||||
void detailedPowerStatus();
|
||||
void basicSolderingStatus(bool boostModeOn);
|
||||
bool checkExitSoldering();
|
||||
TemperatureType_t getTipTemp(void);
|
||||
|
||||
#endif // SOLDERING_COMMON_H_
|
||||
38
source/Core/Threads/UI/logic/utils/checkUndervoltage.cpp
Normal file
38
source/Core/Threads/UI/logic/utils/checkUndervoltage.cpp
Normal file
@@ -0,0 +1,38 @@
|
||||
#include "Buttons.hpp"
|
||||
#include "OperatingModeUtilities.h"
|
||||
#include "configuration.h"
|
||||
#ifdef POW_DC
|
||||
extern volatile TemperatureType_t currentTempTargetDegC;
|
||||
// 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(SmallSymbolVolts, FontStyle::SMALL);
|
||||
} else {
|
||||
OLED::print(translatedString(Tr->UVLOWarningString), FontStyle::LARGE);
|
||||
}
|
||||
|
||||
OLED::refresh();
|
||||
GUIDelay();
|
||||
waitForButtonPress();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
46
source/Core/Threads/UI/logic/utils/drawPowerSourceIcon.cpp
Normal file
46
source/Core/Threads/UI/logic/utils/drawPowerSourceIcon.cpp
Normal file
@@ -0,0 +1,46 @@
|
||||
#include "OperatingModeUtilities.h"
|
||||
|
||||
void gui_drawBatteryIcon(void) {
|
||||
#if defined(POW_PD) || defined(POW_QC) || defined(POW_PD_EXT)
|
||||
if (!getIsPoweredByDCIN()) {
|
||||
// On non-DC inputs we replace this symbol with the voltage we are operating on
|
||||
// If <9V then show single digit, if not show dual small ones vertically stacked
|
||||
uint16_t V = getInputVoltageX10(getSettingValue(SettingsOptions::VoltageDiv), 0);
|
||||
if (V % 10 >= 5) {
|
||||
V = (V / 10) + 1; // round up
|
||||
} else {
|
||||
V = V / 10;
|
||||
}
|
||||
if (V > 9) {
|
||||
int16_t xPos = OLED::getCursorX();
|
||||
OLED::printNumber(V / 10, 1, FontStyle::SMALL);
|
||||
OLED::setCursor(xPos, 8);
|
||||
OLED::printNumber(V % 10, 1, FontStyle::SMALL);
|
||||
OLED::setCursor(xPos + 12, 0); // need to reset this as if we drew a wide char
|
||||
} else {
|
||||
OLED::printNumber(V, 1, FontStyle::LARGE);
|
||||
}
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
#ifdef POW_DC
|
||||
if (getSettingValue(SettingsOptions::MinDCVoltageCells)) {
|
||||
// User is on a lithium battery
|
||||
// we need to calculate which of the 10 levels they are on
|
||||
uint8_t cellCount = getSettingValue(SettingsOptions::MinDCVoltageCells) + 2;
|
||||
uint32_t cellV = getInputVoltageX10(getSettingValue(SettingsOptions::VoltageDiv), 0) / cellCount;
|
||||
// Should give us approx cell voltage X10
|
||||
// Range is 42 -> Minimum voltage setting (systemSettings.minVoltageCells) = 9 steps therefore we will use battery 0-9
|
||||
if (cellV < getSettingValue(SettingsOptions::MinVoltageCells)) {
|
||||
cellV = getSettingValue(SettingsOptions::MinVoltageCells);
|
||||
}
|
||||
cellV -= getSettingValue(SettingsOptions::MinVoltageCells); // Should leave us a number of 0-9
|
||||
if (cellV > 9) {
|
||||
cellV = 9;
|
||||
}
|
||||
OLED::drawBattery(cellV + 1);
|
||||
} else {
|
||||
OLED::drawSymbol(15); // Draw the DC Logo
|
||||
}
|
||||
#endif
|
||||
}
|
||||
19
source/Core/Threads/UI/logic/utils/getSleepTimeout.cpp
Normal file
19
source/Core/Threads/UI/logic/utils/getSleepTimeout.cpp
Normal file
@@ -0,0 +1,19 @@
|
||||
#include "OperatingModeUtilities.h"
|
||||
|
||||
#ifndef NO_SLEEP_MODE
|
||||
|
||||
uint32_t getSleepTimeout(void) {
|
||||
|
||||
if (getSettingValue(SettingsOptions::Sensitivity) && getSettingValue(SettingsOptions::SleepTime)) {
|
||||
|
||||
uint32_t sleepThres = 0;
|
||||
if (getSettingValue(SettingsOptions::SleepTime) < 6) {
|
||||
sleepThres = getSettingValue(SettingsOptions::SleepTime) * 10 * 1000;
|
||||
} else {
|
||||
sleepThres = (getSettingValue(SettingsOptions::SleepTime) - 5) * 60 * 1000;
|
||||
}
|
||||
return sleepThres;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
11
source/Core/Threads/UI/logic/utils/min.cpp
Normal file
11
source/Core/Threads/UI/logic/utils/min.cpp
Normal file
@@ -0,0 +1,11 @@
|
||||
|
||||
|
||||
#include "OperatingModeUtilities.h"
|
||||
#include <stdint.h>
|
||||
uint16_t min(uint16_t a, uint16_t b) {
|
||||
if (a > b) {
|
||||
return b;
|
||||
} else {
|
||||
return a;
|
||||
}
|
||||
}
|
||||
20
source/Core/Threads/UI/logic/utils/printSleepCountdown.cpp
Normal file
20
source/Core/Threads/UI/logic/utils/printSleepCountdown.cpp
Normal file
@@ -0,0 +1,20 @@
|
||||
#include "Buttons.hpp"
|
||||
#include "OperatingModeUtilities.h"
|
||||
extern TickType_t lastMovementTime;
|
||||
#ifndef NO_SLEEP_MODE
|
||||
void printCountdownUntilSleep(int sleepThres) {
|
||||
/*
|
||||
* Print seconds or minutes (if > 99 seconds) until sleep
|
||||
* mode is triggered.
|
||||
*/
|
||||
TickType_t lastEventTime = lastButtonTime < lastMovementTime ? lastMovementTime : lastButtonTime;
|
||||
TickType_t downCount = sleepThres - xTaskGetTickCount() + lastEventTime;
|
||||
if (downCount > (99 * TICKS_SECOND)) {
|
||||
OLED::printNumber(downCount / 60000 + 1, 2, FontStyle::SMALL);
|
||||
OLED::print(SmallSymbolMinutes, FontStyle::SMALL);
|
||||
} else {
|
||||
OLED::printNumber(downCount / 1000 + 1, 2, FontStyle::SMALL);
|
||||
OLED::print(SmallSymbolSeconds, FontStyle::SMALL);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
24
source/Core/Threads/UI/logic/utils/shouldDeviceShutdown.cpp
Normal file
24
source/Core/Threads/UI/logic/utils/shouldDeviceShutdown.cpp
Normal file
@@ -0,0 +1,24 @@
|
||||
#include "OperatingModeUtilities.h"
|
||||
|
||||
extern TickType_t lastMovementTime;
|
||||
extern TickType_t lastHallEffectSleepStart;
|
||||
#include "Buttons.hpp"
|
||||
|
||||
bool shouldShutdown(void) {
|
||||
if (getSettingValue(SettingsOptions::ShutdownTime)) { // only allow shutdown exit if time > 0
|
||||
if (lastMovementTime) {
|
||||
if (((TickType_t)(xTaskGetTickCount() - lastMovementTime)) > (TickType_t)(getSettingValue(SettingsOptions::ShutdownTime) * TICKS_MIN)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (lastHallEffectSleepStart) {
|
||||
if (((TickType_t)(xTaskGetTickCount() - lastHallEffectSleepStart)) > (TickType_t)(getSettingValue(SettingsOptions::ShutdownTime) * TICKS_MIN)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (getButtonState() == BUTTON_B_LONG) { // allow also if back button is pressed long
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
45
source/Core/Threads/UI/logic/utils/shouldDeviceSleep.cpp
Normal file
45
source/Core/Threads/UI/logic/utils/shouldDeviceSleep.cpp
Normal file
@@ -0,0 +1,45 @@
|
||||
#include "Buttons.hpp"
|
||||
#include "OperatingModeUtilities.h"
|
||||
|
||||
TickType_t lastHallEffectSleepStart = 0;
|
||||
extern TickType_t lastMovementTime;
|
||||
|
||||
bool shouldBeSleeping() {
|
||||
#ifndef NO_SLEEP_MODE
|
||||
// Return true if the iron should be in sleep mode
|
||||
if (getSettingValue(SettingsOptions::Sensitivity) && getSettingValue(SettingsOptions::SleepTime)) {
|
||||
// In auto start we are asleep until movement
|
||||
if (lastMovementTime == 0 && lastButtonTime == 0) {
|
||||
return true;
|
||||
}
|
||||
if (lastMovementTime > 0 || lastButtonTime > 0) {
|
||||
if (((xTaskGetTickCount() - lastMovementTime) > getSleepTimeout()) && ((xTaskGetTickCount() - lastButtonTime) > getSleepTimeout())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef HALL_SENSOR
|
||||
// If the hall effect sensor is enabled in the build, check if its over
|
||||
// threshold, and if so then we force sleep
|
||||
if (getHallSensorFitted() && lookupHallEffectThreshold()) {
|
||||
int16_t hallEffectStrength = getRawHallEffect();
|
||||
if (hallEffectStrength < 0) {
|
||||
hallEffectStrength = -hallEffectStrength;
|
||||
}
|
||||
// Have absolute value of measure of magnetic field strength
|
||||
if (hallEffectStrength > lookupHallEffectThreshold()) {
|
||||
if (lastHallEffectSleepStart == 0) {
|
||||
lastHallEffectSleepStart = xTaskGetTickCount();
|
||||
}
|
||||
if ((xTaskGetTickCount() - lastHallEffectSleepStart) > TICKS_SECOND) {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
lastHallEffectSleepStart = 0;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
Reference in New Issue
Block a user