-
-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #59 from PaulFreund/feature/runtimeFeatureSettings
Community feature settings in main settings menu
- Loading branch information
Showing
8 changed files
with
514 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Copyright © 2021-2023 Synthstrom Audible Limited | ||
* | ||
* This file is part of The Synthstrom Audible Deluge Firmware. | ||
* | ||
* The Synthstrom Audible Deluge Firmware is free software: you can redistribute it and/or modify it under the | ||
* terms of the GNU General Public License as published by the Free Software Foundation, | ||
* either version 3 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; | ||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
* See the GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along with this program. | ||
* If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include <MenuItemRuntimeFeatureSetting.h> | ||
#include "RuntimeFeatureSettings.h" | ||
#include "soundeditor.h" | ||
|
||
MenuItemRuntimeFeatureSetting runtimeFeatureSettingMenuItem; | ||
|
||
MenuItemRuntimeFeatureSetting::MenuItemRuntimeFeatureSetting(char const* newName) : MenuItemSelection(newName) { | ||
} | ||
|
||
void MenuItemRuntimeFeatureSetting::readCurrentValue() { | ||
for (uint32_t idx = 0; idx < RUNTIME_FEATURE_SETTING_MAX_OPTIONS; ++idx) { | ||
if (runtimeFeatureSettings.settings[currentSettingIndex].options[idx].value | ||
== runtimeFeatureSettings.settings[currentSettingIndex].value) { | ||
soundEditor.currentValue = idx; | ||
return; | ||
} | ||
} | ||
|
||
soundEditor.currentValue = 0; | ||
} | ||
|
||
void MenuItemRuntimeFeatureSetting::writeCurrentValue() { | ||
runtimeFeatureSettings.settings[currentSettingIndex].value = | ||
runtimeFeatureSettings.settings[currentSettingIndex].options[soundEditor.currentValue].value; | ||
} | ||
|
||
char const** MenuItemRuntimeFeatureSetting::getOptions() { | ||
static char const* options[RUNTIME_FEATURE_SETTING_MAX_OPTIONS] = {0}; | ||
uint32_t optionCount = 0; | ||
for (uint32_t idx = 0; idx < RUNTIME_FEATURE_SETTING_MAX_OPTIONS; ++idx) { | ||
if (runtimeFeatureSettings.settings[currentSettingIndex].options[idx].displayName != NULL) { | ||
options[optionCount++] = runtimeFeatureSettings.settings[currentSettingIndex].options[idx].displayName; | ||
} | ||
else { | ||
options[optionCount] = NULL; | ||
break; | ||
} | ||
} | ||
return (char const**)&options; | ||
} | ||
|
||
int MenuItemRuntimeFeatureSetting::getNumOptions() { | ||
for (uint32_t idx = 0; idx < RUNTIME_FEATURE_SETTING_MAX_OPTIONS; ++idx) { | ||
if (runtimeFeatureSettings.settings[currentSettingIndex].options[idx].displayName == NULL) { | ||
return idx; | ||
} | ||
} | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright © 2021-2023 Synthstrom Audible Limited | ||
* | ||
* This file is part of The Synthstrom Audible Deluge Firmware. | ||
* | ||
* The Synthstrom Audible Deluge Firmware is free software: you can redistribute it and/or modify it under the | ||
* terms of the GNU General Public License as published by the Free Software Foundation, | ||
* either version 3 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; | ||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
* See the GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along with this program. | ||
* If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#ifndef MENUITEMRUNTIMEFEATURESETTING_H_ | ||
#define MENUITEMRUNTIMEFEATURESETTING_H_ | ||
|
||
#include "MenuItemSelection.h" | ||
|
||
class MenuItemRuntimeFeatureSetting final : public MenuItemSelection { | ||
public: | ||
MenuItemRuntimeFeatureSetting(char const* newName = NULL); | ||
void readCurrentValue(); | ||
void writeCurrentValue(); | ||
char const** getOptions(); | ||
int getNumOptions(); | ||
|
||
private: | ||
friend class MenuItemRuntimeFeatureSettings; | ||
uint32_t currentSettingIndex; | ||
}; | ||
|
||
extern MenuItemRuntimeFeatureSetting runtimeFeatureSettingMenuItem; | ||
|
||
#endif /* MENUITEMRUNTIMEFEATURESETTING_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
/* | ||
* Copyright © 2021-2023 Synthstrom Audible Limited | ||
* | ||
* This file is part of The Synthstrom Audible Deluge Firmware. | ||
* | ||
* The Synthstrom Audible Deluge Firmware is free software: you can redistribute it and/or modify it under the | ||
* terms of the GNU General Public License as published by the Free Software Foundation, | ||
* either version 3 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; | ||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
* See the GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along with this program. | ||
* If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include <MenuItemRuntimeFeatureSettings.h> | ||
#include <MenuItemRuntimeFeatureSetting.h> | ||
#include "RuntimeFeatureSettings.h" | ||
#include "soundeditor.h" | ||
#include "numericdriver.h" | ||
#include <cstdio> | ||
|
||
MenuItemRuntimeFeatureSettings runtimeFeatureSettingsMenu; | ||
|
||
void MenuItemRuntimeFeatureSettings::beginSession(MenuItem* navigatedBackwardFrom) { | ||
if (!navigatedBackwardFrom) { | ||
lastActiveValue = 0; // Reset last active value | ||
} | ||
|
||
soundEditor.currentValue = lastActiveValue; // Restore | ||
|
||
#if HAVE_OLED | ||
soundEditor.menuCurrentScroll = soundEditor.currentValue; | ||
#else | ||
drawValue(); | ||
#endif | ||
} | ||
|
||
void MenuItemRuntimeFeatureSettings::selectEncoderAction(int offset) { | ||
soundEditor.currentValue += offset; | ||
int numOptions = RuntimeFeatureSettingType::MaxElement; | ||
|
||
#if HAVE_OLED | ||
if (soundEditor.currentValue > numOptions - 1) soundEditor.currentValue = numOptions - 1; | ||
else if (soundEditor.currentValue < 0) soundEditor.currentValue = 0; | ||
#else | ||
if (soundEditor.currentValue >= numOptions) soundEditor.currentValue -= numOptions; | ||
else if (soundEditor.currentValue < 0) soundEditor.currentValue += numOptions; | ||
#endif | ||
|
||
lastActiveValue = soundEditor.currentValue; | ||
|
||
#if HAVE_OLED | ||
if (soundEditor.currentValue < soundEditor.menuCurrentScroll) | ||
soundEditor.menuCurrentScroll = soundEditor.currentValue; | ||
|
||
if (offset >= 0) { | ||
int d = soundEditor.currentValue; | ||
int numSeen = 1; | ||
while (true) { | ||
d--; | ||
if (d == soundEditor.menuCurrentScroll) break; | ||
numSeen++; | ||
if (numSeen >= OLED_MENU_NUM_OPTIONS_VISIBLE) { | ||
soundEditor.menuCurrentScroll = d; | ||
break; | ||
} | ||
} | ||
} | ||
#endif | ||
|
||
drawValue(); | ||
} | ||
|
||
void MenuItemRuntimeFeatureSettings::drawValue() { | ||
#if HAVE_OLED | ||
renderUIsForOled(); | ||
#else | ||
numericDriver.setScrollingText(runtimeFeatureSettings.settings[soundEditor.currentValue].displayName); | ||
#endif | ||
} | ||
|
||
MenuItem* MenuItemRuntimeFeatureSettings::selectButtonPress() { | ||
#if HAVE_OLED | ||
runtimeFeatureSettingMenuItem.basicTitle = runtimeFeatureSettings.settings[soundEditor.currentValue] | ||
.displayName; // A bit ugly, but saves us extending a class. | ||
#endif | ||
runtimeFeatureSettingMenuItem.currentSettingIndex = soundEditor.currentValue; | ||
return &runtimeFeatureSettingMenuItem; | ||
} | ||
|
||
#if HAVE_OLED | ||
|
||
void MenuItemRuntimeFeatureSettings::drawPixelsForOled() { | ||
char const* itemNames[OLED_MENU_NUM_OPTIONS_VISIBLE]; | ||
|
||
int selectedRow = -1; | ||
|
||
int displayRow = soundEditor.menuCurrentScroll; | ||
int row = 0; | ||
while (row < OLED_MENU_NUM_OPTIONS_VISIBLE && displayRow < RuntimeFeatureSettingType::MaxElement) { | ||
itemNames[row] = runtimeFeatureSettings.settings[displayRow].displayName; | ||
if (displayRow == soundEditor.currentValue) { | ||
selectedRow = row; | ||
} | ||
row++; | ||
displayRow++; | ||
} | ||
|
||
while (row < OLED_MENU_NUM_OPTIONS_VISIBLE) { | ||
itemNames[row++] = NULL; | ||
} | ||
|
||
drawItemsForOled(itemNames, selectedRow); | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright © 2021-2023 Synthstrom Audible Limited | ||
* | ||
* This file is part of The Synthstrom Audible Deluge Firmware. | ||
* | ||
* The Synthstrom Audible Deluge Firmware is free software: you can redistribute it and/or modify it under the | ||
* terms of the GNU General Public License as published by the Free Software Foundation, | ||
* either version 3 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; | ||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
* See the GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along with this program. | ||
* If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#ifndef MENUITEMRUNTIMEFEATURESETTINGS_H_ | ||
#define MENUITEMRUNTIMEFEATURESETTINGS_H_ | ||
|
||
#include "MenuItem.h" | ||
|
||
class MenuItemRuntimeFeatureSettings final : public MenuItem { | ||
public: | ||
MenuItemRuntimeFeatureSettings(char const* newName = 0) : MenuItem(newName) {} | ||
void beginSession(MenuItem* navigatedBackwardFrom = NULL); | ||
void selectEncoderAction(int offset); | ||
void drawValue(); | ||
MenuItem* selectButtonPress(); | ||
void drawPixelsForOled(); | ||
|
||
private: | ||
uint32_t lastActiveValue = 0; | ||
// getSetting? | ||
}; | ||
|
||
extern MenuItemRuntimeFeatureSettings runtimeFeatureSettingsMenu; | ||
|
||
#endif /* MENUITEMRUNTIMEFEATURESETTINGS_H_ */ |
Oops, something went wrong.