feat(button): Add AC frequency detection switch support (Moes MS-104B)#2658
Open
igorufox wants to merge 3 commits into
Open
feat(button): Add AC frequency detection switch support (Moes MS-104B)#2658igorufox wants to merge 3 commits into
igorufox wants to merge 3 commits into
Conversation
added 2 commits
December 29, 2025 20:21
… logic for state change detection
This commit introduces a software filter for the `AcSwitch` module to improve reliability by rejecting noise pulses and leakage currents. Key changes: * **Frequency Filtering:** The ISR now validates pulse duration against the expected period for 50Hz or 60Hz mains frequency (with a ±3.5% tolerance). Pulses outside this range are ignored. * **Configuration:** Added `btnAcFreq` setting (and `BUTTON_AC_FREQ` build flag) to define the expected mains frequency. Setting it to 0 disables the filter. * **Debug Improvements:** Enhanced `btnAcDbg` output to show pulse period statistics (min/max/avg) and valid pulse counts, aiding in diagnostics. * **Integration:** Updated `Button` module to pass the frequency configuration to `AcSwitch`. This addresses issues where noise or leakage current (e.g., from pilot lights) could be misinterpreted as a valid signal on AC-coupled inputs.
mcspr
reviewed
Dec 30, 2025
| @@ -0,0 +1,40 @@ | |||
| ; User defined configuration for Moes MS-104B 2-Gang Switch Module | |||
|
|
|||
| [env:moes-ms-104b] | |||
Collaborator
There was a problem hiding this comment.
cfg below usually goes into config/hardware.h, .ini flags are then replaced with just -DMOES_MS_104B
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.
Description
This PR introduces support for AC Frequency Detection Switches.
Some devices, such as the Moes MS-104B (2-Gang Switch Module), do not use standard logic levels (High/Low) to represent the state of the physical wall switch. Instead, they use an optocoupler connected to the AC mains.
Standard debounce logic interprets these pulses as rapid button presses. This PR adds a new
AcSwitchmodule that counts pulses within a time window to determine the stable state (ON/OFF).Key Changes
New
AcSwitchClass:Button Module Integration:
BUTTON_FREQUENCYflag totypes.h.button.cppto initializeAcSwitchwhenBUTTON_FREQUENCYis set in the config.btnAcDbgto enable specific debug logs for AC detection tuning without recompiling.Configuration
To use this feature, define the button config as
BUTTON_FREQUENCY.Example
platformio.ini/hardware.h: