mirror of
https://github.com/Ralim/IronOS.git
synced 2025-02-26 07:53:55 +00:00
Merge remote-tracking branch 'upstream/dev' into dev
This commit is contained in:
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);
|
||||
}
|
||||
16
source/Core/Threads/UI/logic/utils/OperatingModeUtilities.h
Normal file
16
source/Core/Threads/UI/logic/utils/OperatingModeUtilities.h
Normal file
@@ -0,0 +1,16 @@
|
||||
#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 printVoltage(void); //
|
||||
bool checkForUnderVoltage(void); //
|
||||
uint16_t min(uint16_t a, uint16_t b); //
|
||||
void printCountdownUntilSleep(int sleepThres); //
|
||||
#endif
|
||||
98
source/Core/Threads/UI/logic/utils/SolderingCommon.cpp
Normal file
98
source/Core/Threads/UI/logic/utils/SolderingCommon.cpp
Normal file
@@ -0,0 +1,98 @@
|
||||
//
|
||||
// Created by laura on 24.04.23.
|
||||
//
|
||||
|
||||
#include "SolderingCommon.h"
|
||||
#include "OperatingModes.h"
|
||||
#include "Types.h"
|
||||
#include "configuration.h"
|
||||
#include "history.hpp"
|
||||
#include "ui_drawing.hpp"
|
||||
|
||||
extern bool heaterThermalRunaway;
|
||||
|
||||
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 POW_PD_EXT == 2
|
||||
if (FS2711::has_run_selection()) {
|
||||
poweredbyPD = true;
|
||||
// FS2711IC has VBUS always connected
|
||||
pdHasVBUSConnected = true;
|
||||
}
|
||||
#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
|
||||
}
|
||||
9
source/Core/Threads/UI/logic/utils/SolderingCommon.h
Normal file
9
source/Core/Threads/UI/logic/utils/SolderingCommon.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#include "Types.h"
|
||||
#include <stdint.h>
|
||||
#ifndef SOLDERING_COMMON_H_
|
||||
#define SOLDERING_COMMON_H_
|
||||
|
||||
bool checkExitSoldering();
|
||||
TemperatureType_t getTipTemp(void);
|
||||
|
||||
#endif // SOLDERING_COMMON_H_
|
||||
25
source/Core/Threads/UI/logic/utils/checkUndervoltage.cpp
Normal file
25
source/Core/Threads/UI/logic/utils/checkUndervoltage.cpp
Normal file
@@ -0,0 +1,25 @@
|
||||
#include "Buttons.hpp"
|
||||
#include "OperatingModeUtilities.h"
|
||||
#include "configuration.h"
|
||||
#include "ui_drawing.hpp"
|
||||
#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;
|
||||
ui_draw_warning_undervoltage();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
#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;
|
||||
}
|
||||
}
|
||||
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