Skip to content

Commit d177b9a

Browse files
author
Blaine Schmeisser
committed
Have consistent spacing.
It looks like you're mostly using 3 spaces so I went with that.
1 parent f27718d commit d177b9a

1 file changed

Lines changed: 51 additions & 54 deletions

File tree

BigRedButton.js

Lines changed: 51 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -13,49 +13,49 @@ var LID_DOWN=0x15, LID_UP=0x17, BUTTON_DOWN=0x16;
1313

1414
function getAllDevices()
1515
{
16-
if (!allDevices) {
17-
allDevices = HID.devices(7476,13);
18-
}
19-
return allDevices;
16+
if (!allDevices) {
17+
allDevices = HID.devices(7476,13);
18+
}
19+
return allDevices;
2020
}
2121

2222
function BigRedButton(index)
2323
{
24-
if (!arguments.length) {
25-
index = 0;
26-
}
27-
28-
var bigRedButton = getAllDevices();
29-
if (!bigRedButton.length) {
30-
throw new Error("No BigRedButton could be found");
31-
}
32-
if (index > bigRedButton.length || index < 0) {
33-
throw new Error("Index " + index + " out of range, only " + bigRedButton.length + " BigRedButton found");
34-
}
35-
this.button = bigRedButton[index];
36-
this.hid = new HID.HID(bigRedButton[index].path);
37-
38-
this.hid.write(cmd_status);
39-
40-
var that=this;
41-
this.hid.read(function(error,data) {
42-
last_state=data[0];
43-
that.hid.read(that.interpretData.bind(that));
44-
});
45-
this.interval = setInterval(this.askForStatus.bind(this),100);
46-
this.close = function() {
47-
clearInterval(this.interval);
48-
this.interval = false;
49-
setTimeout(function() {
50-
this.hid.close();
51-
}.bind(this), 100);
52-
};
24+
if (!arguments.length) {
25+
index = 0;
26+
}
27+
28+
var bigRedButton = getAllDevices();
29+
if (!bigRedButton.length) {
30+
throw new Error("No BigRedButton could be found");
31+
}
32+
if (index > bigRedButton.length || index < 0) {
33+
throw new Error("Index " + index + " out of range, only " + bigRedButton.length + " BigRedButton found");
34+
}
35+
this.button = bigRedButton[index];
36+
this.hid = new HID.HID(bigRedButton[index].path);
37+
38+
this.hid.write(cmd_status);
39+
40+
var that=this;
41+
this.hid.read(function(error,data) {
42+
last_state=data[0];
43+
that.hid.read(that.interpretData.bind(that));
44+
});
45+
this.interval = setInterval(this.askForStatus.bind(this),100);
46+
this.close = function() {
47+
clearInterval(this.interval);
48+
this.interval = false;
49+
setTimeout(function() {
50+
this.hid.close();
51+
}.bind(this), 100);
52+
};
5353
}
5454

5555
util.inherits(BigRedButton, events.EventEmitter);
5656

5757
BigRedButton.prototype.askForStatus = function() {
58-
this.hid.write(cmd_status);
58+
this.hid.write(cmd_status);
5959
};
6060

6161
BigRedButton.prototype.interpretData = function(error, data) {
@@ -65,39 +65,36 @@ BigRedButton.prototype.interpretData = function(error, data) {
6565
}
6666
var n_state=data[0];
6767

68-
if(last_state!=n_state) {
69-
if(last_state==LID_DOWN && n_state==LID_UP) {
70-
this.emit("lidRaised");
71-
} else if (last_state==LID_UP && n_state==BUTTON_DOWN) {
72-
this.emit("buttonPressed");
73-
} else if(last_state==BUTTON_DOWN && n_state==LID_UP) {
74-
this.emit("buttonReleased");
75-
} else if(last_state==BUTTON_DOWN && n_state==LID_DOWN) {
76-
this.emit("buttonReleased");
77-
this.emit("lidClosed");
78-
} else if(last_state==LID_UP && n_state==LID_DOWN) {
79-
this.emit("lidClosed");
80-
}
81-
last_state=n_state;
68+
if (last_state!=n_state) {
69+
if (last_state==LID_DOWN && n_state==LID_UP) {
70+
this.emit("lidRaised");
71+
} else if (last_state==LID_UP && n_state==BUTTON_DOWN) {
72+
this.emit("buttonPressed");
73+
} else if (last_state==BUTTON_DOWN && n_state==LID_UP) {
74+
this.emit("buttonReleased");
75+
} else if (last_state==BUTTON_DOWN && n_state==LID_DOWN) {
76+
this.emit("buttonReleased");
77+
this.emit("lidClosed");
78+
} else if (last_state==LID_UP && n_state==LID_DOWN) {
79+
this.emit("lidClosed");
80+
}
81+
last_state=n_state;
8282
}
8383

8484
this.hid.read(this.interpretData.bind(this));
8585
}
8686

8787
BigRedButton.prototype.isLidUp = function() {
88-
return last_state==LID_UP || last_state==BUTTON_DOWN;
88+
return last_state==LID_UP || last_state==BUTTON_DOWN;
8989
}
9090

9191
BigRedButton.prototype.isButtonPressed = function() {
92-
return last_state==BUTTON_DOWN;
92+
return last_state==BUTTON_DOWN;
9393
}
9494

9595
BigRedButton.prototype.isLidDown = function() {
96-
return last_state==LID_DOWN;
96+
return last_state==LID_DOWN;
9797
}
9898

9999
exports.BigRedButton = BigRedButton;
100100
exports.deviceCount = function () { return getAllDevices().length; }
101-
102-
103-

0 commit comments

Comments
 (0)