Skip to content

Commit

Permalink
WIP PoC |/!\|
Browse files Browse the repository at this point in the history
  • Loading branch information
ia committed Aug 4, 2023
1 parent 679bf0c commit cc33aaf
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 38 deletions.
27 changes: 23 additions & 4 deletions Translations/make_translation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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<uint8_t>(SettingsItemIndex::{eid}) == {i});\n"
)
sanity_checks_text += f"static_assert(static_cast<uint8_t>(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<uint8_t>(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<uint8_t>(SettingsItemIndex::NUM_ITEMS) == {len(defs['menuOptions'])} - OFFSET_PROFILE);\n"
return sanity_checks_text


Expand Down
5 changes: 4 additions & 1 deletion source/Core/BSP/MHP30/configuration.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#ifndef CONFIGURATION_H_
#define CONFIGURATION_H_

#define PROFILE_SUPPORT

#include "Settings.h"
#include <stdint.h>
/**
Expand Down Expand Up @@ -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
Expand Down
38 changes: 22 additions & 16 deletions source/Core/Inc/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@

#ifndef SETTINGS_H_
#define SETTINGS_H_

#include <stdbool.h>
#include <stdint.h>

#define SETTINGSVERSION (0x2A) // This number is frozen, do not edit

enum SettingsOptions {
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 5 additions & 1 deletion source/Core/Inc/Translation.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include <stdbool.h>
#include <stdint.h>

#include "configuration.h"

extern const bool HasFahrenheit;

extern const char *SmallSymbolPlus;
Expand Down Expand Up @@ -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;
Expand All @@ -63,6 +65,7 @@ enum class SettingsItemIndex : uint8_t {
TempChangeShortStep,
TempChangeLongStep,
LockingMode,
#ifdef PROFILE_SUPPORT
ProfilePhases,
ProfilePreheatTemp,
ProfilePreheatSpeed,
Expand All @@ -77,6 +80,7 @@ enum class SettingsItemIndex : uint8_t {
ProfilePhase5Temp,
ProfilePhase5Duration,
ProfileCooldownSpeed,
#endif
MotionSensitivity,
SleepTemperature,
SleepTimeout,
Expand Down
45 changes: 29 additions & 16 deletions source/Core/Src/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <string.h> // for memset

bool sanitiseSettings();

#ifdef POW_QC_20V
Expand Down Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions source/Core/Threads/OperatingModes/SolderingProfile.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#include "configuration.h"

#ifdef PROFILE_SUPPORT

#include "OperatingModes.h"
#include "SolderingCommon.h"
Expand Down Expand Up @@ -221,3 +224,5 @@ void gui_solderingProfileMode() {
GUIDelay();
}
}

#endif /* PROFILE_SUPPORT */

0 comments on commit cc33aaf

Please sign in to comment.