From e7553b2bdb53a8614357d50cf49f1cbff0e1fa08 Mon Sep 17 00:00:00 2001 From: deeebug <77402236+deeebug@users.noreply.github.com> Date: Mon, 9 Oct 2023 23:04:17 +0545 Subject: [PATCH] Add Macro Lock to Focus Mode addon --- headers/addons/focus_mode.h | 4 ++++ proto/config.proto | 1 + src/addons/input_macro.cpp | 5 +++-- src/config_utils.cpp | 1 + src/configs/webconfig.cpp | 2 ++ www/server/app.js | 1 + www/src/Addons/FocusMode.tsx | 20 ++++++++++++++++++++ www/src/Locales/en/Common.jsx | 1 + 8 files changed, 33 insertions(+), 2 deletions(-) diff --git a/headers/addons/focus_mode.h b/headers/addons/focus_mode.h index 67c141aec..fdbddc337 100644 --- a/headers/addons/focus_mode.h +++ b/headers/addons/focus_mode.h @@ -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" diff --git a/proto/config.proto b/proto/config.proto index 2627bfbde..4aec1ec69 100644 --- a/proto/config.proto +++ b/proto/config.proto @@ -586,6 +586,7 @@ message FocusModeOptions optional bool oledLockEnabled = 4; optional bool rgbLockEnabled = 5; optional bool buttonLockEnabled = 6; + optional bool macroLockEnabled = 7; } message MacroInput diff --git a/src/addons/input_macro.cpp b/src/addons/input_macro.cpp index fd0524cba..1a9ad8f2d 100644 --- a/src/addons/input_macro.cpp +++ b/src/addons/input_macro.cpp @@ -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() { @@ -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(); diff --git a/src/config_utils.cpp b/src/config_utils.cpp index da1f4cd56..d4f1b0c1a 100644 --- a/src/config_utils.cpp +++ b/src/config_utils.cpp @@ -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); diff --git a/src/configs/webconfig.cpp b/src/configs/webconfig.cpp index 3a382d061..d163098ed 100644 --- a/src/configs/webconfig.cpp +++ b/src/configs/webconfig.cpp @@ -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; @@ -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); diff --git a/www/server/app.js b/www/server/app.js index 9b31e99b0..9f8193aba 100644 --- a/www/server/app.js +++ b/www/server/app.js @@ -458,6 +458,7 @@ app.get('/api/getAddonsOptions', (req, res) => { FocusModeAddonEnabled: 1, focusModeOledLockEnabled: 0, focusModeRgbLockEnabled: 0, + focusModeMacroLockEnabled: 0, BuzzerSpeakerAddonEnabled: 1, BootselButtonAddonEnabled: 1, DualDirectionalInputEnabled: 1, diff --git a/www/src/Addons/FocusMode.tsx b/www/src/Addons/FocusMode.tsx index 2ab5c9fad..e8d46d294 100644 --- a/www/src/Addons/FocusMode.tsx +++ b/www/src/Addons/FocusMode.tsx @@ -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') @@ -40,6 +44,7 @@ export const focusModeState = { FocusModeAddonEnabled: 0, focusModeOledLockEnabled: 0, focusModeRgbLockEnabled: 0, + focusModeMacroLockEnabled: 0, }; const FocusMode = ({ @@ -97,6 +102,21 @@ const FocusMode = ({ }} /> +