Skip to content

Commit

Permalink
issue #7: add: duration offset
Browse files Browse the repository at this point in the history
  • Loading branch information
rsporny committed Jul 29, 2018
1 parent ab6f940 commit 40b9f94
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Sample accessory:
"pinDown": 11,
"durationUp": 13000,
"durationDown": 13000,
"durationOffset": 1000,
"pinClosed": 17,
"pinOpen": 18,
"activeLow": false,
Expand All @@ -38,6 +39,7 @@ Fields:
- `pinDown` pin for moving down
- `durationUp` milliseconds to open blinds completely
- `durationDown` milliseconds to close blinds completely
- `durationOffset` [optional, default: *0*] milliseconds added to durationUp and durationDown to make sure that blinds are completely open or closed
- `pinClosed` [optional] pin connected to reed switch which is active when blind is closed, see *reedActiveLow*
- `pinOpen` [optional] pin connected to reed switch which is active when blind is open, see *reedActiveLow*
- `activeLow` [optional, default: *true*] true: relay activated by low state (0), false: relay activated by high state (1), affects *pinUp*, *pinDown*
Expand Down
1 change: 1 addition & 0 deletions config-sample.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"pinDown": 3,
"durationUp": 27000,
"durationDown": 25000,
"durationOffset": 1000,
"pinClosed": 17,
"pinOpen": 18,
"activeLow": false,
Expand Down
6 changes: 4 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ module.exports = function(homebridge) {
}

function BlindsAccessory(log, config) {
_.defaults(config, {activeLow: true, reedSwitchActiveLow: true});
_.defaults(config, {durationOffset: 0, activeLow: true, reedSwitchActiveLow: true});

this.log = log;
this.name = config['name'];
this.pinUp = config['pinUp'];
this.pinDown = config['pinDown'];
this.durationUp = config['durationUp'];
this.durationDown = config['durationDown'];
this.durationOffset = config['durationOffset'];
this.pinClosed = config['pinClosed'];
this.pinOpen = config['pinOpen'];
this.initialState = config['activeLow'] ? rpio.HIGH : rpio.LOW;
Expand Down Expand Up @@ -158,9 +159,10 @@ BlindsAccessory.prototype.setTargetPosition = function(position, callback) {

BlindsAccessory.prototype.togglePin = function(pin, duration) {
if (rpio.read(pin) != this.activeState) rpio.write(pin, this.activeState);
if (this.durationOffset && (this.targetPosition == 0 || this.targetPosition == 100)) this.duration += this.durationOffset;
this.togglePinTimeout = setTimeout(function() {
rpio.write(pin, this.initialState);
}.bind(this), duration);
}.bind(this), parseInt(duration));
}

BlindsAccessory.prototype.setFinalBlindsState = function() {
Expand Down

0 comments on commit 40b9f94

Please sign in to comment.