-
-
Notifications
You must be signed in to change notification settings - Fork 4k
Usermods on Steroids: A Plugin Framework #5319
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
JoaDick
wants to merge
4
commits into
wled:main
Choose a base branch
from
JoaDick:squash/Usermod
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.
+1,395
−9
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
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
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
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 |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| # Dummy usermod to simulate random sensor readings. | ||
|
|
||
| Use `UM_PluginDemo` and `UM_DummySensor` together as an example for how direct interactions between | ||
| usermods can be realized through the plugin API. |
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 |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| /** | ||
| * (c) 2026 Joachim Dick | ||
| * Licensed under the EUPL v. 1.2 or later | ||
| */ | ||
|
|
||
| #include "wled.h" | ||
| #include "PluginAPI/custom/DummySensor/DummySensor.h" | ||
|
|
||
| //-------------------------------------------------------------------------------------------------- | ||
|
|
||
| static constexpr char _name[] = "Dummy-Sensor"; | ||
|
|
||
| /** Dummy usermod implementation that simulates random sensor readings. | ||
| */ | ||
| class UM_DummySensor : public Usermod, public DummySensor, public TemperatureSensor, public HumiditySensor | ||
| { | ||
|
|
||
| // ----- usermod functions ----- | ||
|
|
||
| void setup() override | ||
| { | ||
| // register sensor plugins | ||
| pluginManager.registerTemperatureSensor(*this, _name); | ||
| pluginManager.registerHumiditySensor(*this, _name); | ||
| // this dummy can deliver readings instantly | ||
| _isTemperatureValid = true; | ||
| _isHumidityValid = true; | ||
| } | ||
|
|
||
| void loop() override {} | ||
|
|
||
| // ----- DummySensor (our own) custom plugin functions ----- | ||
|
|
||
| void enableTemperatureSensor() override | ||
| { | ||
| if (!_isTemperatureSensorEnabled) | ||
| pluginManager.registerTemperatureSensor(*this, _name); | ||
| _isTemperatureSensorEnabled = true; | ||
| } | ||
|
|
||
| void disableTemperatureSensor() override | ||
| { | ||
| if (_isTemperatureSensorEnabled) | ||
| pluginManager.unregisterTemperatureSensor(*this); | ||
| _isTemperatureSensorEnabled = false; | ||
| } | ||
|
|
||
| bool isTemperatureSensorEnabled() override { return _isTemperatureSensorEnabled; } | ||
|
|
||
| void enableHumiditySensor() override | ||
| { | ||
| if (!_isHumiditySensorEnabled) | ||
| pluginManager.registerHumiditySensor(*this, _name); | ||
| _isHumiditySensorEnabled = true; | ||
| } | ||
|
|
||
| void disableHumiditySensor() override | ||
| { | ||
| if (_isHumiditySensorEnabled) | ||
| pluginManager.unregisterHumiditySensor(*this); | ||
| _isHumiditySensorEnabled = false; | ||
| } | ||
|
|
||
| bool isHumiditySensorEnabled() override { return _isHumiditySensorEnabled; } | ||
|
|
||
| // ----- TemperatureSensor plugin functions ----- | ||
|
|
||
| /// @copydoc TemperatureSensor::do_getTemperatureC() | ||
| float do_getTemperatureC() override { return readTemperature(); } | ||
|
|
||
| // ----- HumiditySensor plugin functions ----- | ||
|
|
||
| /// @copydoc HumiditySensor::do_getHumidity() | ||
| float do_getHumidity() override { return readHumidity(); } | ||
|
|
||
| // ----- internal processing functions ----- | ||
|
|
||
| /// The dummy implementation to simulate temperature values (based on perlin noise). | ||
| float readTemperature() | ||
| { | ||
| const int32_t raw = perlin16(strip.now * 8) - 0x8000; | ||
| // simulate some random temperature around 20°C | ||
| return 20.0f + raw / 65535.0f * 30.0f; | ||
| } | ||
|
|
||
| /// The dummy implementation to simulate humidity values (a sine wave). | ||
| float readHumidity() | ||
| { | ||
| const int32_t raw = beatsin16_t(1); | ||
| // simulate some random humidity between 10% and 90% | ||
| return 10.0f + raw / 65535.0f * 80.0f; | ||
| } | ||
|
|
||
| // ----- member variables ----- | ||
|
|
||
| bool _isTemperatureSensorEnabled = false; | ||
| bool _isHumiditySensorEnabled = false; | ||
| }; | ||
|
|
||
| //-------------------------------------------------------------------------------------------------- | ||
|
|
||
| static UM_DummySensor um_DummySensor; | ||
| REGISTER_USERMOD(um_DummySensor); | ||
| DEFINE_PLUGIN_API(DummySensor, um_DummySensor); | ||
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 |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| { | ||
| "name": "UM_DummySensor", | ||
| "build": { "libArchive": false } | ||
| } |
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 |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| # Examples for writing custom plugins. | ||
|
|
||
| Use `UM_PluginDemo` and `UM_DummySensor` together as an example for how direct interactions between | ||
| usermods can be realized through the plugin API. |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.