Skip to content

Commit

Permalink
Track digitalPortQueue as bits
Browse files Browse the repository at this point in the history
  • Loading branch information
rwaldron committed Aug 24, 2018
1 parent e8b9211 commit 7949f3f
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions lib/firmata.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var com = require("./com");

// Program specifics
var i2cActive = new Map();
var digitalPortQueue = [];
var digitalPortQueue = 0x0000;

/**
* constants
Expand Down Expand Up @@ -958,9 +958,9 @@ Board.prototype.pinMode = function(pin, mode) {

Board.prototype.digitalWrite = function(pin, value, enqueue) {
let port = this.updateDigitalPort(pin, value);

if (enqueue) {
digitalPortQueue[port] = true;
digitalPortQueue |= 1 << port;
} else {
this.writeDigitalPort(port);
}
Expand Down Expand Up @@ -992,10 +992,12 @@ Board.prototype.updateDigitalPort = function(pin, value) {
*/

Board.prototype.flushDigitalPorts = function() {
Object.keys(digitalPortQueue).forEach( port => {
this.writeDigitalPort(port);
});
digitalPortQueue = [];
for (let i = 0; i < this.ports.length; i++) {
if (digitalPortQueue >> i) {
this.writeDigitalPort(i);
}
}
digitalPortQueue = 0x0000;
};

/**
Expand Down

0 comments on commit 7949f3f

Please sign in to comment.