Change events and update example in digital pin.

This commit is contained in:
Edgar O Silva 2013-11-04 23:30:22 -06:00
parent 3dec21c459
commit 81bd0adb83
3 changed files with 30 additions and 12 deletions

18
dist/digital-pin.js vendored
View File

@ -42,7 +42,7 @@
this.ready = false;
}
DigitalPin.prototype.open = function(mode) {
DigitalPin.prototype.connect = function(mode) {
var _this = this;
return FS.writeFile("" + GPIO_PATH + "/export", "" + this.pinNum, function(err) {
if (err) {
@ -114,7 +114,7 @@
} else {
_this.pinFile = "" + GPIO_PATH + "/gpio" + _this.pinNum + "/value";
_this.ready = true;
return _this.self.emit('open', mode);
return _this.self.emit('connect', mode);
}
});
} else if (mode === 'r') {
@ -125,17 +125,25 @@
} else {
_this.pinFile = "" + GPIO_PATH + "/gpio" + _this.pinNum + "/value";
_this.ready = true;
return _this.self.emit('open', mode);
return _this.self.emit('connect', mode);
}
});
}
};
DigitalPin.prototype.setHigh = function() {
return this.self.digitalWrite(1);
};
DigitalPin.prototype.setLow = function() {
return this.self.digitalWrite(0);
};
DigitalPin.prototype.toggle = function() {
if (this.status === 'low') {
return this.self.digitalWrite(1);
return this.self.setHigh();
} else {
return this.self.digitalWrite(0);
return this.self.setLow();
}
};

View File

@ -2,11 +2,15 @@ require('../dist/digital-pin')
pin4 = new Cylon.IO.DigitalPin(pin: 4)
pin4.on('create', (data) ->
pin4.on('open', (data) ->
console.log("Pin files have been created")
)
pin4.on('open', (data) ->
pin4.on('digitalWrite', (value) ->
console.log("Value writen to pin -> #{ value }")
)
pin4.on('connect', (data) ->
console.log("Pin mode has been setup!")
pin4.digitalWrite(1)
)

View File

@ -30,7 +30,7 @@ namespace 'Cylon.IO', ->
@status = 'low'
@ready = false
open: (mode) ->
connect: (mode) ->
# Creates the GPIO file to read/write from
FS.writeFile("#{ GPIO_PATH }/export", "#{ @pinNum }", (err) =>
if(err)
@ -90,7 +90,7 @@ namespace 'Cylon.IO', ->
else
@pinFile = "#{ GPIO_PATH }/gpio#{ @pinNum }/value"
@ready = true
@self.emit('open', mode)
@self.emit('connect', mode)
)
else if mode =='r'
FS.writeFile("#{ GPIO_PATH }/gpio#{ @pinNum }/direction", GPIO_DIRECTION_READ, (err) =>
@ -100,11 +100,17 @@ namespace 'Cylon.IO', ->
else
@pinFile = "#{ GPIO_PATH }/gpio#{ @pinNum }/value"
@ready = true
@self.emit('open', mode)
@self.emit('connect', mode)
)
setHigh: ->
@self.digitalWrite(1)
setLow: ->
@self.digitalWrite(0)
toggle: ->
if @status == 'low'
@self.digitalWrite(1)
@self.setHigh()
else
@self.digitalWrite(0)
@self.setLow()