1+ var _ = require ( "underscore" ) ;
12var rpio = require ( "rpio" ) ;
23var Service , Characteristic ;
34
@@ -13,12 +14,16 @@ module.exports = function(homebridge) {
1314}
1415
1516function BlindsAccessory ( log , config ) {
17+ _ . defaults ( config , { activeLow : true } ) ;
18+
1619 this . log = log ;
1720 this . name = config [ 'name' ] ;
1821 this . pinUp = config [ "pinUp" ] ;
1922 this . pinDown = config [ "pinDown" ] ;
2023 this . durationUp = config [ 'durationUp' ] ;
2124 this . durationDown = config [ 'durationDown' ] ;
25+ this . initialState = config [ 'activeLow' ] ? rpio . HIGH : rpio . LOW ;
26+ this . activeState = config [ 'activeLow' ] ? rpio . LOW : rpio . HIGH ;
2227
2328 this . currentPosition = 0 ; // down by default
2429 this . targetPosition = 0 ; // down by default
@@ -36,8 +41,8 @@ function BlindsAccessory(log, config) {
3641 rpio . init ( {
3742 mapping : 'gpio'
3843 } ) ;
39- rpio . open ( this . pinUp , rpio . OUTPUT , rpio . HIGH ) ;
40- rpio . open ( this . pinDown , rpio . OUTPUT , rpio . HIGH ) ;
44+ rpio . open ( this . pinUp , rpio . OUTPUT , this . initialState ) ;
45+ rpio . open ( this . pinDown , rpio . OUTPUT , this . initialState ) ;
4146
4247 this . service
4348 . getCharacteristic ( Characteristic . CurrentPosition )
@@ -106,9 +111,9 @@ BlindsAccessory.prototype.setTargetPosition = function(position, callback) {
106111}
107112
108113BlindsAccessory . prototype . togglePin = function ( pin , duration ) {
109- rpio . write ( pin , rpio . LOW ) ;
114+ rpio . write ( pin , this . activeState ) ;
110115 setTimeout ( function ( ) {
111- rpio . write ( pin , rpio . HIGH ) ;
116+ rpio . write ( pin , this . initialState ) ;
112117 } . bind ( this ) , duration ) ;
113118}
114119
0 commit comments