aura-sdk
Version:
ASUS's Aura Sync Node.js bindings
85 lines • 3.13 kB
JavaScript
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const color_1 = __importDefault(require("color"));
class Controller {
constructor(deviceName, auraSDK) {
this.auraSDK = auraSDK;
this.deviceName = deviceName;
this.ledCount = this.auraSDK.setup();
}
/**
* Joins multiple controllers into one array of callable functions
* @param controllers array of controllers to join
*/
static joinControllers(controllers) {
const arr = [];
for (let controller of controllers) {
for (let i = 0; i < controller.getLedCount(); i++) {
arr.push({
getDeviceName: () => controller.getDeviceName(),
setColor: (color) => controller.setColor(i, color),
setColorNow: (color) => controller.setColorNow(i, color)
});
}
}
return arr;
}
/**
* Get number of controllable leds in this controller
*/
getLedCount() {
return this.ledCount;
}
/**
* Get the device name (motherboard, GPU, DRAM)
*/
getDeviceName() {
return this.deviceName;
}
/**
* Sets the color of the LED at the given index
* @param index index of the LED to change
* @param color color of the LED. This uses [color](https://www.npmjs.com/package/color) package to convert the string to RGB.
*/
setColor(index, color) {
const [r, g, b] = color_1.default(color).rgb().array();
this.auraSDK.setcolor(index, Math.floor(r), Math.floor(g), Math.floor(b));
}
/**
* Sets the color of all the leds in the controller
* @param color color of the LEDs. This uses [color](https://www.npmjs.com/package/color) package to convert the string to RGB.
*/
setAllColor(color) {
for (let i = 0; i < this.getLedCount(); i++) {
this.setColor(i, color);
}
}
/**
* Sets the color of the LED at the given index and immediately updates them
* @param index index of the LED to change
* @param color color of the LED. This uses [color](https://www.npmjs.com/package/color) package to convert the string to RGB.
*/
setColorNow(index, color) {
this.setColor(index, color);
this.updateColor();
}
/**
* Sets the color of all the leds in the controller and immediately updates them
* @param color color of the LEDs. This uses [color](https://www.npmjs.com/package/color) package to convert the string to RGB.
*/
setAllColorNow(color) {
this.setAllColor(color);
this.updateColor();
}
/**
* Updates the LEDs attached to the controller to reflect the current state
*/
updateColor() {
this.auraSDK.updateColor();
}
}
exports.Controller = Controller;
//# sourceMappingURL=controller.js.map
;