Last active
July 12, 2018 01:11
-
-
Save Grayda/5581263f41da6bddec84cd7c25965e0a to your computer and use it in GitHub Desktop.
Revisions
-
Grayda revised this gist
Jul 12, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,7 +3,7 @@ var _ = require("lodash") var device device = setup() setInterval(function() { setState(!getState()) console.log("Relay enabled? " + getState()) -
Grayda revised this gist
Jul 9, 2018 . 1 changed file with 5 additions and 0 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -26,10 +26,15 @@ function setup() { } function getState() { // Byte 8 = State. 3 = on, 0 = off return device.getFeatureReport(0x00, 0x10)[8] !== 0 ? true : false } function setState(state) { // Byte 0 = Report ID // Byte 1 = State // Byte 2 = Relay // Bytes 3-8 = Padding var ON = [0x00, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00] var OFF = [0x00, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00] device.sendFeatureReport(state ? ON : OFF) -
Grayda created this gist
Jul 9, 2018 .There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,36 @@ var HID = require('node-hid'); var _ = require("lodash") var device setup() setInterval(function() { setState(!getState()) console.log("Relay enabled? " + getState()) }, 1000) function setup() { relay = _.find(HID.devices(), function(item) { return item.product.indexOf("USBRelay") != -1 }) if (relay) { console.log("Found relay!") return new HID.HID(relay.path); } else { console.log("No relay found!") return false } } function getState() { return device.getFeatureReport(0x00, 0x10)[8] !== 0 ? true : false } function setState(state) { var ON = [0x00, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00] var OFF = [0x00, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00] device.sendFeatureReport(state ? ON : OFF) }