Skip to content

Commit dd754a8

Browse files
author
Rob Bultman
committed
Adding USB reset.
1 parent 622efc5 commit dd754a8

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@ The **Message Type** field is a 1-byte value that is meant to indicate to the re
130130
|0x0a|Update Resource|JSON|
131131
|0x0b|Resource Updated|JSON|
132132
|0x0c|Set device UUID|String|
133-
|0x0d-0x0F|Reserved for Future Use|n/a|
133+
|0x0d|Keepalive|none|
134+
|0x0e-0x0F|Reserved for Future Use|n/a|
134135
|0x10|filterAlert|Unsigned, 8-bit integer|
135136
|0x11|waterFilterCalendarTimer|Unsigned, 16-bit integer|
136137
|0x12|waterFilterCalendarPercentUsed|Unsigned, 8-bit integer|

chillhub-devices.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ function ChillhubDevice(ttyPath, receive, announce) {
3333
self.registered = false;
3434
self.deviceRegTimer = null;
3535
self.resourceRegTimer = null;
36+
self.keepaliveTimer = null;
3637
self.deviceRegCount = 5;
3738

3839
self.uid = ttyPath;
@@ -335,6 +336,7 @@ function ChillhubDevice(ttyPath, receive, announce) {
335336
console.log("Attachment successfully created.");
336337
self.resources = resources;
337338
self.registered = true;
339+
self.keepaliveTimer = setInterval(self.sendKeepalive, 2500);
338340
}
339341
});
340342
}
@@ -418,6 +420,16 @@ function ChillhubDevice(ttyPath, receive, announce) {
418420
});
419421
}
420422

423+
self.sendKeepalive = function () {
424+
self.send({
425+
type: 0x0d,
426+
content: {
427+
numericType: 'U8',
428+
numericValue: 1
429+
}
430+
});
431+
}
432+
421433
self.checkForDeviceRegistration = function checkForDeviceRegistration() {
422434
if (self.deviceRegCount <= 0) {
423435
resetUSB();
@@ -446,6 +458,9 @@ var removeDevice = function(device) {
446458
if (devices[device].deviceRegTimer != null) {
447459
clearTimeout(devices[device].deviceRegTimer);
448460
}
461+
if (devices[device].keepaliveTimer != null) {
462+
clearInterval(devices[device].keepaliveTimer);
463+
}
449464
devices[device].cleanup();
450465
delete devices[device];
451466
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "chillhub-firmware",
3-
"version": "0.1.10",
3+
"version": "0.1.11",
44
"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.",
55
"main": "chillhub.js",
66
"scripts": {

0 commit comments

Comments
 (0)