diff --git a/src/consts.ts b/src/consts.ts index 4a853e0..dac8b22 100644 --- a/src/consts.ts +++ b/src/consts.ts @@ -71,10 +71,13 @@ export enum DeviceType { DUPLO_TRAIN_BASE_SPEEDOMETER = 44, CONTROL_PLUS_LARGE_MOTOR = 46, CONTROL_PLUS_XLARGE_MOTOR = 47, + CONTROL_PLUS_GEST = 54, POWERED_UP_REMOTE_BUTTON = 55, RSSI = 56, - CONTROL_PLUS_ACCELEROMETER = 58, - CONTROL_PLUS_TILT = 59 + CONTROL_PLUS_ACCELEROMETER = 57, + CONTROL_PLUS_GYRO = 58, + CONTROL_PLUS_TILT = 59, + TEMPERATURE = 60, } diff --git a/src/controlplushub.ts b/src/controlplushub.ts index 03298e9..fbea784 100644 --- a/src/controlplushub.ts +++ b/src/controlplushub.ts @@ -31,8 +31,10 @@ export class ControlPlusHub extends LPF2Hub { } protected _currentPort = 0x3b; + protected _currentMaxMA = 4175; protected _voltagePort = 0x3c; protected _voltageMaxRaw = 4095; + protected _voltageMaxV = 9.615; constructor (device: IBLEDevice, autoSubscribe: boolean = true) { super(device, autoSubscribe); @@ -42,7 +44,8 @@ export class ControlPlusHub extends LPF2Hub { "B": new Port("B", 1), "C": new Port("C", 2), "D": new Port("D", 3), - "ACCEL": new Port("ACCEL", 98), + "ACCEL": new Port("ACCEL", 97), + "GYRO": new Port("GYRO", 98), "TILT": new Port("TILT", 99) }; this.on("attach", (port, type) => { diff --git a/src/lpf2hub.ts b/src/lpf2hub.ts index c38d9af..3f9c658 100644 --- a/src/lpf2hub.ts +++ b/src/lpf2hub.ts @@ -548,12 +548,27 @@ export class LPF2Hub extends Hub { this.emit("tilt", "TILT", this._lastTiltX, this._lastTiltY, this._lastTiltZ); break; } - case Consts.DeviceType.CONTROL_PLUS_ACCELEROMETER: { - const accelX = Math.round((data.readInt16LE(4) / 28571) * 2000); - const accelY = Math.round((data.readInt16LE(6) / 28571) * 2000); - const accelZ = Math.round((data.readInt16LE(8) / 28571) * 2000); + case Consts.DeviceType.CONTROL_PLUS_GYRO: { + const gyroX = Math.round(data.readInt16LE(4) * 7 / 400); + const gyroY = Math.round(data.readInt16LE(6) * 7 / 400); + const gyroZ = Math.round(data.readInt16LE(8) * 7 / 400); /** - * Emits when accelerometer detects movement. Measured in DPS - degrees per second. + * Emits when gyroscope detects movement. Measured in DPS - degrees per second. + * @event LPF2Hub#gyro + * @param {string} port + * @param {number} x + * @param {number} y + * @param {number} z + */ + this.emit("gyro", "GYRO", gyroX, gyroY, gyroZ); + break; + } + case Consts.DeviceType.CONTROL_PLUS_ACCELEROMETER: { + const accelX = Math.round(data.readInt16LE(4) / 4.096); + const accelY = Math.round(data.readInt16LE(6) / 4.096); + const accelZ = Math.round(data.readInt16LE(8) / 4.096); + /** + * Emits when accelerometer detects movement. Measured in mG. * @event LPF2Hub#accel * @param {string} port * @param {number} x