1
0
forked from me/IronOS

Pass one settings refactor

This commit is contained in:
Ben V. Brown
2021-09-12 13:31:03 +10:00
parent fc47c71ec3
commit eb2a748e3f
10 changed files with 452 additions and 496 deletions

View File

@@ -41,10 +41,10 @@ uint32_t TipThermoModel::convertTipRawADCTouV(uint16_t rawADC, bool ski
// Now to divide this down by the gain
valueuV /= OP_AMP_GAIN_STAGE;
if (systemSettings.CalibrationOffset && skipCalOffset == false) {
if (getSettingValue(SettingsOptions::CalibrationOffset) && skipCalOffset == false) {
// Remove uV tipOffset
if (valueuV > systemSettings.CalibrationOffset)
valueuV -= systemSettings.CalibrationOffset;
if (valueuV > getSettingValue(SettingsOptions::CalibrationOffset))
valueuV -= getSettingValue(SettingsOptions::CalibrationOffset);
else
valueuV = 0;
}

View File

@@ -9,65 +9,49 @@
#ifndef SETTINGS_H_
#define SETTINGS_H_
#include <stdbool.h>
#include <stdint.h>
#define SETTINGSVERSION (0x2A)
/*Change this if you change the struct below to prevent people getting \
out of sync*/
#define SETTINGSVERSION (0x2A) // This number is frozen, do not edit
/*
* This struct must be a multiple of 2 bytes as it is saved / restored from
* flash in uint16_t chunks
*/
typedef struct {
uint8_t version; // Used to track if a reset is needed on firmware upgrade
enum SettingsOptions {
SolderingTemp, // current set point for the iron
SleepTemp, // temp to drop to in sleep
SleepTime, // minutes timeout to sleep
MinDCVoltageCells, // The voltage we cut out at for under voltage when powered by DC jack
MinVoltageCells, // Minimum allowed voltage per cell <3S - 3.0V (30)> <4S - 2.4V (24)> <...> (Minimum recommended 2.7V)
QCIdealVoltage, // Desired QC3.0 voltage (9,12,20V)
OrientationMode, // Selects between Auto,Right and left handed layouts
Sensitivity, // Sensitivity of accelerometer (5 bits)
AnimationLoop, // Animation loop switch
AnimationSpeed, // Animation speed (in miliseconds)
AutoStartMode, // Should the unit automatically jump straight into soldering mode when power is applied
ShutdownTime, // Time until unit shuts down if left alone
CoolingTempBlink, // Should the temperature blink on the cool down screen until its <50C
DetailedIDLE, // Detailed idle screen
DetailedSoldering, // Detailed soldering screens
TemperatureInF, // Should the temp be in F or C (true is F)
DescriptionScrollSpeed, // Description scroll speed
LockingMode, // Store the locking mode
KeepAwakePulse, // Keep Awake pulse power in 0.1 watts (10 = 1Watt)
KeepAwakePulseWait, // Time between Keep Awake pulses in 2500 ms = 2.5 s increments
KeepAwakePulseDuration, // Duration of the Keep Awake pusle in 250 ms increments
VoltageDiv, // Voltage divisor factor
BoostTemp, // Boost mode set point for the iron
CalibrationOffset, // This stores the temperature offset for this tip in the iron.
PowerLimit, // Maximum power iron allowed to output
ReverseButtonTempChangeEnabled, // Change the plus and minus button assigment
TempChangeLongStep, // Change the plus and minus button assigment
TempChangeShortStep, // Change the plus and minus button assigment
HallEffectSensitivity, // Operating mode of the hall effect sensor
AccelMissingWarningCounter, // Counter of how many times we have warned we cannot detect the accelerometer
PDMissingWarningCounter, // Counter of how many times we have warned we cannot detect the pd interface
UILanguage, // Selected UI Language code, null-terminated *only if* the length is less than 8 chars
PDNegTimeout, // PD timeout in 100ms steps
uint16_t SolderingTemp; // current set point for the iron
uint16_t SleepTemp; // temp to drop to in sleep
uint8_t SleepTime; // minutes timeout to sleep
uint8_t minDCVoltageCells; // The voltage we cut out at for under voltage when powered by DC jack
uint8_t minVoltageCells; // Minimum allowed voltage per cell <3S - 3.0V (30)> <4S - 2.4V (24)> <...> (Minimum recommended 2.7V)
uint8_t QCIdealVoltage; // Desired QC3.0 voltage (9,12,20V)
uint8_t OrientationMode : 2; // Selects between Auto,Right and left handed layouts
uint8_t sensitivity : 4; // Sensitivity of accelerometer (5 bits)
uint8_t animationLoop : 1; // Animation loop switch
uint8_t animationSpeed : 2; // Animation speed (in miliseconds)
uint8_t autoStartMode : 2; // Should the unit automatically jump straight
// into soldering mode when power is applied
uint8_t ShutdownTime; // Time until unit shuts down if left alone
//
SettingsOptionsLength, //
};
uint8_t coolingTempBlink : 1; // Should the temperature blink on the cool
// down screen until its <50C
uint8_t detailedIDLE : 1; // Detailed idle screen
uint8_t detailedSoldering : 1; // Detailed soldering screens
uint8_t temperatureInF : 1; // Should the temp be in F or C (true is F)
uint8_t descriptionScrollSpeed : 1; // Description scroll speed
uint8_t lockingMode : 2; // Store the locking mode
uint8_t KeepAwakePulse; // Keep Awake pulse power in 0.1 watts (10 = 1Watt)
uint8_t KeepAwakePulseWait; // Time between Keep Awake pulses in 2500 ms = 2.5 s increments
uint8_t KeepAwakePulseDuration; // Duration of the Keep Awake pusle in 250 ms increments
uint16_t voltageDiv; // Voltage divisor factor
uint16_t BoostTemp; // Boost mode set point for the iron
uint16_t CalibrationOffset; // This stores the temperature offset for this tip
// in the iron.
uint8_t powerLimit; // Maximum power iron allowed to output
uint8_t ReverseButtonTempChangeEnabled; // Change the plus and minus button assigment
uint16_t TempChangeLongStep; // Change the plus and minus button assigment
uint16_t TempChangeShortStep; // Change the plus and minus button assigment
uint8_t hallEffectSensitivity; // Operating mode of the hall effect sensor
uint8_t accelMissingWarningCounter; // Counter of how many times we have warned we cannot detect the accelerometer
uint8_t pdMissingWarningCounter; // Counter of how many times we have warned we cannot detect the pd interface
char uiLanguage[8]; // Selected UI Language code, null-terminated *only if* the length is less than 8 chars
uint8_t PDNegTimeout; // PD timeout in 100ms steps
uint32_t padding; // This is here for in case we are not an even divisor so
// that nothing gets cut off
// MUST BE LAST
} systemSettingsType;
typedef enum {
OFF = 0, // Off (disabled)
SLOW = 1, //
@@ -75,12 +59,22 @@ typedef enum {
FAST = 3, //
MAX_VALUE = 4 //
} settingOffSpeed_t;
extern volatile systemSettingsType systemSettings;
// Settings wide operations
void saveSettings();
bool loadSettings();
void resetSettings();
void saveSettings();
bool restoreSettings();
// Settings access
uint16_t getSettingValue(const enum SettingsOptions option);
// Returns true if setting is now on the last value (next iteration will wrap)
bool nextSettingValue(const enum SettingsOptions option);
bool prevSettingValue(const enum SettingsOptions option);
void setSettingValue(const enum SettingsOptions option, const uint16_t newValue);
// Special access
uint8_t lookupVoltageLevel();
uint16_t lookupHallEffectThreshold();
void resetSettings();
#endif /* SETTINGS_H_ */

View File

@@ -40,7 +40,7 @@ bool ScrollMessage::drawUpdate(const char *message, uint32_t currentTick) {
int16_t messageOffset;
uint16_t msgWidth = messageWidth(message);
if (msgWidth > OLED_WIDTH) {
messageOffset = ((currentTick - messageStart) / (systemSettings.descriptionScrollSpeed == 1 ? TICKS_100MS / 10 : (TICKS_100MS / 5)));
messageOffset = ((currentTick - messageStart) / (getSettingValue(SettingsOptions::DescriptionScrollSpeed) == 1 ? TICKS_100MS / 10 : (TICKS_100MS / 5)));
messageOffset %= msgWidth + OLED_WIDTH; // Roll around at the end
if (messageOffset < OLED_WIDTH) {
// Snap the message to the left edge.

View File

@@ -12,85 +12,147 @@
#include "BSP.h"
#include "Setup.h"
#include "configuration.h"
#include <string.h> // for memset
bool sanitiseSettings();
#include "string.h"
/*
* This struct must be a multiple of 2 bytes as it is saved / restored from
* flash in uint16_t chunks
*/
typedef struct {
uint16_t length; // Length of valid bytes following
uint16_t settingsValues[SettingsOptionsLength];
// used to make this nicely "good enough" aligned to 32 butes to make driver code trivial
uint32_t padding;
} systemSettingsType;
//~1024 is common programming size, setting threshold to be lower so we have warning
static_assert(sizeof(systemSettingsType) < 512);
// char (*__kaboom)[sizeof(systemSettingsType)] = 1; // Uncomment to print size at compile time
volatile systemSettingsType systemSettings;
void saveSettings() {
// First we erase the flash
flash_save_buffer((uint8_t *)&systemSettings, sizeof(systemSettingsType));
}
// For every setting we need to store the min/max/increment values
typedef struct {
const uint16_t min; // Inclusive minimum value
const uint16_t max; // Exclusive maximum value
const uint16_t increment; // Standard increment
const uint16_t defaultValue; // Default vaue after reset
} SettingConstants;
static const SettingConstants settingsConstants[(int)SettingsOptions::SettingsOptionsLength] = {
//{min,max,increment,default}
{0, 0, 0, 0}, // SolderingTemp
{10, 580, 0, 0}, // SleepTemp
{0, 16, 1, 0}, // SleepTime
{0, 5, 1, 0}, // MinDCVoltageCells
{24, 38, 1, 31}, // MinVoltageCells
{0, 0, 0, 0}, // QCIdealVoltage
{0, 0, 0, 0}, // OrientationMode
{0, 10, 0, 0}, // Sensitivity
{0, 1, 1, 1}, // AnimationLoop
{0, settingOffSpeed_t::MAX_VALUE, 1, settingOffSpeed_t::MEDIUM}, // AnimationSpeed
{0, 4, 1, 0}, // AutoStartMode
{0, 60, 1, 0}, // ShutdownTime
{0, 1, 1, 0}, // CoolingTempBlink
{0, 1, 1, 0}, // DetailedIDLE
{0, 1, 1, 0}, // DetailedSoldering
{0, 1, 1, 0}, // TemperatureInF
{0, 0, 0, 0}, // DescriptionScrollSpeed
{0, 3, 1, 0}, // LockingMode
{0, 100, 1, 0}, // KeepAwakePulse
{1, POWER_PULSE_WAIT_MAX, 1, 0}, // KeepAwakePulseWait
{1, POWER_PULSE_DURATION_MAX, 1, 0}, // KeepAwakePulseDuration
{360, 900, 1, 0}, // VoltageDiv
{0, 0, 0, 0}, // BoostTemp
{0, 0, 0, 0}, // CalibrationOffset
{0, MAX_POWER_LIMIT, POWER_LIMIT_STEPS, 0}, // PowerLimit
{0, 1, 1, 0}, // ReverseButtonTempChangeEnabled
{5, 90, 5, 10}, // TempChangeLongStep
{1, TEMP_CHANGE_SHORT_STEP_MAX, 1, 1}, // TempChangeShortStep
{0, 4, 1, 0}, // HallEffectSensitivity
{0, 10, 1, 0}, // AccelMissingWarningCounter
{0, 10, 1, 0}, // PDMissingWarningCounter
{0, 0, 0, 0}, // UILanguage
{0, 50, 1, 0}, // PDNegTimeout
bool restoreSettings() {
};
void saveSettings() { flash_save_buffer((uint8_t *)&systemSettings, sizeof(systemSettingsType)); }
bool loadSettings() {
// We read the flash
flash_read_buffer((uint8_t *)&systemSettings, sizeof(systemSettingsType));
// if the version is correct were done
// if not we reset and save
if (systemSettings.version != SETTINGSVERSION) {
// probably not setup
resetSettings();
return true;
}
return false;
// Then ensure all values are valid
return sanitiseSettings();
}
// Lookup function for cutoff setting -> X10 voltage
/*
* 0=DC
* 1=3S
* 2=4S
* 3=5S
* 4=6S
*/
uint8_t lookupVoltageLevel() {
if (systemSettings.minDCVoltageCells == 0)
return 90; // 9V since iron does not function effectively below this
else
return (systemSettings.minDCVoltageCells * systemSettings.minVoltageCells) + (systemSettings.minVoltageCells * 2);
bool sanitiseSettings() {
// For all settings, need to ensure settings are in a valid range
// First for any not know about due to array growth, reset them and update the length value
bool dirty = false;
if (systemSettings.length < (int)SettingsOptions::SettingsOptionsLength) {
dirty = true;
for (int i = systemSettings.length; i < (int)SettingsOptions::SettingsOptionsLength; i++) {
systemSettings.settingsValues[i] = 0xFFFF; // Ensure its as if it was erased
}
systemSettings.length = (int)SettingsOptions::SettingsOptionsLength;
}
for (int i = 0; i < (int)SettingsOptions::SettingsOptionsLength; i++) {
// Check min max for all settings, if outside the range, move to default
if (systemSettings.settingsValues[i] < settingsConstants[i].min || systemSettings.settingsValues[i] > settingsConstants[i].max) {
systemSettings.settingsValues[i] = settingsConstants[i].defaultValue;
dirty = true;
}
}
if (dirty) {
saveSettings();
}
return dirty;
}
void resetSettings() {
memset((void *)&systemSettings, 0, sizeof(systemSettingsType));
systemSettings.SleepTemp = SLEEP_TEMP; // Temperature the iron sleeps at - default 150.0 C
systemSettings.SleepTime = SLEEP_TIME; // How many seconds/minutes we wait until going
// to sleep - default 1 min
systemSettings.SolderingTemp = SOLDERING_TEMP; // Default soldering temp is 320.0 C
systemSettings.minDCVoltageCells = CUT_OUT_SETTING; // default to no cut-off voltage
systemSettings.minVoltageCells = RECOM_VOL_CELL; // Minimum voltage per cell (Recommended 3.3V (33))
systemSettings.QCIdealVoltage = 0; // Default to 9V for QC3.0 Voltage
systemSettings.PDNegTimeout = 0; // Default for PD timout to 0
systemSettings.version = SETTINGSVERSION; // Store the version number to allow for easier upgrades
systemSettings.detailedSoldering = DETAILED_SOLDERING; // Detailed soldering screen
systemSettings.detailedIDLE = DETAILED_IDLE; // Detailed idle screen (off for first time users)
systemSettings.OrientationMode = ORIENTATION_MODE; // Default to automatic
systemSettings.sensitivity = SENSITIVITY; // Default high sensitivity
systemSettings.voltageDiv = VOLTAGE_DIV; // Default divider from schematic
systemSettings.ShutdownTime = SHUTDOWN_TIME; // How many minutes until the unit turns itself off
systemSettings.BoostTemp = BOOST_TEMP; // default to 400C
systemSettings.autoStartMode = AUTO_START_MODE; // Auto start off for safety
systemSettings.lockingMode = LOCKING_MODE; // Disable locking for safety
systemSettings.coolingTempBlink = COOLING_TEMP_BLINK; // Blink the temperature on the cooling screen when its > 50C
systemSettings.temperatureInF = TEMPERATURE_INF; // default to 0
systemSettings.descriptionScrollSpeed = DESCRIPTION_SCROLL_SPEED; // default to slow
systemSettings.animationLoop = ANIMATION_LOOP; // Default false
systemSettings.animationSpeed = ANIMATION_SPEED; // Default 400 ms (Medium)
systemSettings.CalibrationOffset = CALIBRATION_OFFSET; // the adc offset in uV
systemSettings.powerLimit = POWER_LIMIT; // 30 watts default limit
systemSettings.ReverseButtonTempChangeEnabled = REVERSE_BUTTON_TEMP_CHANGE; //
systemSettings.TempChangeShortStep = TEMP_CHANGE_SHORT_STEP; //
systemSettings.TempChangeLongStep = TEMP_CHANGE_LONG_STEP; //
systemSettings.KeepAwakePulse = POWER_PULSE_DEFAULT; // Power of the power pulse
systemSettings.KeepAwakePulseWait = POWER_PULSE_WAIT_DEFAULT; // Time between Keep Awake pulses in 2.5 second increments
systemSettings.KeepAwakePulseDuration = POWER_PULSE_DURATION_DEFAULT; // Duration of the Keep Awake pusle in 250ms increments
systemSettings.hallEffectSensitivity = 1;
systemSettings.accelMissingWarningCounter = 0;
systemSettings.pdMissingWarningCounter = 0;
memset((void *)&systemSettings, 0xFF, sizeof(systemSettingsType));
sanitiseSettings();
saveSettings(); // Save defaults
}
void setSettingValue(const enum SettingsOptions option, const uint16_t newValue) {
const auto constants = settingsConstants[(int)option];
systemSettings.settingsValues[(int)option] = newValue;
if (systemSettings.settingsValues[(int)option] < constants.min) {
systemSettings.settingsValues[(int)option] = constants.min;
}
// If hit max, constrain
if (systemSettings.settingsValues[(int)option] >= constants.max) {
systemSettings.settingsValues[(int)option] = constants.max - 1;
}
}
uint16_t getSettingValue(const enum SettingsOptions option) { return systemSettings.settingsValues[(int)option]; }
bool nextSettingValue(const enum SettingsOptions option) {
const auto constants = settingsConstants[(int)option];
if (systemSettings.settingsValues[(int)option] == (constants.max - 1)) {
systemSettings.settingsValues[(int)option] = constants.min;
} else {
systemSettings.settingsValues[(int)option] += constants.increment;
}
return systemSettings.settingsValues[(int)option] == constants.max - 1;
}
bool prevSettingValue(const enum SettingsOptions option) {
const auto constants = settingsConstants[(int)option];
int value = systemSettings.settingsValues[(int)option];
if (value == constants.min) {
value = constants.max;
} else {
value -= constants.increment;
}
systemSettings.settingsValues[(int)option] = value;
return systemSettings.settingsValues[(int)option] == constants.min;
}
uint16_t lookupHallEffectThreshold() {
// Return the threshold above which the hall effect sensor is "activated"
switch (systemSettings.hallEffectSensitivity) {
switch (getSettingValue(SettingsOptions::HallEffectSensitivity)) {
case 0:
return 0;
case 1: // Low
@@ -103,3 +165,19 @@ uint16_t lookupHallEffectThreshold() {
return 0; // Off
}
}
// Lookup function for cutoff setting -> X10 voltage
/*
* 0=DC
* 1=3S
* 2=4S
* 3=5S
* 4=6S
*/
uint8_t lookupVoltageLevel() {
auto minVoltageOnCell = getSettingValue(SettingsOptions::MinDCVoltageCells);
auto minVoltageCellCount = getSettingValue(SettingsOptions::MinVoltageCells);
if (minVoltageOnCell == 0)
return 90; // 9V since iron does not function effectively below this
else
return (minVoltageOnCell * minVoltageCellCount) + (minVoltageCellCount * 2);
}

View File

@@ -311,18 +311,13 @@ static int userConfirmation(const char *message) {
return 0;
}
#ifdef POW_DC
static bool settings_setInputVRange(void) {
systemSettings.minDCVoltageCells = (systemSettings.minDCVoltageCells + 1) % 5;
if (systemSettings.minDCVoltageCells == 1 && systemSettings.minVoltageCells < 30)
systemSettings.minVoltageCells = 30;
return systemSettings.minDCVoltageCells == 4;
}
static bool settings_setInputVRange(void) { return nextSettingValue(SettingsOptions::MinDCVoltageCells); }
static bool settings_displayInputVRange(void) {
printShortDescription(SettingsItemIndex::DCInCutoff, 6);
if (systemSettings.minDCVoltageCells) {
OLED::printNumber(2 + systemSettings.minDCVoltageCells, 1, FontStyle::LARGE);
if (getSettingValue(SettingsOptions::MinDCVoltageCells)) {
OLED::printNumber(2 + getSettingValue(SettingsOptions::MinDCVoltageCells), 1, FontStyle::LARGE);
OLED::print(SymbolCellCount, FontStyle::LARGE);
} else {
OLED::print(SymbolDC, FontStyle::LARGE);
@@ -330,21 +325,14 @@ static bool settings_displayInputVRange(void) {
return false;
}
static bool settings_setInputMinVRange(void) {
systemSettings.minVoltageCells = (systemSettings.minVoltageCells + 1) % 38;
if (systemSettings.minDCVoltageCells == 1 && systemSettings.minVoltageCells < 30)
systemSettings.minVoltageCells = 30;
else if (systemSettings.minVoltageCells < 24)
systemSettings.minVoltageCells = 24;
return systemSettings.minVoltageCells == 37;
}
static bool settings_setInputMinVRange(void) { return nextSettingValue(SettingsOptions::MinVoltageCells); }
static bool settings_displayInputMinVRange(void) {
if (systemSettings.minDCVoltageCells) {
if (getSettingValue(SettingsOptions::MinDCVoltageCells)) {
printShortDescription(SettingsItemIndex::MinVolCell, 4);
OLED::printNumber(systemSettings.minVoltageCells / 10, 2, FontStyle::LARGE);
OLED::printNumber(getSettingValue(SettingsOptions::MinVoltageCells) / 10, 2, FontStyle::LARGE);
OLED::print(SymbolDot, FontStyle::LARGE);
OLED::printNumber(systemSettings.minVoltageCells % 10, 1, FontStyle::LARGE);
OLED::printNumber(getSettingValue(SettingsOptions::MinVoltageCells) % 10, 1, FontStyle::LARGE);
} else {
printShortDescription(SettingsItemIndex::MinVolCell, 5);
OLED::print(translatedString(Tr->SettingNAChar), FontStyle::LARGE);
@@ -368,7 +356,7 @@ static bool settings_displayQCInputV(void) {
printShortDescription(SettingsItemIndex::QCMaxVoltage, 5);
// 0 = 9V, 1=12V, 2=20V (Fixed Voltages)
// These are only used in QC modes
switch (systemSettings.QCIdealVoltage) {
switch (getSettingValue(SettingsOptions::QCIdealVoltage)) {
case 0:
OLED::printNumber(9, 2, FontStyle::LARGE);
OLED::print(SymbolVolts, FontStyle::LARGE);
@@ -390,192 +378,159 @@ static bool settings_displayQCInputV(void) {
#endif
#ifdef POW_PD
static bool settings_setPDNegTimeout(void) {
systemSettings.PDNegTimeout = (systemSettings.PDNegTimeout + 1) % 50;
return systemSettings.PDNegTimeout == 49;
}
static bool settings_setPDNegTimeout(void) { return nextSettingValue(SettingsOptions::PDNegTimeout); }
static bool settings_displayPDNegTimeout(void) {
printShortDescription(SettingsItemIndex::PDNegTimeout, 5);
OLED::printNumber(systemSettings.PDNegTimeout, 2, FontStyle::LARGE);
OLED::printNumber(getSettingValue(SettingsOptions::PDNegTimeout), 2, FontStyle::LARGE);
return systemSettings.PDNegTimeout == 49;
return false;
}
#endif
#ifndef NO_SLEEP_MODE
static bool settings_setSleepTemp(void) {
// If in C, 10 deg, if in F 20 deg
if (systemSettings.temperatureInF) {
systemSettings.SleepTemp += 20;
if (systemSettings.SleepTemp > 580)
systemSettings.SleepTemp = 60;
return systemSettings.SleepTemp == 580;
uint16_t temp = getSettingValue(SettingsOptions::SleepTemp);
if (getSettingValue(SettingsOptions::TemperatureInF)) {
temp += 20;
if (temp > 580)
temp = 60;
setSettingValue(SettingsOptions::SleepTemp, temp);
return temp == 580;
} else {
systemSettings.SleepTemp += 10;
if (systemSettings.SleepTemp > 300)
systemSettings.SleepTemp = 10;
return systemSettings.SleepTemp == 300;
temp += 10;
if (temp > 300)
temp = 10;
setSettingValue(SettingsOptions::SleepTemp, temp);
return temp == 300;
}
}
static bool settings_displaySleepTemp(void) {
printShortDescription(SettingsItemIndex::SleepTemperature, 5);
OLED::printNumber(systemSettings.SleepTemp, 3, FontStyle::LARGE);
OLED::printNumber(getSettingValue(SettingsOptions::SleepTemp), 3, FontStyle::LARGE);
return false;
}
static bool settings_setSleepTime(void) {
systemSettings.SleepTime++; // Go up 1 minute at a time
if (systemSettings.SleepTime >= 16) {
systemSettings.SleepTime = 0; // can't set time over 10 mins
}
// Remember that ^ is the time of no movement
if (DetectedAccelerometerVersion == NO_DETECTED_ACCELEROMETER)
systemSettings.SleepTime = 0; // Disable sleep on no accel
return systemSettings.SleepTime == 15;
}
static bool settings_setSleepTime(void) { return nextSettingValue(SettingsOptions::SleepTime); }
static bool settings_displaySleepTime(void) {
printShortDescription(SettingsItemIndex::SleepTimeout, 5);
if (systemSettings.SleepTime == 0) {
if (getSettingValue(SettingsOptions::SleepTime) == 0) {
OLED::print(translatedString(Tr->OffString), FontStyle::LARGE);
} else if (systemSettings.SleepTime < 6) {
OLED::printNumber(systemSettings.SleepTime * 10, 2, FontStyle::LARGE);
} else if (getSettingValue(SettingsOptions::SleepTime) < 6) {
OLED::printNumber(getSettingValue(SettingsOptions::SleepTime) * 10, 2, FontStyle::LARGE);
OLED::print(SymbolSeconds, FontStyle::LARGE);
} else {
OLED::printNumber(systemSettings.SleepTime - 5, 2, FontStyle::LARGE);
OLED::printNumber(getSettingValue(SettingsOptions::SleepTime) - 5, 2, FontStyle::LARGE);
OLED::print(SymbolMinutes, FontStyle::LARGE);
}
return false;
}
#endif
static bool settings_setShutdownTime(void) {
systemSettings.ShutdownTime++;
if (systemSettings.ShutdownTime > 60) {
systemSettings.ShutdownTime = 0; // wrap to off
}
if (DetectedAccelerometerVersion == NO_DETECTED_ACCELEROMETER)
systemSettings.ShutdownTime = 0; // Disable shutdown on no accel
return systemSettings.ShutdownTime == 60;
}
static bool settings_setShutdownTime(void) { return nextSettingValue(SettingsOptions::ShutdownTime); }
static bool settings_displayShutdownTime(void) {
printShortDescription(SettingsItemIndex::ShutdownTimeout, 5);
if (systemSettings.ShutdownTime == 0) {
if (getSettingValue(SettingsOptions::ShutdownTime) == 0) {
OLED::print(translatedString(Tr->OffString), FontStyle::LARGE);
} else {
OLED::printNumber(systemSettings.ShutdownTime, 2, FontStyle::LARGE);
OLED::printNumber(getSettingValue(SettingsOptions::ShutdownTime), 2, FontStyle::LARGE);
OLED::print(SymbolMinutes, FontStyle::LARGE);
}
return false;
}
static bool settings_setTempF(void) {
systemSettings.temperatureInF = !systemSettings.temperatureInF;
if (systemSettings.temperatureInF) {
nextSettingValue(SettingsOptions::SleepTime);
uint16_t BoostTemp = getSettingValue(SettingsOptions::BoostTemp);
uint16_t SolderingTemp = getSettingValue(SettingsOptions::SolderingTemp);
uint16_t SleepTemp = getSettingValue(SettingsOptions::SleepTemp);
if (getSettingValue(SettingsOptions::TemperatureInF)) {
// Change sleep, boost and soldering temps to the F equiv
// C to F == F= ( (C*9) +160)/5
systemSettings.BoostTemp = ((systemSettings.BoostTemp * 9) + 160) / 5;
systemSettings.SolderingTemp = ((systemSettings.SolderingTemp * 9) + 160) / 5;
systemSettings.SleepTemp = ((systemSettings.SleepTemp * 9) + 160) / 5;
BoostTemp = ((BoostTemp * 9) + 160) / 5;
SolderingTemp = ((SolderingTemp * 9) + 160) / 5;
SleepTemp = ((SleepTemp * 9) + 160) / 5;
} else {
// Change sleep, boost and soldering temps to the C equiv
// F->C == C = ((F-32)*5)/9
systemSettings.BoostTemp = ((systemSettings.BoostTemp - 32) * 5) / 9;
systemSettings.SolderingTemp = ((systemSettings.SolderingTemp - 32) * 5) / 9;
systemSettings.SleepTemp = ((systemSettings.SleepTemp - 32) * 5) / 9;
BoostTemp = ((BoostTemp - 32) * 5) / 9;
SolderingTemp = ((SolderingTemp - 32) * 5) / 9;
SleepTemp = ((SleepTemp - 32) * 5) / 9;
}
// Rescale both to be multiples of 10
systemSettings.BoostTemp = systemSettings.BoostTemp / 10;
systemSettings.BoostTemp *= 10;
systemSettings.SolderingTemp = systemSettings.SolderingTemp / 10;
systemSettings.SolderingTemp *= 10;
systemSettings.SleepTemp = systemSettings.SleepTemp / 10;
systemSettings.SleepTemp *= 10;
BoostTemp = BoostTemp / 10;
BoostTemp *= 10;
SolderingTemp = SolderingTemp / 10;
SolderingTemp *= 10;
SleepTemp = SleepTemp / 10;
SleepTemp *= 10;
setSettingValue(SettingsOptions::BoostTemp, BoostTemp);
setSettingValue(SettingsOptions::SolderingTemp, SolderingTemp);
setSettingValue(SettingsOptions::SleepTemp, SleepTemp);
return false;
}
static bool settings_displayTempF(void) {
printShortDescription(SettingsItemIndex::TemperatureUnit, 7);
OLED::print((systemSettings.temperatureInF) ? SymbolDegF : SymbolDegC, FontStyle::LARGE);
OLED::print((getSettingValue(SettingsOptions::TemperatureInF)) ? SymbolDegF : SymbolDegC, FontStyle::LARGE);
return false;
}
static bool settings_setSensitivity(void) {
systemSettings.sensitivity++;
systemSettings.sensitivity = systemSettings.sensitivity % 10;
return systemSettings.sensitivity == 9;
}
static bool settings_setSensitivity(void) { return nextSettingValue(SettingsOptions::Sensitivity); }
static bool settings_displaySensitivity(void) {
printShortDescription(SettingsItemIndex::MotionSensitivity, 7);
OLED::printNumber(systemSettings.sensitivity, 1, FontStyle::LARGE, false);
OLED::printNumber(getSettingValue(SettingsOptions::Sensitivity), 1, FontStyle::LARGE, false);
return false;
}
static bool settings_setAdvancedSolderingScreens(void) {
systemSettings.detailedSoldering = !systemSettings.detailedSoldering;
return false;
}
static bool settings_setAdvancedSolderingScreens(void) { return nextSettingValue(SettingsOptions::DetailedSoldering); }
static bool settings_displayAdvancedSolderingScreens(void) {
printShortDescription(SettingsItemIndex::AdvancedSoldering, 7);
OLED::drawCheckbox(systemSettings.detailedSoldering);
OLED::drawCheckbox(getSettingValue(SettingsOptions::DetailedSoldering));
return false;
}
static bool settings_setAdvancedIDLEScreens(void) {
systemSettings.detailedIDLE = !systemSettings.detailedIDLE;
return false;
}
static bool settings_setAdvancedIDLEScreens(void) { return nextSettingValue(SettingsOptions::DetailedIDLE); }
static bool settings_displayAdvancedIDLEScreens(void) {
printShortDescription(SettingsItemIndex::AdvancedIdle, 7);
OLED::drawCheckbox(systemSettings.detailedIDLE);
OLED::drawCheckbox(getSettingValue(SettingsOptions::DetailedIDLE));
return false;
}
static bool settings_setPowerLimit(void) {
systemSettings.powerLimit += POWER_LIMIT_STEPS;
if (systemSettings.powerLimit > MAX_POWER_LIMIT)
systemSettings.powerLimit = 0;
return systemSettings.powerLimit + POWER_LIMIT_STEPS > MAX_POWER_LIMIT;
}
static bool settings_setPowerLimit(void) { return nextSettingValue(SettingsOptions::PowerLimit); }
static bool settings_displayPowerLimit(void) {
printShortDescription(SettingsItemIndex::PowerLimit, 5);
if (systemSettings.powerLimit == 0) {
if (getSettingValue(SettingsOptions::PowerLimit) == 0) {
OLED::print(translatedString(Tr->OffString), FontStyle::LARGE);
} else {
OLED::printNumber(systemSettings.powerLimit, 2, FontStyle::LARGE);
OLED::printNumber(getSettingValue(SettingsOptions::PowerLimit), 2, FontStyle::LARGE);
OLED::print(SymbolWatts, FontStyle::LARGE);
}
return false;
}
static bool settings_setScrollSpeed(void) {
if (systemSettings.descriptionScrollSpeed == 0)
systemSettings.descriptionScrollSpeed = 1;
else
systemSettings.descriptionScrollSpeed = 0;
return false;
}
static bool settings_setScrollSpeed(void) { return nextSettingValue(SettingsOptions::DescriptionScrollSpeed); }
static bool settings_displayScrollSpeed(void) {
printShortDescription(SettingsItemIndex::ScrollingSpeed, 7);
OLED::print(translatedString((systemSettings.descriptionScrollSpeed) ? Tr->SettingFastChar : Tr->SettingSlowChar), FontStyle::LARGE);
OLED::print(translatedString((getSettingValue(SettingsOptions::DescriptionScrollSpeed)) ? Tr->SettingFastChar : Tr->SettingSlowChar), FontStyle::LARGE);
return false;
}
#ifndef NO_DISPLAY_ROTATE
static bool settings_setDisplayRotation(void) {
systemSettings.OrientationMode++;
systemSettings.OrientationMode = systemSettings.OrientationMode % 3;
switch (systemSettings.OrientationMode) {
bool res = nextSettingValue(SettingsOptions::OrientationMode);
switch (getSettingValue(SettingsOptions::OrientationMode)) {
case 0:
OLED::setRotation(false);
break;
@@ -588,13 +543,13 @@ static bool settings_setDisplayRotation(void) {
default:
break;
}
return systemSettings.OrientationMode == 2;
return res;
}
static bool settings_displayDisplayRotation(void) {
printShortDescription(SettingsItemIndex::DisplayRotation, 7);
switch (systemSettings.OrientationMode) {
switch (getSettingValue(SettingsOptions::OrientationMode)) {
case 0:
OLED::print(translatedString(Tr->SettingRightChar), FontStyle::LARGE);
break;
@@ -612,50 +567,48 @@ static bool settings_displayDisplayRotation(void) {
}
#endif
static bool settings_setBoostTemp(void) {
if (systemSettings.temperatureInF) {
if (systemSettings.BoostTemp == 0) {
systemSettings.BoostTemp = MIN_BOOST_TEMP_F; // loop back at 480
uint16_t value = getSettingValue(SettingsOptions::BoostTemp);
if (getSettingValue(SettingsOptions::TemperatureInF)) {
if (value == 0) {
value = MIN_BOOST_TEMP_F; // loop back at 480
} else {
systemSettings.BoostTemp += 20; // Go up 20F at a time
value += 20; // Go up 20F at a time
}
if (systemSettings.BoostTemp > MAX_TEMP_F) {
systemSettings.BoostTemp = 0; // jump to off
if (value > MAX_TEMP_F) {
value = 0; // jump to off
}
return systemSettings.BoostTemp == MAX_TEMP_F - 10;
} else {
if (systemSettings.BoostTemp == 0) {
systemSettings.BoostTemp = MIN_BOOST_TEMP_C; // loop back at 250
} else {
systemSettings.BoostTemp += 10; // Go up 10C at a time
}
if (systemSettings.BoostTemp > MAX_TEMP_C) {
systemSettings.BoostTemp = 0; // Go to off state
}
return systemSettings.BoostTemp == MAX_TEMP_C;
setSettingValue(SettingsOptions::BoostTemp, value);
return value == MAX_TEMP_F - 10;
}
if (value == 0) {
value = MIN_BOOST_TEMP_C; // loop back at 250
} else {
value += 10; // Go up 10C at a time
}
if (value > MAX_TEMP_C) {
value = 0; // Go to off state
}
setSettingValue(SettingsOptions::BoostTemp, value);
return value == MAX_TEMP_C;
}
static bool settings_displayBoostTemp(void) {
printShortDescription(SettingsItemIndex::BoostTemperature, 5);
if (systemSettings.BoostTemp) {
OLED::printNumber(systemSettings.BoostTemp, 3, FontStyle::LARGE);
if (getSettingValue(SettingsOptions::BoostTemp)) {
OLED::printNumber(getSettingValue(SettingsOptions::BoostTemp), 3, FontStyle::LARGE);
} else {
OLED::print(translatedString(Tr->OffString), FontStyle::LARGE);
}
return false;
}
static bool settings_setAutomaticStartMode(void) {
systemSettings.autoStartMode++;
systemSettings.autoStartMode %= 4;
return systemSettings.autoStartMode == 3;
}
static bool settings_setAutomaticStartMode(void) { return nextSettingValue(SettingsOptions::AutoStartMode); }
static bool settings_displayAutomaticStartMode(void) {
printShortDescription(SettingsItemIndex::AutoStart, 7);
switch (systemSettings.autoStartMode) {
switch (getSettingValue(SettingsOptions::AutoStartMode)) {
case 0:
OLED::print(translatedString(Tr->SettingStartNoneChar), FontStyle::LARGE);
break;
@@ -675,16 +628,12 @@ static bool settings_displayAutomaticStartMode(void) {
return false;
}
static bool settings_setLockingMode(void) {
systemSettings.lockingMode++;
systemSettings.lockingMode %= 3;
return systemSettings.lockingMode == 2;
}
static bool settings_setLockingMode(void) { return nextSettingValue(SettingsOptions::LockingMode); }
static bool settings_displayLockingMode(void) {
printShortDescription(SettingsItemIndex::LockingMode, 7);
switch (systemSettings.lockingMode) {
switch (getSettingValue(SettingsOptions::LockingMode)) {
case 0:
OLED::print(translatedString(Tr->SettingLockDisableChar), FontStyle::LARGE);
break;
@@ -701,14 +650,11 @@ static bool settings_displayLockingMode(void) {
return false;
}
static bool settings_setCoolingBlinkEnabled(void) {
systemSettings.coolingTempBlink = !systemSettings.coolingTempBlink;
return false;
}
static bool settings_setCoolingBlinkEnabled(void) { return nextSettingValue(SettingsOptions::CoolingTempBlink); }
static bool settings_displayCoolingBlinkEnabled(void) {
printShortDescription(SettingsItemIndex::CooldownBlink, 7);
OLED::drawCheckbox(systemSettings.coolingTempBlink);
OLED::drawCheckbox(getSettingValue(SettingsOptions::CoolingTempBlink));
return false;
}
@@ -726,12 +672,12 @@ static bool settings_displayResetSettings(void) {
}
static void setTipOffset() {
systemSettings.CalibrationOffset = 0;
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 (systemSettings.CalibrationOffset == 0) {
while (setoffset == 0) {
uint32_t offset = 0;
for (uint8_t i = 0; i < 16; i++) {
offset += getTipRawTemp(1);
@@ -744,12 +690,13 @@ static void setTipOffset() {
OLED::refresh();
osDelay(100);
}
systemSettings.CalibrationOffset = TipThermoModel::convertTipRawADCTouV(offset / 16);
setoffset = TipThermoModel::convertTipRawADCTouV(offset / 16);
}
setSettingValue(SettingsOptions::CalibrationOffset, setoffset);
OLED::clearScreen();
OLED::setCursor(0, 0);
OLED::drawCheckbox(true);
OLED::printNumber(systemSettings.CalibrationOffset, 4, FontStyle::LARGE);
OLED::printNumber(setoffset, 4, FontStyle::LARGE);
OLED::refresh();
osDelay(1200);
}
@@ -777,27 +724,25 @@ static bool settings_setCalibrateVIN(void) {
for (;;) {
OLED::setCursor(0, 0);
OLED::printNumber(getInputVoltageX10(systemSettings.voltageDiv, 0) / 10, 2, FontStyle::LARGE);
uint16_t voltage = getInputVoltageX10(getSettingValue(SettingsOptions::VoltageDiv), 0);
OLED::printNumber(voltage / 10, 2, FontStyle::LARGE);
OLED::print(SymbolDot, FontStyle::LARGE);
OLED::printNumber(getInputVoltageX10(systemSettings.voltageDiv, 0) % 10, 1, FontStyle::LARGE, false);
OLED::printNumber(voltage % 10, 1, FontStyle::LARGE, false);
OLED::print(SymbolVolts, FontStyle::LARGE);
ButtonState buttons = getButtonState();
switch (buttons) {
switch (getButtonState()) {
case BUTTON_F_SHORT:
systemSettings.voltageDiv++;
nextSettingValue(SettingsOptions::VoltageDiv);
break;
case BUTTON_B_SHORT:
systemSettings.voltageDiv--;
prevSettingValue(SettingsOptions::VoltageDiv);
break;
case BUTTON_BOTH:
case BUTTON_F_LONG:
case BUTTON_B_LONG:
saveSettings();
OLED::setCursor(0, 0);
OLED::printNumber(systemSettings.voltageDiv, 3, FontStyle::LARGE);
OLED::printNumber(getSettingValue(SettingsOptions::VoltageDiv), 3, FontStyle::LARGE);
OLED::refresh();
waitForButtonPressOrTimeout(1 * TICKS_SECOND);
return false;
@@ -808,108 +753,60 @@ static bool settings_setCalibrateVIN(void) {
OLED::refresh();
osDelay(40);
// Cap to sensible values
#if defined(MODEL_TS80) + defined(MODEL_TS80P) > 0
if (systemSettings.voltageDiv < 500) {
systemSettings.voltageDiv = 500;
} else if (systemSettings.voltageDiv > 900) {
systemSettings.voltageDiv = 900;
}
#else
if (systemSettings.voltageDiv < 360) {
systemSettings.voltageDiv = 360;
} else if (systemSettings.voltageDiv > 520) {
systemSettings.voltageDiv = 520;
}
#endif
}
return false;
}
static bool settings_setReverseButtonTempChangeEnabled(void) {
systemSettings.ReverseButtonTempChangeEnabled = !systemSettings.ReverseButtonTempChangeEnabled;
return false;
}
static bool settings_setReverseButtonTempChangeEnabled(void) { return nextSettingValue(SettingsOptions::ReverseButtonTempChangeEnabled); }
static bool settings_displayReverseButtonTempChangeEnabled(void) {
printShortDescription(SettingsItemIndex::ReverseButtonTempChange, 7);
OLED::drawCheckbox(systemSettings.ReverseButtonTempChangeEnabled);
OLED::drawCheckbox(getSettingValue(SettingsOptions::ReverseButtonTempChangeEnabled));
return false;
}
static bool settings_setTempChangeShortStep(void) {
systemSettings.TempChangeShortStep += TEMP_CHANGE_SHORT_STEP;
if (systemSettings.TempChangeShortStep > TEMP_CHANGE_SHORT_STEP_MAX) {
systemSettings.TempChangeShortStep = TEMP_CHANGE_SHORT_STEP; // loop back at TEMP_CHANGE_SHORT_STEP_MAX
}
return systemSettings.TempChangeShortStep == TEMP_CHANGE_SHORT_STEP_MAX;
}
static bool settings_setTempChangeShortStep(void) { return nextSettingValue(SettingsOptions::TempChangeShortStep); }
static bool settings_displayTempChangeShortStep(void) {
printShortDescription(SettingsItemIndex::TempChangeShortStep, 6);
OLED::printNumber(systemSettings.TempChangeShortStep, 2, FontStyle::LARGE);
OLED::printNumber(getSettingValue(SettingsOptions::TempChangeShortStep), 2, FontStyle::LARGE);
return false;
}
static bool settings_setTempChangeLongStep(void) {
if (systemSettings.TempChangeLongStep == TEMP_CHANGE_SHORT_STEP) {
systemSettings.TempChangeLongStep = TEMP_CHANGE_LONG_STEP / 2;
} else if (systemSettings.TempChangeLongStep == TEMP_CHANGE_LONG_STEP / 2) {
systemSettings.TempChangeLongStep = TEMP_CHANGE_LONG_STEP;
} else {
systemSettings.TempChangeLongStep += TEMP_CHANGE_LONG_STEP;
}
if (systemSettings.TempChangeLongStep > TEMP_CHANGE_LONG_STEP_MAX) {
systemSettings.TempChangeLongStep = TEMP_CHANGE_SHORT_STEP; // loop back at TEMP_CHANGE_LONG_STEP_MAX
}
return systemSettings.TempChangeLongStep == TEMP_CHANGE_LONG_STEP_MAX;
}
static bool settings_setTempChangeLongStep(void) { return nextSettingValue(SettingsOptions::TempChangeLongStep); }
static bool settings_displayTempChangeLongStep(void) {
printShortDescription(SettingsItemIndex::TempChangeLongStep, 6);
OLED::printNumber(systemSettings.TempChangeLongStep, 2, FontStyle::LARGE);
OLED::printNumber(getSettingValue(SettingsOptions::TempChangeLongStep), 2, FontStyle::LARGE);
return false;
}
static bool settings_setPowerPulse(void) {
systemSettings.KeepAwakePulse += POWER_PULSE_INCREMENT;
systemSettings.KeepAwakePulse %= POWER_PULSE_MAX;
return systemSettings.KeepAwakePulse == POWER_PULSE_MAX - 1;
}
static bool settings_setPowerPulse(void) { return nextSettingValue(SettingsOptions::KeepAwakePulse); }
static bool settings_displayPowerPulse(void) {
printShortDescription(SettingsItemIndex::PowerPulsePower, 5);
if (systemSettings.KeepAwakePulse) {
OLED::printNumber(systemSettings.KeepAwakePulse / 10, 1, FontStyle::LARGE);
if (getSettingValue(SettingsOptions::KeepAwakePulse)) {
OLED::printNumber(getSettingValue(SettingsOptions::KeepAwakePulse) / 10, 1, FontStyle::LARGE);
OLED::print(SymbolDot, FontStyle::LARGE);
OLED::printNumber(systemSettings.KeepAwakePulse % 10, 1, FontStyle::LARGE);
OLED::printNumber(getSettingValue(SettingsOptions::KeepAwakePulse) % 10, 1, FontStyle::LARGE);
} else {
OLED::print(translatedString(Tr->OffString), FontStyle::LARGE);
}
return false;
}
static bool settings_setAnimationLoop(void) {
systemSettings.animationLoop = !systemSettings.animationLoop;
return false;
}
static bool settings_setAnimationLoop(void) { return nextSettingValue(SettingsOptions::AnimationLoop); }
static bool settings_displayAnimationLoop(void) {
printShortDescription(SettingsItemIndex::AnimLoop, 7);
OLED::drawCheckbox(systemSettings.animationLoop);
OLED::drawCheckbox(getSettingValue(SettingsOptions::AnimationLoop));
return false;
}
static bool settings_setAnimationSpeed(void) {
systemSettings.animationSpeed++;
systemSettings.animationSpeed %= settingOffSpeed_t::MAX_VALUE;
return systemSettings.animationSpeed == (uint8_t)settingOffSpeed_t::FAST;
}
static bool settings_setAnimationSpeed(void) { return nextSettingValue(SettingsOptions::AnimationSpeed); }
static bool settings_displayAnimationSpeed(void) {
printShortDescription(SettingsItemIndex::AnimSpeed, 7);
switch (systemSettings.animationSpeed) {
switch (getSettingValue(SettingsOptions::AnimationSpeed)) {
case settingOffSpeed_t::SLOW:
OLED::print(translatedString(Tr->SettingSlowChar), FontStyle::LARGE);
break;
@@ -926,20 +823,12 @@ static bool settings_displayAnimationSpeed(void) {
return false;
}
static bool settings_setPowerPulseWait(void) {
// Constrain to range 1 to POWER_PULSE_WAIT_MAX inclusive
auto &wait = systemSettings.KeepAwakePulseWait;
if (++wait > POWER_PULSE_WAIT_MAX) {
wait = 1;
}
return wait == POWER_PULSE_WAIT_MAX;
}
static bool settings_setPowerPulseWait(void) { return nextSettingValue(SettingsOptions::KeepAwakePulseWait); }
static bool settings_displayPowerPulseWait(void) {
if (systemSettings.KeepAwakePulse) {
if (getSettingValue(SettingsOptions::KeepAwakePulse)) {
printShortDescription(SettingsItemIndex::PowerPulseWait, 7);
OLED::printNumber(systemSettings.KeepAwakePulseWait, 1, FontStyle::LARGE);
OLED::printNumber(getSettingValue(SettingsOptions::KeepAwakePulseWait), 1, FontStyle::LARGE);
return false;
} else {
return true; // skip
@@ -948,18 +837,13 @@ static bool settings_displayPowerPulseWait(void) {
static bool settings_setPowerPulseDuration(void) {
// Constrain to range 1 to POWER_PULSE_DURATION_MAX inclusive
auto &duration = systemSettings.KeepAwakePulseDuration;
if (++duration > POWER_PULSE_DURATION_MAX) {
duration = 1;
}
return duration == POWER_PULSE_DURATION_MAX;
return nextSettingValue(SettingsOptions::KeepAwakePulseDuration);
}
static bool settings_displayPowerPulseDuration(void) {
if (systemSettings.KeepAwakePulse) {
if (getSettingValue(SettingsOptions::KeepAwakePulse)) {
printShortDescription(SettingsItemIndex::PowerPulseDuration, 7);
OLED::printNumber(systemSettings.KeepAwakePulseDuration, 1, FontStyle::LARGE);
OLED::printNumber(getSettingValue(SettingsOptions::KeepAwakePulseDuration), 1, FontStyle::LARGE);
return false;
} else {
return true; // skip
@@ -969,7 +853,7 @@ static bool settings_displayPowerPulseDuration(void) {
#ifdef HALL_SENSOR
static bool settings_displayHallEffect(void) {
printShortDescription(SettingsItemIndex::HallEffSensitivity, 7);
switch (systemSettings.hallEffectSensitivity) {
switch (getSettingValue(SettingsOptions::HallEffectSensitivity)) {
case 1:
OLED::print(translatedString(Tr->SettingSensitivityLow), FontStyle::LARGE);
break;
@@ -986,13 +870,7 @@ static bool settings_displayHallEffect(void) {
}
return false;
}
static bool settings_setHallEffect(void) {
// To keep life simpler for now, we have a few preset sensitivity levels
// Off, Low, Medium, High
systemSettings.hallEffectSensitivity++;
systemSettings.hallEffectSensitivity %= 4;
return systemSettings.hallEffectSensitivity == 3;
}
static bool settings_setHallEffect(void) { return nextSettingValue(SettingsOptions::HallEffectSensitivity); }
#endif
// Indicates whether a menu transition is in progress, so that the menu icon
@@ -1003,13 +881,10 @@ static void displayMenu(size_t index) {
// Call into the menu
// Draw title
OLED::printWholeScreen(translatedString(Tr->SettingsMenuEntries[index]));
// Draw symbol
// 16 pixel wide image
// 2 pixel wide scrolling indicator
static TickType_t menuSwitchLoopTick = 0;
static size_t menuCurrentIndex = sizeof(rootSettingsMenu) + 1;
TickType_t step = TICKS_100MS * 5;
switch (systemSettings.animationSpeed) {
switch (getSettingValue(SettingsOptions::AnimationSpeed)) {
case settingOffSpeed_t::FAST:
step = TICKS_100MS * 3;
break;
@@ -1020,13 +895,13 @@ static void displayMenu(size_t index) {
break;
}
size_t currentFrame;
if (!animOpenState && systemSettings.animationSpeed != settingOffSpeed_t::OFF) {
if (!animOpenState && (getSettingValue(SettingsOptions::AnimationSpeed) != settingOffSpeed_t::OFF)) {
if (menuCurrentIndex != index) {
menuCurrentIndex = index;
menuSwitchLoopTick = xTaskGetTickCount();
}
currentFrame = ((xTaskGetTickCount() - menuSwitchLoopTick) / step);
if (systemSettings.animationLoop) {
if (getSettingValue(SettingsOptions::AnimationLoop)) {
currentFrame %= 3;
} else if (currentFrame > 2) {
currentFrame = 2;
@@ -1035,8 +910,11 @@ static void displayMenu(size_t index) {
// We want the animation to restart after completing the transition.
menuCurrentIndex = sizeof(rootSettingsMenu) + 1;
// Always draw the last frame if icon animation is disabled.
currentFrame = systemSettings.animationSpeed == settingOffSpeed_t::OFF ? 2 : 0;
currentFrame = getSettingValue(SettingsOptions::AnimationSpeed) == settingOffSpeed_t::OFF ? 2 : 0;
}
// Draw symbol
// 16 pixel wide image
// 2 pixel wide scrolling indicator
OLED::drawArea(OLED_WIDTH - 16 - 2, 0, 16, 16, (&SettingsMenuIcons[index][(16 * 2) * currentFrame]));
}

View File

@@ -40,7 +40,7 @@ int main(void) {
setTipX10Watts(0); // force tip off
resetWatchdog();
// Testing for which accelerometer is mounted
settingsWereReset = restoreSettings(); // load the settings from flash
settingsWereReset = loadSettings(); // load the settings from flash
resetWatchdog();
/* Create the thread(s) */

View File

@@ -33,7 +33,7 @@ static uint32_t availableW10(uint8_t sample) {
// P = V^2 / R, v*v = v^2 * 100
// R = R*10
// P therefore is in V^2*100/R*10 = W*10.
uint32_t v = getInputVoltageX10(systemSettings.voltageDiv, sample); // 100 = 10v
uint32_t v = getInputVoltageX10(getSettingValue(SettingsOptions::VoltageDiv), sample); // 100 = 10v
uint32_t availableWattsX10 = (v * v) / tipResistance;
// However, 100% duty cycle is not possible as there is a dead time while the ADC takes a reading
// Therefore need to scale available milliwats by this
@@ -50,7 +50,7 @@ uint8_t X10WattsToPWM(int32_t milliWatts, uint8_t sample) {
// Scale input milliWatts to the pwm range available
if (milliWatts < 1) {
// keep the battery voltage updating the filter
getInputVoltageX10(systemSettings.voltageDiv, sample);
getInputVoltageX10(getSettingValue(SettingsOptions::VoltageDiv), sample);
return 0;
}

View File

@@ -53,7 +53,7 @@ void warnUser(const char *warning, const int timeout) {
}
void printVoltage() {
uint32_t volt = getInputVoltageX10(systemSettings.voltageDiv, 0);
uint32_t volt = getInputVoltageX10(getSettingValue(SettingsOptions::VoltageDiv), 0);
OLED::printNumber(volt / 10, 2, FontStyle::SMALL);
OLED::print(SymbolDot, FontStyle::SMALL);
OLED::printNumber(volt % 10, 1, FontStyle::SMALL);
@@ -68,7 +68,7 @@ void GUIDelay() {
void gui_drawTipTemp(bool symbol, const FontStyle font) {
// Draw tip temp handling unit conversion & tolerance near setpoint
uint32_t Temp = 0;
if (systemSettings.temperatureInF) {
if (getSettingValue(SettingsOptions::TemperatureInF)) {
Temp = TipThermoModel::getTipInF();
} else {
Temp = TipThermoModel::getTipInC();
@@ -78,13 +78,13 @@ void gui_drawTipTemp(bool symbol, const FontStyle font) {
if (symbol) {
if (font == FontStyle::LARGE) {
// Big font, can draw nice symbols
if (systemSettings.temperatureInF)
if (getSettingValue(SettingsOptions::TemperatureInF))
OLED::drawSymbol(0);
else
OLED::drawSymbol(1);
} else {
// Otherwise fall back to chars
if (systemSettings.temperatureInF)
if (getSettingValue(SettingsOptions::TemperatureInF))
OLED::print(SymbolDegF, FontStyle::SMALL);
else
OLED::print(SymbolDegC, FontStyle::SMALL);
@@ -98,7 +98,7 @@ static bool checkVoltageForExit() {
if (!getIsPoweredByDCIN()) {
return false;
}
uint16_t v = getInputVoltageX10(systemSettings.voltageDiv, 0);
uint16_t v = getInputVoltageX10(getSettingValue(SettingsOptions::VoltageDiv), 0);
// Dont check for first 2 seconds while the ADC stabilizes and the DMA fills
// the buffer
@@ -107,7 +107,7 @@ static bool checkVoltageForExit() {
currentTempTargetDegC = 0;
OLED::clearScreen();
OLED::setCursor(0, 0);
if (systemSettings.detailedSoldering) {
if (getSettingValue(SettingsOptions::DetailedSoldering)) {
OLED::print(translatedString(Tr->UndervoltageString), FontStyle::SMALL);
OLED::setCursor(0, 8);
OLED::print(translatedString(Tr->InputVoltageString), FontStyle::SMALL);
@@ -131,7 +131,7 @@ static void gui_drawBatteryIcon() {
if (!getIsPoweredByDCIN()) {
// On TS80 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
uint8_t V = getInputVoltageX10(systemSettings.voltageDiv, 0);
uint8_t V = getInputVoltageX10(getSettingValue(SettingsOptions::VoltageDiv), 0);
if (V % 10 >= 5)
V = V / 10 + 1; // round up
else
@@ -149,16 +149,16 @@ static void gui_drawBatteryIcon() {
}
#endif
#ifdef POW_DC
if (systemSettings.minDCVoltageCells) {
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 = systemSettings.minDCVoltageCells + 2;
uint32_t cellV = getInputVoltageX10(systemSettings.voltageDiv, 0) / cellCount;
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 < systemSettings.minVoltageCells)
cellV = systemSettings.minVoltageCells;
cellV -= systemSettings.minVoltageCells; // Should leave us a number of 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);
@@ -190,6 +190,7 @@ static void gui_solderingTempAdjust() {
} else {
waitForRelease = false;
}
int16_t delta = 0;
switch (buttons) {
case BUTTON_NONE:
// stay
@@ -201,36 +202,36 @@ static void gui_solderingTempAdjust() {
break;
case BUTTON_B_LONG:
if (xTaskGetTickCount() - autoRepeatTimer + autoRepeatAcceleration > PRESS_ACCEL_INTERVAL_MAX) {
if (systemSettings.ReverseButtonTempChangeEnabled) {
systemSettings.SolderingTemp += systemSettings.TempChangeLongStep;
if (getSettingValue(SettingsOptions::ReverseButtonTempChangeEnabled)) {
delta = getSettingValue(SettingsOptions::TempChangeLongStep);
} else
systemSettings.SolderingTemp -= systemSettings.TempChangeLongStep;
delta = -getSettingValue(SettingsOptions::TempChangeLongStep);
autoRepeatTimer = xTaskGetTickCount();
autoRepeatAcceleration += PRESS_ACCEL_STEP;
}
break;
case BUTTON_B_SHORT:
if (systemSettings.ReverseButtonTempChangeEnabled) {
systemSettings.SolderingTemp += systemSettings.TempChangeShortStep;
if (getSettingValue(SettingsOptions::ReverseButtonTempChangeEnabled)) {
delta = getSettingValue(SettingsOptions::TempChangeShortStep);
} else
systemSettings.SolderingTemp -= systemSettings.TempChangeShortStep;
delta = -getSettingValue(SettingsOptions::TempChangeShortStep);
break;
case BUTTON_F_LONG:
if (xTaskGetTickCount() - autoRepeatTimer + autoRepeatAcceleration > PRESS_ACCEL_INTERVAL_MAX) {
if (systemSettings.ReverseButtonTempChangeEnabled) {
systemSettings.SolderingTemp -= systemSettings.TempChangeLongStep;
if (getSettingValue(SettingsOptions::ReverseButtonTempChangeEnabled)) {
delta = -getSettingValue(SettingsOptions::TempChangeLongStep);
} else
systemSettings.SolderingTemp += systemSettings.TempChangeLongStep;
delta = getSettingValue(SettingsOptions::TempChangeLongStep);
autoRepeatTimer = xTaskGetTickCount();
autoRepeatAcceleration += PRESS_ACCEL_STEP;
}
break;
case BUTTON_F_SHORT:
if (systemSettings.ReverseButtonTempChangeEnabled) {
systemSettings.SolderingTemp -= systemSettings.TempChangeShortStep; // add 10
if (getSettingValue(SettingsOptions::ReverseButtonTempChangeEnabled)) {
delta = -getSettingValue(SettingsOptions::TempChangeShortStep);
} else
systemSettings.SolderingTemp += systemSettings.TempChangeShortStep; // add 10
delta = getSettingValue(SettingsOptions::TempChangeShortStep);
break;
default:
break;
@@ -239,17 +240,20 @@ static void gui_solderingTempAdjust() {
autoRepeatAcceleration = PRESS_ACCEL_INTERVAL_MAX - PRESS_ACCEL_INTERVAL_MIN;
}
// constrain between 10-450 C
if (systemSettings.temperatureInF) {
if (systemSettings.SolderingTemp > MAX_TEMP_F)
systemSettings.SolderingTemp = MAX_TEMP_F;
if (systemSettings.SolderingTemp < MIN_TEMP_F)
systemSettings.SolderingTemp = MIN_TEMP_F;
uint16_t newTemp = getSettingValue(SettingsOptions::SolderingTemp);
newTemp += delta;
if (getSettingValue(SettingsOptions::TemperatureInF)) {
if (newTemp > MAX_TEMP_F)
newTemp = MAX_TEMP_F;
if (newTemp < MIN_TEMP_F)
newTemp = MIN_TEMP_F;
} else {
if (systemSettings.SolderingTemp > MAX_TEMP_C)
systemSettings.SolderingTemp = MAX_TEMP_C;
if (systemSettings.SolderingTemp < MIN_TEMP_C)
systemSettings.SolderingTemp = MIN_TEMP_C;
if (newTemp > MAX_TEMP_C)
newTemp = MAX_TEMP_C;
if (newTemp < MIN_TEMP_C)
newTemp = MIN_TEMP_C;
}
setSettingValue(SettingsOptions::SolderingTemp, newTemp);
if (xTaskGetTickCount() - lastChange > (TICKS_SECOND * 2))
return; // exit if user just doesn't press anything for a bit
@@ -259,14 +263,15 @@ static void gui_solderingTempAdjust() {
#else
if (OLED::getRotation()) {
#endif
OLED::print(systemSettings.ReverseButtonTempChangeEnabled ? SymbolPlus : SymbolMinus, FontStyle::LARGE);
OLED::print(getSettingValue(SettingsOptions::ReverseButtonTempChangeEnabled) ? SymbolPlus : SymbolMinus, FontStyle::LARGE);
} else {
OLED::print(systemSettings.ReverseButtonTempChangeEnabled ? SymbolMinus : SymbolPlus, FontStyle::LARGE);
OLED::print(getSettingValue(SettingsOptions::ReverseButtonTempChangeEnabled) ? SymbolMinus : SymbolPlus, FontStyle::LARGE);
}
OLED::print(SymbolSpace, FontStyle::LARGE);
OLED::printNumber(systemSettings.SolderingTemp, 3, FontStyle::LARGE);
if (systemSettings.temperatureInF)
OLED::printNumber(getSettingValue(SettingsOptions::SolderingTemp), 3, FontStyle::LARGE);
if (getSettingValue(SettingsOptions::TemperatureInF))
OLED::drawSymbol(0);
else {
OLED::drawSymbol(1);
@@ -277,23 +282,23 @@ static void gui_solderingTempAdjust() {
#else
if (OLED::getRotation()) {
#endif
OLED::print(systemSettings.ReverseButtonTempChangeEnabled ? SymbolMinus : SymbolPlus, FontStyle::LARGE);
OLED::print(getSettingValue(SettingsOptions::ReverseButtonTempChangeEnabled) ? SymbolMinus : SymbolPlus, FontStyle::LARGE);
} else {
OLED::print(systemSettings.ReverseButtonTempChangeEnabled ? SymbolPlus : SymbolMinus, FontStyle::LARGE);
OLED::print(getSettingValue(SettingsOptions::ReverseButtonTempChangeEnabled) ? SymbolPlus : SymbolMinus, FontStyle::LARGE);
}
OLED::refresh();
GUIDelay();
}
}
static bool shouldShutdown() {
if (systemSettings.ShutdownTime) { // only allow shutdown exit if time > 0
if (getSettingValue(SettingsOptions::ShutdownTime)) { // only allow shutdown exit if time > 0
if (lastMovementTime) {
if (((TickType_t)(xTaskGetTickCount() - lastMovementTime)) > (TickType_t)(systemSettings.ShutdownTime * TICKS_MIN)) {
if (((TickType_t)(xTaskGetTickCount() - lastMovementTime)) > (TickType_t)(getSettingValue(SettingsOptions::ShutdownTime) * TICKS_MIN)) {
return true;
}
}
if (lastHallEffectSleepStart) {
if (((TickType_t)(xTaskGetTickCount() - lastHallEffectSleepStart)) > (TickType_t)(systemSettings.ShutdownTime * TICKS_MIN)) {
if (((TickType_t)(xTaskGetTickCount() - lastHallEffectSleepStart)) > (TickType_t)(getSettingValue(SettingsOptions::ShutdownTime) * TICKS_MIN)) {
return true;
}
}
@@ -314,14 +319,14 @@ static int gui_SolderingSleepingMode(bool stayOff, bool autoStarted) {
if (checkVoltageForExit())
return 1; // return non-zero on error
#endif
if (systemSettings.temperatureInF) {
currentTempTargetDegC = stayOff ? 0 : TipThermoModel::convertFtoC(min(systemSettings.SleepTemp, systemSettings.SolderingTemp));
if (getSettingValue(SettingsOptions::TemperatureInF)) {
currentTempTargetDegC = stayOff ? 0 : TipThermoModel::convertFtoC(min(getSettingValue(SettingsOptions::SleepTemp), getSettingValue(SettingsOptions::SolderingTemp)));
} else {
currentTempTargetDegC = stayOff ? 0 : min(systemSettings.SleepTemp, systemSettings.SolderingTemp);
currentTempTargetDegC = stayOff ? 0 : min(getSettingValue(SettingsOptions::SleepTemp), getSettingValue(SettingsOptions::SolderingTemp));
}
// draw the lcd
uint16_t tipTemp;
if (systemSettings.temperatureInF)
if (getSettingValue(SettingsOptions::TemperatureInF))
tipTemp = TipThermoModel::getTipInF();
else {
tipTemp = TipThermoModel::getTipInC();
@@ -329,12 +334,12 @@ static int gui_SolderingSleepingMode(bool stayOff, bool autoStarted) {
OLED::clearScreen();
OLED::setCursor(0, 0);
if (systemSettings.detailedSoldering) {
if (getSettingValue(SettingsOptions::DetailedSoldering)) {
OLED::print(translatedString(Tr->SleepingAdvancedString), FontStyle::SMALL);
OLED::setCursor(0, 8);
OLED::print(translatedString(Tr->SleepingTipAdvancedString), FontStyle::SMALL);
OLED::printNumber(tipTemp, 3, FontStyle::SMALL);
if (systemSettings.temperatureInF)
if (getSettingValue(SettingsOptions::TemperatureInF))
OLED::print(SymbolDegF, FontStyle::SMALL);
else {
OLED::print(SymbolDegC, FontStyle::SMALL);
@@ -346,7 +351,7 @@ static int gui_SolderingSleepingMode(bool stayOff, bool autoStarted) {
} else {
OLED::print(translatedString(Tr->SleepingSimpleString), FontStyle::LARGE);
OLED::printNumber(tipTemp, 3, FontStyle::LARGE);
if (systemSettings.temperatureInF)
if (getSettingValue(SettingsOptions::TemperatureInF))
OLED::drawSymbol(0);
else {
OLED::drawSymbol(1);
@@ -404,13 +409,13 @@ static void display_countdown(int sleepThres) {
}
static uint32_t getSleepTimeout() {
if (systemSettings.sensitivity && systemSettings.SleepTime) {
if (getSettingValue(SettingsOptions::Sensitivity) && getSettingValue(SettingsOptions::SleepTime)) {
uint32_t sleepThres = 0;
if (systemSettings.SleepTime < 6)
sleepThres = systemSettings.SleepTime * 10 * 1000;
if (getSettingValue(SettingsOptions::SleepTime) < 6)
sleepThres = getSettingValue(SettingsOptions::SleepTime) * 10 * 1000;
else
sleepThres = (systemSettings.SleepTime - 5) * 60 * 1000;
sleepThres = (getSettingValue(SettingsOptions::SleepTime) - 5) * 60 * 1000;
return sleepThres;
}
return 0;
@@ -419,7 +424,7 @@ static uint32_t getSleepTimeout() {
static bool shouldBeSleeping(bool inAutoStart) {
#ifndef NO_SLEEP_MODE
// Return true if the iron should be in sleep mode
if (systemSettings.sensitivity && systemSettings.SleepTime) {
if (getSettingValue(SettingsOptions::Sensitivity) && getSettingValue(SettingsOptions::SleepTime)) {
if (inAutoStart) {
// In auto start we are asleep until movement
if (lastMovementTime == 0 && lastButtonTime == 0) {
@@ -482,7 +487,7 @@ static void gui_solderingMode(uint8_t jumpToSleep) {
}
for (;;) {
ButtonState buttons = getButtonState();
if (buttonsLocked && (systemSettings.lockingMode != 0)) { // If buttons locked
if (buttonsLocked && (getSettingValue(SettingsOptions::LockingMode) != 0)) { // If buttons locked
switch (buttons) {
case BUTTON_NONE:
boostModeOn = false;
@@ -494,7 +499,7 @@ static void gui_solderingMode(uint8_t jumpToSleep) {
break;
case BUTTON_F_LONG:
// if boost mode is enabled turn it on
if (systemSettings.BoostTemp && (systemSettings.lockingMode == 1)) {
if (getSettingValue(SettingsOptions::BoostTemp) && (getSettingValue(SettingsOptions::LockingMode) == 1)) {
boostModeOn = true;
}
break;
@@ -524,19 +529,19 @@ static void gui_solderingMode(uint8_t jumpToSleep) {
break;
case BUTTON_F_LONG:
// if boost mode is enabled turn it on
if (systemSettings.BoostTemp)
if (getSettingValue(SettingsOptions::BoostTemp))
boostModeOn = true;
break;
case BUTTON_F_SHORT:
case BUTTON_B_SHORT: {
uint16_t oldTemp = systemSettings.SolderingTemp;
uint16_t oldTemp = getSettingValue(SettingsOptions::SolderingTemp);
gui_solderingTempAdjust(); // goto adjust temp mode
if (oldTemp != systemSettings.SolderingTemp) {
if (oldTemp != getSettingValue(SettingsOptions::SolderingTemp)) {
saveSettings(); // only save on change
}
} break;
case BUTTON_BOTH_LONG:
if (systemSettings.lockingMode != 0) {
if (getSettingValue(SettingsOptions::LockingMode) != 0) {
// Lock buttons
buttonsLocked = true;
warnUser(translatedString(Tr->LockingKeysString), TICKS_SECOND);
@@ -550,11 +555,11 @@ static void gui_solderingMode(uint8_t jumpToSleep) {
OLED::setCursor(0, 0);
OLED::clearScreen();
// Draw in the screen details
if (systemSettings.detailedSoldering) {
if (getSettingValue(SettingsOptions::DetailedSoldering)) {
gui_drawTipTemp(true, FontStyle::LARGE);
#ifndef NO_SLEEP_MODE
if (systemSettings.sensitivity && systemSettings.SleepTime) {
if (getSettingValue(SettingsOptions::Sensitivity) && getSettingValue(SettingsOptions::SleepTime)) {
OLED::setCursor(47, 0);
display_countdown(getSleepTimeout());
}
@@ -610,16 +615,16 @@ static void gui_solderingMode(uint8_t jumpToSleep) {
OLED::refresh();
// Update the setpoints for the temperature
if (boostModeOn) {
if (systemSettings.temperatureInF)
currentTempTargetDegC = TipThermoModel::convertFtoC(systemSettings.BoostTemp);
if (getSettingValue(SettingsOptions::TemperatureInF))
currentTempTargetDegC = TipThermoModel::convertFtoC(getSettingValue(SettingsOptions::BoostTemp));
else {
currentTempTargetDegC = (systemSettings.BoostTemp);
currentTempTargetDegC = (getSettingValue(SettingsOptions::BoostTemp));
}
} else {
if (systemSettings.temperatureInF)
currentTempTargetDegC = TipThermoModel::convertFtoC(systemSettings.SolderingTemp);
if (getSettingValue(SettingsOptions::TemperatureInF))
currentTempTargetDegC = TipThermoModel::convertFtoC(getSettingValue(SettingsOptions::SolderingTemp));
else {
currentTempTargetDegC = (systemSettings.SolderingTemp);
currentTempTargetDegC = (getSettingValue(SettingsOptions::SolderingTemp));
}
}
@@ -768,8 +773,8 @@ void showWarnings() {
}
// Display alert if accelerometer is not detected
if (DetectedAccelerometerVersion == NO_DETECTED_ACCELEROMETER) {
if (systemSettings.accelMissingWarningCounter < 2) {
systemSettings.accelMissingWarningCounter++;
if (getSettingValue(SettingsOptions::AccelMissingWarningCounter) < 2) {
nextSettingValue(SettingsOptions::AccelMissingWarningCounter);
saveSettings();
warnUser(translatedString(Tr->NoAccelerometerMessage), 10 * TICKS_SECOND);
}
@@ -777,8 +782,8 @@ void showWarnings() {
#ifdef POW_PD
// We expect pd to be present
if (!usb_pd_detect()) {
if (systemSettings.pdMissingWarningCounter < 2) {
systemSettings.pdMissingWarningCounter++;
if (getSettingValue(SettingsOptions::PDMissingWarningCounter) < 2) {
nextSettingValue(SettingsOptions::PDMissingWarningCounter);
saveSettings();
warnUser(translatedString(Tr->NoPowerDeliveryMessage), 10 * TICKS_SECOND);
}
@@ -789,7 +794,8 @@ void showWarnings() {
uint8_t idleScreenBGF[sizeof(idleScreenBG)];
/* StartGUITask function */
void startGUITask(void const *argument __unused) {
void startGUITask(void const *argument) {
(void)argument;
prepareTranslations();
OLED::initialize(); // start up the LCD
@@ -809,7 +815,7 @@ void startGUITask(void const *argument __unused) {
}
}
getTipRawTemp(1); // reset filter
OLED::setRotation(systemSettings.OrientationMode & 1);
OLED::setRotation(getSettingValue(SettingsOptions::OrientationMode) & 1);
uint32_t ticks = xTaskGetTickCount();
ticks += (TICKS_SECOND * 4); // 4 seconds from now
while (xTaskGetTickCount() < ticks) {
@@ -823,9 +829,9 @@ void startGUITask(void const *argument __unused) {
showWarnings();
if (systemSettings.autoStartMode) {
if (getSettingValue(SettingsOptions::AutoStartMode)) {
// jump directly to the autostart mode
gui_solderingMode(systemSettings.autoStartMode - 1);
gui_solderingMode(getSettingValue(SettingsOptions::AutoStartMode) - 1);
buttonLockout = true;
}
@@ -878,7 +884,7 @@ void startGUITask(void const *argument __unused) {
}
currentTempTargetDegC = 0; // ensure tip is off
getInputVoltageX10(systemSettings.voltageDiv, 0);
getInputVoltageX10(getSettingValue(SettingsOptions::VoltageDiv), 0);
uint32_t tipTemp = TipThermoModel::getTipInC();
if (tipTemp > 55) {
setStatusLED(LED_COOLING_STILL_HOT);
@@ -892,25 +898,26 @@ void startGUITask(void const *argument __unused) {
// This is zero cost really as state is only changed on display updates
OLED::setDisplayState(OLED::DisplayState::ON);
if ((tipTemp < 50) && systemSettings.sensitivity && (((xTaskGetTickCount() - lastMovementTime) > MOVEMENT_INACTIVITY_TIME) && ((xTaskGetTickCount() - lastButtonTime) > BUTTON_INACTIVITY_TIME))) {
if ((tipTemp < 50) && getSettingValue(SettingsOptions::Sensitivity)
&& (((xTaskGetTickCount() - lastMovementTime) > MOVEMENT_INACTIVITY_TIME) && ((xTaskGetTickCount() - lastButtonTime) > BUTTON_INACTIVITY_TIME))) {
OLED::setDisplayState(OLED::DisplayState::OFF);
setStatusLED(LED_OFF);
}
// Clear the lcd buffer
OLED::clearScreen();
OLED::setCursor(0, 0);
if (systemSettings.detailedIDLE) {
if (getSettingValue(SettingsOptions::DetailedIDLE)) {
if (isTipDisconnected()) {
OLED::print(translatedString(Tr->TipDisconnectedString), FontStyle::SMALL);
} else {
if (!(systemSettings.coolingTempBlink && (tipTemp > 55) && (xTaskGetTickCount() % 1000 < 300)))
if (!(getSettingValue(SettingsOptions::CoolingTempBlink) && (tipTemp > 55) && (xTaskGetTickCount() % 1000 < 300)))
// Blink temp if setting enable and temp < 55°
// 1000 tick/sec
// OFF 300ms ON 700ms
gui_drawTipTemp(true, FontStyle::LARGE); // draw in the temp
OLED::setCursor(73, 0); // top right
OLED::printNumber(systemSettings.SolderingTemp, 3, FontStyle::SMALL); // draw set temp
if (systemSettings.temperatureInF)
gui_drawTipTemp(true, FontStyle::LARGE); // draw in the temp
OLED::setCursor(73, 0); // top right
OLED::printNumber(getSettingValue(SettingsOptions::SolderingTemp), 3, FontStyle::SMALL); // draw set temp
if (getSettingValue(SettingsOptions::TemperatureInF))
OLED::print(SymbolDegF, FontStyle::SMALL);
else
OLED::print(SymbolDegC, FontStyle::SMALL);
@@ -963,7 +970,7 @@ void startGUITask(void const *argument __unused) {
// If we have a tip connected draw the temp, if not we leave it blank
if (!tipDisconnectedDisplay) {
// draw in the temp
if (!(systemSettings.coolingTempBlink && (xTaskGetTickCount() % 260 < 160)))
if (!(getSettingValue(SettingsOptions::CoolingTempBlink) && (xTaskGetTickCount() % 260 < 160)))
gui_drawTipTemp(false, FontStyle::LARGE); // draw in the temp
} else {
// Draw in missing tip symbol

View File

@@ -70,7 +70,7 @@ void detectAccelerometerVersion() {
#endif
{
// disable imu sensitivity
systemSettings.sensitivity = 0;
setSettingValue(SettingsOptions::Sensitivity, 0);
DetectedAccelerometerVersion = NO_DETECTED_ACCELEROMETER;
}
}
@@ -116,23 +116,21 @@ void startMOVTask(void const *argument __unused) {
lastMovementTime = 0;
// Mask 2 seconds if we are in autostart so that if user is plugging in and
// then putting in stand it doesnt wake instantly
if (systemSettings.autoStartMode)
if (getSettingValue(SettingsOptions::AutoStartMode))
osDelay(2 * TICKS_SECOND);
int16_t datax[MOVFilter] = {0};
int16_t datay[MOVFilter] = {0};
int16_t dataz[MOVFilter] = {0};
uint8_t currentPointer = 0;
int16_t tx = 0, ty = 0, tz = 0;
int32_t avgx, avgy, avgz;
if (systemSettings.sensitivity > 9)
systemSettings.sensitivity = 9;
int16_t datax[MOVFilter] = {0};
int16_t datay[MOVFilter] = {0};
int16_t dataz[MOVFilter] = {0};
uint8_t currentPointer = 0;
int16_t tx = 0, ty = 0, tz = 0;
int32_t avgx, avgy, avgz;
Orientation rotation = ORIENTATION_FLAT;
for (;;) {
int32_t threshold = 1500 + (9 * 200);
threshold -= systemSettings.sensitivity * 200; // 200 is the step size
threshold -= getSettingValue(SettingsOptions::Sensitivity) * 200; // 200 is the step size
readAccelerometer(tx, ty, tz, rotation);
if (systemSettings.OrientationMode == 2) {
if (getSettingValue(SettingsOptions::OrientationMode) == 2) {
if (rotation != ORIENTATION_FLAT) {
OLED::setRotation(rotation == ORIENTATION_LEFT_HAND); // link the data through
}

View File

@@ -122,18 +122,19 @@ void startPIDTask(void const *argument __unused) {
tipTempCRunawayTemp = currentTipTempInC;
runawaylastChangeTime = xTaskGetTickCount();
}
// If the user turns on the option of using an occasional pulse to keep the power bank on
if (systemSettings.KeepAwakePulse) {
const TickType_t powerPulseWait = powerPulseWaitUnit * systemSettings.KeepAwakePulseWait;
if (getSettingValue(SettingsOptions::KeepAwakePulse)) {
const TickType_t powerPulseWait = powerPulseWaitUnit * getSettingValue(SettingsOptions::KeepAwakePulseWait);
if (xTaskGetTickCount() - lastPowerPulseStart > powerPulseWait) {
const TickType_t powerPulseDuration = powerPulseDurationUnit * systemSettings.KeepAwakePulseDuration;
const TickType_t powerPulseDuration = powerPulseDurationUnit * getSettingValue(SettingsOptions::KeepAwakePulseDuration);
lastPowerPulseStart = xTaskGetTickCount();
lastPowerPulseEnd = lastPowerPulseStart + powerPulseDuration;
}
// If current PID is less than the pulse level, check if we want to constrain to the pulse as the floor
if (x10WattsOut < systemSettings.KeepAwakePulse && xTaskGetTickCount() < lastPowerPulseEnd) {
x10WattsOut = systemSettings.KeepAwakePulse;
if (x10WattsOut < getSettingValue(SettingsOptions::KeepAwakePulse) && xTaskGetTickCount() < lastPowerPulseEnd) {
x10WattsOut = getSettingValue(SettingsOptions::KeepAwakePulse);
}
}
@@ -144,8 +145,8 @@ void startPIDTask(void const *argument __unused) {
if (heaterThermalRunaway) {
x10WattsOut = 0;
}
if (systemSettings.powerLimit && x10WattsOut > (systemSettings.powerLimit * 10)) {
x10WattsOut = systemSettings.powerLimit * 10;
if (getSettingValue(SettingsOptions::PowerLimit) && x10WattsOut > (getSettingValue(SettingsOptions::PowerLimit) * 10)) {
x10WattsOut = getSettingValue(SettingsOptions::PowerLimit) * 10;
}
if (powerSupplyWattageLimit && x10WattsOut > powerSupplyWattageLimit * 10) {
x10WattsOut = powerSupplyWattageLimit * 10;