Simplify template parameters to a single per-element buffer - #403
Draft
SukuWc wants to merge 4 commits into
Draft
Conversation
Replace the per-page linked list of template buffers with a single buffer per element that is reinitialized to defaults on every page change, instead of allocating one buffer per page and swapping the live pointer on page load. - Remove struct grid_ui_template_buffer and the buffer list (template_buffer_list_head, _create/_find/_list_length). - Add grid_ui_element_template_parameter_reset(): lazily allocates the element's single buffer, then runs the initializer to load defaults. - Retype template_init_t and all *_template_parameter_init functions to take struct grid_ui_element* instead of the removed buffer type. - Drop the now-redundant page_change_cb mechanism entirely (potmeter was its only user, and its value refresh is already done by the initializer that runs on each page load). - Update grid_ui_page_clear_template_parameters (drop unused page arg) and its decode.c call sites. Stored config is unaffected: grid_ui_page_read re-runs the config scripts after the reset, so only transient runtime-only gtv values reset on page change. Verified: host tests pass (1/1), ESP32 firmware builds clean. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
SukuWc
marked this pull request as draft
July 16, 2026 19:12
…eset Split the single-buffer lifecycle into an explicit allocate-at-init step and a reset step, removing the lazy allocation and a now-redundant helper: - Add grid_ui_element_template_parameter_init(): allocates the element's template parameter buffer once (sized to template_parameter_list_length, no phantom min-1 slot) and seeds it with defaults. Called from the tail of each element type-init, where the length is known. - Fold the template-parameter reset into grid_ui_element_reset() with two guard clauses, and drop the standalone grid_ui_element_template_parameter_reset() — grid_ui_element_reset is now the single per-element runtime reset (timer, name, template parameters). - Simplify grid_ui_bulk_page_load to a single grid_ui_element_reset() call per element (drops the redundant timer clear). - Remove grid_ui_page_clear_template_parameters() and its two decode.c call sites: after a store/clear the following bulk_page_load already resets every element to defaults, so the synchronous clear was redundant. - Update the encoder unit test to rely on encoder_init's allocate+seed. Allocation now happens once at boot before any read, matching the original seed-at-creation behavior; page load reseeds via grid_ui_element_reset. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
grid_ui_event_get_script passes the address of a stack buffer to the Lua "gsg" helper as an integer, which writes the script source back into it. Both ends cast through uint32_t, which truncates the pointer on 64-bit builds (the host unit-test build warns with -Wpointer-to-int-cast). On the 32-bit target pointers fit, so this was silent there but is a latent bug off-target. Route the pointer through uintptr_t on both sides and format it as unsigned long long (%llu), which matches Lua's 64-bit lua_Integer. Warning- free and correct on both 32- and 64-bit; unchanged behavior on the target. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replaces the per-page linked list of template buffers with a single buffer per element, reinitialized to defaults on page change — instead of allocating one buffer per page and swapping the live
template_parameter_listpointer on page load.Changes
struct grid_ui_template_bufferand the buffer list (template_buffer_list_head,_create/_find/_list_length).grid_ui_element_template_parameter_reset(): lazily allocates the element's single buffer, then runs the initializer to load defaults.template_init_tand all*_template_parameter_initfunctions (including the two VSN screen variants) to takestruct grid_ui_element*instead of the removed buffer type.page_change_cbmechanism entirely — potmeter was its only user, and its value refresh is already performed by the initializer that runs on each page load.grid_ui_page_clear_template_parameters(drop the unusedpagearg) and update itsgrid_decode.ccall sites.common/test/grid_ui_encoder_test.cto use the new API.Net: 19 files changed, +57 / −190. Firmware binary shrinks ~128 bytes.
Behavior
Stored config is unaffected:
grid_ui_page_readre-runs the config scripts after the reset, so configured min/max/mode are re-established — only transient runtime-onlygtvvalues reset on page change.Concurrency note (reviewed, benign)
The reset now mutates the live buffer in place (main task) while the ADC ISR reads
template_parameter_list[MODE]. This is safe: all slots are 4-byte-alignedint32_t(atomic on Xtensa-LX7 / Cortex-M4), the buffer pointer is stable during a reset, the ISR's array index comes fromele->index(not the buffer), and any transient value self-heals on the next ADC sample. Worst case is one sample binned at the default resolution during the brief page-load window — already the intended reset-to-defaults behavior.Testing
1/1passlua_build→pico_build→esp_build)🤖 Generated with Claude Code