Skip to content

Commit 8c54f51

Browse files
committed
hold to disable focus mode
1 parent a4a4e7f commit 8c54f51

File tree

8 files changed

+31
-41
lines changed

8 files changed

+31
-41
lines changed

headers/gamepad.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,8 @@ class Gamepad {
218218

219219
HotkeyEntry hotkeys[16];
220220
GamepadHotkey lastAction = HOTKEY_NONE;
221+
222+
absolute_time_t disableFocusModeTimeout = nil_time;
221223
};
222224

223225
#endif

headers/storagemanager.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,6 @@ class Storage {
6464
void setFunctionalPinMappings();
6565
char* currentProfileLabel();
6666

67-
void setFocusModeOverride( bool enabled );
68-
6967
void ResetSettings(); // EEPROM Reset Feature
7068

7169
uint32_t GetFlashSize() { return systemFlashSize; }

proto/enums.proto

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,8 +368,7 @@ enum GamepadHotkey
368368
HOTKEY_AMBIENT_LIGHT_EFFECTS_FRAME_SPEED_UP = 68;
369369
HOTKEY_AMBIENT_LIGHT_EFFECTS_FRAME_SPEED_DOWN = 69;
370370
HOTKEY_AMBIENT_LIGHT_EFFECTS_CUSTOM_LINKAGE = 70;
371-
HOTKEY_ENABLE_FOCUS_MODE_OVERRIDE = 71;
372-
HOTKEY_DISABLE_FOCUS_MODE_OVERRIDE = 72;
371+
HOTKEY_FOCUS_MODE_TOGGLE = 71;
373372
}
374373

375374
enum AnimationEffects

src/addons/focus_mode.cpp

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,23 +32,6 @@ void FocusModeAddon::process() {
3232

3333
if (!options.enabled) return;
3434

35-
//check if held
36-
37-
//is buttons held?
38-
//first just use aux
39-
// if( gamepad->state.aux )
40-
// {
41-
// if (is_nil_time(focusModeDisableTimeout)) {
42-
// focusModeDisableTimeout = make_timeout_time_ms(3000);
43-
// }
44-
45-
// if( time_reached( focusModeDisableTimeout ) )
46-
// {
47-
// Storage::getInstance().getAddonOptions().focusModeOptions.overrideEnabled = false;
48-
// }
49-
// }
50-
51-
5235
if ( options.overrideEnabled || values & mapFocusMode->pinMask ) {
5336
if (buttonLockMask & GAMEPAD_MASK_DU) {
5437
gamepad->state.dpad &= ~GAMEPAD_MASK_UP;

src/gamepad.cpp

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -691,20 +691,36 @@ void Gamepad::processHotkeyAction(GamepadHotkey action) {
691691
EventManager::getInstance().triggerEvent(new GPMenuNavigateEvent(GpioAction::MENU_NAVIGATION_TOGGLE));
692692
}
693693
break;
694-
case HOTKEY_ENABLE_FOCUS_MODE_OVERRIDE:
695-
if (action != lastAction) {
696-
Storage::getInstance().setFocusModeOverride( true );
697-
reqSave = true;
694+
case HOTKEY_FOCUS_MODE_TOGGLE:
695+
{
696+
auto &focusModeOptions = Storage::getInstance().getAddonOptions().focusModeOptions;
697+
698+
if( !focusModeOptions.overrideEnabled )
699+
{
700+
if (action != lastAction)
701+
{
702+
focusModeOptions.overrideEnabled = true;
703+
reqSave = true;
704+
}
698705
}
699-
break;
700-
case HOTKEY_DISABLE_FOCUS_MODE_OVERRIDE:
701-
if (action != lastAction) {
702-
703-
//can I force timer here?
706+
else // override is already enabled, hold action to disable
707+
{
708+
//start timer if last action was not HOTKEY_FOCUS_MODE_TOGGLE (i.e.. it has not been held), or
709+
//if the timer has not yet been started
710+
if( lastAction != action || is_nil_time(disableFocusModeTimeout))
711+
{
712+
constexpr uint32_t focusModeToggleHoldMs = 3000;
713+
disableFocusModeTimeout = make_timeout_time_ms(focusModeToggleHoldMs);
714+
}
704715

705-
Storage::getInstance().setFocusModeOverride( false );
706-
reqSave = true;
716+
if( time_reached( disableFocusModeTimeout ) )
717+
{
718+
disableFocusModeTimeout = nil_time;
719+
focusModeOptions.overrideEnabled = false;
720+
reqSave = true;
721+
}
707722
}
723+
}
708724
break;
709725
default: // Unknown action
710726
break;

src/storagemanager.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,6 @@ char* Storage::currentProfileLabel() {
106106
return this->config.profileOptions.gpioMappingsSets[config.gamepadOptions.profileNumber-2].profileLabel;
107107
}
108108

109-
void Storage::setFocusModeOverride( bool enabled )
110-
{
111-
config.addonOptions.focusModeOptions.overrideEnabled = enabled;
112-
}
113-
114109
void Storage::setFunctionalPinMappings()
115110
{
116111
GpioMappingInfo* alts = nullptr;

www/src/Locales/en/SettingsPage.jsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,6 @@ export default {
139139
'menu-nav-back': 'Menu Back',
140140
'menu-nav-toggle': 'Menu Toggle',
141141
'focus-mode-toggle': 'Focus Mode Toggle',
142-
'focus-mode-override-enable': 'Enable Focus Mode Override',
143-
'focus-mode-override-disable': 'Disable Focus Mode Override',
144142
},
145143
'forced-setup-mode-label': 'Forced Setup Mode',
146144
'forced-setup-mode-options': {

www/src/Pages/SettingsPage.jsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,8 +294,7 @@ const HOTKEY_ACTIONS = [
294294
{ labelKey: 'hotkey-actions.menu-nav-select', value: 48 },
295295
{ labelKey: 'hotkey-actions.menu-nav-back', value: 49 },
296296
{ labelKey: 'hotkey-actions.menu-nav-toggle', value: 50 },
297-
{ labelKey: 'hotkey-actions.focus-mode-override-enable', value: 71 },
298-
{ labelKey: 'hotkey-actions.focus-mode-override-disable', value: 72 },
297+
{ labelKey: 'hotkey-actions.focus-mode-toggle', value: 71 },
299298
];
300299

301300
const FORCED_SETUP_MODES = [

0 commit comments

Comments
 (0)