diff --git a/eg/onboard-led.js b/eg/onboard-led.js index ca4f78c..0ef2388 100644 --- a/eg/onboard-led.js +++ b/eg/onboard-led.js @@ -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); }); diff --git a/lib/tessel.js b/lib/tessel.js index a0550a9..a8dc57b 100644 --- a/lib/tessel.js +++ b/lib/tessel.js @@ -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); @@ -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) { diff --git a/test/tessel.js b/test/tessel.js index 2a1cd3a..dcbb831 100644 --- a/test/tessel.js +++ b/test/tessel.js @@ -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(); }, @@ -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(); + }, + };