Skip to content

Commit

Permalink
Initial states (does not interact with LEDs on initialization)
Browse files Browse the repository at this point in the history
Signed-off-by: Rick Waldron <waldron.rick@gmail.com>
  • Loading branch information
rwaldron committed Apr 13, 2016
1 parent 15da8df commit b900ee1
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 14 deletions.
14 changes: 5 additions & 9 deletions eg/onboard-led.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,9 @@ board.on("ready", function() {

var leds = ["L0", "L1", "L2", "L3"];

leds.forEach(function(pin) {
this.digitalWrite(pin, this.HIGH);
}.bind(this));

setTimeout(function() {
leds.forEach(function(pin) {
this.digitalWrite(pin, this.LOW);
}.bind(this));
}.bind(this), 1000);
leds.forEach(led => this.digitalWrite(led, this.HIGH));

setTimeout(() => {
leds.forEach(led => this.digitalWrite(led, this.LOW));
}, 1000);
});
14 changes: 9 additions & 5 deletions lib/tessel.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,14 +276,15 @@ function Pin(options) {
// options.port
// options.index

var pin = options.port === "L" ? tessel.led[options.index] : tessel.port[options.port].pin[options.index];
var pin = options.port === "L" ?
tessel.led[options.index] : tessel.port[options.port].pin[options.index];
var state = {
isAnalogInput: false,
isPwm: false,
isServo: false,
pin: pin,
index: ports.byPortName[options.port].offset + options.index,
mode: 0
mode: undefined
};

Object.assign(this, options.capabilities);
Expand Down Expand Up @@ -330,9 +331,12 @@ function Pin(options) {
}
});

// Set all pins to OUTPUT and LOW
this.mode = 1;
this.value = 0;
// Don't mess with the error or warning leds...
if (options.port !== L) {
// But otherwise, set all pins to OUTPUT and LOW
this.mode = 1;
this.value = 0;
}
}

Pin.prototype.write = function(value) {
Expand Down
56 changes: 56 additions & 0 deletions test/tessel.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ exports["Tessel Constructor"] = {
setUp: function(done) {
this.sandbox = sinon.sandbox.create();
this.hostname = this.sandbox.stub(os, "hostname", _ => "NOT A REAL TESSEL");
this.output = this.sandbox.stub(T2.Pin.prototype, "output");
this.tessel = new Tessel();
done();
},
Expand Down Expand Up @@ -121,6 +122,61 @@ exports["Tessel Constructor"] = {
test.equal(this.tessel.analogPins.length, 10);
test.done();
},

initialMode: function(test) {
test.expect(20);

test.equal(this.tessel.pins[0].mode, 1);
test.equal(this.tessel.pins[1].mode, 1);
test.equal(this.tessel.pins[2].mode, 1);
test.equal(this.tessel.pins[3].mode, 1);
test.equal(this.tessel.pins[4].mode, 1);
test.equal(this.tessel.pins[5].mode, 1);
test.equal(this.tessel.pins[6].mode, 1);
test.equal(this.tessel.pins[7].mode, 1);
test.equal(this.tessel.pins[8].mode, 1);
test.equal(this.tessel.pins[9].mode, 1);
test.equal(this.tessel.pins[10].mode, 1);
test.equal(this.tessel.pins[11].mode, 1);
test.equal(this.tessel.pins[12].mode, 1);
test.equal(this.tessel.pins[13].mode, 1);
test.equal(this.tessel.pins[14].mode, 1);
test.equal(this.tessel.pins[15].mode, 1);
test.equal(this.tessel.pins[16].mode, undefined);
test.equal(this.tessel.pins[17].mode, undefined);
test.equal(this.tessel.pins[18].mode, undefined);
test.equal(this.tessel.pins[19].mode, undefined);

test.done();
},

initialValue: function(test) {
test.expect(20);

test.equal(this.tessel.pins[0].value, 0);
test.equal(this.tessel.pins[1].value, 0);
test.equal(this.tessel.pins[2].value, 0);
test.equal(this.tessel.pins[3].value, 0);
test.equal(this.tessel.pins[4].value, 0);
test.equal(this.tessel.pins[5].value, 0);
test.equal(this.tessel.pins[6].value, 0);
test.equal(this.tessel.pins[7].value, 0);
test.equal(this.tessel.pins[8].value, 0);
test.equal(this.tessel.pins[9].value, 0);
test.equal(this.tessel.pins[10].value, 0);
test.equal(this.tessel.pins[11].value, 0);
test.equal(this.tessel.pins[12].value, 0);
test.equal(this.tessel.pins[13].value, 0);
test.equal(this.tessel.pins[14].value, 0);
test.equal(this.tessel.pins[15].value, 0);
test.equal(this.tessel.pins[16].value, undefined);
test.equal(this.tessel.pins[17].value, undefined);
test.equal(this.tessel.pins[18].value, undefined);
test.equal(this.tessel.pins[19].value, undefined);

test.done();
},

};


Expand Down

0 comments on commit b900ee1

Please sign in to comment.