Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Community feature settings in main settings menu #59

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
7bda39f
Started implementing "Community features" menu item
PaulFreund Jun 15, 2023
542a20f
Added stubs for the runtime feature settings infrastructure
PaulFreund Jun 18, 2023
ee8feee
Added stubs for reading and writing code
PaulFreund Jun 18, 2023
4b2cb59
Finished menu and initialization, XML missing
PaulFreund Jun 20, 2023
7362f27
Started XML writing
PaulFreund Jun 20, 2023
c02a834
Writing file and beginning of parsing (untested)
PaulFreund Jun 20, 2023
9119772
Finished feature
PaulFreund Jun 20, 2023
968acb7
Merge branch 'community' of https://github.com/SynthstromAudible/Delu…
PaulFreund Jun 20, 2023
2d420b2
Wrong capitalization in header
PaulFreund Jun 20, 2023
9c24bc2
Merge branch 'community' of https://github.com/SynthstromAudible/Delu…
PaulFreund Jun 20, 2023
d6be7a1
Removed test type IDs
PaulFreund Jun 20, 2023
629e8f5
Merge remote-tracking branch 'upstream/community' into feature/runtim…
PaulFreund Jun 20, 2023
640a3bf
Clang Format changed files
PaulFreund Jun 20, 2023
003a242
Merge branch 'community' of https://github.com/SynthstromAudible/Delu…
PaulFreund Jun 21, 2023
dc6b935
Fixed wrong header capitalization
PaulFreund Jun 21, 2023
5a2309f
Merge branch 'SynthstromAudible:community' into community
PaulFreund Jun 21, 2023
9e13850
Merge branch 'community' into feature/runtimeFeatureSettings
PaulFreund Jun 21, 2023
2687854
Re-Formatted with clang-format 14.0.6
PaulFreund Jun 21, 2023
3acfe50
Merge branch 'SynthstromAudible:community' into feature/runtimeFeatur…
PaulFreund Jun 25, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/Deluge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
#include "SaveSongUI.h"
#include "oled.h"
#include "ContextMenuOverwriteBootloader.h"
#include "RuntimeFeatureSettings.h"
#include "Deluge.h"

#if AUTOMATED_TESTER_ENABLED
Expand Down Expand Up @@ -801,6 +802,9 @@ extern "C" int main2(void) {
FlashStorage::writeSettings();
}

new (&runtimeFeatureSettings) RuntimeFeatureSettings;
runtimeFeatureSettings.readSettingsFromFile();

usbLock = 1;
openUSBHost();

Expand Down
67 changes: 67 additions & 0 deletions src/MenuItemRuntimeFeatureSetting.cpp
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;
}
38 changes: 38 additions & 0 deletions src/MenuItemRuntimeFeatureSetting.h
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_ */
119 changes: 119 additions & 0 deletions src/MenuItemRuntimeFeatureSettings.cpp
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
39 changes: 39 additions & 0 deletions src/MenuItemRuntimeFeatureSettings.h
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_ */