Skip to content

Dummy Data Injector#5566

Open
SuksAE wants to merge 8 commits into
letscontrolit:megafrom
SuksAE:Dummy_Injector
Open

Dummy Data Injector#5566
SuksAE wants to merge 8 commits into
letscontrolit:megafrom
SuksAE:Dummy_Injector

Conversation

@SuksAE

@SuksAE SuksAE commented Jun 17, 2026

Copy link
Copy Markdown

Here is the pull request for the Dummy Data Injector Plugin.

I did not know what to use for the documentation status (|P187_status| in
file 'docs/source/Plugin/_plugin_substitutions_p18x.repl') - maybe you have
a suggestion...

Thanks

Comment thread src/_P187_Dummy_Data_Injector.ino Outdated
Comment thread src/_P187_Dummy_Data_Injector.ino Outdated
Comment thread src/_P187_Dummy_Data_Injector.ino Outdated
Comment thread src/_P187_Dummy_Data_Injector.ino Outdated
Comment thread src/_P187_Dummy_Data_Injector.ino Outdated
Comment thread src/_P187_Dummy_Data_Injector.ino Outdated
Comment thread src/_P187_Dummy_Data_Injector.ino Outdated
Comment thread src/_P187_Dummy_Data_Injector.ino Outdated
Comment thread docs/source/Plugin/P187.rst Outdated
":ref:`P079_page`", "✓", "✓", "P079"
":ref:`P146_page`", "✓", "✓", "P146"
":ref:`P152_page`", "✓", "✓", "P152"
":ref:`P187_page`", "✓", "", "P187"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is re-generated when the PR is merged, so no need to include it in your PR. Unfortunately, the .gitignore entry for this file is ignored 🤓

Comment thread docs/source/Plugin/_plugin_substitutions_p18x.repl Outdated
Comment thread docs/source/Plugin/P187_Config_Initial.png Outdated
@tonhuisman

Copy link
Copy Markdown
Contributor

@SuksAE Thanks for your PR! It's a very good first PR 😃

I've added a few comments, all with the intent of making this even better 👍 we are a friendly bunch, so don't hesitate to ask for more info if something isn't clear, or you have a specific reason for doing things different from what's suggested.

Comment thread src/_P187_Dummy_Data_Injector.ino
Comment thread src/_P187_Dummy_Data_Injector.ino
@SuksAE

SuksAE commented Jun 18, 2026

Copy link
Copy Markdown
Author

@SuksAE Thanks for your PR! It's a very good first PR 😃

I've added a few comments, all with the intent of making this even better 👍 we are a friendly bunch, so don't hesitate to ask for more info if something isn't clear, or you have a specific reason for doing things different from what's suggested.

Indeed I have a question:

I just found out that PLUGIN_SET_DEFAULTS is called before PLUGIN_INIT.

Is this intentional, or is this an error? I mean I can't set default values before the plugin is initialised, or am I wrong?

@tonhuisman

Copy link
Copy Markdown
Contributor

I just found out that PLUGIN_SET_DEFAULTS is called before PLUGIN_INIT.

Is this intentional, or is this an error? I mean I can't set default values before the plugin is initialised, or am I wrong?

PLUGIN_SET_DEFAULTS is called only once, right after the new plugin instance is added to the Devices list. And never again after that. This is the place to set initial defaults for your plugin.

PLUGIN_INIT is called every time the plugin is enabled, and should return true if all is OK, or false if there is an error causing the plugin to stay disabled.

@SuksAE

SuksAE commented Jun 19, 2026

Copy link
Copy Markdown
Author

One more questions I hope you can help me:

As I am not a git expert - how can I remove the file docs/source/Plugin/_plugin_sets_overview.repl from the PR?

@SuksAE

SuksAE commented Jun 19, 2026

Copy link
Copy Markdown
Author

except from removing _plugin_sets_overview.repl from the PR, I hope I have adressed all your findings...

please re-check...

Comment thread src/_P187_Dummy_Data_Injector.ino Outdated
@tonhuisman

tonhuisman commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

how can I remove the file docs/source/Plugin/_plugin_sets_overview.repl from the PR?

By restoring it to its original contents (checkout mega, copy the file somewhere, checkout this branch, copy the file contents in the file, commit the 'change' and push that). The net result will be that the file is not changed, so no longer in the PR 😉

Comment thread src/_P187_Dummy_Data_Injector.ino Outdated
@SuksAE

SuksAE commented Jun 20, 2026

Copy link
Copy Markdown
Author

done. please check...

Comment thread src/src/PluginStructs/P187_data_struct.cpp Outdated
break;
case P187_OUTPUT_TRAPEZ:

if ((P187_time[i] * P187_param[i].param2 / 360.0f) < P187_param[i].param4) // rising edge

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe also check to see if param4 is nearly 0.
See the functions in ESPEasy_math.h For example essentiallyZero.

}
else if ((P187_time[i] * P187_param[i].param2 / 360.0f) < (P187_param[i].param4 + P187_param[i].param3 + P187_param[i].param5)) // falling edge
{
UserVar.setFloat(event->TaskIndex, i,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto for param5

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

both are integers...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

both are integers...

Well that's an even simpler check :)

@TD-er

TD-er commented Jun 20, 2026

Copy link
Copy Markdown
Member

Why not naming the plugin something with "Function Generator" in the name?
As the code seems to be doing just the work of the electronic workbench device with the same name :)

@SuksAE

SuksAE commented Jun 20, 2026

Copy link
Copy Markdown
Author

Why not naming the plugin something with "Function Generator" in the name? As the code seems to be doing just the work of the electronic workbench device with the same name :)

Because then I would not be happy with the current implementation - I would want more functionality of a function generator (more different patterns, arbitrary output data read from a .wav file in LittleFS, controllable via network commands, ...) and a timing resolution of way less than a second.
This implementation suits my current use case and I have to start working on my next project on monday. But maybe some time in the future I will revisit this idea...

@SuksAE

SuksAE commented Jun 21, 2026

Copy link
Copy Markdown
Author

revised time handling...

int t_ms; // time within period in ms

if (now < periodStart[i]) { // check for overflow (happens each ~49 days)
t_ms = (now + (ULONG_MAX - periodStart[i]));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the timeDiff function in src/src/Helpers/ESPEasy_time_calc.h
Or timePassedSince, but since you want to use the same now timestamp (which is perfectly fine) I guess using timeDiff is the better choice here.

Comment on lines +112 to +136
/*
Configuration and working variables are implemented as is because:

-- excerpt from https://github.com/letscontrolit/ESPEasy/pull/5566#issuecomment-4739927575:

PLUGIN_SET_DEFAULTS is called only once, right after the new plugin instance is added to the Devices list.
And never again after that. This is the place to set initial defaults for your plugin.

PLUGIN_INIT is called every time the plugin is enabled, and should return true if all is OK,
or false if there is an error causing the plugin to stay disabled.

-- excerpt end

So in PLUGIN_SET_DEFAULTS, the persistent configuration values in flash are initialized.
This flash data is used in PLUGIN_WEBFORM_LOAD to provide data for the UI generation. The
flash data is updated in PLUGIN_WEBFORM_SAVE when new configuration values are submitted by
the user.

Afterwards, when the plugin task instance is enabled via the UI (and output data starts
to be generated), a working copy of the configuration values is created by loading them
from flash to RAM.
Stored together with the volatile variables, this data is used for fast processing of
the signal generation code.
*/

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why you have included this quit elaborate text? Smells like it's AI generated, as it's 'how things work' in ESPEasy, no need to 'document' that in the source code, AFAICS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants