mirror of
https://github.com/MarekZegare4/MeshCore-Solo.git
synced 2026-08-07 04:36:11 +00:00
refactor(ui): share radio preset picker between Settings and Repeater
Settings › Radio and Tools › Repeater had near-identical preset-picker logic (name/list-index lookup, save/delete, popup build, selection handling) plus their own copy of the nearest-bandwidth search — only the target fields (companion params vs. dedicated repeater profile) and the apply call differed. Extract the shared logic into RadioPresetPicker (a Target of field pointers + a Result the screen acts on), with no dependency on UITask so each screen keeps its own apply/dirty/keyboard/alert handling. Move the nearest-bandwidth search to nearestBwIndex() in RadioPresets.h. Removes ~6 duplicated methods and 4 state fields from each screen. Verified: WioTrackerL1_companion_solo_dual builds clean. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
a8c7a200dc
commit
0e333aeb5e
@@ -41,6 +41,18 @@ static const int RADIO_PRESET_COUNT = sizeof(RADIO_PRESETS) / sizeof(RADIO_PRESE
|
||||
static const float LORA_BW_OPTS[] = { 7.8f, 10.4f, 15.6f, 20.8f, 31.25f, 41.7f, 62.5f, 125.0f, 250.0f, 500.0f };
|
||||
static const int LORA_BW_OPT_COUNT = sizeof(LORA_BW_OPTS) / sizeof(LORA_BW_OPTS[0]);
|
||||
|
||||
// Index of the LORA_BW_OPTS entry nearest `bw` — used both to render the current
|
||||
// BW and to step left/right through the table without drifting off-grid.
|
||||
static inline int nearestBwIndex(float bw) {
|
||||
int best = 0;
|
||||
float best_diff = 1e9f;
|
||||
for (int i = 0; i < LORA_BW_OPT_COUNT; i++) {
|
||||
float diff = fabsf(bw - LORA_BW_OPTS[i]);
|
||||
if (diff < best_diff) { best_diff = diff; best = i; }
|
||||
}
|
||||
return best;
|
||||
}
|
||||
|
||||
// True if (freq, bw, sf, cr) matches the radio's currently-applied (cur_*) params.
|
||||
// Floats are compared with a small epsilon since they may have round-tripped
|
||||
// through unit conversions (e.g. kHz integers from the companion app).
|
||||
|
||||
Reference in New Issue
Block a user