settings.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /*
  2. * settings.h
  3. *
  4. * Created on: Jan 12, 2021
  5. * Author: David Original work by Jose (PTDreamer), 2017
  6. */
  7. #ifndef SETTINGS_H_
  8. #define SETTINGS_H_
  9. #include "main.h"
  10. #include "pid.h"
  11. #include "board.h"
  12. #define ProfileSize 3 // Number of profiles
  13. #define TipSize 10 // Number of tips for each profile
  14. #define TipCharSize 5 // String size for each tip name (Including null terminator)
  15. #ifndef T12_Cal250
  16. #define T12_Cal250 1100 // Default values to be used in the calibration if not adjusted
  17. #define T12_Cal350 1200 // TODO: Move these values to the board profile, so each board can have a closer default calibration
  18. #define T12_Cal450 1300 // But we don't have calibration data from users!
  19. #endif
  20. #define C210_Cal250 300
  21. #define C210_Cal350 400
  22. #define C210_Cal450 500
  23. #define C245_Cal250 900
  24. #define C245_Cal350 1000
  25. #define C245_Cal450 1100
  26. //#define SWSTRING "SW: v1.10" // For releases
  27. #define SWSTRING "SW: 2021-07-02" // For git
  28. #define SETTINGS_VERSION 3 // Change this if you change the struct below to prevent people getting out of sync
  29. #define StoreSize 2 // In KB
  30. #define FLASH_ADDR (0x8000000 + ((FLASH_SZ-StoreSize)*1024)) // Last 2KB flash (Minimum erase size, page size=2KB)
  31. enum{
  32. wakeInputmode_shake = 0,
  33. wakeInputmode_stand = 1,
  34. wakeButton_Off = 0,
  35. wakeButton_On = 1,
  36. wakeShake_Off = 0,
  37. wakeShake_On = 1,
  38. source_wakeInput = 0,
  39. source_wakeButton = 1,
  40. no_update = 0,
  41. needs_update = 1,
  42. runaway_ok = 0,
  43. runaway_25 = 1,
  44. runaway_50 = 2,
  45. runaway_75 = 3,
  46. runaway_100 = 4,
  47. runaway_500 = 5,
  48. runaway_triggered = 1,
  49. noError = 0,
  50. setError = 1,
  51. debug_Off = 0,
  52. debug_On = 1,
  53. calibration_Off = 0,
  54. calibration_On = 1,
  55. saveKeepingProfiles = 0,
  56. saveWipingProfiles = 1,
  57. setup_Off = 0,
  58. setup_On = 1,
  59. encoder_normal = 0,
  60. encoder_reverse = 1,
  61. mode_Celsius = 0,
  62. mode_Farenheit = 1,
  63. mode_sleep = 0,
  64. mode_standby = 1,
  65. mode_run = 2,
  66. initialized = 0,
  67. buzzer_Off = 0,
  68. buzzer_On = 1,
  69. profile_T12 = 0,
  70. profile_C245 = 1,
  71. profile_C210 = 2,
  72. profile_None = 0xff
  73. };
  74. typedef struct tipData {
  75. uint16_t calADC_At_250;
  76. uint16_t calADC_At_350;
  77. uint16_t calADC_At_450;
  78. char name[TipCharSize];
  79. pid_values_t PID;
  80. }tipData;
  81. typedef struct{
  82. uint8_t NotInitialized;
  83. uint8_t ID;
  84. uint8_t impedance;
  85. uint8_t tempUnit;
  86. uint8_t currentNumberOfTips;
  87. uint8_t currentTip;
  88. uint8_t filterFactor;
  89. int8_t CalNTC;
  90. uint16_t UserSetTemperature;
  91. uint16_t MaxSetTemperature;
  92. uint16_t MinSetTemperature;
  93. uint16_t sleepTimeout;
  94. uint16_t standbyTimeout;
  95. uint16_t standbyTemperature;
  96. uint16_t pwmPeriod;
  97. uint16_t pwmDelay;
  98. uint16_t noIronValue;
  99. uint16_t power;
  100. uint16_t Cal250_default;
  101. uint16_t Cal350_default;
  102. uint16_t Cal450_default;
  103. tipData tip[TipSize];
  104. }profile_t;
  105. typedef struct{
  106. uint8_t NotInitialized; // Always 1 if flash is erased
  107. uint8_t contrast;
  108. uint8_t OledOffset;
  109. uint8_t currentProfile;
  110. uint8_t saveSettingsDelay;
  111. uint8_t initMode;
  112. uint8_t tempStep;
  113. uint8_t screenDimming;
  114. uint8_t tempUnit;
  115. uint8_t activeDetection;
  116. uint8_t buzzerMode;
  117. uint8_t wakeOnButton;
  118. uint8_t wakeOnShake;
  119. uint8_t WakeInputMode;
  120. uint8_t StandMode;
  121. uint8_t EncoderMode;
  122. uint16_t errorDelay;
  123. uint16_t guiUpdateDelay;
  124. uint16_t lvp;
  125. uint32_t version; // Used to track if a reset is needed on firmware upgrade
  126. }settings_t;
  127. typedef __attribute__((aligned(4))) struct{
  128. settings_t settings;
  129. uint32_t settingsChecksum;
  130. profile_t Profile;
  131. uint32_t ProfileChecksum;
  132. bool setupMode;
  133. }systemSettings_t;
  134. typedef __attribute__((aligned(4))) struct{
  135. profile_t Profile[ProfileSize];
  136. uint32_t ProfileChecksum[ProfileSize];
  137. settings_t settings;
  138. uint32_t settingsChecksum;
  139. }flashSettings_t;
  140. extern systemSettings_t systemSettings;
  141. extern flashSettings_t* flashSettings;
  142. void Diag_init(void);
  143. void checkSettings(void);
  144. void saveSettings(bool wipeAllProfileData);
  145. void restoreSettings();
  146. uint32_t ChecksumSettings(settings_t* settings);
  147. uint32_t ChecksumProfile(profile_t* profile);
  148. void resetSystemSettings(void);
  149. void resetCurrentProfile(void);
  150. void storeTipData(uint8_t tip);
  151. void loadProfile(uint8_t tip);
  152. #endif /* SETTINGS_H_ */