Merge branch 'master' into pr/1010
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -12,85 +12,152 @@
|
||||
#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;
|
||||
|
||||
bool restoreSettings() {
|
||||
static const SettingConstants settingsConstants[(int)SettingsOptions::SettingsOptionsLength] = {
|
||||
//{min,max,increment,default}
|
||||
{10, 580, 5, 320}, // SolderingTemp
|
||||
{10, 580, 5, 150}, // SleepTemp
|
||||
{0, 16, 1, SLEEP_TIME}, // SleepTime
|
||||
{0, 5, 1, CUT_OUT_SETTING}, // MinDCVoltageCells
|
||||
{24, 38, 1, RECOM_VOL_CELL}, // MinVoltageCells
|
||||
{0, QC_SETTINGS_MAX, 1, 0}, // QCIdealVoltage
|
||||
{0, 3, 1, ORIENTATION_MODE}, // OrientationMode
|
||||
{0, 10, 1, SENSITIVITY}, // Sensitivity
|
||||
{0, 2, 1, ANIMATION_LOOP}, // AnimationLoop
|
||||
{0, settingOffSpeed_t::MAX_VALUE, 1, ANIMATION_SPEED}, // AnimationSpeed
|
||||
{0, 4, 1, AUTO_START_MODE}, // AutoStartMode
|
||||
{0, 61, 1, SHUTDOWN_TIME}, // ShutdownTime
|
||||
{0, 2, 1, COOLING_TEMP_BLINK}, // CoolingTempBlink
|
||||
{0, 2, 1, DETAILED_IDLE}, // DetailedIDLE
|
||||
{0, 2, 1, DETAILED_SOLDERING}, // DetailedSoldering
|
||||
{0, 2, 1, TEMPERATURE_INF}, // TemperatureInF
|
||||
{0, 2, 1, DESCRIPTION_SCROLL_SPEED}, // DescriptionScrollSpeed
|
||||
{0, 3, 1, LOCKING_MODE}, // LockingMode
|
||||
{0, 100, 1, POWER_PULSE_DEFAULT}, // KeepAwakePulse
|
||||
{1, POWER_PULSE_WAIT_MAX, 1, POWER_PULSE_WAIT_DEFAULT}, // KeepAwakePulseWait
|
||||
{1, POWER_PULSE_DURATION_MAX, 1, POWER_PULSE_DURATION_DEFAULT}, // KeepAwakePulseDuration
|
||||
{360, 900, 1, VOLTAGE_DIV}, // VoltageDiv
|
||||
{100, 580, 10, BOOST_TEMP}, // BoostTemp
|
||||
{100, 2500, 1, CALIBRATION_OFFSET}, // CalibrationOffset
|
||||
{0, MAX_POWER_LIMIT, POWER_LIMIT_STEPS, POWER_LIMIT}, // PowerLimit
|
||||
{0, 2, 1, REVERSE_BUTTON_TEMP_CHANGE}, // ReverseButtonTempChangeEnabled
|
||||
{5, TEMP_CHANGE_LONG_STEP_MAX, 5, TEMP_CHANGE_LONG_STEP}, // TempChangeLongStep
|
||||
{1, TEMP_CHANGE_SHORT_STEP_MAX, 1, TEMP_CHANGE_SHORT_STEP}, // TempChangeShortStep
|
||||
{0, 4, 1, 1}, // HallEffectSensitivity
|
||||
{0, 10, 1, 0}, // AccelMissingWarningCounter
|
||||
{0, 10, 1, 0}, // PDMissingWarningCounter
|
||||
{0, 0xFFFF, 0, 41431 /*EN*/}, // UILanguage
|
||||
{0, 51, 1, 0}, // PDNegTimeout
|
||||
|
||||
};
|
||||
|
||||
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.padding != 0xFFFFFFFF) {
|
||||
systemSettings.padding = 0xFFFFFFFF; // Force padding to 0xFFFFFFFF so that rolling forwards / back should be easier
|
||||
dirty = true;
|
||||
}
|
||||
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 - constants.increment)) {
|
||||
systemSettings.settingsValues[(int)option] = constants.min;
|
||||
} else {
|
||||
systemSettings.settingsValues[(int)option] += constants.increment;
|
||||
}
|
||||
return systemSettings.settingsValues[(int)option] == constants.max - constants.increment;
|
||||
}
|
||||
|
||||
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 +170,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);
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -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) */
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user