From cc33aaf7cb7f00489c2191b4141e6d11eb2dd5fd Mon Sep 17 00:00:00 2001 From: Ivan Zorin Date: Fri, 4 Aug 2023 06:03:08 +0300 Subject: [PATCH] WIP PoC |/!\| --- Translations/make_translation.py | 27 +++++++++-- source/Core/BSP/MHP30/configuration.h | 5 ++- source/Core/Inc/Settings.h | 38 +++++++++------- source/Core/Inc/Translation.h | 6 ++- source/Core/Src/Settings.cpp | 45 ++++++++++++------- .../OperatingModes/SolderingProfile.cpp | 5 +++ 6 files changed, 88 insertions(+), 38 deletions(-) diff --git a/Translations/make_translation.py b/Translations/make_translation.py index 505e42f56..2a5db7c33 100755 --- a/Translations/make_translation.py +++ b/Translations/make_translation.py @@ -1218,8 +1218,14 @@ def write_grouped_indexes(output_text: str, name: str, mainKey: str, subKey: str + translated_index.str_start_offset ) + if record["id"] == "ProfilePhases": + output_text += "#ifdef PROFILE_SUPPORT\n" + output_text += f" /* {record['id'].ljust(max_len)[:max_len]} */ {start_index}, // {escape(raw_string)}\n" + if record["id"] == "ProfileCooldownSpeed": + output_text += "#endif /* PROFILE_SUPPORT */\n" + output_text += f" }}, // {name}\n\n" return output_text @@ -1254,12 +1260,25 @@ def write_grouped_indexes(output_text: str, name: str, mainKey: str, subKey: str def get_translation_sanity_checks_text(defs: dict) -> str: sanity_checks_text = "\n// Verify SettingsItemIndex values:\n" + sanity_checks_text += "#define OFFSET_PROFILE 0\n" + for i, mod in enumerate(defs["menuOptions"]): eid = mod["id"] - sanity_checks_text += ( - f"static_assert(static_cast(SettingsItemIndex::{eid}) == {i});\n" - ) - sanity_checks_text += f"static_assert(static_cast(SettingsItemIndex::NUM_ITEMS) == {len(defs['menuOptions'])});\n" + + if eid == "ProfilePhases": + sanity_checks_text += "#ifdef PROFILE_SUPPORT\n" + + sanity_checks_text += f"static_assert(static_cast(SettingsItemIndex::{eid}) == {i} - OFFSET_PROFILE);\n" + + if eid == "ProfileCooldownSpeed": + sanity_checks_text += "#else\n" + sanity_checks_text += "#ifdef OFFSET_PROFILE\n" + sanity_checks_text += "#undef OFFSET_PROFILE\n" + sanity_checks_text += "#endif\n" + sanity_checks_text += "#define OFFSET_PROFILE 14\n" + sanity_checks_text += "#endif /* PROFILE_SUPPORT */\n" + + sanity_checks_text += f"static_assert(static_cast(SettingsItemIndex::NUM_ITEMS) == {len(defs['menuOptions'])} - OFFSET_PROFILE);\n" return sanity_checks_text diff --git a/source/Core/BSP/MHP30/configuration.h b/source/Core/BSP/MHP30/configuration.h index c99afc649..b112da0fd 100644 --- a/source/Core/BSP/MHP30/configuration.h +++ b/source/Core/BSP/MHP30/configuration.h @@ -1,5 +1,8 @@ #ifndef CONFIGURATION_H_ #define CONFIGURATION_H_ + +#define PROFILE_SUPPORT + #include "Settings.h" #include /** @@ -150,7 +153,7 @@ #define ACCEL_SC7 #define ACCEL_MSA -#define PROFILE_SUPPORT +//#define PROFILE_SUPPORT #define POW_PD 1 #define POW_PD_EXT 0 diff --git a/source/Core/Inc/Settings.h b/source/Core/Inc/Settings.h index c1eef1280..165646712 100644 --- a/source/Core/Inc/Settings.h +++ b/source/Core/Inc/Settings.h @@ -9,8 +9,10 @@ #ifndef SETTINGS_H_ #define SETTINGS_H_ + #include #include + #define SETTINGSVERSION (0x2A) // This number is frozen, do not edit enum SettingsOptions { @@ -53,22 +55,26 @@ enum SettingsOptions { CalibrateCJC = 36, // Toggle calibrate CJC at next boot BluetoothLE = 37, // Toggle BLE if present PDVpdo = 38, // Toggle PPS & EPR - ProfilePhases = 39, // Number of profile mode phases - ProfilePreheatTemp = 40, // Temperature to preheat to before the first phase - ProfilePreheatSpeed = 41, // Maximum allowed preheat speed in degrees per second - ProfilePhase1Temp = 42, // Temperature to target for the end of phase 1 - ProfilePhase1Duration = 43, // Target duration for phase 1 - ProfilePhase2Temp = 44, // Temperature to target for the end of phase 2 - ProfilePhase2Duration = 45, // Target duration for phase 2 - ProfilePhase3Temp = 46, // Temperature to target for the end of phase 3 - ProfilePhase3Duration = 47, // Target duration for phase 3 - ProfilePhase4Temp = 48, // Temperature to target for the end of phase 4 - ProfilePhase4Duration = 49, // Target duration for phase 4 - ProfilePhase5Temp = 50, // Temperature to target for the end of phase 5 - ProfilePhase5Duration = 51, // Target duration for phase 5 - ProfileCooldownSpeed = 52, // Maximum allowed cooldown speed in degrees per second - // - SettingsOptionsLength = 53, // + +#ifdef PROFILE_SUPPORT + ProfilePhases , // Number of profile mode phases + ProfilePreheatTemp , // Temperature to preheat to before the first phase + ProfilePreheatSpeed , // Maximum allowed preheat speed in degrees per second + ProfilePhase1Temp , // Temperature to target for the end of phase 1 + ProfilePhase1Duration , // Target duration for phase 1 + ProfilePhase2Temp , // Temperature to target for the end of phase 2 + ProfilePhase2Duration , // Target duration for phase 2 + ProfilePhase3Temp , // Temperature to target for the end of phase 3 + ProfilePhase3Duration , // Target duration for phase 3 + ProfilePhase4Temp , // Temperature to target for the end of phase 4 + ProfilePhase4Duration , // Target duration for phase 4 + ProfilePhase5Temp , // Temperature to target for the end of phase 5 + ProfilePhase5Duration , // Target duration for phase 5 + ProfileCooldownSpeed , // Maximum allowed cooldown speed in degrees per second +#endif + + // ENDING MARKER WITH TOTAL LENGTH of ALL COMPILED-IN OPTIONS + SettingsOptionsLength }; typedef enum { diff --git a/source/Core/Inc/Translation.h b/source/Core/Inc/Translation.h index e3bde065b..686b77e06 100644 --- a/source/Core/Inc/Translation.h +++ b/source/Core/Inc/Translation.h @@ -11,6 +11,8 @@ #include #include +#include "configuration.h" + extern const bool HasFahrenheit; extern const char *SmallSymbolPlus; @@ -41,7 +43,7 @@ extern const char *LargeSymbolDC; extern const char *SmallSymbolDC; extern const char *LargeSymbolCellCount; extern const char *SmallSymbolCellCount; -// + extern const char *SmallSymbolVersionNumber; extern const char *SmallSymbolPDDebug; extern const char *SmallSymbolState; @@ -63,6 +65,7 @@ enum class SettingsItemIndex : uint8_t { TempChangeShortStep, TempChangeLongStep, LockingMode, +#ifdef PROFILE_SUPPORT ProfilePhases, ProfilePreheatTemp, ProfilePreheatSpeed, @@ -77,6 +80,7 @@ enum class SettingsItemIndex : uint8_t { ProfilePhase5Temp, ProfilePhase5Duration, ProfileCooldownSpeed, +#endif MotionSensitivity, SleepTemperature, SleepTimeout, diff --git a/source/Core/Src/Settings.cpp b/source/Core/Src/Settings.cpp index 5196f4a48..5430a1d95 100644 --- a/source/Core/Src/Settings.cpp +++ b/source/Core/Src/Settings.cpp @@ -8,12 +8,15 @@ * devices flash */ -#include "Settings.h" +#include "configuration.h" + #include "BSP.h" +#include "Settings.h" #include "Setup.h" #include "Translation.h" -#include "configuration.h" + #include // for memset + bool sanitiseSettings(); #ifdef POW_QC_20V @@ -90,23 +93,33 @@ static const SettingConstants settingsConstants[(int)SettingsOptions::SettingsOp {0, 1, 1, 0}, // CalibrateCJC {0, 1, 1, 1}, // BluetoothLE {0, 1, 1, 1}, // PDVpdo - {1, 5, 1, 4}, // ProfilePhases - {MIN_TEMP_C, MAX_TEMP_F, 5, 90}, // ProfilePreheatTemp - {1, 10, 1, 1}, // ProfilePreheatSpeed - {MIN_TEMP_C, MAX_TEMP_F, 5, 130}, // ProfilePhase1Temp - {10, 180, 5, 90}, // ProfilePhase1Duration - {MIN_TEMP_C, MAX_TEMP_F, 5, 140}, // ProfilePhase2Temp - {10, 180, 5, 30}, // ProfilePhase2Duration - {MIN_TEMP_C, MAX_TEMP_F, 5, 165}, // ProfilePhase3Temp - {10, 180, 5, 30}, // ProfilePhase3Duration - {MIN_TEMP_C, MAX_TEMP_F, 5, 140}, // ProfilePhase4Temp - {10, 180, 5, 30}, // ProfilePhase4Duration - {MIN_TEMP_C, MAX_TEMP_F, 5, 90}, // ProfilePhase5Temp - {10, 180, 5, 30}, // ProfilePhase5Duration - {1, 10, 1, 2}, // ProfileCooldownSpeed +#ifdef PROFILE_SUPPORT + {1, 5, 1, 4}, // ProfilePhases + {MIN_TEMP_C, MAX_TEMP_F, 5, 90}, // ProfilePreheatTemp + {1, 10, 1, 1}, // ProfilePreheatSpeed + {MIN_TEMP_C, MAX_TEMP_F, 5, 130}, // ProfilePhase1Temp + {10, 180, 5, 90}, // ProfilePhase1Duration + {MIN_TEMP_C, MAX_TEMP_F, 5, 140}, // ProfilePhase2Temp + {10, 180, 5, 30}, // ProfilePhase2Duration + {MIN_TEMP_C, MAX_TEMP_F, 5, 165}, // ProfilePhase3Temp + {10, 180, 5, 30}, // ProfilePhase3Duration + {MIN_TEMP_C, MAX_TEMP_F, 5, 140}, // ProfilePhase4Temp + {10, 180, 5, 30}, // ProfilePhase4Duration + {MIN_TEMP_C, MAX_TEMP_F, 5, 90}, // ProfilePhase5Temp + {10, 180, 5, 30}, // ProfilePhase5Duration + {1, 10, 1, 2} // ProfileCooldownSpeed +#endif }; + static_assert((sizeof(settingsConstants) / sizeof(SettingConstants)) == ((int)SettingsOptions::SettingsOptionsLength)); +#ifdef PROFILE_SUPPORT +static_assert((SettingsOptions::ProfilePhase1Temp) == 42); // TODO: REMOVE ME: TEMP. DEBUG FOR PoC +static_assert((SettingsOptions::SettingsOptionsLength) == 53); +#else +static_assert((SettingsOptions::SettingsOptionsLength) == 39); +#endif + void saveSettings() { #ifdef CANT_DIRECT_READ_SETTINGS // For these devices flash is not 1:1 mapped, so need to read into staging buffer diff --git a/source/Core/Threads/OperatingModes/SolderingProfile.cpp b/source/Core/Threads/OperatingModes/SolderingProfile.cpp index df6b58056..d36243230 100644 --- a/source/Core/Threads/OperatingModes/SolderingProfile.cpp +++ b/source/Core/Threads/OperatingModes/SolderingProfile.cpp @@ -1,3 +1,6 @@ +#include "configuration.h" + +#ifdef PROFILE_SUPPORT #include "OperatingModes.h" #include "SolderingCommon.h" @@ -221,3 +224,5 @@ void gui_solderingProfileMode() { GUIDelay(); } } + +#endif /* PROFILE_SUPPORT */