Skip to content

Commit

Permalink
Allow multiple presses
Browse files Browse the repository at this point in the history
  • Loading branch information
chee committed May 20, 2019
1 parent 404a899 commit d944ac2
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions index.js
Expand Up @@ -16,6 +16,8 @@ function TagAccessory(log, config) {
this.noble = require('noble');
this.noble.on('stateChange', this.onStateChange.bind(this));
this.noble.on('discover', this.onDiscoverPeripheral.bind(this));

this.presses = -1;
}

TagAccessory.prototype.getServices = function() {
Expand Down Expand Up @@ -110,7 +112,17 @@ TagAccessory.prototype.identify = function(callback) {
};

TagAccessory.prototype.onKeyPress = function() {
this.log('key press');
var characteristic = this.service.getCharacteristic(Characteristic.ProgrammableSwitchEvent);
characteristic.setValue(true);
this.presses += 1;

if (this.presses > 3) {
this.presses = 3
}

clearTimeout(this.timeout)

this.timeout = setTimeout(() => {
characteristic.setValue(this.presses);
this.presses = -1
}, 250)
};

0 comments on commit d944ac2

Please sign in to comment.