nullhart
4/8/2018 - 11:04 PM

video_board.js

var HID = require("node-hid");
var exec = require("child_process").exec;

console.log("\u0007");
// var devices = HID.devices();
// var device = new HID.HID(1452, 632);
var device = new HID.HID(
  "IOService:/AppleACPIPlatformExpert/PCI0@0/AppleACPIPCI/XHC1@14/XHC1@14000000/HS02@14100000/USB 2.0 Hub@14100000/AppleUSB20Hub@14100000/AppleUSB20HubPort@14130000/Generic   USB  Joystick  @14130000/IOUSBHostInterface@0/IOUSBHostHIDDevice@14130000,0"
);

var state;
device.on("data", function(data) {
  //   console.log(data.slice(5, 6));
  console.log(JSON.stringify(data.slice(5, 6)[0]));
  if (data.slice(5, 6)[0] == 47 && state != 47) {
    state = data.slice(5, 6)[0];
    console.log("it works");
    exec("say I hate you");
  }

  if (data.slice(5, 6)[0] == 15 && state != 15) {
    state = data.slice(5, 6)[0];
  }
  if (data.slice(5, 6)[0] == 31 && state != 31) {
    state = data.slice(5, 6)[0];
    console.log("other button");
    exec("say Go die...");
    // console.log(button);
  }
  if (data.slice(5, 6)[0] == 79 && state != 79) {
    state = data.slice(5, 6)[0];
    exec("say FUck off");
    // console.log(button);
  }
});

device.on("error", function(err) {
  console.log(err);
  return;
});