Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
d453fe5
Basic implementation of BasicMotor types
Dec 6, 2019
4af1d3d
Added autosubscribe when adding eventlisteners
Dec 7, 2019
8ffc60b
attachedDevices now a map
Dec 7, 2019
93a1369
Basic code for passing messages through to the device
Dec 9, 2019
d382c3d
Basic ColorDistanceSensor and TachoMotor handling
Dec 9, 2019
a02249f
Implemented basic lights, device busy-ness
Dec 9, 2019
f9cea9a
Yay, port object is no longer a thing
Dec 9, 2019
7fdc754
Start of hub refactor
Dec 9, 2019
5c03e5c
More refactoring
Dec 9, 2019
1793eb0
Removing commented code
Dec 9, 2019
6beeda5
Implemented methods for retrieving hubs and devices
Dec 11, 2019
6a7c489
Added more motor types
nathankellenicki Dec 15, 2019
198d637
Renamed devices
nathankellenicki Dec 16, 2019
81cbdac
Merge branch 'feature/devices' of github.com:nathankellenicki/node-po…
Dec 16, 2019
31ac932
Motion and tilt sensor
Dec 16, 2019
2a67242
Removed some commented code from hubs
Dec 16, 2019
023b141
Better handling of device initialisation, implemented more modes
Dec 17, 2019
37be7f8
Rename
Dec 17, 2019
406e9e9
Rename again
Dec 17, 2019
225f331
Better directory structure
Dec 17, 2019
df70d8a
Renamed devices
nathankellenicki Dec 17, 2019
04b79ad
Renamed devices
nathankellenicki Dec 17, 2019
388bce1
Mapping of events to modes
Dec 17, 2019
36c34a9
Exported device ModeMap
Dec 17, 2019
ffd3cce
Exported hub PortMap
Dec 17, 2019
364089b
Power to speed when rotating by angle
Dec 18, 2019
de4feb0
Added functions to wait for port attachments
Dec 18, 2019
c1b8697
VoltageSensor
Dec 18, 2019
2e06a17
CurrentSensor
Dec 18, 2019
6d23179
PUPRemoteButton
Dec 18, 2019
195c0d5
HubLED and MoveHubTiltSensor
Dec 18, 2019
6e77d69
Control+ (Technic Medium Hub) sensors
Dec 19, 2019
a5a9b2e
Control+ (Technic Medium Hub) devices, renamed hubs to be more inline…
Dec 19, 2019
705fbd3
writeDirect function on device
Dec 19, 2019
bc644c8
Duplo motors and sensors
Dec 19, 2019
0350176
Bug fixes, hubs now wait for hub properties before being connected
Dec 19, 2019
2dabedd
More WeDo 2.0 devices
Dec 20, 2019
579f823
Device events now emit on hub too
nathankellenicki Dec 23, 2019
9113d22
Named internal ports on hubs
nathankellenicki Dec 23, 2019
c5146bd
Renamed button to remoteButton on RC
nathankellenicki Dec 24, 2019
290f469
Device events emit value objects
nathankellenicki Dec 27, 2019
077a737
WeDo 2.0 unsubscribing
Jan 6, 2020
9f087e3
Merge branch 'feature/devices' of github.com:nathankellenicki/node-po…
nathankellenicki Jan 7, 2020
673f5ff
Start of port combining
Jan 8, 2020
afa7c74
Merge branch 'feature/devices' of github.com:nathankellenicki/node-po…
Jan 8, 2020
875293a
Fixed linting errors and removed namespaces
Jan 8, 2020
bf721ed
Virtual port attachment and detachment
Jan 8, 2020
b43b59e
Virtual ports tested
Jan 9, 2020
f7e86d3
Added setSpeed, virtual port multiparam options
Jan 9, 2020
74be8a7
Initial absolute motor support
Jan 10, 2020
56eaa7c
Fixed parts of absolute angle
nathankellenicki Jan 10, 2020
63f1c10
Servo calibration and reset
Jan 10, 2020
5fde49c
Adding power and brightness ramping back in
Jan 13, 2020
ea20b1b
Can not retrieve human readable device type from devices. Updated web…
Jan 13, 2020
dfd22b1
Can not retrieve human readable device type from devices. Updated web…
Jan 13, 2020
0c3ff8b
Devices now cache notified values for easy retrieval without events
Jan 13, 2020
225b60f
Devices now cache notified values for easy retrieval without events
Jan 13, 2020
d329ce6
Added support for Spike Prime motors
Jan 13, 2020
ef31567
Added support for Technic Color Sensor and Technic Distance Sensor (S…
Jan 15, 2020
407acce
Added Technic Force Sensor (Spike Prime)
Jan 15, 2020
c6f8015
Added example of slow speed train control with a Medium Linear Motor …
Jan 29, 2020
e34eea9
Removed examples with old API
Jan 29, 2020
c0009f8
Updated vernie sample, added braking style
Feb 7, 2020
e721e0f
Updated docs, readme, version
nathankellenicki Feb 10, 2020
a34c422
Added announement to readme
nathankellenicki Feb 10, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions examples/new_device_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
*
* This demonstrates connecting multiple hubs to your laptop. Once connected, all the hubs LED lights will cycle through the same colors simultaneously.
*
*/

const PoweredUP = require("..");

const poweredUP = new PoweredUP.PoweredUP();
poweredUP.scan(); // Start scanning for hubs

console.log("Looking for Hubs...");

poweredUP.on("discover", async (hub) => { // Wait to discover hubs

await hub.connect(); // Connect to hub
console.log(`Connected to ${hub.name}!`);

hub.on("attach", (device) => {

if (device instanceof PoweredUP.ControlPlusLargeMotor) {
const motor = device;
motor.setSpeed(30);
}

if (device instanceof PoweredUP.ColorDistanceSensor) {
const sensor = device;
sensor.on("distance", (distance) => { // Adding an event handler for distance automatically subscribes to distance notifications
console.log(`Distance ${distance}`);
})
}

device.on("detach", () => {
console.log(device.connected);
})

});

hub.on("disconnect", () => {
console.log("Hub disconnected");
})

});
41 changes: 41 additions & 0 deletions src/basicmotor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { Device } from "./device";
import { Hub } from "./hub";

import * as Consts from "./consts";

import { mapSpeed } from "./utils";

export class BasicMotor extends Device {


constructor (hub: Hub, portId: number, type: number = Consts.DeviceType.UNKNOWN) {
super(hub, portId, type);
}


/**
* Set the motor speed.
* @method BasicMotor#setSpeed
* @param {number} speed For forward, a value between 1 - 100 should be set. For reverse, a value between -1 to -100. Stop is 0.
* @returns {Promise} Resolved upon successful completion of command.
*/
public setSpeed (speed: number) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since basic motors don't have a tachometer, this is actually setPower. I guess this makes it easier for the API, but would you then have setSpeed and setPower for tacho motors or just setSpeed?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I guess I haven't liked power as I think for most users speed is a more appropriate term for what they want, even if it isn't exactly the same. I don't this library should attempt to exactly emulate LWP functionally, instead adding a user friendly layer on top of it.

Perhaps we could have setSpeed(50) set power by default, however with an options object (such as setSpeed(50, { maxPower: 50 }) to switch to maintaining the speed with power?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nutki I've gone with setPower and done a 180 on this. :) Will implement setSpeed appropriately later.

return new Promise((resolve) => {
const data = Buffer.from([0x81, this.portId, 0x11, 0x51, 0x00, mapSpeed(speed)]);
this.send(data);
return resolve();
});
}


/**
* Fully (hard) stop the motor.
* @method BasicMotor#brake
* @returns {Promise} Resolved upon successful completion of command.
*/
public brake () {
return this.setSpeed(127);
}


}
Loading