"use strict";
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const lpf2hub_1 = require("./lpf2hub");
const port_1 = require("./port");
const Consts = __importStar(require("./consts"));
const Debug = require("debug");
const debug = Debug("pupremote");
/**
* The PUPRemote is emitted if the discovered device is a Powered UP Remote.
* @class PUPRemote
* @extends LPF2Hub
* @extends Hub
*/
class PUPRemote extends lpf2hub_1.LPF2Hub {
// We set JSDoc to ignore these events as a Powered UP Remote will never emit them.
/**
* @event PUPRemote#distance
* @ignore
*/
/**
* @event PUPRemote#color
* @ignore
*/
/**
* @event PUPRemote#tilt
* @ignore
*/
/**
* @event PUPRemote#rotate
* @ignore
*/
/**
* @event PUPRemote#speed
* @ignore
*/
/**
* @event PUPRemote#attach
* @ignore
*/
/**
* @event PUPRemote#detach
* @ignore
*/
static IsPUPRemote(peripheral) {
return (peripheral.advertisement.serviceUuids.indexOf(Consts.BLEService.LPF2_HUB.replace(/-/g, "")) >= 0 && peripheral.advertisement.manufacturerData[3] === Consts.BLEManufacturerData.POWERED_UP_REMOTE_ID);
}
constructor(peripheral, autoSubscribe = true) {
super(peripheral, autoSubscribe);
this.type = Consts.HubType.POWERED_UP_REMOTE;
this._ports = {
"LEFT": new port_1.Port("LEFT", 0),
"RIGHT": new port_1.Port("RIGHT", 1)
};
debug("Discovered Powered UP Remote");
}
connect() {
return new Promise(async (resolve, reject) => {
debug("Connecting to Powered UP Remote");
await super.connect();
debug("Connect completed");
return resolve();
});
}
/**
* Set the color of the LED on the Remote via a color value.
* @method PUPRemote#setLEDColor
* @param {Color} color
* @returns {Promise} Resolved upon successful issuance of command.
*/
setLEDColor(color) {
return new Promise((resolve, reject) => {
let data = Buffer.from([0x41, 0x34, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00]);
this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, data);
if (color === false) {
color = 0;
}
data = Buffer.from([0x81, 0x34, 0x11, 0x51, 0x00, color]);
this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, data);
return resolve();
});
}
/**
* Set the color of the LED on the Hub via RGB values.
* @method PUPRemote#setLEDRGB
* @param {number} red
* @param {number} green
* @param {number} blue
* @returns {Promise} Resolved upon successful issuance of command.
*/
setLEDRGB(red, green, blue) {
return new Promise((resolve, reject) => {
let data = Buffer.from([0x41, 0x34, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00]);
this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, data);
data = Buffer.from([0x81, 0x34, 0x11, 0x51, 0x01, red, green, blue]);
this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, data);
return resolve();
});
}
}
exports.PUPRemote = PUPRemote;