Skip to content
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

[FR] A map function for rules #5189

Open
chromoxdor opened this issue Dec 22, 2024 · 6 comments · May be fixed by #5190
Open

[FR] A map function for rules #5189

chromoxdor opened this issue Dec 22, 2024 · 6 comments · May be fixed by #5190

Comments

@chromoxdor
Copy link
Contributor

chromoxdor commented Dec 22, 2024

It would be very convenient to have a map function in rules.

Something like:

Map,<variableindex>,<inputvalue>,<fromLow>, <fromHigh>,<toLow>,<toHigh>
where "map" writes the data to a variable like "let"

@tonhuisman
Copy link
Contributor

tonhuisman commented Dec 22, 2024

I would put this in the Math functions category, and make it compatible with the Arduino map(value, fromLow, fromHigh, toLow, toHigh) function (actually, calling that function with the arguments provided 😅), returning the mapped value to apply it where needed, like in a let assignment or an if condition 😉

@tonhuisman tonhuisman linked a pull request Dec 22, 2024 that will close this issue
1 task
@tonhuisman
Copy link
Contributor

tonhuisman commented Dec 22, 2024

@chromoxdor I've added the map() function as a feature, can you please test with some scenarios? Build available from this Actions run

NB: You will need quotes around the function when used in a Let command, as it currently uses commas as an argument separator.

@tonhuisman
Copy link
Contributor

Hmm, those quotes make me a bit unhappy, so we might need to use a different argument separator, probably a colon (:), like used with the string functions 🤔

@tonhuisman
Copy link
Contributor

@chromoxdor I've switched a few things:

  • Using existing function mapADCtoFloat(), similar to Arduino map() but supporting float values
  • Using colon as the separator, as a comma causes too many parsing issues, and (confusing) quotes have to be used

@chromoxdor
Copy link
Contributor Author

@tonhuisman Wow! That was fast.
I am in a bit of pre-Christmas stress at the moment, but I will happily test the function tonight.
Thank you very much!

@chromoxdor
Copy link
Contributor Author

First test where successful.
A colon as separator is perfect and I really like it!
The closing bracket is not colored correctly, which I will look into ..... probably next year ;)

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 a pull request may close this issue.

2 participants