-
Notifications
You must be signed in to change notification settings - Fork 86
/
settings.h
418 lines (358 loc) · 13.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
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
/*
* 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 ENABLE_DBG_SAVE
#define SWSTRING "SW: 1.13.12 " // Software version reported in settings screen
#define SYSTEM_SETTINGS_VERSION 29 // Change this if you change the system settings struct to prevent getting out of sync
#define PROFILE_SETTINGS_VERSION 4 // Same, but for profile settings struct
#define TIP_SETTINGS_VERSION 1 // Same, but for tip settings struct
#define ADDONS_SETTINGS_VERSION 1 // Same, but for addons settings struct
#define LANGUAGE_COUNT_WITH_CHINESE 9 // Number of languages including chinese variations
#ifdef DISABLE_CHINESE
#define LANGUAGE_COUNT (LANGUAGE_COUNT_WITH_CHINESE - 2)
#else
#define LANGUAGE_COUNT (LANGUAGE_COUNT_WITH_CHINESE)
#endif
#define NUM_PROFILES 3 // Number of profiles
#define NUM_TIPS 85 // 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.
#define TEMPSETTINGS_SAVE_TIME 3000 // Last tip/profile/temperature in flash are updated after 3 seconds with no changes. This is not applied when battery option is enabled (Stored instantly).
#define DEFAULT_TEMPERATURE 320 // Temperature loaded by default
#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{
lang_english,
lang_russian,
lang_swedish,
lang_german,
lang_turkish,
lang_bulgarian,
lang_czech,
#ifndef DISABLE_CHINESE
lang_schinese,
lang_tchinese,
#endif
}languages_t;
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,
mode_coldboost = 4,
initialized = 0,
profile_T12 = 0,
profile_C245 = 1,
profile_C210 = 2,
profile_None = 0xff,
save_settings = 1,
save_profile = 2,
save_addons = 8,
save_all = save_settings | save_profile | save_addons,
reset_settings = 0x10,
reset_profile = 0x20,
reset_profiles = 0x40,
reset_addons = 0x80,
reset_all = reset_settings | reset_profiles | reset_addons,
no_mode = 0,
save_tip = 1,
add_tip = 2,
delete_tip = 3,
reset_tips = 4,
reset_allTips = 5,
perform_scanFix = 0, // Perform check over existing flash, reset any wrong section
no_reboot = 0,
do_reboot = 1,
ram_to_flash = 0,
flash_to_ram = 1,
output_PWM,
output_Low,
output_High,
dim_off = 0,
dim_sleep = 1,
dim_always = 2,
error_sleep = 0,
error_run = 1,
error_resume = 2,
normal_update = 0,
force_update = 1,
#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(2048))) typedef struct{ // 2KB aligned, as flash sector erase size
uint8_t version;
uint8_t currentNumberOfTips;
tipData_t tip[NUM_TIPS];
}flashTipData_t;
typedef struct{
flashTipData_t data;
uint32_t crc;
}flashTipSlot_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{
uint16_t version; // Always 0xFFFF if flash is erased, used to detect blank flash, or settings version mismatch
uint8_t ID;
uint8_t impedance;
uint8_t tempUnit;
uint8_t pwmMul;
uint8_t errorResumeMode;
uint8_t shakeFiltering;
uint8_t WakeInputMode;
uint8_t StandMode;
uint8_t smartActiveEnabled;
uint8_t coldBoostEnabled;
uint8_t smartActiveLoad;
uint8_t standDelay;
filter_t tipFilter;
ntc_data_t ntc;
uint16_t standbyTemperature;
uint16_t MaxSetTemperature;
uint16_t MinSetTemperature;
uint16_t boostTemperature;
uint16_t coldBoostTemperature;
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;
uint32_t errorTimeout;
uint32_t boostTimeout;
uint32_t coldBoostTimeout;
uint32_t sleepTimeout;
uint32_t standbyTimeout;
}profile_settings_t;
__attribute__((aligned(4))) typedef struct{
uint16_t version; // Always 0xFF if flash is erased, used to detect blank flash, or settings version mismatch
uint16_t sector_size;
uint8_t language;
uint8_t contrastOrBrightness;
uint8_t displayStartColumn;
uint8_t displayStartLine;
uint8_t displayXflip;
uint8_t displayYflip;
uint8_t displayResRatio;
uint8_t hasBattery;
uint8_t dim_inSleep;
uint8_t EncoderMode;
uint8_t debugEnabled;
uint8_t activeDetection;
uint8_t dim_mode;
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;
uint8_t displayVcom;
uint8_t displayClk;
uint8_t displayPrecharge;
uint16_t guiUpdateDelay;
uint32_t dim_Timeout;
}systemSettings_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
uint8_t version;
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{
systemSettings_t system;
#ifdef ENABLE_ADDONS
addonSettings_t addons;
#endif
profile_settings_t profile;
tipData_t currentTipData;
uint8_t setupMode;
uint8_t isSaving;
uint8_t currentProfile;
uint8_t currentTip;
}settings_t;
__attribute__((aligned(4))) typedef struct{
systemSettings_t system;
#ifdef ENABLE_ADDONS
addonSettings_t addons;
#endif
profile_settings_t profile[NUM_PROFILES];
uint32_t systemChecksum;
uint32_t addonsChecksum;
uint32_t profileChecksum[NUM_PROFILES];
} flashSettings_t;
typedef struct{
uint16_t profile[128];
uint16_t tip[NUM_PROFILES][128];
uint16_t temperature[512];
}temp_settings_t;
typedef struct{
uint8_t tipIndex[NUM_PROFILES];
uint8_t tip[NUM_PROFILES];
uint8_t profileIndex;
uint8_t profile;
uint8_t prevTip[NUM_PROFILES];
uint8_t prevProfile;
uint16_t prevTemp;
uint16_t tempIndex;
uint16_t temp;
uint32_t tempCheckTime;
uint32_t tipCheckTime;
uint32_t profileCheckTime;
}flashTemp_t;
#define BACKUP_RAM_SIZE_IN_BYTES 20u
#define NUM_BACKUP_RAM_REGISTERS (BACKUP_RAM_SIZE_IN_BYTES / 2u) // each register holds 2 byte of data in the lower nibble
typedef union {
struct {
struct {
// max (BACKUP_RAM_SIZE_IN_BYTES - 4) byte of data in total
uint16_t lastTipTemp[NUM_PROFILES];
uint8_t lastSelTip[NUM_PROFILES];
uint8_t lastProfile;
} values;
uint32_t crc;
};
uint8_t bytes[BACKUP_RAM_SIZE_IN_BYTES];
} backupRamData_t;
extern settings_t settings;
extern const systemSettings_t defaultSystemSettings;
extern const profile_settings_t defaultProfileSettings;
extern const tipData_t defaultTipData[NUM_PROFILES];
#ifdef ENABLE_DBG_SAVE
extern uint8_t save_prevstate_debug, save_laststate_debug;
#endif
/** Cyclic task to save the current temperature/tip/profile if needed. */
void updateTempData(bool force);
/** Save the settings to flash. */
void saveSettings(uint8_t save_mode, uint8_t reboot_mode);
void saveTip(uint8_t save_mode, uint8_t tip_index);
/** Reads the save flag. */
uint8_t getSaveFlag(void);
/** Loads the settings from flash on boot. */
void restoreSettings(void);
flashSettings_t * getFlashSettings(void);
systemSettings_t* getSystemSettings(void);
settings_t * getSettings(void);
systemSettings_t * getDefaultSystemSettings(void);
systemSettings_t * getFlashSystemSettings(void);
flashSettings_t * getFlashSettings(void);
/** Load/change to the profile with the given index */
void loadProfile(uint8_t profile);
void setCurrentProfile(uint8_t profile);
uint8_t getCurrentProfile(void);
uint8_t getCurrentProfileID(void);
profile_settings_t * getProfileSettings(void);
profile_settings_t * getDefaultProfileSettings(void);
profile_settings_t * getFlashProfileSettings(void);
#ifdef ENABLE_ADDONS
addonSettings_t * getAddons(void);
addonSettings_t * getDefaultAddons(void);
addonSettings_t * getFlashAddons(void);
bool isAddonSettingsChanged(void);
#endif
void loadTipDataFromFlash(uint8_t tip);
tipData_t * getFlashTipData(uint8_t tip);
tipData_t * getCurrentTipData(void);
tipData_t * getDefaultTipData(void);
void setCurrentTipData(tipData_t * tip);
uint8_t getCurrentTip(void);
uint8_t getCurrentNumberOfTips(void);
void setCurrentTip(uint8_t tip);
/** Checks if the current system settings in RAM were changed */
bool isSystemSettingsChanged(void);
/** Checks if the current profile in RAM is changed */
bool isCurrentProfileChanged(void);
/** Copies last Profile / Temperature / Tip data between flash and ram when battery option is changed*/
void copy_bkp_data(uint8_t mode);
/** Set initial values after setup screen */
void flashTempSettingsInitialSetup(void);
#endif /* SETTINGS_H_ */