Skip to content

Commit

Permalink
Minor nitpicking
Browse files Browse the repository at this point in the history
  • Loading branch information
rwaldron committed Dec 18, 2017
1 parent 6549985 commit 2491d59
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 30 deletions.
25 changes: 13 additions & 12 deletions lib/encoder7bit.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
"use strict";
/**
* "Inspired" by Encoder7Bit.h/Encoder7Bit.cpp in the
* Firmata source code.
*/
module.exports = {
to7BitArray: function(data) {
var shift = 0;
var previous = 0;
var output = [];
to7BitArray(data) {
let shift = 0;
let previous = 0;
const output = [];

data.forEach(function(byte) {
data.forEach(byte => {
if (shift === 0) {
output.push(byte & 0x7f);
shift++;
Expand All @@ -31,14 +32,14 @@ module.exports = {

return output;
},
from7BitArray: function(encoded) {
var expectedBytes = (encoded.length) * 7 >> 3;
var decoded = [];
from7BitArray(encoded) {
const expectedBytes = (encoded.length) * 7 >> 3;
const decoded = [];

for (var i = 0; i < expectedBytes; i++) {
var j = i << 3;
var pos = parseInt(j / 7, 10);
var shift = j % 7;
for (let i = 0; i < expectedBytes; i++) {
const j = i << 3;
const pos = parseInt(j / 7, 10);
const shift = j % 7;
decoded[i] = (encoded[pos] >> shift) | ((encoded[pos + 1] << (7 - shift)) & 0xFF);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/firmata.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use strict";

// Built-in Dependencies
var Emitter = require("events").EventEmitter;
const Emitter = require("events");

// Internal Dependencies
var Encoder7Bit = require("./encoder7bit");

This comment has been minimized.

Copy link
@rwaldron

rwaldron Dec 19, 2017

Author Collaborator

I missed this line during interactive stage/commit, will get it next round of updates

Expand Down
33 changes: 16 additions & 17 deletions lib/onewireutils.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
var Encoder7Bit = require("./encoder7bit");

var OneWireUtils = {
crc8: function(data) {
var crc = 0;

for (var i = 0; i < data.length; i++) {
var inbyte = data[i];

for (var n = 8; n; n--) {
var mix = (crc ^ inbyte) & 0x01;
"use strict";
const Encoder7Bit = require("./encoder7bit");
const OneWireUtils = {
crc8(data) {
let crc = 0;

for (let inbyte of data) {
for (let n = 8; n; n--) {
const mix = (crc ^ inbyte) & 0x01;
crc >>= 1;

if (mix) {
Expand All @@ -18,21 +16,22 @@ var OneWireUtils = {
inbyte >>= 1;
}
}

return crc;
},

readDevices: function(data) {
var deviceBytes = Encoder7Bit.from7BitArray(data);
var devices = [];
readDevices(data) {
const deviceBytes = Encoder7Bit.from7BitArray(data);
const devices = [];

for (var i = 0; i < deviceBytes.length; i += 8) {
var device = deviceBytes.slice(i, i + 8);
for (let i = 0; i < deviceBytes.length; i += 8) {
const device = deviceBytes.slice(i, i + 8);

if (device.length !== 8) {
continue;
}

var check = OneWireUtils.crc8(device.slice(0, 7));
const check = OneWireUtils.crc8(device.slice(0, 7));

if (check !== device[7]) {
console.error("ROM invalid!");
Expand Down

0 comments on commit 2491d59

Please sign in to comment.