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

Implement shared settings menu #397

Merged
merged 78 commits into from
Jan 18, 2025
Merged
Changes from 1 commit
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
a770e3c
Start implementing a new settings menu we can use in multiple scripts
chrisib Nov 27, 2024
2b1982a
Add a simple script to help debug the new settings menu. Implement ba…
chrisib Nov 30, 2024
f52dbb3
Give the menu control over the knob & button so we can add handlers
chrisib Nov 30, 2024
750e139
Add callbacks for long/short press
chrisib Nov 30, 2024
5eb16c8
Implement a multi-level menu based on Pam's for testing
chrisib Dec 1, 2024
df4fbd9
Fix a bug in the configuration save-to-file. Fix a bug where scrollin…
chrisib Dec 1, 2024
a8283a0
Dynamically generate menu entries for all CV outputs
chrisib Dec 1, 2024
bb3f423
Load the saved settings on startup
chrisib Dec 1, 2024
dc366c3
Make the ConfigSettings object subscriptable and searchable
chrisib Dec 1, 2024
e42a3ce
Fix loading & saving the menu settings
chrisib Dec 1, 2024
46c88e2
Linting
chrisib Dec 1, 2024
e2fbb45
Add missing comma
chrisib Dec 1, 2024
d3ec9f3
Don't use dicts for creating menu items implicitly; require calling t…
chrisib Dec 1, 2024
3ee905c
Set the number of arguments for the lambda, assign the graphics property
chrisib Dec 1, 2024
d5b1587
Expose the float resolution so we can have more/less precision if needed
chrisib Dec 1, 2024
08ed368
Linting
chrisib Dec 1, 2024
5b2cabd
The default linter is really inconsistent with how it wants arguments…
chrisib Dec 1, 2024
1e32ecb
Make MenuItem abstract to allow creating other customized menu items …
chrisib Dec 1, 2024
c3a8171
Update the documentation for the sequential switch, simplify the b1 h…
chrisib Dec 1, 2024
0dee4a4
More documentation updates, remove some unnecessary code
chrisib Dec 1, 2024
402ce10
Add a check to see if the menu is actually dirty & needs to be redraw…
chrisib Dec 1, 2024
a2f5e9c
Remove the menu test; now that we have functional scripts using the n…
chrisib Dec 1, 2024
b14a7a8
Linting
chrisib Dec 1, 2024
da0e201
Force a re-render on a clock pulse, allow B1 to be used as a manual c…
chrisib Dec 1, 2024
5e930a3
Linting
chrisib Dec 1, 2024
e2ac2c8
Fix using K1 to exit the screensaver
chrisib Dec 1, 2024
88ee008
Use regexes to check the JSON formatting in the tests; these should i…
chrisib Dec 1, 2024
f6191a1
Fix a bug in the type hints; referring to our own type is failing in …
chrisib Dec 3, 2024
088ae19
Add another test to make sure the class name actually resolves to a c…
chrisib Dec 3, 2024
9a8c648
Add support for using AIN and K1 to control Euclid
chrisib Dec 4, 2024
822dfe6
Update the euclid docs to specify that AIN and K1 are now used
chrisib Dec 4, 2024
0169bcf
Minor cleanup
chrisib Dec 4, 2024
bc493aa
Keep the same timer instance but init & deinit it when needed. Fix a …
chrisib Dec 4, 2024
6b814ea
Cleanup
chrisib Dec 4, 2024
982cb2c
Disable some annoying formatting checks
chrisib Dec 4, 2024
889cfe9
Restore accidentally overwritten euclid script
chrisib Dec 4, 2024
5c8f7e3
Move the autoselect timer object up to the menu level so we avoid a p…
chrisib Dec 5, 2024
3553e16
Change the I2C frequencies to a choice (there are finite options). Ch…
chrisib Dec 5, 2024
ebc2b78
Update configuration docs
chrisib Dec 5, 2024
f8bc4df
Add a first-draft configuration-editor tool. Fix some issues discover…
chrisib Dec 5, 2024
b112842
Fix a copy & paste error
chrisib Dec 5, 2024
293a8fd
Move the SettingsMenu to the bottom so the type hints don't make the …
chrisib Dec 5, 2024
eda8396
Use a normal loop, lower the float resolution
chrisib Dec 5, 2024
5079fdb
Separate the settings into sections, process the config point name to…
chrisib Dec 5, 2024
e3bd566
Move where we turn off format checking
chrisib Dec 5, 2024
a843e24
Some code optimization in the config editor, fix the boot-to-menu opt…
chrisib Dec 6, 2024
3b6145e
Reorganize the configuration manual to group things into the same sub…
chrisib Dec 6, 2024
58b47bf
Add a danger property to the config points so we can mark especially …
chrisib Dec 6, 2024
af63601
Start overhauling Pam's to use the new menu system
chrisib Dec 7, 2024
39f24db
Fix some format strings that weren't formatted, troubleshoot some ini…
chrisib Dec 7, 2024
f806a8b
Only apply the boolean labels for boolean configs; always using them …
chrisib Dec 7, 2024
88ec1bc
Fix a bug in the new ! rendering (fixed on my testing hardware, but n…
chrisib Dec 7, 2024
7158759
Fix bugs when dynamically changing choices
chrisib Dec 7, 2024
0bc0fc3
Re-add the CV input wrapper class; it's used for the S&H functionalit…
chrisib Dec 7, 2024
cd6f676
Make the default swing 50%; 0 results in notes being crushed out of e…
chrisib Dec 7, 2024
e090949
Re-implement the AIN/K1 gain + precision menu items
chrisib Dec 7, 2024
d3789be
Wake up from screensaver on a knob turn
chrisib Dec 7, 2024
a30d0e7
Rewrite the wrapper for K1/AIN
chrisib Dec 7, 2024
4436ed1
Allow AIN/K1 control over most menu items
chrisib Dec 7, 2024
0e14267
Add line breaks to the EuroPiScript settings files
chrisib Dec 7, 2024
e166158
Fix some bugs related to the new AIN/K1 selections. Add banks for loa…
chrisib Dec 7, 2024
01ed14f
Use regexes for checking JSON strings' validity
chrisib Dec 7, 2024
becd00e
Remove an extra newline
chrisib Dec 7, 2024
23a2b1d
Linting
chrisib Dec 7, 2024
7ff50ba
Missing comma
chrisib Dec 7, 2024
4fe7c56
Remove the autoselect knob & ain options from the wave_shape; we want…
chrisib Dec 10, 2024
29353f0
Show the auto-selected value in parentheses when applicable in the se…
chrisib Dec 15, 2024
5aae510
Fix a bug with the buffered analogue reader where knob percentages we…
chrisib Dec 15, 2024
47073c9
Add a ui_dirty flag to the MenuItem so we can re-render it on-demand …
chrisib Dec 15, 2024
2de33f6
Add `(S&H)` to the wave-shape ain & knob labels to differentiate them…
chrisib Dec 15, 2024
e4e9265
Fix a crash with the ActionMenuItem rendering
chrisib Dec 31, 2024
79d9286
Add missing `self.`
chrisib Dec 31, 2024
5f0b179
Add a note about where to find examples of the SettingsMenu in use
chrisib Dec 31, 2024
d551dd8
Add a dedicated example for the settings menu, mention the config edi…
chrisib Jan 1, 2025
aa5b524
Add additional documentation to the menu example, save the settings, …
chrisib Jan 1, 2025
c5afd7a
Merge branch 'main' into settings-menu
chrisib Jan 8, 2025
3738e99
Merge branch 'main' into settings-menu
chrisib Jan 10, 2025
f5fc753
Add a second config editor for experimental settings
chrisib Jan 12, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add callbacks for long/short press
chrisib committed Nov 30, 2024
commit 750e139a0ddca6766ae93fdb9081c1dfe814be74
35 changes: 32 additions & 3 deletions software/firmware/experimental/settings_menu.py
Original file line number Diff line number Diff line change
@@ -52,18 +52,36 @@ class SettingsMenu:
# Treat a long press as anything more than 500ms
LONG_PRESS_MS = 500

def __init__(self, menu_spec, button=europi.b2, knob=europi.k2):
def __init__(
self,
menu_spec,
button=europi.b2,
knob=europi.k2,
short_press_cb=lambda:None,
long_press_cb=lambda:None
):
"""
Create a new menu from the given specification

Long/short press callbacks are invoked inside the handler for the falling edge of the button. It is recommended
to avoid any lengthy operations inside these callbacks, as they may prevent other interrupts from being
handled properly.

@param menu_spec A dict representing the structure of the menu
@param button The button the user presses to interact with the menu
@param knob The knob the user turns to scroll through the menu. This may be an experimental.knobs.KnobBank
with 3 menu levels called "main_menu", "submenu" and "choice", or a raw knob like europi.k2
@param short_press_cb An optional callback function to invoke when the user interacts with a short-press of
the button
@param long_press_cb An optional callback function to invoke when the user interacts with a long-press of
the button
"""
self.knob = knob
self.button = button

self.short_press_cb = short_press_cb
self.long_press_cb = long_press_cb

self.button.handler(self.on_button_press)
self.button.handler_falling(self.on_button_release)

@@ -81,11 +99,12 @@ def __init__(self, menu_spec, button=europi.b2, knob=europi.k2):
self.settings_dirty = False

def on_button_press(self):
"""Handler for the rising edge of the button signal"""
self.button_down_at = time.ticks_ms()

def on_button_release(self):
now = time.ticks_ms()
if time.ticks_diff(now, self.button_down_at) >= LONG_PRESS_MS:
"""Handler for the falling edge of the button signal"""
if time.ticks_diff(time.ticks_ms(), self.button_down_at) >= LONG_PRESS_MS:
self.long_press()
else:
self.short_press()
@@ -108,6 +127,8 @@ def short_press(self):
else:
self.active_item.set_current("submenu")

self.short_press_cb()

def long_press(self):
"""
Handle a long button press
@@ -123,6 +144,8 @@ def long_press(self):
if type(self.knob) is KnobBank:
self.knob.set_current("main_menu")

self.long_press_cb()

def draw(self, oled=europi.oled):
"""
Draw the menu to the given display
@@ -141,6 +164,12 @@ def draw(self, oled=europi.oled):

@property
def visible_items(self):
"""
Get the set of visible menu items for the current state of the menu

Menu items can be shown/hidden by setting their is_visible property. Normally this should be done in
a value-change callback of a menu item to show/hide dependent other items.
"""
items = []
if self.active_item.parent:
# we're in a child menu