forked from deividAlfa/stm32_soldering_iron_controller
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettings.h
341 lines (297 loc) · 10.1 KB
/
settings.h
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
/*
* settings.h
*
* Created on: Jan 12, 2021
* Author: David Original work by Jose Barros (PTDreamer), 2017
*/
#ifndef SETTINGS_H_
#define SETTINGS_H_
#include "main.h"
#include "pid.h"
#include "board.h"
#define SWSTRING "SW: "__DATE__ // Software version reported in settings screen
#define SETTINGS_VERSION 23 // Change this if you change the settings/profile struct to prevent getting out of sync
#define LANGUAGE_COUNT 7 // Number of languages
#define NUM_PROFILES 3 // Number of profiles
#define NUM_TIPS 35 // Number of tips for each profile
#define TIP_LEN 8 // String size for each tip name (Including null termination)
#define _BLANK_TIP " " // Empty tip name, containing (TIP_LEN) spaces. Defined here for quick updating if TIP_LEN is modified.
#ifndef PROFILE_VALUES
#define T12_Cal250 1100 // Default values to be used in the calibration if not adjusted
#define T12_Cal350 1200
#define T12_Cal450 1300
#define C210_Cal250 300
#define C210_Cal350 400
#define C210_Cal450 500
#define C245_Cal250 900
#define C245_Cal350 1000
#define C245_Cal450 1100
#endif
typedef enum{
mode_shake = 0,
mode_stand = 1,
wake_off = 0,
wake_standby = 1,
wake_sleep = 2,
wake_all = 3,
no_update = 0,
needs_update = 1,
runaway_ok = 0,
runaway_25 = 1,
runaway_50 = 2,
runaway_75 = 3,
runaway_100 = 4,
runaway_500 = 5,
runaway_triggered = 1,
disable = 0,
enable = 1,
old_reading = 0,
new_reading = 1,
read_average = 0,
read_unfiltered = 1,
encoder_normal = 0,
encoder_reverse = 1,
mode_Celsius = 0,
mode_Farenheit = 1,
mode_sleep = 0,
mode_standby = 1,
mode_run = 2,
mode_boost = 3,
initialized = 0,
profile_T12 = 0,
profile_C245 = 1,
profile_C210 = 2,
profile_None = 0xff,
save_Settings = 1,
reboot_after_save = 0x40,
save_settings_reboot = 0x41,
reset_Profiles = 0x80,
reset_Profile = 0x81,
reset_Settings = 0x82,
#ifdef ENABLE_ADDONS
reset_Addons = 0x83,
#endif
reset_All = 0x84,
reboot_mask = 0xBF,
keepProfiles = 1,
wipeProfiles = 0x80,
output_PWM,
output_Low,
output_High,
lang_english = 0,
lang_russian = 1,
lang_swedish = 2,
lang_german = 3,
lang_turkish = 4,
lang_tchinese = 5,
lang_bulgarian = 6,
dim_off = 0,
dim_sleep = 1,
dim_always = 2,
error_sleep = 0,
error_run = 1,
error_resume = 2,
#ifdef ENABLE_ADDON_FUME_EXTRACTOR
fume_extractor_mode_disabled = 0,
fume_extractor_mode_auto = 1,
fume_extractor_mode_always_on = 2,
#endif
#ifdef ENABLE_ADDON_SWITCH_OFF_REMINDER
switch_off_reminder_short_beep = 0,
switch_off_reminder_medium_beep = 1,
switch_off_reminder_long_beep = 2,
#endif
}system_types;
__attribute__((aligned(4))) typedef struct{
int8_t coefficient; // Filter normally applied
int8_t counter; // Counter for threshold limit
int8_t min; // Minimum filtering when decreasing
int8_t step; // Start decreasing the filter coefficient, assume it's a fast temperature change, so provide faster response
int8_t count_limit; // Count the spikes, if exceeding this limit, start reducing the filter coefficient.
uint16_t threshold; // Base noise limit, if diff exceeds this limit, trigger threshold limit and start decreasing filtering
uint16_t reset_threshold; // Threshold for completely resetting the filter
}filter_t;
__attribute__((aligned(4))) typedef struct{
uint16_t calADC_At_250;
uint16_t calADC_At_400;
char name[TIP_LEN+1];
pid_values_t PID;
}tipData_t;
__attribute__((aligned(4))) typedef struct{
uint8_t enabled;
uint8_t detection;
uint8_t pullup;
uint16_t pull_res;
uint16_t NTC_res;
uint16_t NTC_beta;
uint16_t high_NTC_res;
uint16_t low_NTC_res;
uint16_t high_NTC_beta;
uint16_t low_NTC_beta;
}ntc_data_t;
__attribute__((aligned(4))) typedef struct{
uint8_t state; // Always 0xFF if flash is erased
uint8_t ID;
uint8_t impedance;
uint8_t tempUnit;
uint8_t currentNumberOfTips;
uint8_t defaultTip;
uint8_t pwmMul;
uint8_t errorResumeMode;
uint8_t shakeFiltering;
uint8_t WakeInputMode;
uint8_t StandMode;
uint8_t smartActiveEnabled;
uint8_t smartActiveLoad;
uint8_t standDelay;
uint8_t : 8; // reserved
uint8_t : 8;
uint8_t : 8;
uint8_t : 8;
uint8_t : 8;
uint8_t : 8;
uint8_t : 8;
filter_t tipFilter;
ntc_data_t ntc;
uint16_t standbyTemperature;
uint16_t defaultTemperature;
uint16_t MaxSetTemperature;
uint16_t MinSetTemperature;
uint16_t boostTemperature;
uint16_t readPeriod;
uint16_t readDelay;
uint16_t noIronValue;
uint16_t power;
uint16_t calADC_At_0;
uint16_t Cal250_default;
uint16_t Cal400_default;
uint16_t : 16; // reserved
uint16_t : 16;
uint16_t : 16;
uint16_t : 16;
uint16_t : 16;
tipData_t tip[NUM_TIPS];
uint32_t errorTimeout;
uint32_t boostTimeout;
uint32_t sleepTimeout;
uint32_t standbyTimeout;
uint32_t : 32; // reserved
uint32_t : 32;
uint32_t : 32;
uint32_t : 32;
uint32_t : 32;
}profile_t;
__attribute__((aligned(4))) typedef struct{
uint32_t version; // Used to track if a reset is needed on firmware upgrade
uint8_t state; // Always 0xFF if flash is erased
uint8_t language;
uint8_t contrastOrBrightness;
uint8_t displayOffset;
__attribute__((packed)) struct {
uint8_t displayXflip : 1;
uint8_t displayYflip : 1;
#ifdef SSD1306
uint8_t : 6; // reserved
#elif defined(ST7565)
uint8_t : 2; // reserved
uint8_t displayResRatio : 4;
#endif
};
unsigned rememberLastProfile :1;
unsigned rememberLastTemp :1;
unsigned rememberLastTip :1;
unsigned dim_inSleep :1;
unsigned EncoderMode :1;
unsigned debugEnabled :1;
unsigned activeDetection :1;
unsigned clone_fix :1;
uint8_t dim_mode;
uint8_t bootProfile;
uint8_t initMode;
uint8_t tempUnit;
uint8_t tempStep;
uint8_t tempBigStep;
uint8_t guiTempDenoise;
uint8_t buzzerMode;
uint8_t buttonWakeMode;
uint8_t shakeWakeMode;
uint8_t lvp;
#ifdef SSD1306
uint8_t displayVcom;
uint8_t displayClk;
uint8_t displayPrecharge;
#else
uint8_t : 8; // reserved
uint8_t : 8;
uint8_t : 8;
#endif
uint8_t : 8;
uint8_t : 8;
uint8_t : 8;
uint8_t : 8;
uint8_t : 8;
uint8_t : 8;
uint8_t : 8;
uint16_t guiUpdateDelay;
uint16_t : 16; // reserved
uint16_t : 16;
uint16_t : 16;
uint16_t : 16;
uint16_t : 16;
uint32_t dim_Timeout;
uint32_t : 32; // reserved
uint32_t : 32;
uint32_t : 32;
uint32_t : 32;
uint32_t : 32;
}settings_t;
#ifdef ENABLE_ADDONS
__attribute__((aligned(4))) typedef struct {
// bitmask for enabled addons, used to check if switching on and off multiple addons causes the struct
// to be the same size, thus matching CRC, but in reality its incompatible due to layout change
uint64_t enabledAddons;
#ifdef ENABLE_ADDON_FUME_EXTRACTOR
uint8_t fumeExtractorMode;
uint8_t fumeExtractorAfterrun; // amount of delay in 5 second increments
#endif
#ifdef ENABLE_ADDON_SWITCH_OFF_REMINDER
uint8_t swOffReminderEnabled; // enabled, disabled
uint8_t swOffReminderInactivityDelay; // amount of minutes in sleep mode before start beeping,
uint8_t swOffReminderBeepType; // beep type: short, medium, long
uint8_t swOffReminderPeriod; // amount of minutes between reminders
#endif
}addonSettings_t;
#endif
__attribute__((aligned(4))) typedef struct{
settings_t settings;
uint32_t settingsChecksum;
profile_t Profile;
uint32_t ProfileChecksum;
#ifdef ENABLE_ADDONS
addonSettings_t addonSettings;
uint32_t addonSettingsChecksum;
#endif
uint8_t save_Flag;
uint8_t setupMode;
uint8_t isSaving;
uint8_t currentProfile;
uint8_t currentTip;
}systemSettings_t;
extern systemSettings_t systemSettings;
extern const settings_t defaultSettings;
/** Cyclic task to save the settings if needed. */
void checkSettings(void);
/** Sets a flag to save the settings in the background task. */
void saveSettingsFromMenu(uint8_t mode);
/** Loads the settings from flash on boot. */
void restoreSettings();
/** Load/change to the profile with the given index */
void loadProfile(uint8_t profile);
/** Checks if the current profile in RAM is changed */
bool isCurrentProfileChanged(void);
#ifdef HAS_BATTERY
/** Restores settings from the backup ram used in the last session (eg last temp/tip).
* Call this after all the modules */
void restoreLastSessionSettings(void);
#endif
#endif /* SETTINGS_H_ */