Source: hubs/hub.js

  1. "use strict";
  2. var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
  3. if (k2 === undefined) k2 = k;
  4. var desc = Object.getOwnPropertyDescriptor(m, k);
  5. if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
  6. desc = { enumerable: true, get: function() { return m[k]; } };
  7. }
  8. Object.defineProperty(o, k2, desc);
  9. }) : (function(o, m, k, k2) {
  10. if (k2 === undefined) k2 = k;
  11. o[k2] = m[k];
  12. }));
  13. var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
  14. Object.defineProperty(o, "default", { enumerable: true, value: v });
  15. }) : function(o, v) {
  16. o["default"] = v;
  17. });
  18. var __importStar = (this && this.__importStar) || function (mod) {
  19. if (mod && mod.__esModule) return mod;
  20. var result = {};
  21. if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
  22. __setModuleDefault(result, mod);
  23. return result;
  24. };
  25. Object.defineProperty(exports, "__esModule", { value: true });
  26. exports.PortMap = exports.Hub = void 0;
  27. const compare_versions_1 = require("compare-versions");
  28. const lpf2hub_1 = require("./lpf2hub");
  29. const Consts = __importStar(require("../consts"));
  30. const Debug = require("debug");
  31. const debug = Debug("hub");
  32. /**
  33. * The Hub is emitted if the discovered device is a Hub.
  34. * @class Hub
  35. * @extends LPF2Hub
  36. * @extends BaseHub
  37. */
  38. class Hub extends lpf2hub_1.LPF2Hub {
  39. static IsHub(peripheral) {
  40. return (peripheral.advertisement &&
  41. peripheral.advertisement.serviceUuids &&
  42. peripheral.advertisement.serviceUuids.indexOf(Consts.BLEService.LPF2_HUB.replace(/-/g, "")) >= 0 &&
  43. peripheral.advertisement.manufacturerData &&
  44. peripheral.advertisement.manufacturerData.length > 3 &&
  45. peripheral.advertisement.manufacturerData[3] === Consts.BLEManufacturerData.HUB_ID);
  46. }
  47. constructor(device) {
  48. super(device, exports.PortMap, Consts.HubType.HUB);
  49. this._currentPort = 0x3b;
  50. debug("Discovered Powered UP Hub");
  51. }
  52. async connect() {
  53. debug("Connecting to Powered UP Hub");
  54. await super.connect();
  55. debug("Connect completed");
  56. }
  57. _checkFirmware(version) {
  58. if ((0, compare_versions_1.compareVersions)("1.1.00.0004", version) === 1) {
  59. throw new Error(`Your Powered Up Hub's (${this.name}) firmware is out of date and unsupported by this library. Please update it via the official Powered Up app.`);
  60. }
  61. }
  62. }
  63. exports.Hub = Hub;
  64. exports.PortMap = {
  65. "A": 0,
  66. "B": 1,
  67. "HUB_LED": 50,
  68. "CURRENT_SENSOR": 59,
  69. "VOLTAGE_SENSOR": 60
  70. };
  71. //# sourceMappingURL=hub.js.map