-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Add option to round scaled sensor values #1804
base: main
Are you sure you want to change the base?
Conversation
Thanks for taking the time to submit this. I think the first thing to ask here is why not just use That said, I hate that you have to keep a separate fork for code.org. What's the age range of your audience? I have a few other, less subjective comments:
We've been trying to avoid adding optional parameters to method signatures since it's not very scalable. Instead, this is something I would expect to be set in the constructor options object and to be changed as either a public property of the instance or through a dedicated getter/setter. If you pass |
Thanks so much for the feedback! I will investigate a way so that we don't need this customization to |
Hello @dtex - thanks again for your feedback. I did a little digging and found out that we have existing curriculum that expects the result of |
This PR adds the option for scaled values from a sensor to be rounded . @dtex @islemaster
In the forked
code-dot-org/johnny-five
project, scaled values are always rounded as implemented in this PR. However, I wanted to allow the choice for scaled values to be returned as a float or an integer.Thus, I added an optional boolean parameterrounded
to theSensor
methodscale
with the default value offalse
so that current users of this method are not impacted by this change. I added theisScaledRounded
as aSensor
instance property which is initialized tofalse
. Iftrue
is passed by the parameterrounded
thenisScaledRounded
is assignedtrue
. Thus, the scaled value is returned as a rounded integer.My initial approach is described above. but as suggested by @dtex , I added to the constructor
options
object anisScaledRounded
property. It can be updated as a public property of the instance as shown by this unit test added by the PR.Testing
I revised existing unit tests in
test/board.js
andtest/sensor.js
and added a unit test for whenSensor.scale
whenisScaledRounded
is assigned totrue
.Just a note that if this PR is merged, then
code-dot-org/code-dot-org
is able to get onto mainline johnny-five. For this particular customization, the only changes needed are to add anoptions
propertyisScaledRounded
when the light and sound sensors are initialized inPlaygroundComponents.js