-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Analog button fix #5659
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
Open
benjamw
wants to merge
3
commits into
wled:main
Choose a base branch
from
benjamw:analog_button_fix
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+91
−26
Open
Analog button fix #5659
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -190,7 +190,7 @@ | |
| } | ||
| } | ||
| function pMP() { // populateMacroPresets | ||
| var presetOpts = '<option value="0">Default Action</option>' + sortedPresetOptions; | ||
| var presetOpts = '<option value="0">Default Action (0)</option>' + sortedPresetOptions; | ||
| var fields = ['A0','A1','MC','MN']; | ||
| for (var f of fields) { | ||
| var inp = gN(f); | ||
|
|
@@ -219,13 +219,37 @@ | |
| rPS(sel, presetOpts, "data-preset"); | ||
| } | ||
| } | ||
| function bAO() { // buildAnalogOptions: analog functions + per-segment opacity (segment 0 included; MD=0 => segment 0) | ||
| var o = '<optgroup label="Analog Functions"><option value="250">Global brightness (250)</option><option value="249">Effect speed (249)</option><option value="248">Effect intensity (248)</option><option value="247">Palette (247)</option><option value="200">Primary color hue (200)</option></optgroup><optgroup label="Analog Segment Opacity">'; | ||
| for (var j=0; j<=32; j++) o += `<option value="${j}">Segment ${j} (${j})</option>`; | ||
| o += '</optgroup>'; | ||
| return o; | ||
| } | ||
| function isAnalogBtn(t) { return t==7 || t==8; } // BTN_TYPE_ANALOG / BTN_TYPE_ANALOG_INVERTED | ||
| function btnTypeName(t) { // mirrors the button type dropdown on the LED settings page | ||
| switch (+t) { | ||
| case 2: return 'Pushbutton'; | ||
| case 3: return 'Push inverted'; | ||
| case 4: return 'Switch'; | ||
| case 5: return 'PIR sensor'; | ||
| case 6: return 'Touch'; | ||
| case 7: return 'Analog'; | ||
| case 8: return 'Analog inverted'; | ||
| case 9: return 'Touch (switch)'; | ||
| default: return 'Disabled'; | ||
| } | ||
| } | ||
| function rBPO() { // refreshButtonPresetOptions | ||
| var presetOpts = '<option value="0">Default Action</option>' + sortedPresetOptions; | ||
| var presetOpts = '<option value="0">Default Action (0)</option>' + sortedPresetOptions; | ||
| var analogOpts = bAO(); | ||
| var container = gId("macros"); | ||
| if (!container) return; | ||
| // analog buttons only have an MD select (MP/ML are hidden 0 inputs); MD uses analog options, never presets | ||
| var sels = container.querySelectorAll('select[name^="MP"],select[name^="ML"],select[name^="MD"]'); | ||
| for (var sel of sels) { | ||
| rPS(sel, presetOpts, "data-preset"); | ||
| var bb = sel.closest ? sel.closest(".bb") : null; | ||
| var t = bb ? parseInt(bb.getAttribute("data-btype")||"0",10) : 0; | ||
| rPS(sel, isAnalogBtn(t) ? analogOpts : presetOpts, "data-preset"); | ||
| } | ||
| } | ||
| function Wd() | ||
|
|
@@ -246,33 +270,54 @@ | |
| if (d.Sf.LTR.value==="S") { d.Sf.LT.value = -1*parseFloat(d.Sf.LT.value); } | ||
| if (d.Sf.LNR.value==="W") { d.Sf.LN.value = -1*parseFloat(d.Sf.LN.value); } | ||
| } | ||
| function addRow(i,p,l,d) { | ||
| function addRow(i,p,l,d,t) { | ||
| if (t===undefined) t = 0; | ||
| var b = String.fromCharCode((i<10?48:55)+i); | ||
| var presetOpts = '<option value="0">Default Action</option>' + sortedPresetOptions; | ||
| var analog = isAnalogBtn(t); | ||
| var presetOpts = '<option value="0">Default Action (0)</option>' + sortedPresetOptions; | ||
| var typeName = btnTypeName(t); | ||
| var buttonBlock = document.createElement('div'); | ||
| buttonBlock.className = 'bb'; | ||
| buttonBlock.innerHTML = ` | ||
| <div class="bh">Button (switch) ${i}</div> | ||
| <div class="bs"> | ||
| <div class="ba"> | ||
| <label>Short (on → off)</label> | ||
| <select name="MP${b}" class="s" required>${presetOpts}</select> | ||
| </div> | ||
| <div class="ba"> | ||
| <label>Long (off → on)</label> | ||
| <select name="ML${b}" class="s" required>${presetOpts}</select> | ||
| buttonBlock.setAttribute('data-btype', t); // read back by rBPO() to rebuild selects correctly | ||
| if (analog) { | ||
| // analog buttons: MD holds the function/segment; short/long press are unused and forced to 0 | ||
| buttonBlock.innerHTML = ` | ||
| <div class="bh">Button ${i} - ${typeName}</div> | ||
| <div class="bs"> | ||
| <input type="hidden" name="MP${b}" value="0"> | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we require the hidden values? i.e. they are set to default zero in firmware if missing, see set.cpp |
||
| <input type="hidden" name="ML${b}" value="0"> | ||
| <div class="ba"> | ||
| <label>Analog function</label> | ||
| <select name="MD${b}" class="s" required>${bAO()}</select> | ||
| </div> | ||
| </div> | ||
| <div class="ba"> | ||
| <label>Double press (n/a)</label> | ||
| <select name="MD${b}" class="s" required>${presetOpts}</select> | ||
| <hr style="width:100%;margin:8px 0 0 0;"> | ||
| `; | ||
| sPSV(buttonBlock.querySelector('select[name="MD'+b+'"]'), String(d), "data-preset"); | ||
| } else { | ||
| buttonBlock.innerHTML = ` | ||
| <div class="bh">Button ${i} - ${typeName}</div> | ||
| <div class="bs"> | ||
| <div class="ba"> | ||
| <label>Short (on → off)</label> | ||
| <select name="MP${b}" class="s" required>${presetOpts}</select> | ||
| </div> | ||
| <div class="ba"> | ||
| <label>Long (off → on)</label> | ||
| <select name="ML${b}" class="s" required>${presetOpts}</select> | ||
| </div> | ||
| <div class="ba"> | ||
| <label>Double press (n/a)</label> | ||
| <select name="MD${b}" class="s" required>${presetOpts}</select> | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| </div> | ||
| </div> | ||
| </div> | ||
| <hr style="width:100%;margin:8px 0 0 0;"> | ||
| `; | ||
| var buttonSels = buttonBlock.querySelectorAll("select"); | ||
| var buttonVals = [String(p), String(l), String(d)]; | ||
| for (var si=0; si<buttonSels.length; si++) { | ||
| sPSV(buttonSels[si], buttonVals[si], "data-preset"); | ||
| <hr style="width:100%;margin:8px 0 0 0;"> | ||
| `; | ||
| var buttonSels = buttonBlock.querySelectorAll("select"); | ||
| var buttonVals = [String(p), String(l), String(d)]; | ||
| for (var si=0; si<buttonSels.length; si++) { | ||
| sPSV(buttonSels[si], buttonVals[si], "data-preset"); | ||
| } | ||
| } | ||
| gId("macros").appendChild(buttonBlock); | ||
| } | ||
|
|
||
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
single use variable adds code for no benefit