Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add macro to enable tip types for supported hardware only #2031

Merged
merged 4 commits into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions source/Core/BSP/Miniware/configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@
#define TEMP_NTC 1
#define ACCEL_I2CBB1 1
#define POW_EPR 1
#define TIP_TYPE_SUPPORT 1 // Support for tips of different types, i.e. resistance
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically, I try to make the similar approach as for PROFILE_SUPPORT: we just enable everything related under the macro.

#define AUTO_TIP_SELECTION 1 // Can auto-select the tip
#define TIPTYPE_T12 1 // Can manually pick a T12 tip
#define HAS_POWER_DEBUG_MENU
Expand Down
1 change: 1 addition & 0 deletions source/Core/BSP/Pinecilv2/configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@
#define POW_EPR 1
#define ENABLE_QC2 1
#define MAG_SLEEP_SUPPORT 1
#define TIP_TYPE_SUPPORT 1 // Support for tips of different types, i.e. resistance
#define AUTO_TIP_SELECTION 1 // Can auto-select the tip
#define TIPTYPE_T12 1 // Can manually pick a T12 tip
#define DEVICE_HAS_VALIDATION_SUPPORT
Expand Down
13 changes: 12 additions & 1 deletion source/Core/Inc/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ typedef enum {
* Some devices allow multiple types of tips to be fitted, this allows selecting them or overriding the logic
* The first type will be the default (gets value of 0)
*/
#ifdef TIP_TYPE_SUPPORT
typedef enum {
#ifdef AUTO_TIP_SELECTION
TIP_TYPE_AUTO, // If the hardware supports automatic detection
Expand All @@ -142,7 +143,15 @@ typedef enum {
// #endif
TIP_TYPE_MAX, // Max value marker
} tipType_t;
uint8_t getUserSelectedTipResistance(); // returns the resistance matching the selected tip type or 0 for auto
#else
typedef enum {
TIP_TYPE_AUTO = 0, // value for the default case
TIP_TYPE_MAX = 0, // marker for settings when not supported
} tipType_t;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implement duplicated tipType_t stub for two reasons:

  • TIP_TYPE_MAX = 0 for settings struct to avoid compile-time error and set 0/auto as default right there for non-supported models;
  • TIP_TYPE_AUTO = 0 for backward compatibility with the stub function (see below).

#endif /* TIP_TYPE_SUPPORT */

// returns the resistance matching the selected tip type or 0 for auto and when not supported
uint8_t getUserSelectedTipResistance();

// Settings wide operations
void saveSettings();
Expand All @@ -162,5 +171,7 @@ void setSettingValue(const enum SettingsOptions option, const uint16_t newValue)
// Special access helpers, to reduce logic duplication
uint8_t lookupVoltageLevel();
uint16_t lookupHallEffectThreshold();
#ifdef TIP_TYPE_SUPPORT
const char *lookupTipName(); // Get the name string for the current soldering tip
#endif /* TIP_TYPE_SUPPORT */
#endif /* SETTINGS_H_ */
7 changes: 7 additions & 0 deletions source/Core/Src/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ uint8_t lookupVoltageLevel() {
}
}

#ifdef TIP_TYPE_SUPPORT
const char *lookupTipName() {
// Get the name string for the current soldering tip
tipType_t value = (tipType_t)getSettingValue(SettingsOptions::SolderingTipType);
Expand Down Expand Up @@ -334,7 +335,10 @@ const char *lookupTipName() {
break;
}
}
#endif /* TIP_TYPE_SUPPORT */

// Returns the resistance for the current tip selected by the user or 0 for auto
#ifdef TIP_TYPE_SUPPORT
uint8_t getUserSelectedTipResistance() {
tipType_t value = (tipType_t)getSettingValue(SettingsOptions::SolderingTipType);

Expand Down Expand Up @@ -370,3 +374,6 @@ uint8_t getUserSelectedTipResistance() {
break;
}
}
#else
uint8_t getUserSelectedTipResistance() { return tipType_t::TIP_TYPE_AUTO; }
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of twisting my head about how to do it inside of the existed instance of getUserSelectedTipResistance(), I thought that the most simple & straight-forward approach is just to make the duplicated stub with the single return.

#endif /* TIP_TYPE_SUPPORT */
14 changes: 11 additions & 3 deletions source/Core/Src/settingsGUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,10 @@ static bool showHallEffect(void);
#endif /* HALL_SENSOR */

// Tip type selection
#ifdef TIP_TYPE_SUPPORT
static void displaySolderingTipType(void);
static bool showSolderingTipType(void);
#endif /* TIP_TYPE_SUPPORT */

// Menu functions

Expand Down Expand Up @@ -267,12 +269,12 @@ const menuitem powerMenu[] = {

const menuitem solderingMenu[] = {
/*
* Tip Type
* Boost Mode Temp
* Auto Start
* Temp Change Short Step
* Temp Change Long Step
* Locking Mode
* Tip Type
* Profile Phases
* Profile Preheat Temperature
* Profile Preheat Max Temperature Change Per Second
Expand All @@ -288,8 +290,6 @@ const menuitem solderingMenu[] = {
* Profile Phase 5 Duration (s)
* Profile Cooldown Max Temperature Change Per Second
*/
/* Tip Type */
{SETTINGS_DESC(SettingsItemIndex::SolderingTipType), nullptr, displaySolderingTipType, showSolderingTipType, SettingsOptions::SolderingTipType, SettingsItemIndex::SolderingTipType, 5},
/* Boost Temp */
{SETTINGS_DESC(SettingsItemIndex::BoostTemperature), setBoostTemp, displayBoostTemp, nullptr, SettingsOptions::BoostTemp, SettingsItemIndex::BoostTemperature, 5},
/* Auto start */
Expand All @@ -300,6 +300,10 @@ const menuitem solderingMenu[] = {
{SETTINGS_DESC(SettingsItemIndex::TempChangeLongStep), nullptr, displayTempChangeLongStep, nullptr, SettingsOptions::TempChangeLongStep, SettingsItemIndex::TempChangeLongStep, 6},
/* Locking Mode */
{SETTINGS_DESC(SettingsItemIndex::LockingMode), nullptr, displayLockingMode, nullptr, SettingsOptions::LockingMode, SettingsItemIndex::LockingMode, 7},
#ifdef TIP_TYPE_SUPPORT
/* Tip Type */
{SETTINGS_DESC(SettingsItemIndex::SolderingTipType), nullptr, displaySolderingTipType, showSolderingTipType, SettingsOptions::SolderingTipType, SettingsItemIndex::SolderingTipType, 5},
#endif /* TIP_TYPE_SUPPORT */
Comment on lines +303 to +306
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took liberty to move the setting down inside of the soldering menu since in the UX design & usability usually they put variable/non-constant options closer to "the end" of "the list". So while temperature settings are applied to nearly every target (hence, "first in a row"), targets with support of different tips are limited. Just for the same reason we don't put "[thermo] profiles" submenu in the top of the list.

#ifdef PROFILE_SUPPORT
/* Profile Phases */
{SETTINGS_DESC(SettingsItemIndex::ProfilePhases), nullptr, displayProfilePhases, nullptr, SettingsOptions::ProfilePhases, SettingsItemIndex::ProfilePhases, 7},
Expand Down Expand Up @@ -763,12 +767,16 @@ static void displayHallEffectSleepTime(void) {
}
}
#endif /* HALL_SENSOR */

#ifdef TIP_TYPE_SUPPORT
static void displaySolderingTipType(void) {
// TODO wrapping X value
OLED::print(lookupTipName(), FontStyle::SMALL, 255, OLED::getCursorX());
}
// If there is no detection, and no options, max is 0
static bool showSolderingTipType(void) { return tipType_t::TIP_TYPE_MAX != 0; }
#endif /* TIP_TYPE_SUPPORT */

static void setTempF(const enum SettingsOptions option) {
uint16_t Temp = getSettingValue(option);
if (getSettingValue(SettingsOptions::TemperatureInF)) {
Expand Down
Loading