Support for Technic Small Hub and Technic Small Angular Motor
This commit is contained in:
parent
10a0a9457a
commit
e3259f4ba7
@ -18,6 +18,7 @@ export enum HubType {
|
|||||||
DUPLO_TRAIN_BASE = 5,
|
DUPLO_TRAIN_BASE = 5,
|
||||||
TECHNIC_MEDIUM_HUB = 6,
|
TECHNIC_MEDIUM_HUB = 6,
|
||||||
MARIO = 7,
|
MARIO = 7,
|
||||||
|
TECHNIC_SMALL_HUB = 8,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -85,6 +86,8 @@ export enum DeviceType {
|
|||||||
TECHNIC_COLOR_SENSOR = 61, // Spike Prime
|
TECHNIC_COLOR_SENSOR = 61, // Spike Prime
|
||||||
TECHNIC_DISTANCE_SENSOR = 62, // Spike Prime
|
TECHNIC_DISTANCE_SENSOR = 62, // Spike Prime
|
||||||
TECHNIC_FORCE_SENSOR = 63, // Spike Prime
|
TECHNIC_FORCE_SENSOR = 63, // Spike Prime
|
||||||
|
TECHNIC_3X3_COLOR_LIGHT_MATRIX = 64, // Spike Essential
|
||||||
|
TECHNIC_SMALL_ANGULAR_MOTOR = 65, // Spike Essential
|
||||||
MARIO_ACCELEROMETER = 71,
|
MARIO_ACCELEROMETER = 71,
|
||||||
MARIO_BARCODE_SENSOR = 73,
|
MARIO_BARCODE_SENSOR = 73,
|
||||||
MARIO_PANTS_SENSOR = 74,
|
MARIO_PANTS_SENSOR = 74,
|
||||||
@ -184,7 +187,8 @@ export enum BLEManufacturerData {
|
|||||||
HUB_ID = 65,
|
HUB_ID = 65,
|
||||||
REMOTE_CONTROL_ID = 66,
|
REMOTE_CONTROL_ID = 66,
|
||||||
MARIO_ID = 67,
|
MARIO_ID = 67,
|
||||||
TECHNIC_MEDIUM_HUB = 128
|
TECHNIC_MEDIUM_HUB_ID = 128,
|
||||||
|
TECHNIC_SMALL_HUB_ID = 131
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
17
src/devices/technicsmallangularmotor.ts
Normal file
17
src/devices/technicsmallangularmotor.ts
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
import { AbsoluteMotor } from "./absolutemotor";
|
||||||
|
|
||||||
|
import { IDeviceInterface } from "../interfaces";
|
||||||
|
|
||||||
|
import * as Consts from "../consts";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @class TechnicSmallAngularMotor
|
||||||
|
* @extends AbsoluteMotor
|
||||||
|
*/
|
||||||
|
export class TechnicSmallAngularMotor extends AbsoluteMotor {
|
||||||
|
|
||||||
|
constructor (hub: IDeviceInterface, portId: number, modeMap: {[event: string]: number} = {}, type: Consts.DeviceType = Consts.DeviceType.TECHNIC_SMALL_ANGULAR_MOTOR) {
|
||||||
|
super(hub, portId, {}, type);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -28,6 +28,7 @@ import { TechnicDistanceSensor } from "../devices/technicdistancesensor";
|
|||||||
import { TechnicForceSensor } from "../devices/technicforcesensor";
|
import { TechnicForceSensor } from "../devices/technicforcesensor";
|
||||||
import { TechnicLargeAngularMotor } from "../devices/techniclargeangularmotor";
|
import { TechnicLargeAngularMotor } from "../devices/techniclargeangularmotor";
|
||||||
import { TechnicLargeLinearMotor } from "../devices/techniclargelinearmotor";
|
import { TechnicLargeLinearMotor } from "../devices/techniclargelinearmotor";
|
||||||
|
import { TechnicSmallAngularMotor } from "../devices/technicsmallangularmotor";
|
||||||
import { TechnicMediumAngularMotor } from "../devices/technicmediumangularmotor";
|
import { TechnicMediumAngularMotor } from "../devices/technicmediumangularmotor";
|
||||||
import { TechnicMediumHubAccelerometerSensor } from "../devices/technicmediumhubaccelerometersensor";
|
import { TechnicMediumHubAccelerometerSensor } from "../devices/technicmediumhubaccelerometersensor";
|
||||||
import { TechnicMediumHubGyroSensor } from "../devices/technicmediumhubgyrosensor";
|
import { TechnicMediumHubGyroSensor } from "../devices/technicmediumhubgyrosensor";
|
||||||
@ -407,6 +408,7 @@ export class BaseHub extends EventEmitter {
|
|||||||
[Consts.DeviceType.TECHNIC_MEDIUM_HUB_GYRO_SENSOR]: TechnicMediumHubGyroSensor,
|
[Consts.DeviceType.TECHNIC_MEDIUM_HUB_GYRO_SENSOR]: TechnicMediumHubGyroSensor,
|
||||||
[Consts.DeviceType.TECHNIC_MEDIUM_HUB_ACCELEROMETER]: TechnicMediumHubAccelerometerSensor,
|
[Consts.DeviceType.TECHNIC_MEDIUM_HUB_ACCELEROMETER]: TechnicMediumHubAccelerometerSensor,
|
||||||
[Consts.DeviceType.MEDIUM_LINEAR_MOTOR]: MediumLinearMotor,
|
[Consts.DeviceType.MEDIUM_LINEAR_MOTOR]: MediumLinearMotor,
|
||||||
|
[Consts.DeviceType.TECHNIC_SMALL_ANGULAR_MOTOR]: TechnicSmallAngularMotor,
|
||||||
[Consts.DeviceType.TECHNIC_MEDIUM_ANGULAR_MOTOR]: TechnicMediumAngularMotor,
|
[Consts.DeviceType.TECHNIC_MEDIUM_ANGULAR_MOTOR]: TechnicMediumAngularMotor,
|
||||||
[Consts.DeviceType.TECHNIC_LARGE_ANGULAR_MOTOR]: TechnicLargeAngularMotor,
|
[Consts.DeviceType.TECHNIC_LARGE_ANGULAR_MOTOR]: TechnicLargeAngularMotor,
|
||||||
[Consts.DeviceType.TECHNIC_LARGE_LINEAR_MOTOR]: TechnicLargeLinearMotor,
|
[Consts.DeviceType.TECHNIC_LARGE_LINEAR_MOTOR]: TechnicLargeLinearMotor,
|
||||||
|
@ -26,7 +26,7 @@ export class TechnicMediumHub extends LPF2Hub {
|
|||||||
peripheral.advertisement.serviceUuids.indexOf(Consts.BLEService.LPF2_HUB.replace(/-/g, "")) >= 0 &&
|
peripheral.advertisement.serviceUuids.indexOf(Consts.BLEService.LPF2_HUB.replace(/-/g, "")) >= 0 &&
|
||||||
peripheral.advertisement.manufacturerData &&
|
peripheral.advertisement.manufacturerData &&
|
||||||
peripheral.advertisement.manufacturerData.length > 3 &&
|
peripheral.advertisement.manufacturerData.length > 3 &&
|
||||||
peripheral.advertisement.manufacturerData[3] === Consts.BLEManufacturerData.TECHNIC_MEDIUM_HUB
|
peripheral.advertisement.manufacturerData[3] === Consts.BLEManufacturerData.TECHNIC_MEDIUM_HUB_ID
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
57
src/hubs/technicsmallhub.ts
Normal file
57
src/hubs/technicsmallhub.ts
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
import { Peripheral } from "@abandonware/noble";
|
||||||
|
import compareVersion from "compare-versions";
|
||||||
|
|
||||||
|
import { IBLEAbstraction } from "../interfaces";
|
||||||
|
|
||||||
|
import { LPF2Hub } from "./lpf2hub";
|
||||||
|
|
||||||
|
import * as Consts from "../consts";
|
||||||
|
|
||||||
|
import Debug = require("debug");
|
||||||
|
const debug = Debug("hub");
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The TechnicSmallHub is emitted if the discovered device is a Technic Small Hub.
|
||||||
|
* @class Hub
|
||||||
|
* @extends LPF2Hub
|
||||||
|
* @extends BaseHub
|
||||||
|
*/
|
||||||
|
export class TechnicSmallHub extends LPF2Hub {
|
||||||
|
|
||||||
|
|
||||||
|
public static IsTechnicSmallHub (peripheral: Peripheral) {
|
||||||
|
return (
|
||||||
|
peripheral.advertisement &&
|
||||||
|
peripheral.advertisement.serviceUuids &&
|
||||||
|
peripheral.advertisement.serviceUuids.indexOf(Consts.BLEService.LPF2_HUB.replace(/-/g, "")) >= 0 &&
|
||||||
|
peripheral.advertisement.manufacturerData &&
|
||||||
|
peripheral.advertisement.manufacturerData.length > 3 &&
|
||||||
|
peripheral.advertisement.manufacturerData[3] === Consts.BLEManufacturerData.TECHNIC_SMALL_HUB_ID
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected _currentPort = 0x3b;
|
||||||
|
|
||||||
|
constructor (device: IBLEAbstraction) {
|
||||||
|
super(device, PortMap, Consts.HubType.TECHNIC_SMALL_HUB);
|
||||||
|
debug("Discovered Spike Essential Hub");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public async connect () {
|
||||||
|
debug("Connecting to Spike Essential Hub");
|
||||||
|
await super.connect();
|
||||||
|
debug("Connect completed");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
export const PortMap: {[portName: string]: number} = {
|
||||||
|
"A": 0,
|
||||||
|
"B": 1,
|
||||||
|
"HUB_LED": 49,
|
||||||
|
"CURRENT_SENSOR": 59,
|
||||||
|
"VOLTAGE_SENSOR": 60
|
||||||
|
};
|
@ -32,6 +32,7 @@ import { TechnicDistanceSensor } from "./devices/technicdistancesensor";
|
|||||||
import { TechnicForceSensor } from "./devices/technicforcesensor";
|
import { TechnicForceSensor } from "./devices/technicforcesensor";
|
||||||
import { TechnicLargeAngularMotor } from "./devices/techniclargeangularmotor";
|
import { TechnicLargeAngularMotor } from "./devices/techniclargeangularmotor";
|
||||||
import { TechnicLargeLinearMotor } from "./devices/techniclargelinearmotor";
|
import { TechnicLargeLinearMotor } from "./devices/techniclargelinearmotor";
|
||||||
|
import { TechnicSmallAngularMotor } from "./devices/technicsmallangularmotor";
|
||||||
import { TechnicMediumAngularMotor } from "./devices/technicmediumangularmotor";
|
import { TechnicMediumAngularMotor } from "./devices/technicmediumangularmotor";
|
||||||
import { TechnicMediumHubAccelerometerSensor } from "./devices/technicmediumhubaccelerometersensor";
|
import { TechnicMediumHubAccelerometerSensor } from "./devices/technicmediumhubaccelerometersensor";
|
||||||
import { TechnicMediumHubGyroSensor } from "./devices/technicmediumhubgyrosensor";
|
import { TechnicMediumHubGyroSensor } from "./devices/technicmediumhubgyrosensor";
|
||||||
|
@ -32,6 +32,7 @@ import { TechnicDistanceSensor } from "./devices/technicdistancesensor";
|
|||||||
import { TechnicForceSensor } from "./devices/technicforcesensor";
|
import { TechnicForceSensor } from "./devices/technicforcesensor";
|
||||||
import { TechnicLargeAngularMotor } from "./devices/techniclargeangularmotor";
|
import { TechnicLargeAngularMotor } from "./devices/techniclargeangularmotor";
|
||||||
import { TechnicLargeLinearMotor } from "./devices/techniclargelinearmotor";
|
import { TechnicLargeLinearMotor } from "./devices/techniclargelinearmotor";
|
||||||
|
import { TechnicSmallAngularMotor } from "./devices/technicsmallangularmotor";
|
||||||
import { TechnicMediumAngularMotor } from "./devices/technicmediumangularmotor";
|
import { TechnicMediumAngularMotor } from "./devices/technicmediumangularmotor";
|
||||||
import { TechnicMediumHubAccelerometerSensor } from "./devices/technicmediumhubaccelerometersensor";
|
import { TechnicMediumHubAccelerometerSensor } from "./devices/technicmediumhubaccelerometersensor";
|
||||||
import { TechnicMediumHubGyroSensor } from "./devices/technicmediumhubgyrosensor";
|
import { TechnicMediumHubGyroSensor } from "./devices/technicmediumhubgyrosensor";
|
||||||
|
@ -15,6 +15,7 @@ import { EventEmitter } from "events";
|
|||||||
|
|
||||||
import Debug = require("debug");
|
import Debug = require("debug");
|
||||||
import { IBLEAbstraction } from "./interfaces";
|
import { IBLEAbstraction } from "./interfaces";
|
||||||
|
import { TechnicSmallHub } from "./hubs/technicsmallhub";
|
||||||
const debug = Debug("poweredup");
|
const debug = Debug("poweredup");
|
||||||
|
|
||||||
|
|
||||||
@ -151,7 +152,10 @@ export class PoweredUP extends EventEmitter {
|
|||||||
case Consts.BLEManufacturerData.DUPLO_TRAIN_BASE_ID:
|
case Consts.BLEManufacturerData.DUPLO_TRAIN_BASE_ID:
|
||||||
resolve(Consts.HubType.DUPLO_TRAIN_BASE);
|
resolve(Consts.HubType.DUPLO_TRAIN_BASE);
|
||||||
break;
|
break;
|
||||||
case Consts.BLEManufacturerData.TECHNIC_MEDIUM_HUB:
|
case Consts.BLEManufacturerData.TECHNIC_SMALL_HUB_ID:
|
||||||
|
resolve(Consts.HubType.TECHNIC_SMALL_HUB);
|
||||||
|
break;
|
||||||
|
case Consts.BLEManufacturerData.TECHNIC_MEDIUM_HUB_ID:
|
||||||
resolve(Consts.HubType.TECHNIC_MEDIUM_HUB);
|
resolve(Consts.HubType.TECHNIC_MEDIUM_HUB);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -208,6 +212,9 @@ export class PoweredUP extends EventEmitter {
|
|||||||
case Consts.HubType.DUPLO_TRAIN_BASE:
|
case Consts.HubType.DUPLO_TRAIN_BASE:
|
||||||
hub = new DuploTrainBase(device);
|
hub = new DuploTrainBase(device);
|
||||||
break;
|
break;
|
||||||
|
case Consts.HubType.TECHNIC_SMALL_HUB:
|
||||||
|
hub = new TechnicSmallHub(device);
|
||||||
|
break;
|
||||||
case Consts.HubType.TECHNIC_MEDIUM_HUB:
|
case Consts.HubType.TECHNIC_MEDIUM_HUB:
|
||||||
hub = new TechnicMediumHub(device);
|
hub = new TechnicMediumHub(device);
|
||||||
break;
|
break;
|
||||||
|
@ -18,6 +18,7 @@ import { EventEmitter } from "events";
|
|||||||
import Debug = require("debug");
|
import Debug = require("debug");
|
||||||
const debug = Debug("poweredup");
|
const debug = Debug("poweredup");
|
||||||
import noble = require("@abandonware/noble");
|
import noble = require("@abandonware/noble");
|
||||||
|
import { TechnicSmallHub } from "./hubs/technicsmallhub";
|
||||||
|
|
||||||
let ready = false;
|
let ready = false;
|
||||||
let wantScan = false;
|
let wantScan = false;
|
||||||
@ -168,6 +169,8 @@ export class PoweredUP extends EventEmitter {
|
|||||||
hub = new RemoteControl(device);
|
hub = new RemoteControl(device);
|
||||||
} else if (DuploTrainBase.IsDuploTrainBase(peripheral)) {
|
} else if (DuploTrainBase.IsDuploTrainBase(peripheral)) {
|
||||||
hub = new DuploTrainBase(device);
|
hub = new DuploTrainBase(device);
|
||||||
|
} else if (TechnicSmallHub.IsTechnicSmallHub(peripheral)) {
|
||||||
|
hub = new TechnicSmallHub(device);
|
||||||
} else if (TechnicMediumHub.IsTechnicMediumHub(peripheral)) {
|
} else if (TechnicMediumHub.IsTechnicMediumHub(peripheral)) {
|
||||||
hub = new TechnicMediumHub(device);
|
hub = new TechnicMediumHub(device);
|
||||||
} else if (Mario.IsMario(peripheral)) {
|
} else if (Mario.IsMario(peripheral)) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user