blob: d08bf1216d86bb25da9d9a3c8e9c3d88be6ac8c7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
/*
* Settings.c
*
* Created on: 29 Sep 2016
* Author: Ralim
*
* This file holds the users settings and saves / restores them to the devices flash
*/
#include "Settings.h"
#define FLASH_ADDR (0x8000000|48896)/*Flash start OR'ed with the maximum amount of flash - 256 bytes*/
void saveSettings() {
//First we erase the flash
FLASH_Unlock(); //unlock flash writing
FLASH_ClearFlag(FLASH_FLAG_EOP | FLASH_FLAG_PGERR | FLASH_FLAG_WRPRTERR);
while (FLASH_ErasePage(FLASH_ADDR) != FLASH_COMPLETE)
; //wait for it
//erased the chunk
//now we program it
uint16_t *data = (uint16_t*) &systemSettings;
for (uint8_t i = 0; i < (sizeof(systemSettings) / 2); i++) {
FLASH_ProgramHalfWord(FLASH_ADDR + (i * 2), data[i]);
}
}
void restoreSettings() {
//We read the flash
uint16_t *data = (uint16_t*) &systemSettings;
for (uint8_t i = 0; i < (sizeof(systemSettings) / 2); i++) {
data[i] = *(uint16_t *) (FLASH_ADDR + (i * 2));
}
//if the version is correct were done
//if not we reset and save
if (systemSettings.version != SETTINGSVERSION) {
//probably not setup
resetSettings();
saveSettings();
}
}
//Lookup function for cutoff setting -> X10 voltage
/*
* 0=DC
* 1=3S
* 2=4S
* 3=5S
* 4=6S
*/
uint8_t lookupVoltageLevel(uint8_t level) {
if (level == 0)
return 100; //10V since iron does not function below this
else
return (level * 33) + (33 * 2);
}
void resetSettings() {
systemSettings.SleepTemp = 1500;//Temperature the iron sleeps at - default 150.0 C
systemSettings.SleepTime = 1;//How many minutes we wait until going to sleep - default 1 min
systemSettings.SolderingTemp = 3200; //Default soldering temp is 320.0 C
systemSettings.cutoutSetting = 0; //default to no cut-off voltage
systemSettings.version = SETTINGSVERSION;//Store the version number to allow for easier upgrades
systemSettings.displayTempInF = 0; //default to C
systemSettings.flipDisplay = 0; //Default to right handed mode
systemSettings.sensitivity = 6; //Default high sensitivity
systemSettings.tempCalibration = 239; //Default to their calibration value
systemSettings.voltageDiv = 144; //Default divider from schematic
systemSettings.ShutdownTime = 30;//How many minutes until the unit turns itself off
systemSettings.displayUpdateSpeed = 1; //How fast the LCD updates
systemSettings.temperatureRounding = 0; //How the temperature is rounded off
systemSettings.boostModeEnabled = 0;//Default to safe, with no boost mode
systemSettings.BoostTemp = 4000; //default to 400C
}
|