Control+ (Technic Medium Hub) sensors
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
parent
195c0d5123
commit
6e77d697fc
@ -74,9 +74,9 @@ export enum DeviceType {
|
||||
CONTROL_PLUS_GEST = 54,
|
||||
PUP_REMOTE_BUTTON = 55,
|
||||
RSSI = 56,
|
||||
CONTROL_PLUS_ACCELEROMETER = 57,
|
||||
CONTROL_PLUS_GYRO = 58,
|
||||
CONTROL_PLUS_TILT = 59,
|
||||
TECHNIC_MEDIUM_HUB_ACCELEROMETER = 57,
|
||||
TECHNIC_MEDIUM_HUB_GYRO_SENSOR = 58,
|
||||
TECHNIC_MEDIUM_HUB_TILT_SENSOR = 59,
|
||||
TEMPERATURE = 60,
|
||||
}
|
||||
|
||||
|
@ -21,9 +21,9 @@ export class MoveHubTiltSensor extends Device {
|
||||
* @param {number} x
|
||||
* @param {number} y
|
||||
*/
|
||||
const tiltX = -(message.readInt8(4));
|
||||
const tiltX = message.readInt8(4);
|
||||
const tiltY = message.readInt8(5);
|
||||
this.emit("tilt", tiltX, tiltY);
|
||||
this.emit("tilt", -tiltX, tiltY);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
46
src/devices/technicmediumhubaccelerometersensor.ts
Normal file
46
src/devices/technicmediumhubaccelerometersensor.ts
Normal file
@ -0,0 +1,46 @@
|
||||
import { Device } from "./device";
|
||||
|
||||
import { IDeviceInterface } from "../interfaces";
|
||||
|
||||
import * as Consts from "../consts";
|
||||
|
||||
export class TechnicMediumHubAccelerometerSensor extends Device {
|
||||
|
||||
constructor (hub: IDeviceInterface, portId: number) {
|
||||
super(hub, portId, TechnicMediumHubAccelerometerSensor.ModeMap, Consts.DeviceType.TECHNIC_MEDIUM_HUB_ACCELEROMETER);
|
||||
}
|
||||
|
||||
public receive (message: Buffer) {
|
||||
const mode = this._mode;
|
||||
|
||||
switch (mode) {
|
||||
case TechnicMediumHubAccelerometerSensor.Mode.ACCEL:
|
||||
/**
|
||||
* Emits when accelerometer detects movement. Measured in mG.
|
||||
* @event LPF2Hub#accel
|
||||
* @param {string} port
|
||||
* @param {number} x
|
||||
* @param {number} y
|
||||
* @param {number} z
|
||||
*/
|
||||
const accelX = Math.round(message.readInt16LE(4) / 4.096);
|
||||
const accelY = Math.round(message.readInt16LE(6) / 4.096);
|
||||
const accelZ = Math.round(message.readInt16LE(8) / 4.096);
|
||||
this.emit("accel", accelX, accelY, accelZ);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export namespace TechnicMediumHubAccelerometerSensor {
|
||||
|
||||
export enum Mode {
|
||||
ACCEL = 0x00
|
||||
}
|
||||
|
||||
export const ModeMap: {[event: string]: number} = {
|
||||
"accel": TechnicMediumHubAccelerometerSensor.Mode.ACCEL
|
||||
}
|
||||
|
||||
}
|
45
src/devices/technicmediumhubgyrosensor.ts
Normal file
45
src/devices/technicmediumhubgyrosensor.ts
Normal file
@ -0,0 +1,45 @@
|
||||
import { Device } from "./device";
|
||||
|
||||
import { IDeviceInterface } from "../interfaces";
|
||||
|
||||
import * as Consts from "../consts";
|
||||
|
||||
export class TechnicMediumHubGyroSensor extends Device {
|
||||
|
||||
constructor (hub: IDeviceInterface, portId: number) {
|
||||
super(hub, portId, TechnicMediumHubGyroSensor.ModeMap, Consts.DeviceType.TECHNIC_MEDIUM_HUB_GYRO_SENSOR);
|
||||
}
|
||||
|
||||
public receive (message: Buffer) {
|
||||
const mode = this._mode;
|
||||
|
||||
switch (mode) {
|
||||
case TechnicMediumHubGyroSensor.Mode.GYRO:
|
||||
/**
|
||||
* Emits when gyroscope detects movement. Measured in DPS - degrees per second.
|
||||
* @event TechnicMediumHubGyroSensor#gyro
|
||||
* @param {number} x
|
||||
* @param {number} y
|
||||
* @param {number} z
|
||||
*/
|
||||
const gyroX = Math.round(message.readInt16LE(4) * 7 / 400);
|
||||
const gyroY = Math.round(message.readInt16LE(6) * 7 / 400);
|
||||
const gyroZ = Math.round(message.readInt16LE(8) * 7 / 400);
|
||||
this.emit("gyro", gyroX, gyroY, -gyroZ);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export namespace TechnicMediumHubGyroSensor {
|
||||
|
||||
export enum Mode {
|
||||
GYRO = 0x00
|
||||
}
|
||||
|
||||
export const ModeMap: {[event: string]: number} = {
|
||||
"gyro": TechnicMediumHubGyroSensor.Mode.GYRO
|
||||
}
|
||||
|
||||
}
|
45
src/devices/technicmediumhubtiltsensor.ts
Normal file
45
src/devices/technicmediumhubtiltsensor.ts
Normal file
@ -0,0 +1,45 @@
|
||||
import { Device } from "./device";
|
||||
|
||||
import { IDeviceInterface } from "../interfaces";
|
||||
|
||||
import * as Consts from "../consts";
|
||||
|
||||
export class TechnicMediumHubTiltSensor extends Device {
|
||||
|
||||
constructor (hub: IDeviceInterface, portId: number) {
|
||||
super(hub, portId, TechnicMediumHubTiltSensor.ModeMap, Consts.DeviceType.TECHNIC_MEDIUM_HUB_TILT_SENSOR);
|
||||
}
|
||||
|
||||
public receive (message: Buffer) {
|
||||
const mode = this._mode;
|
||||
|
||||
switch (mode) {
|
||||
case TechnicMediumHubTiltSensor.Mode.TILT:
|
||||
/**
|
||||
* Emits when a tilt sensor is activated.
|
||||
* @event TechnicMediumHubTiltSensor#tilt
|
||||
* @param {number} x
|
||||
* @param {number} y
|
||||
* @param {number} z
|
||||
*/
|
||||
const tiltZ = message.readInt16LE(4);
|
||||
const tiltY = message.readInt16LE(6);
|
||||
const tiltX = message.readInt16LE(8);
|
||||
this.emit("tilt", tiltX, tiltY, -tiltZ);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export namespace TechnicMediumHubTiltSensor {
|
||||
|
||||
export enum Mode {
|
||||
TILT = 0x00
|
||||
}
|
||||
|
||||
export const ModeMap: {[event: string]: number} = {
|
||||
"tilt": TechnicMediumHubTiltSensor.Mode.TILT
|
||||
}
|
||||
|
||||
}
|
@ -14,6 +14,9 @@ import { MoveHubTiltSensor } from "../devices/movehubtiltsensor";
|
||||
import { PUPRemoteButton } from "../devices/pupremotebutton";
|
||||
import { SimpleMediumLinearMotor } from "../devices/simplemediumlinearmotor";
|
||||
import { TechnicLargeLinearMotor } from "../devices/techniclargelinearmotor";
|
||||
import { TechnicMediumHubAccelerometerSensor } from "../devices/technicmediumhubaccelerometersensor";
|
||||
import { TechnicMediumHubGyroSensor } from "../devices/technicmediumhubgyrosensor";
|
||||
import { TechnicMediumHubTiltSensor } from "../devices/technicmediumhubtiltsensor";
|
||||
import { TechnicXLargeLinearMotor } from "../devices/technicxlargelinearmotor";
|
||||
import { TiltSensor } from "../devices/tiltsensor";
|
||||
import { TrainMotor } from "../devices/trainmotor";
|
||||
@ -322,6 +325,15 @@ export class Hub extends EventEmitter {
|
||||
case Consts.DeviceType.MOVE_HUB_TILT_SENSOR:
|
||||
device = new MoveHubTiltSensor(this, portId);
|
||||
break;
|
||||
case Consts.DeviceType.TECHNIC_MEDIUM_HUB_TILT_SENSOR:
|
||||
device = new TechnicMediumHubTiltSensor(this, portId);
|
||||
break;
|
||||
case Consts.DeviceType.TECHNIC_MEDIUM_HUB_GYRO_SENSOR:
|
||||
device = new TechnicMediumHubGyroSensor(this, portId);
|
||||
break;
|
||||
case Consts.DeviceType.TECHNIC_MEDIUM_HUB_ACCELEROMETER:
|
||||
device = new TechnicMediumHubAccelerometerSensor(this, portId);
|
||||
break;
|
||||
case Consts.DeviceType.MEDIUM_LINEAR_MOTOR:
|
||||
device = new MediumLinearMotor(this, portId);
|
||||
break;
|
||||
|
@ -22,6 +22,9 @@ import { MoveHubTiltSensor } from "./devices/movehubtiltsensor";
|
||||
import { PUPRemoteButton } from "./devices/pupremotebutton";
|
||||
import { SimpleMediumLinearMotor } from "./devices/simplemediumlinearmotor";
|
||||
import { TechnicLargeLinearMotor } from "./devices/techniclargelinearmotor";
|
||||
import { TechnicMediumHubAccelerometerSensor } from "./devices/technicmediumhubaccelerometersensor";
|
||||
import { TechnicMediumHubGyroSensor } from "./devices/technicmediumhubgyrosensor";
|
||||
import { TechnicMediumHubTiltSensor } from "./devices/technicmediumhubtiltsensor";
|
||||
import { TechnicXLargeLinearMotor } from "./devices/technicxlargelinearmotor";
|
||||
import { TiltSensor } from "./devices/tiltsensor";
|
||||
import { TrainMotor } from "./devices/trainmotor";
|
||||
@ -50,6 +53,9 @@ window.PoweredUP = {
|
||||
MoveHubTiltSensor,
|
||||
PUPRemoteButton,
|
||||
SimpleMediumLinearMotor,
|
||||
TechnicMediumHubAccelerometerSensor,
|
||||
TechnicMediumHubGyroSensor,
|
||||
TechnicMediumHubTiltSensor,
|
||||
TechnicLargeLinearMotor,
|
||||
TechnicXLargeLinearMotor,
|
||||
TiltSensor,
|
||||
|
@ -22,6 +22,9 @@ import { MoveHubTiltSensor } from "./devices/movehubtiltsensor";
|
||||
import { PUPRemoteButton } from "./devices/pupremotebutton";
|
||||
import { SimpleMediumLinearMotor } from "./devices/simplemediumlinearmotor";
|
||||
import { TechnicLargeLinearMotor } from "./devices/techniclargelinearmotor";
|
||||
import { TechnicMediumHubAccelerometerSensor } from "./devices/technicmediumhubaccelerometersensor";
|
||||
import { TechnicMediumHubGyroSensor } from "./devices/technicmediumhubgyrosensor";
|
||||
import { TechnicMediumHubTiltSensor } from "./devices/technicmediumhubtiltsensor";
|
||||
import { TechnicXLargeLinearMotor } from "./devices/technicxlargelinearmotor";
|
||||
import { TiltSensor } from "./devices/tiltsensor";
|
||||
import { TrainMotor } from "./devices/trainmotor";
|
||||
@ -50,6 +53,9 @@ export {
|
||||
MoveHubTiltSensor,
|
||||
PUPRemoteButton,
|
||||
SimpleMediumLinearMotor,
|
||||
TechnicMediumHubAccelerometerSensor,
|
||||
TechnicMediumHubGyroSensor,
|
||||
TechnicMediumHubTiltSensor,
|
||||
TechnicLargeLinearMotor,
|
||||
TechnicXLargeLinearMotor,
|
||||
TiltSensor,
|
||||
|
Loading…
x
Reference in New Issue
Block a user