@openhps/sphero
Version:
Open Hybrid Positioning System - Sphero component
68 lines • 3.22 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.findLightningMcQueen = exports.findSpheroMiniByName = exports.findSpheroMini = exports.findR2Q5 = exports.findR2D2 = exports.findBB9E = exports.find = exports.findToy = void 0;
const bb9e_1 = require("./toys/bb9e");
const lightning_mcqueen_1 = require("./toys/lightning-mcqueen");
const r2d2_1 = require("./toys/r2d2");
const r2q5_1 = require("./toys/r2q5");
const sphero_mini_1 = require("./toys/sphero-mini");
const types_1 = require("./toys/types");
function findToy(type) {
return new Promise((resolve, reject) => {
navigator.bluetooth.requestDevice({
filters: [{
services: [types_1.ServicesUUID.apiV2ControlService]
}],
optionalServices: [types_1.ServicesUUID.nordicDfuService]
}).then((device) => {
resolve(device);
}).catch(ex => {
reject(ex);
});
});
}
exports.findToy = findToy;
const startToy = (toy) => __awaiter(void 0, void 0, void 0, function* () {
yield toy.start();
});
const find = (toyType, name) => __awaiter(void 0, void 0, void 0, function* () {
const device = yield findToy(toyType);
const toy = new toyType.class(device);
yield startToy(toy);
return toy;
});
exports.find = find;
const findBB9E = () => __awaiter(void 0, void 0, void 0, function* () {
return (yield (0, exports.find)(bb9e_1.BB9E.advertisement));
});
exports.findBB9E = findBB9E;
const findR2D2 = () => __awaiter(void 0, void 0, void 0, function* () {
return (yield (0, exports.find)(r2d2_1.R2D2.advertisement));
});
exports.findR2D2 = findR2D2;
const findR2Q5 = () => __awaiter(void 0, void 0, void 0, function* () {
return (yield (0, exports.find)(r2q5_1.R2Q5.advertisement));
});
exports.findR2Q5 = findR2Q5;
const findSpheroMini = () => __awaiter(void 0, void 0, void 0, function* () {
return (yield (0, exports.find)(sphero_mini_1.SpheroMini.advertisement));
});
exports.findSpheroMini = findSpheroMini;
const findSpheroMiniByName = (name) => __awaiter(void 0, void 0, void 0, function* () {
return (yield (0, exports.find)(sphero_mini_1.SpheroMini.advertisement, name));
});
exports.findSpheroMiniByName = findSpheroMiniByName;
const findLightningMcQueen = () => __awaiter(void 0, void 0, void 0, function* () {
return (yield (0, exports.find)(lightning_mcqueen_1.LightningMcQueen.advertisement));
});
exports.findLightningMcQueen = findLightningMcQueen;
//# sourceMappingURL=scanner.js.map