Skip to content

Commit

Permalink
simplified
Browse files Browse the repository at this point in the history
  • Loading branch information
jackcarey committed Jul 16, 2022
1 parent cbb44fa commit 375380b
Showing 1 changed file with 8 additions and 33 deletions.
41 changes: 8 additions & 33 deletions source/BuzzController.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,46 +4,21 @@
var BuzzController = Controller;
const hid_supported = "hid" in window.navigator;

Object.defineProperty(BuzzController, "light_state", {
get: function () {
return this._light_state;
},
set: function (newData) {
this._light_state = newData % 15;
setLights.bind(this);
setLights(this._light_state);
}
});

Object.defineProperty(BuzzController, "lights", {
get: function () {
return this._light_state;
return this._lights;
},
set: function (newData) {
//TODO HID setup
let data_type = ""+ typeof newData;
this._light_mode = data_type;
switch(data_type) {
case "boolean":
//all on or all off
this.light_state = newData ? 15 : 0;
break;
case "number":
//set based on the 4 binary columns
this.light_state = newData;
break;
case "object": // assumes array
//TODO: handle sequence array
break;
case "function":
//TODO: handle transform function
break;
//if newData is negative, wrap it round from the maxiumum
if (newData <= 0) {
newData = 15 + newData;
}
this._lights = newData % 15;
setLights.bind(this);
setLights(this._lights);
}
});

console.log("B", Object.getOwnPropertyNames(BuzzController));

async function runHIDSetup() {
if (hid_supported) {
let hid_gamepads = await navigator.hid.getDevices();
Expand Down Expand Up @@ -72,7 +47,7 @@ async function runHIDSetup() {
await this.hid_device.open();
}
}
}else{
} else {
console.log("not supported!");
}
}
Expand Down

0 comments on commit 375380b

Please sign in to comment.