Implemented switching A and B buttons, closing #2034

getButtonState() now have an option int/bool argument to swap the result via XOR
This commit is contained in:
Leo
2025-01-26 05:03:46 +02:00
parent c229cec87f
commit 1fb84d5f50
50 changed files with 212 additions and 53 deletions

View File

@@ -57,7 +57,8 @@
*/
#define ORIENTATION_MODE 0 // 0: Right 1:Left 2:Automatic - Default right
#define MAX_ORIENTATION_MODE 1 // Unlikely to ever change
#define REVERSE_BUTTON_TEMP_CHANGE 0 // 0:Default 1:Reverse - Reverse the plus and minus button assigment for temperature change
#define REVERSE_BUTTON_TEMP_CHANGE 0 // 0:Default 1:Reverse - Reverse the plus and minus button assignment for temperature change
#define REVERSE_BUTTON_NAV 0 // 0:Default 1:Reverse - Reverse the A and B button assignment in the menus
/**
* OLED Brightness

View File

@@ -57,7 +57,8 @@
*/
#define ORIENTATION_MODE 2 // 0: Right 1:Left 2:Automatic - Default Automatic
#define MAX_ORIENTATION_MODE 2 // Up to auto
#define REVERSE_BUTTON_TEMP_CHANGE 0 // 0:Default 1:Reverse - Reverse the plus and minus button assigment for temperature change
#define REVERSE_BUTTON_TEMP_CHANGE 0 // 0:Default 1:Reverse - Reverse the plus and minus button assignment for temperature change
#define REVERSE_BUTTON_NAV 0 // 0:Default 1:Reverse - Reverse the A and B button assignment in the menus
/**
* OLED Brightness

View File

@@ -57,7 +57,8 @@
*/
#define ORIENTATION_MODE 2 // 0: Right 1:Left 2:Automatic - Default Automatic
#define MAX_ORIENTATION_MODE 2 // Up to auto
#define REVERSE_BUTTON_TEMP_CHANGE 0 // 0:Default 1:Reverse - Reverse the plus and minus button assigment for temperature change
#define REVERSE_BUTTON_TEMP_CHANGE 0 // 0:Default 1:Reverse - Reverse the plus and minus button assignment for temperature change
#define REVERSE_BUTTON_NAV 0 // 0:Default 1:Reverse - Reverse the A and B button assignment in the menus
/**
* OLED Brightness

View File

@@ -57,7 +57,8 @@
*/
#define ORIENTATION_MODE 2 // 0: Right 1:Left 2:Automatic - Default Automatic
#define MAX_ORIENTATION_MODE 2 // Up to auto
#define REVERSE_BUTTON_TEMP_CHANGE 0 // 0:Default 1:Reverse - Reverse the plus and minus button assigment for temperature change
#define REVERSE_BUTTON_TEMP_CHANGE 0 // 0:Default 1:Reverse - Reverse the plus and minus button assignment for temperature change
#define REVERSE_BUTTON_NAV 0 // 0:Default 1:Reverse - Reverse the A and B button assignment in the menus
/**
* OLED Brightness

View File

@@ -66,7 +66,8 @@
*/
#define ORIENTATION_MODE 0 // 0: Right 1:Left (2:Automatic N/A)
#define MAX_ORIENTATION_MODE 1 // Disable auto mode
#define REVERSE_BUTTON_TEMP_CHANGE 0 // 0:Default 1:Reverse - Reverse the plus and minus button assigment for temperature change
#define REVERSE_BUTTON_TEMP_CHANGE 0 // 0:Default 1:Reverse - Reverse the plus and minus button assignment for temperature change
#define REVERSE_BUTTON_NAV 0 // 0:Default 1:Reverse - Reverse the A and B button assignment in the menus
/**
* Temp change settings

View File

@@ -11,7 +11,7 @@
#include <Buttons.hpp>
TickType_t lastButtonTime = 0;
ButtonState getButtonState() {
ButtonState getButtonState(bool revert) {
/*
* Read in the buttons and then determine if a state change needs to occur
*/
@@ -28,8 +28,8 @@ ButtonState getButtonState() {
static TickType_t previousStateChange = 0;
const TickType_t timeout = TICKS_100MS * 4;
uint8_t currentState;
currentState = (getButtonA()) << 0;
currentState |= (getButtonB()) << 1;
currentState = (getButtonA()) << (0 xor revert);
currentState |= (getButtonB()) << (1 xor revert);
if (currentState) {
lastButtonTime = xTaskGetTickCount();

View File

@@ -27,7 +27,7 @@ enum ButtonState {
};
// Returns what buttons are pressed (if any)
ButtonState getButtonState();
ButtonState getButtonState(bool revert=0);
// Helpers
void waitForButtonPressOrTimeout(TickType_t timeout);
void waitForButtonPress();

View File

@@ -47,37 +47,38 @@ enum SettingsOptions {
CalibrationOffset = 23, // This stores the temperature offset for this tip in the iron.
PowerLimit = 24, // Maximum power iron allowed to output
ReverseButtonTempChangeEnabled = 25, // Change the plus and minus button assigment
TempChangeLongStep = 26, // Temperature-change-increment on long button press
TempChangeShortStep = 27, // Temperature-change-increment on short button press
HallEffectSensitivity = 28, // Operating mode of the hall effect sensor
AccelMissingWarningCounter = 29, // Counter of how many times we have warned we cannot detect the accelerometer
PDMissingWarningCounter = 30, // Counter of how many times we have warned we cannot detect the pd interface
UILanguage = 31, // Selected UI Language code, null-terminated *only if* the length is less than 8 chars
PDNegTimeout = 32, // PD timeout in 100ms steps
OLEDInversion = 33, // Invert the colours on the display
OLEDBrightness = 34, // Brightness for the OLED display
LOGOTime = 35, // Duration the logo will be displayed for
CalibrateCJC = 36, // Toggle calibrate CJC at next boot
BluetoothLE = 37, // Toggle BLE if present
USBPDMode = 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
HallEffectSleepTime = 53, // Seconds (/5) timeout to sleep when hall effect over threshold
SolderingTipType = 54, // Selecting the type of soldering tip fitted
ReverseButtonNavEnabled = 26, // Change the A and B button assigment in menus
TempChangeLongStep = 27, // Temperature-change-increment on long button press
TempChangeShortStep = 28, // Temperature-change-increment on short button press
HallEffectSensitivity = 29, // Operating mode of the hall effect sensor
AccelMissingWarningCounter = 30, // Counter of how many times we have warned we cannot detect the accelerometer
PDMissingWarningCounter = 31, // Counter of how many times we have warned we cannot detect the pd interface
UILanguage = 32, // Selected UI Language code, null-terminated *only if* the length is less than 8 chars
PDNegTimeout = 33, // PD timeout in 100ms steps
OLEDInversion = 34, // Invert the colours on the display
OLEDBrightness = 35, // Brightness for the OLED display
LOGOTime = 36, // Duration the logo will be displayed for
CalibrateCJC = 37, // Toggle calibrate CJC at next boot
BluetoothLE = 38, // Toggle BLE if present
USBPDMode = 39, // Toggle PPS & EPR
ProfilePhases = 40, // Number of profile mode phases
ProfilePreheatTemp = 41, // Temperature to preheat to before the first phase
ProfilePreheatSpeed = 42, // Maximum allowed preheat speed in degrees per second
ProfilePhase1Temp = 43, // Temperature to target for the end of phase 1
ProfilePhase1Duration = 44, // Target duration for phase 1
ProfilePhase2Temp = 45, // Temperature to target for the end of phase 2
ProfilePhase2Duration = 46, // Target duration for phase 2
ProfilePhase3Temp = 47, // Temperature to target for the end of phase 3
ProfilePhase3Duration = 48, // Target duration for phase 3
ProfilePhase4Temp = 49, // Temperature to target for the end of phase 4
ProfilePhase4Duration = 50, // Target duration for phase 4
ProfilePhase5Temp = 51, // Temperature to target for the end of phase 5
ProfilePhase5Duration = 52, // Target duration for phase 5
ProfileCooldownSpeed = 53, // Maximum allowed cooldown speed in degrees per second
HallEffectSleepTime = 54, // Seconds (/5) timeout to sleep when hall effect over threshold
SolderingTipType = 55, // Selecting the type of soldering tip fitted
//
SettingsOptionsLength = 55, // End marker
SettingsOptionsLength = 56, // End marker
};
typedef enum {

View File

@@ -90,6 +90,7 @@ enum class SettingsItemIndex : uint8_t {
CooldownBlink,
ScrollingSpeed,
ReverseButtonTempChange,
ReverseButtonNav,
AnimSpeed,
AnimLoop,
Brightness,

View File

@@ -81,6 +81,8 @@ static const SettingConstants settingsConstants[(int)SettingsOptions::SettingsOp
{MIN_CALIBRATION_OFFSET, 2500, 1, CALIBRATION_OFFSET}, // CalibrationOffset
{ 0, MAX_POWER_LIMIT, POWER_LIMIT_STEPS, POWER_LIMIT}, // PowerLimit
{ 0, 1, 1, REVERSE_BUTTON_TEMP_CHANGE}, // ReverseButtonTempChangeEnabled
{ 0, 1, 1,
REVERSE_BUTTON_NAV}, // ReverseButtonNavEnabled
{ 5, TEMP_CHANGE_LONG_STEP_MAX, 5, TEMP_CHANGE_LONG_STEP}, // TempChangeLongStep
{ 1, TEMP_CHANGE_SHORT_STEP_MAX, 1, TEMP_CHANGE_SHORT_STEP}, // TempChangeShortStep
{ 0, 9, 1, 7}, // HallEffectSensitivity

View File

@@ -47,6 +47,7 @@ static void displayAdvancedSolderingScreens(void);
static void displayAdvancedIDLEScreens(void);
static void displayScrollSpeed(void);
static void displayReverseButtonTempChangeEnabled(void);
static void displayReverseButtonNavEnabled(void);
static void displayPowerLimit(void);
#ifdef BLE_ENABLED
@@ -395,6 +396,8 @@ const menuitem UIMenu[] = {
{SETTINGS_DESC(SettingsItemIndex::ScrollingSpeed), nullptr, displayScrollSpeed, nullptr, SettingsOptions::DescriptionScrollSpeed, SettingsItemIndex::ScrollingSpeed, 7},
/* Reverse Temp change buttons +/- */
{SETTINGS_DESC(SettingsItemIndex::ReverseButtonTempChange), nullptr, displayReverseButtonTempChangeEnabled, nullptr, SettingsOptions::ReverseButtonTempChangeEnabled, SettingsItemIndex::ReverseButtonTempChange, 7},
/* Reverse menu nav buttons A/B */
{SETTINGS_DESC(SettingsItemIndex::ReverseButtonNav), nullptr, displayReverseButtonNavEnabled, nullptr, SettingsOptions::ReverseButtonNavEnabled, SettingsItemIndex::ReverseButtonNav, 7},
/* Animation Speed adjustment */
{SETTINGS_DESC(SettingsItemIndex::AnimSpeed), nullptr, displayAnimationSpeed, nullptr, SettingsOptions::AnimationSpeed, SettingsItemIndex::AnimSpeed, 7},
/* Animation Loop switch */
@@ -480,7 +483,7 @@ static int userConfirmation(const char *message) {
for (;;) {
drawScrollingText(message, xTaskGetTickCount() - tickStart);
ButtonState buttons = getButtonState();
ButtonState buttons = getButtonState(getSettingValue(SettingsOptions::ReverseButtonTempChangeEnabled));
switch (buttons) {
case BUTTON_F_SHORT:
// User confirmed
@@ -856,6 +859,7 @@ static void displayCoolingBlinkEnabled(void) { OLED::drawCheckbox(getSettingValu
static void displayScrollSpeed(void) { OLED::print(translatedString((getSettingValue(SettingsOptions::DescriptionScrollSpeed)) ? Tr->SettingFastChar : Tr->SettingSlowChar), FontStyle::LARGE); }
static void displayReverseButtonTempChangeEnabled(void) { OLED::drawCheckbox(getSettingValue(SettingsOptions::ReverseButtonTempChangeEnabled)); }
static void displayReverseButtonNavEnabled(void) { OLED::drawCheckbox(getSettingValue(SettingsOptions::ReverseButtonNavEnabled)); }
static void displayAnimationSpeed(void) {
switch (getSettingValue(SettingsOptions::AnimationSpeed)) {
@@ -952,7 +956,7 @@ static void setCalibrateVIN(void) {
OLED::setCursor(0, 8);
OLED::printNumber(getSettingValue(SettingsOptions::VoltageDiv), 3, FontStyle::SMALL);
switch (getButtonState()) {
switch (getButtonState(getSettingValue(SettingsOptions::ReverseButtonNavEnabled))) {
case BUTTON_F_SHORT:
prevSettingValue(SettingsOptions::VoltageDiv);
break;

View File

@@ -44,7 +44,7 @@ OperatingMode handle_post_init_state();
OperatingMode guiHandleDraw(void) {
OLED::clearScreen(); // Clear ready for render pass
// Read button state
ButtonState buttons = getButtonState();
ButtonState buttons = getButtonState(getSettingValue(SettingsOptions::ReverseButtonNavEnabled));
// Enforce screen on if buttons pressed, movement, hot tip etc
if (buttons != BUTTON_NONE) {
OLED::setDisplayState(OLED::DisplayState::ON);

View File

@@ -55,7 +55,7 @@ OperatingMode gui_solderingTempAdjust(const ButtonState buttonIn, guiContext *cx
(*autoRepeatAcceleration) = PRESS_ACCEL_INTERVAL_MAX - PRESS_ACCEL_INTERVAL_MIN;
}
// If buttons are flipped; flip the delta
if (getSettingValue(SettingsOptions::ReverseButtonTempChangeEnabled)) {
if (getSettingValue(SettingsOptions::ReverseButtonTempChangeEnabled) xor getSettingValue(SettingsOptions::ReverseButtonNavEnabled)) {
delta = -delta;
}
if (delta != 0) {

View File

@@ -17,7 +17,7 @@ bool shouldShutdown(void) {
}
}
}
if (getButtonState() == BUTTON_B_LONG) { // allow also if back button is pressed long
if (getButtonState(getSettingValue(SettingsOptions::ReverseButtonNavEnabled)) == BUTTON_B_LONG) { // allow also if back button is pressed long
return true;
}
return false;