Add option to round scaled sensor values#1804
Add option to round scaled sensor values#1804fisher-alice wants to merge 8 commits intorwaldron:mainfrom
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 |
Hi @dtex , we recently chatted about needing to upgrade |
This PR adds the option for scaled values from a sensor to be rounded . @dtex @islemaster
In the forked
code-dot-org/johnny-fiveproject, 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 parameterroundedto theSensormethodscalewith the default value offalseso that current users of this method are not impacted by this change. I added theisScaledRoundedas aSensorinstance property which is initialized tofalse. Iftrueis passed by the parameterroundedthenisScaledRoundedis 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
optionsobject anisScaledRoundedproperty. 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.jsandtest/sensor.jsand added a unit test for whenSensor.scalewhenisScaledRoundedis assigned totrue.Just a note that if this PR is merged, then
code-dot-org/code-dot-orgis able to get onto mainline johnny-five. For this particular customization, the only changes needed are to add anoptionspropertyisScaledRoundedwhen the light and sound sensors are initialized inPlaygroundComponents.js