Merge branch 'PR-#1-Configuration' into PR-#2-Temp-Steps-and-revert-buttons
This commit is contained in:
@@ -1,130 +1,107 @@
|
|||||||
/**
|
/*
|
||||||
* Settings.c
|
* Settings.c
|
||||||
*
|
*
|
||||||
* Created on: 29 Sep 2016
|
* Created on: 29 Sep 2016
|
||||||
* Author: Ralim
|
* Author: Ralim
|
||||||
|
*
|
||||||
* This file holds the users settings and saves / restores them to the
|
* This file holds the users settings and saves / restores them to the
|
||||||
* devices flash
|
* devices flash
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "Settings.h"
|
#include "Settings.h"
|
||||||
#include "Setup.h"
|
#include "Setup.h"
|
||||||
|
#define FLASH_ADDR \
|
||||||
|
(0x8000000 | \
|
||||||
|
0xFC00) /*Flash start OR'ed with the maximum amount of flash - 1024 bytes*/
|
||||||
#include "string.h"
|
#include "string.h"
|
||||||
#include "../../configuration.h"
|
|
||||||
|
|
||||||
volatile systemSettingsType systemSettings;
|
volatile systemSettingsType systemSettings;
|
||||||
|
|
||||||
/**
|
|
||||||
* Flash start OR'ed with the maximum amount of flash - 1024 bytes
|
|
||||||
*/
|
|
||||||
#define FLASH_ADDR (0x8000000 | 0xFC00)
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Save Settings to flash
|
|
||||||
*/
|
|
||||||
void saveSettings() {
|
void saveSettings() {
|
||||||
// First we erase the flash
|
// First we erase the flash
|
||||||
FLASH_EraseInitTypeDef pEraseInit;
|
FLASH_EraseInitTypeDef pEraseInit;
|
||||||
pEraseInit.TypeErase = FLASH_TYPEERASE_PAGES;
|
pEraseInit.TypeErase = FLASH_TYPEERASE_PAGES;
|
||||||
pEraseInit.Banks = FLASH_BANK_1;
|
pEraseInit.Banks = FLASH_BANK_1;
|
||||||
pEraseInit.NbPages = 1;
|
pEraseInit.NbPages = 1;
|
||||||
pEraseInit.PageAddress = FLASH_ADDR;
|
pEraseInit.PageAddress = FLASH_ADDR;
|
||||||
|
uint32_t failingAddress = 0;
|
||||||
|
HAL_IWDG_Refresh(&hiwdg);
|
||||||
|
__HAL_FLASH_CLEAR_FLAG(
|
||||||
|
FLASH_FLAG_EOP | FLASH_FLAG_WRPERR | FLASH_FLAG_PGERR | FLASH_FLAG_BSY);
|
||||||
|
HAL_FLASH_Unlock();
|
||||||
|
HAL_Delay(10);
|
||||||
|
HAL_IWDG_Refresh(&hiwdg);
|
||||||
|
HAL_FLASHEx_Erase(&pEraseInit, &failingAddress);
|
||||||
|
//^ Erase the page of flash (1024 bytes on this stm32)
|
||||||
|
// erased the chunk
|
||||||
|
// now we program it
|
||||||
|
uint16_t *data = (uint16_t*) &systemSettings;
|
||||||
|
HAL_FLASH_Unlock();
|
||||||
|
|
||||||
uint32_t failingAddress = 0;
|
for (uint8_t i = 0; i < (sizeof(systemSettingsType) / 2); i++) {
|
||||||
HAL_IWDG_Refresh(&hiwdg);
|
HAL_IWDG_Refresh(&hiwdg);
|
||||||
__HAL_FLASH_CLEAR_FLAG( FLASH_FLAG_EOP |
|
HAL_FLASH_Program(FLASH_TYPEPROGRAM_HALFWORD, FLASH_ADDR + (i * 2),
|
||||||
FLASH_FLAG_WRPERR |
|
data[i]);
|
||||||
FLASH_FLAG_PGERR |
|
}
|
||||||
FLASH_FLAG_BSY );
|
HAL_FLASH_Lock();
|
||||||
HAL_FLASH_Unlock();
|
|
||||||
HAL_Delay(10);
|
|
||||||
HAL_IWDG_Refresh(&hiwdg);
|
|
||||||
HAL_FLASHEx_Erase(&pEraseInit, &failingAddress);
|
|
||||||
//^ Erase the page of flash (1024 bytes on this stm32)
|
|
||||||
// erased the chunk
|
|
||||||
// now we program it
|
|
||||||
uint16_t *data = (uint16_t*) &systemSettings;
|
|
||||||
HAL_FLASH_Unlock();
|
|
||||||
|
|
||||||
for (uint8_t i = 0; i < (sizeof(systemSettingsType) / 2); i++) {
|
|
||||||
HAL_IWDG_Refresh(&hiwdg);
|
|
||||||
HAL_FLASH_Program(FLASH_TYPEPROGRAM_HALFWORD, FLASH_ADDR + (i * 2),
|
|
||||||
data[i]);
|
|
||||||
}
|
|
||||||
HAL_FLASH_Lock();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* RestoreSettings from flash
|
|
||||||
* Return:
|
|
||||||
* false - if restore from flash is successfull
|
|
||||||
* true - if settings are reset to its defaults
|
|
||||||
*/
|
|
||||||
bool restoreSettings() {
|
bool restoreSettings() {
|
||||||
// We read from flash
|
// We read the flash
|
||||||
uint16_t *data = (uint16_t*) &systemSettings;
|
uint16_t *data = (uint16_t*) &systemSettings;
|
||||||
for (uint8_t i = 0; i < (sizeof(systemSettingsType) / 2); i++) {
|
for (uint8_t i = 0; i < (sizeof(systemSettingsType) / 2); i++) {
|
||||||
data[i] = *((uint16_t*) (FLASH_ADDR + (i * 2)));
|
data[i] = *((uint16_t*) (FLASH_ADDR + (i * 2)));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (systemSettings.version != SETTINGSVERSION) {
|
// if the version is correct were done
|
||||||
// The settings version does not match.
|
// if not we reset and save
|
||||||
// Resetting the settings to its default.
|
if (systemSettings.version != SETTINGSVERSION) {
|
||||||
resetSettings();
|
// probably not setup
|
||||||
return true;
|
resetSettings();
|
||||||
}
|
return true;
|
||||||
return false; // Settings version from flash is correct were done
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
// Lookup function for cutoff setting -> X10 voltage
|
||||||
/**
|
/*
|
||||||
* lookupVoltageLevel
|
* 0=DC
|
||||||
*
|
* 1=3S
|
||||||
* Lookup function for cutoff setting -> X10 voltage
|
* 2=4S
|
||||||
* 0=DC 1=3S 2=4S 3=5S 4=6S
|
* 3=5S
|
||||||
*
|
* 4=6S
|
||||||
*/
|
*/
|
||||||
uint8_t lookupVoltageLevel(uint8_t level) {
|
uint8_t lookupVoltageLevel(uint8_t level) {
|
||||||
if (level == 0) {
|
if (level == 0)
|
||||||
// 9V - Since iron does not function effectively below this
|
return 90; // 9V since iron does not function effectively below this
|
||||||
return 90;
|
else
|
||||||
} else {
|
return (level * 33) + (33 * 2);
|
||||||
return (level * 33) + (33 * 2);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Reset Settings to its default values.
|
|
||||||
*/
|
|
||||||
void resetSettings() {
|
void resetSettings() {
|
||||||
memset((void*) &systemSettings, 0, sizeof(systemSettingsType));
|
memset((void*) &systemSettings, 0, sizeof(systemSettingsType));
|
||||||
|
systemSettings.SleepTemp = SLEEP_TEMP; // Temperature the iron sleeps at - default 150.0 C
|
||||||
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
|
||||||
systemSettings.SleepTime = SLEEP_TIME; // How many seconds/minutes we wait until going to sleep - default 1 min
|
// to sleep - default 1 min
|
||||||
systemSettings.SolderingTemp = SOLDERING_TEMP; // Default soldering temp is 320.0 C
|
systemSettings.SolderingTemp = SOLDERING_TEMP; // Default soldering temp is 320.0 C
|
||||||
systemSettings.cutoutSetting = CUT_OUT_SETTING; // default to no cut-off voltage (or 18W for TS80)
|
systemSettings.cutoutSetting = CUT_OUT_SETTING; // default to no cut-off voltage (or 18W for TS80)
|
||||||
systemSettings.version = SETTINGSVERSION; // Store the version number to allow for easier upgrades
|
systemSettings.version =
|
||||||
systemSettings.detailedSoldering = DETAILED_SOLDERING; // Detailed soldering screen
|
SETTINGSVERSION; // Store the version number to allow for easier upgrades
|
||||||
systemSettings.detailedIDLE = DETAILED_IDLE; // Detailed idle screen (off for first time users)
|
systemSettings.detailedSoldering = DETAILED_SOLDERING; // Detailed soldering screen
|
||||||
systemSettings.OrientationMode = ORIENTATION_MODE; // Default to automatic
|
systemSettings.detailedIDLE = DETAILED_IDLE; // Detailed idle screen (off for first time users)
|
||||||
systemSettings.sensitivity = SENSITIVITY; // Default high sensitivity
|
systemSettings.OrientationMode = ORIENTATION_MODE; // Default to automatic
|
||||||
systemSettings.voltageDiv = VOLTAGE_DIV; // Default divider from schematic
|
systemSettings.sensitivity = SENSITIVITY; // Default high sensitivity
|
||||||
systemSettings.ShutdownTime = SHUTDOWN_TIME; // How many minutes until the unit turns itself off
|
systemSettings.voltageDiv = VOLTAGE_DIV; // Default divider from schematic
|
||||||
systemSettings.boostModeEnabled = BOOST_MODE_ENABLED; // Default to having boost mode on as most people prefer it
|
systemSettings.ShutdownTime = SHUTDOWN_TIME; // How many minutes until the unit turns itself off
|
||||||
systemSettings.BoostTemp = BOOST_TEMP; // default to 400C
|
systemSettings.boostModeEnabled = BOOST_MODE_ENABLED; // Default to having boost mode on as most people prefer it
|
||||||
systemSettings.autoStartMode = AUTO_START_MODE; // Auto start off for safety
|
systemSettings.BoostTemp = BOOST_TEMP; // default to 400C
|
||||||
systemSettings.coolingTempBlink = COOLING_TEMP_BLINK; // Blink the temperature on the cooling screen when its > 50C
|
systemSettings.autoStartMode = AUTO_START_MODE; // Auto start off for safety
|
||||||
systemSettings.temperatureInF = TEMPERATURE_INF; // default to 0
|
systemSettings.coolingTempBlink = COOLING_TEMP_BLINK; // Blink the temperature on the cooling screen when its > 50C
|
||||||
systemSettings.descriptionScrollSpeed = DESCRIPTION_SCROLL_SPEED; // default to slow
|
systemSettings.temperatureInF = TEMPERATURE_INF; // default to 0
|
||||||
systemSettings.powerLimitEnable = POWER_LIMIT_ENABLE; // Default to no power limit
|
systemSettings.descriptionScrollSpeed = DESCRIPTION_SCROLL_SPEED; // default to slow
|
||||||
systemSettings.CalibrationOffset = CALIBRATION_OFFSET; // the adc offset in uV
|
systemSettings.powerLimitEnable = POWER_LIMIT_ENABLE; // Default to no power limit
|
||||||
systemSettings.pidPowerLimit = PID_POWER_LIMIT; // Sets the max pwm power limit
|
systemSettings.CalibrationOffset = CALIBRATION_OFFSET; // the adc offset in uV
|
||||||
systemSettings.powerLimit = POWER_LIMIT; // 30 watts default limit
|
systemSettings.pidPowerLimit = PID_POWER_LIMIT; // Sets the max pwm power limit
|
||||||
systemSettings.ReverseButtonTempChangeEnabled = REVERSE_BUTTON_TEMP_CHANGE; //
|
systemSettings.powerLimit = POWER_LIMIT; // 30 watts default limit
|
||||||
systemSettings.TempChangeShortStep = TEMP_CHANGE_SHORT_STEP; //
|
systemSettings.ReverseButtonTempChangeEnabled = REVERSE_BUTTON_TEMP_CHANGE; //
|
||||||
systemSettings.TempChangeLongStep = TEMP_CHANGE_LONG_STEP; //
|
systemSettings.TempChangeShortStep = TEMP_CHANGE_SHORT_STEP; //
|
||||||
|
systemSettings.TempChangeLongStep = TEMP_CHANGE_LONG_STEP; //
|
||||||
|
saveSettings(); // Save defaults
|
||||||
saveSettings(); // Save default settings
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,12 +15,12 @@
|
|||||||
#define SOLDERING_TEMP 320 // Default soldering temp is 320.0 °C
|
#define SOLDERING_TEMP 320 // Default soldering temp is 320.0 °C
|
||||||
#define SLEEP_TEMP 150 // Default sleep temperature
|
#define SLEEP_TEMP 150 // Default sleep temperature
|
||||||
#define BOOST_TEMP 420 // Default boost temp.
|
#define BOOST_TEMP 420 // Default boost temp.
|
||||||
#define BOOST_MODE_ENABLED 0 // 0: Disable 1: Enable
|
#define BOOST_MODE_ENABLED 1 // 0: Disable 1: Enable
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Blink the temperature on the cooling screen when its > 50C
|
* Blink the temperature on the cooling screen when its > 50C
|
||||||
*/
|
*/
|
||||||
#define COOLING_TEMP_BLINK 1 // 0: Disable 1: Enable
|
#define COOLING_TEMP_BLINK 0 // 0: Disable 1: Enable
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* How many seconds/minutes we wait until going to sleep/shutdown.
|
* How many seconds/minutes we wait until going to sleep/shutdown.
|
||||||
@@ -76,7 +76,7 @@
|
|||||||
#define VOLTAGE_DIV 467 // 467 - Default divider from schematic
|
#define VOLTAGE_DIV 467 // 467 - Default divider from schematic
|
||||||
#define CALIBRATION_OFFSET 900 // 900 - Default adc offset in uV
|
#define CALIBRATION_OFFSET 900 // 900 - Default adc offset in uV
|
||||||
#define PID_POWER_LIMIT 70 // Sets the max pwm power limit
|
#define PID_POWER_LIMIT 70 // Sets the max pwm power limit
|
||||||
#define POWER_LIMIT 65 // 30 watts default limit
|
#define POWER_LIMIT 30 // 30 watts default limit
|
||||||
#define MAX_POWER_LIMIT 65 //
|
#define MAX_POWER_LIMIT 65 //
|
||||||
#define POWER_LIMIT_STEPS 5 //
|
#define POWER_LIMIT_STEPS 5 //
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user