Skip to content

Commit

Permalink
Adding USB reset.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rob Bultman committed Feb 13, 2015
1 parent 622efc5 commit dd754a8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ The **Message Type** field is a 1-byte value that is meant to indicate to the re
|0x0a|Update Resource|JSON|
|0x0b|Resource Updated|JSON|
|0x0c|Set device UUID|String|
|0x0d-0x0F|Reserved for Future Use|n/a|
|0x0d|Keepalive|none|
|0x0e-0x0F|Reserved for Future Use|n/a|
|0x10|filterAlert|Unsigned, 8-bit integer|
|0x11|waterFilterCalendarTimer|Unsigned, 16-bit integer|
|0x12|waterFilterCalendarPercentUsed|Unsigned, 8-bit integer|
Expand Down
15 changes: 15 additions & 0 deletions chillhub-devices.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ function ChillhubDevice(ttyPath, receive, announce) {
self.registered = false;
self.deviceRegTimer = null;
self.resourceRegTimer = null;
self.keepaliveTimer = null;
self.deviceRegCount = 5;

self.uid = ttyPath;
Expand Down Expand Up @@ -335,6 +336,7 @@ function ChillhubDevice(ttyPath, receive, announce) {
console.log("Attachment successfully created.");
self.resources = resources;
self.registered = true;
self.keepaliveTimer = setInterval(self.sendKeepalive, 2500);
}
});
}
Expand Down Expand Up @@ -418,6 +420,16 @@ function ChillhubDevice(ttyPath, receive, announce) {
});
}

self.sendKeepalive = function () {
self.send({
type: 0x0d,
content: {
numericType: 'U8',
numericValue: 1
}
});
}

self.checkForDeviceRegistration = function checkForDeviceRegistration() {
if (self.deviceRegCount <= 0) {
resetUSB();
Expand Down Expand Up @@ -446,6 +458,9 @@ var removeDevice = function(device) {
if (devices[device].deviceRegTimer != null) {
clearTimeout(devices[device].deviceRegTimer);
}
if (devices[device].keepaliveTimer != null) {
clearInterval(devices[device].keepaliveTimer);
}
devices[device].cleanup();
delete devices[device];
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "chillhub-firmware",
"version": "0.1.10",
"version": "0.1.11",
"description": "ChillHub is a system for creating USB devices that extend the functionality of your fridge. It consists of a raspberry pi (http://www.raspberrypi.org/), a green bean (https://firstbuild.com/greenbean/), and a USB hub in a refrigerator door. ChillHub acts as a mailman the delivers messages from the cloud and the fridge to USB devices and from the USB devices back to the cloud.",
"main": "chillhub.js",
"scripts": {
Expand Down

0 comments on commit dd754a8

Please sign in to comment.