Fixed docs, updated force sensor for WeDo, added Mindstorms motors
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing

This commit is contained in:
Nathan Kellenicki 2020-06-12 12:37:07 -07:00
parent 8cbd0b8879
commit afe4eadf08
10 changed files with 47 additions and 33 deletions

View File

@ -40,11 +40,11 @@ While most Powered Up components and Hubs are compatible with each other, there
| Powered Up LED Lights | <a href="https://brickset.com/sets/88005-1/">88005</a> | Light | Yes | Yes | Yes | Yes | <a href="https://brickset.com/sets/88005-1/">88005</a> |
| Control+ Large Motor | 22169 | Motor/Sensor | *Partial* | No | Yes | Yes | <a href="https://brickset.com/sets/42099-1/">42099</a><br /><a href="https://brickset.com/sets/42100-1/">42100</a> |
| Control+ XLarge Motor | 22172 | Motor/Sensor | *Partial* | No | Yes | Yes | <a href="https://brickset.com/sets/42099-1/">42099</a><br /><a href="https://brickset.com/sets/42100-1/">42100</a> |
| SPIKE Prime Medium Motor | 45678 | Motor/Sensor | *Partial* | Yes | Yes | Yes | <a href="https://brickset.com/sets/45678-1/">45678</a> |
| SPIKE Prime Large Motor | 45678 | Motor/Sensor | *Partial* | Yes | Yes | Yes | <a href="https://brickset.com/sets/45678-1/">45678</a> |
| SPIKE Prime Color Sensor | 45678 | Sensor | No | Yes | Yes | Yes | <a href="https://brickset.com/sets/45678-1/">45678</a> |
| SPIKE Prime Distance Sensor | 45678 | Sensor | No | Yes | Yes | Yes | <a href="https://brickset.com/sets/45678-1/">45678</a> |
| SPIKE Prime Force Sensor | 45678 | Sensor | No | Yes | Yes | Yes | <a href="https://brickset.com/sets/45678-1/">45678</a> |
| SPIKE Prime Medium Motor | 45678 | Motor/Sensor | *Partial* | No | Yes | Yes | <a href="https://brickset.com/sets/45678-1/">45678</a> |
| SPIKE Prime Large Motor | 45678 | Motor/Sensor | *Partial* | No | Yes | Yes | <a href="https://brickset.com/sets/45678-1/">45678</a> |
| SPIKE Prime Color Sensor | 45678 | Sensor | No | No | Yes | Yes | <a href="https://brickset.com/sets/45678-1/">45678</a> |
| SPIKE Prime Distance Sensor | 45678 | Sensor | No | No | Yes | Yes | <a href="https://brickset.com/sets/45678-1/">45678</a> |
| SPIKE Prime Force Sensor | 45678 | Sensor | *Partial* | Yes | Yes | Yes | <a href="https://brickset.com/sets/45678-1/">45678</a> |
In addition, the Hubs themselves have certain built-in features which this library exposes.
@ -62,9 +62,9 @@ In addition, the Hubs themselves have certain built-in features which this libra
* The WeDo 2.0 Smart Hub uses an older firmware which is no longer being updated. As a result, only certain motors and sensors work with it. See the table above.
* When used with the Boost Move Hub, the Control+ Motors do not currently accept commands (This is a known but which requires a firmware update from Lego to fix)
* When used with the Boost Move Hub, the Control+ Motors and SPIKE Prime Motors/Sensors do not currently accept commands (This is a known bug which requires a firmware update from Lego to fix)
* The SPIKE Prime Hub does not use Bluetooth Low Energy, so is not supported via this library. It is recommended you use MicroPython and Bluetooth Classic to develop for this Hub.
* The SPIKE Prime Hub does not use Bluetooth Low Energy, so is not supported via this library. It is recommended you use MicroPython to develop for this Hub using the officially provided tools and software.
### Documentation

View File

@ -23,36 +23,44 @@ poweredUP.on("discover", async (hub) => {
console.log(`Disconnected ${hub.name}`);
})
hub.on("tilt", (port, x, y, z) => {
console.log(`Tilt detected on port ${port} (X: ${x}, Y: ${y}${z !== "undefined" ? `, Z: ${z}`: ""})`);
hub.on("tilt", (device, { x, y, z }) => {
console.log(`Tilt detected on port ${device.portName} (X: ${x}, Y: ${y}${z !== "undefined" ? `, Z: ${z}`: ""})`);
});
hub.on("accel", (port, x, y, z) => {
console.log(`Accelerometer detected on port ${port} (X: ${x}, Y: ${y}, Z: ${z})`);
hub.on("accel", (device, { x, y, z }) => {
console.log(`Accelerometer detected on port ${device.portName} (X: ${x}, Y: ${y}, Z: ${z})`);
});
hub.on("distance", (port, distance) => {
console.log(`Motion detected on port ${port} (Distance: ${distance})`);
hub.on("distance", (device, { distance }) => {
console.log(`Motion detected on port ${device.portName} (Distance: ${distance})`);
});
hub.on("color", (port, color) => {
console.log(`Color detected on port ${port} (Color: ${color})`);
hub.on("color", (device, { color }) => {
console.log(`Color detected on port ${device.portName} (Color: ${color})`);
});
hub.on("rotate", (port, rotation) => {
console.log(`Rotation detected on port ${port} (Rotation: ${rotation})`);
hub.on("rotate", (device, { degrees }) => {
console.log(`Rotation detected on port ${device.portName} (Rotation: ${degrees})`);
});
hub.on("button", (button, state) => {
console.log(`Button press detected (Button: ${button}, State: ${state})`);
hub.on("force", (device, { force }) => {
console.log(`Force detected on port ${device.portName} (Force: ${force})`);
});
hub.on("attach", (port, device) => {
console.log(`Device attached to port ${port} (Device ID: ${device})`) ;
hub.on("button", ({ event }) => {
console.log(`Green button press detected (Event: ${event})`);
});
hub.on("detach", (port) => {
console.log(`Device detached from port ${port}`) ;
hub.on("remoteButton", (device, { event }) => {
console.log(`Remote control button press detected on port ${device.portName} (Event: ${event})`);
});
hub.on("attach", (device) => {
console.log(`Device attached to port ${device.portName} (Device ID: ${device.type})`) ;
});
hub.on("detach", (device) => {
console.log(`Device detached from port ${device.portName}`) ;
});
});

2
package-lock.json generated
View File

@ -1,6 +1,6 @@
{
"name": "node-poweredup",
"version": "6.5.3",
"version": "6.6.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

View File

@ -1,6 +1,6 @@
{
"name": "node-poweredup",
"version": "6.5.3",
"version": "6.6.0",
"description": "A Javascript module to interface with LEGO Powered Up components.",
"homepage": "https://github.com/nathankellenicki/node-poweredup/",
"main": "dist/node/index-node.js",

View File

@ -82,7 +82,9 @@ export enum DeviceType {
TECHNIC_MEDIUM_HUB_TEMPERATURE_SENSOR = 60,
TECHNIC_COLOR_SENSOR = 61, // Spike Prime
TECHNIC_DISTANCE_SENSOR = 62, // Spike Prime
TECHNIC_FORCE_SENSOR = 63 // Spike Prime
TECHNIC_FORCE_SENSOR = 63, // Spike Prime
TECHNIC_MEDIUM_ANGULAR_MOTOR_GREY = 75, // Mindstorms
TECHNIC_LARGE_ANGULAR_MOTOR_GREY = 76, // Mindstorms
}

View File

@ -37,7 +37,11 @@ export class ColorDistanceSensor extends Device {
break;
}
if (message[4] <= 10) {
const distance = Math.floor(message[4] * 25.4) - 20;
let distance = Math.floor(message[4] * 25.4);
if (distance < 0) {
distance = 0;
}
/**
* Emits when a distance sensor is activated.

View File

@ -19,7 +19,7 @@ export class TechnicForceSensor extends Device {
switch (mode) {
case Mode.FORCE:
const force = message[4] / 10;
const force = message[this.isWeDo2SmartHub ? 2 : 4] / 10;
/**
* Emits when force is applied.

View File

@ -10,8 +10,8 @@ import * as Consts from "../consts";
*/
export class TechnicLargeAngularMotor extends AbsoluteMotor {
constructor (hub: IDeviceInterface, portId: number) {
super(hub, portId, {}, Consts.DeviceType.TECHNIC_LARGE_ANGULAR_MOTOR);
constructor (hub: IDeviceInterface, portId: number, modeMap: {[event: string]: number} = {}, type: Consts.DeviceType = Consts.DeviceType.TECHNIC_LARGE_ANGULAR_MOTOR) {
super(hub, portId, {}, type);
}
}

View File

@ -10,8 +10,8 @@ import * as Consts from "../consts";
*/
export class TechnicMediumAngularMotor extends AbsoluteMotor {
constructor (hub: IDeviceInterface, portId: number) {
super(hub, portId, {}, Consts.DeviceType.TECHNIC_MEDIUM_ANGULAR_MOTOR);
constructor (hub: IDeviceInterface, portId: number, modeMap: {[event: string]: number} = {}, type: Consts.DeviceType = Consts.DeviceType.TECHNIC_MEDIUM_ANGULAR_MOTOR) {
super(hub, portId, {}, type);
}
}

View File

@ -422,7 +422,7 @@ export class BaseHub extends EventEmitter {
constructor = deviceConstructors[deviceType as Consts.DeviceType];
if (constructor) {
return new constructor(this, portId);
return new constructor(this, portId, undefined, deviceType);
} else {
return new Device(this, portId, undefined, deviceType);
}