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

Add a threshold option #25

Closed
tobie opened this issue Jun 5, 2015 · 2 comments
Closed

Add a threshold option #25

tobie opened this issue Jun 5, 2015 · 2 comments

Comments

@tobie
Copy link
Member

tobie commented Jun 5, 2015

Johnn-Five implements a treshold attribute which determines the amount of change necessary of the value of the sensor to trigger a change event. Given we want to support sensors with multiple values, we'd at least need to add an attribute for each value. It might be simpler to add a method that would compare the current values with the last emitted ones and return a boolean (which would be used internally to decide whether or nor to trigger the change event). So for example setting up a geoloc sensor to only trigger when changing hemisphere:

new Sensor({
    change: function(prev, curr) {
        return Math.sign(prev.latitude) !== Math.sign(curr.latitude);
    }
});
@domenic
Copy link

domenic commented Jun 5, 2015

Idle idea, not sure if it's a good one: add the following to your proposal.

new Sensor({
  change: Sensor.threshold(5, "latitude")
});

new Sensor({
  change: Sensor.threshold(5) // defaults to "value"
});

@tobie
Copy link
Member Author

tobie commented Oct 16, 2015

Has been tentatively included in the spec, though not properly spec'ed out yet.

@tobie tobie closed this as completed Oct 16, 2015
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

No branches or pull requests

2 participants