Skip to content

Commit

Permalink
Add Macro Lock to Focus Mode addon (#565)
Browse files Browse the repository at this point in the history
  • Loading branch information
deeebug authored Oct 10, 2023
1 parent d42b1d3 commit 43d63aa
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 2 deletions.
4 changes: 4 additions & 0 deletions headers/addons/focus_mode.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
#define FOCUS_MODE_BUTTON_LOCK_ENABLED 0
#endif

#ifndef FOCUS_MODE_MACRO_LOCK_ENABLED
#define FOCUS_MODE_MACRO_LOCK_ENABLED 0
#endif

// FocusMode Module Name
#define FocusModeName "FocusMode"

Expand Down
1 change: 1 addition & 0 deletions proto/config.proto
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,7 @@ message FocusModeOptions
optional bool oledLockEnabled = 4;
optional bool rgbLockEnabled = 5;
optional bool buttonLockEnabled = 6;
optional bool macroLockEnabled = 7;
}

message MacroInput
Expand Down
5 changes: 3 additions & 2 deletions src/addons/input_macro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
#include "hardware/gpio.h"

bool InputMacro::available() {
inputMacroOptions = Storage::getInstance().getAddonOptions().macroOptions;
return inputMacroOptions.enabled;
return Storage::getInstance().getAddonOptions().macroOptions.enabled;
}

void InputMacro::setup() {
Expand All @@ -29,6 +28,8 @@ void InputMacro::setup() {

void InputMacro::preprocess()
{
FocusModeOptions& focusModeOptions = Storage::getInstance().getAddonOptions().focusModeOptions;
if (focusModeOptions.enabled && focusModeOptions.macroLockEnabled) return;
Gamepad * gamepad = Storage::getInstance().GetGamepad();
uint32_t allPins = ~gpio_get_all();

Expand Down
1 change: 1 addition & 0 deletions src/config_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,7 @@ void ConfigUtils::initUnsetPropertiesWithDefaults(Config& config)
INIT_UNSET_PROPERTY(config.addonOptions.focusModeOptions, oledLockEnabled, !!FOCUS_MODE_OLED_LOCK_ENABLED);
INIT_UNSET_PROPERTY(config.addonOptions.focusModeOptions, rgbLockEnabled, !!FOCUS_MODE_RGB_LOCK_ENABLED);
INIT_UNSET_PROPERTY(config.addonOptions.focusModeOptions, buttonLockEnabled, !!FOCUS_MODE_BUTTON_LOCK_ENABLED);
INIT_UNSET_PROPERTY(config.addonOptions.focusModeOptions, macroLockEnabled, !!FOCUS_MODE_MACRO_LOCK_ENABLED);

// PS Passthrough
INIT_UNSET_PROPERTY(config.addonOptions.psPassthroughOptions, enabled, PSPASSTHROUGH_ENABLED);
Expand Down
2 changes: 2 additions & 0 deletions src/configs/webconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1039,6 +1039,7 @@ std::string setAddonOptions()
docToValue(focusModeOptions.buttonLockEnabled, doc, "focusModeButtonLockEnabled");
docToValue(focusModeOptions.oledLockEnabled, doc, "focusModeOledLockEnabled");
docToValue(focusModeOptions.rgbLockEnabled, doc, "focusModeRgbLockEnabled");
docToValue(focusModeOptions.macroLockEnabled, doc, "focusModeMacroLockEnabled");
docToValue(focusModeOptions.enabled, doc, "FocusModeAddonEnabled");

AnalogADS1219Options& analogADS1219Options = Storage::getInstance().getAddonOptions().analogADS1219Options;
Expand Down Expand Up @@ -1564,6 +1565,7 @@ std::string getAddonOptions()
writeDoc(doc, "focusModeButtonLockMask", focusModeOptions.buttonLockMask);
writeDoc(doc, "focusModeButtonLockEnabled", focusModeOptions.buttonLockEnabled);
writeDoc(doc, "focusModeOledLockEnabled", focusModeOptions.oledLockEnabled);
writeDoc(doc, "focusModeMacroLockEnabled", focusModeOptions.macroLockEnabled);
writeDoc(doc, "focusModeRgbLockEnabled", focusModeOptions.rgbLockEnabled);
writeDoc(doc, "FocusModeAddonEnabled", focusModeOptions.enabled);

Expand Down
1 change: 1 addition & 0 deletions www/server/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,7 @@ app.get('/api/getAddonsOptions', (req, res) => {
FocusModeAddonEnabled: 1,
focusModeOledLockEnabled: 0,
focusModeRgbLockEnabled: 0,
focusModeMacroLockEnabled: 0,
BuzzerSpeakerAddonEnabled: 1,
BootselButtonAddonEnabled: 1,
DualDirectionalInputEnabled: 1,
Expand Down
20 changes: 20 additions & 0 deletions www/src/Addons/FocusMode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ export const focusModeScheme = {
.number()
.label('Focus Mode OLED Lock Enabled')
.validateRangeWhenValue('FocusModeAddonEnabled', 0, 1),
focusModeMacroLockEnabled: yup
.number()
.label('Focus Mode Macro Lock Enabled')
.validateRangeWhenValue('FocusModeAddonEnabled', 0, 1),
focusModeRgbLockEnabled: yup
.number()
.label('Focus Mode RGB Lock Enabled')
Expand All @@ -40,6 +44,7 @@ export const focusModeState = {
FocusModeAddonEnabled: 0,
focusModeOledLockEnabled: 0,
focusModeRgbLockEnabled: 0,
focusModeMacroLockEnabled: 0,
};

const FocusMode = ({
Expand Down Expand Up @@ -97,6 +102,21 @@ const FocusMode = ({
}}
/>
</div>
<div className="col-sm-3">
<FormCheck
label={t('Common:lock-macro')}
className="form-check-sm"
type="switch"
reverse
id="FocusModeAddonMacroButton"
isInvalid={false}
checked={Boolean(values.focusModeMacroLockEnabled)}
onChange={(e) => {
handleCheckbox('focusModeMacroLockEnabled', values);
handleChange(e);
}}
/>
</div>
<div className="col-sm-3">
<FormCheck
label={t('Common:lock-buttons')}
Expand Down
1 change: 1 addition & 0 deletions www/src/Locales/en/Common.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export default {
'switch-enabled': 'Enabled',
'lock-oled-screen': 'Lock OLED Screen',
'lock-rgb-led': 'Lock RGB LED',
'lock-macro': 'Lock Macro',
'lock-buttons': 'Lock Buttons',
'loading-text': 'Loading...',
};

0 comments on commit 43d63aa

Please sign in to comment.