Compare commits

...

307 Commits

Author SHA1 Message Date
Nathan Kellenicki
60a42dfc47 New build with PRs
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2024-04-25 17:10:39 -07:00
Nathan Kellenicki
7ebc37a369 Updated drone 2024-04-25 17:09:44 -07:00
2fc1622c25
Merge pull request #169 from Debenben/tiltSensorRename
Rename tiltCount to impactCount for consistency
2024-04-25 17:08:29 -07:00
505bbdc648
Merge pull request #158 from cafjs/master
Fix for #157 (and possibly #131)
2024-04-25 17:05:54 -07:00
69ee57e6ff
Merge pull request #164 from Debenben/mario-pull
Add missing Mario hub to poweredup-browser
2024-04-25 17:02:41 -07:00
e0ae64e7f3
Merge pull request #174 from Debenben/RemoteControlButton
fix #173 RemoteControlButton documentation
2024-04-25 17:00:15 -07:00
Nathan Kellenicki
abecb5385b Updated
Some checks failed
continuous-integration/drone/push Build is failing
2024-04-25 16:38:57 -07:00
bene
2b03176509 fix #173 RemoteControlButton documentation 2022-12-18 13:59:10 +01:00
bene
d117fe10ff Rename tiltCount to impactCount for consistency 2022-10-08 14:09:41 +02:00
bene
3bba7c7e73 Add missing Mario hub to poweredup-browser
fix for issue #152
2022-08-14 10:17:31 +02:00
Antonio Lain
333d300fc4 Undo change package name
Signed-off-by: Antonio Lain <antlai@cafjs.com>
2022-05-27 14:30:26 -07:00
Antonio Lain
d3ccc7ac41 Change package name
Signed-off-by: Antonio Lain <antlai@cafjs.com>
2022-05-27 14:27:27 -07:00
Antonio Lain
a613e9956d Fix for #131 2022-05-27 14:01:57 -07:00
Nathan Kellenicki
e4c68e5749 Another discovery fix
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2022-01-20 22:17:46 -08:00
Nathan Kellenicki
72ef125d4f Connection and discovery improvements
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2022-01-19 20:03:06 -08:00
Nathan Kellenicki
a8a27eaeaa Expose connection status
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2022-01-18 21:31:55 -08:00
Nathan Kellenicki
ce0f4509be Disconnect fix
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2022-01-18 21:17:22 -08:00
Nathan Kellenicki
f71411aacd Fixed Raspberry Pi discovery
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2022-01-18 20:45:38 -08:00
Nathan Kellenicki
e877dbf65e Fixed Raspberry Pi discovery 2022-01-18 20:45:09 -08:00
Nathan Kellenicki
4836695840 Updated version
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2022-01-18 17:57:50 -08:00
Nathan Kellenicki
57ee61e620 Updated docs
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2022-01-18 17:52:45 -08:00
Nathan Kellenicki
32fe39fd8c Merge branch 'master' of github.com:nathankellenicki/node-poweredup 2022-01-18 17:52:25 -08:00
Nathan Kellenicki
ddb71b5d05 Updated docs 2022-01-18 17:49:56 -08:00
fe80b0fd81
Merge pull request #144 from Debenben/commandFeedback
Command feedback
2022-01-18 17:43:52 -08:00
Nathan Kellenicki
a833732f8c Revised distance calculation 2022-01-18 17:41:37 -08:00
Nathan Kellenicki
e6c575a0da Merge branch 'master' of github.com:nathankellenicki/node-poweredup 2022-01-18 17:34:57 -08:00
322b269e5a
Merge pull request #149 from Debenben/colordistanceSensor
change colordistancesensor distance calculation
2022-01-18 17:34:51 -08:00
Nathan Kellenicki
f0169117b5 Merge branch 'master' of github.com:nathankellenicki/node-poweredup 2022-01-18 17:27:06 -08:00
a0279a1fb6
Merge pull request #146 from Debenben/tiltSensor
add workaround for wrong tilt orientation
2022-01-18 17:26:47 -08:00
7b1795c967
Merge pull request #147 from Debenben/tiltSensorExtra
add impact count mode to tiltsensor
2022-01-18 17:10:03 -08:00
de6f60b42c
Merge pull request #150 from Debenben/colordistanceSensorExtra
add additional modes to colordistancesensor
2022-01-18 17:09:07 -08:00
9845a0b118
Merge pull request #143 from Debenben/documentation
update enum documentation
2022-01-18 17:07:59 -08:00
70c753c660
Merge pull request #140 from jncraton/patch-1
Correct typo in example
2022-01-18 17:07:00 -08:00
Nathan Kellenicki
48a8aea80a Fixed Bluetooth discovery until macOS Monterey 2022-01-18 17:02:35 -08:00
Nathan Kellenicki
aabf02580e Updated dependencies 2022-01-18 17:02:16 -08:00
bene
0877d068a5 add additional modes to colordistancesensor 2022-01-09 16:48:25 +01:00
bene
7782d64003 change colordistancesensor distance calculation
ignores inaccurate distance values for small distances and
avoids negative values for distance=0 and partial >0
2022-01-09 16:32:55 +01:00
bene
4cc92c6d37 add impact count mode to tiltsensor 2022-01-09 15:59:15 +01:00
bene
d51851d058 add workaround for wrong tilt orientation 2022-01-09 15:25:21 +01:00
bene
02215ccf40 handle busy/full feedback message
commands with startup and completion information changed from
0x11 (= execute immediately + request feedback) to
0x01 (= buffer if neccessary + request reedback)
can return feedback 0x10 = busy/full. This feedback should not resolve
the buffered commands.
2022-01-09 13:55:18 +01:00
bene
07edc32a8a parse multiple feedback message correctly
Using a virtual port you get feedback for the virtual port and its
componentes in one message.

Change suggested by @aileo
https://github.com/nathankellenicki/node-poweredup/issues/118#issuecomment-754911527
2022-01-09 13:47:15 +01:00
bene
f570afba08 update enum documentation 2022-01-09 13:37:26 +01:00
Jon Craton
52ee5d04c7
Correct typo in example 2021-11-05 20:03:54 -04:00
4bfa4d15e5 Updated readme
All checks were successful
continuous-integration/drone/push Build is passing
2021-09-14 21:21:00 -07:00
6b44373930 Bumped version
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2021-09-14 21:17:51 -07:00
0577491a8c Technic 3x3 Light Matrix support 2021-09-14 21:13:32 -07:00
7b1fdb42e7 Support for Technic Small Hub and Technic Small Angular Motor 2021-09-14 19:22:54 -07:00
e3259f4ba7 Support for Technic Small Hub and Technic Small Angular Motor 2021-09-14 18:21:31 -07:00
10a0a9457a Updated docs
All checks were successful
continuous-integration/drone/push Build is passing
2021-08-29 21:03:59 -07:00
24e8d00db4 Fixed gitignore
All checks were successful
continuous-integration/drone/push Build is passing
2021-08-29 21:01:31 -07:00
e0ec800dcc Fixed gitignore
Some checks failed
continuous-integration/drone/push Build is failing
2021-08-29 20:59:31 -07:00
60dee2c62d Updated docs
Some checks failed
continuous-integration/drone/push Build is failing
2021-08-29 20:56:42 -07:00
671c2d21db Updated build
Some checks failed
continuous-integration/drone/push Build is failing
2021-08-29 20:35:21 -07:00
0e5f94e189 Changed from ink-docstrap to braintree jsdoc template
Some checks failed
continuous-integration/drone/push Build is failing
2021-08-29 20:29:38 -07:00
2e43ee7cf0 Fixed Duplo color sensor, color sensor output on all sensors
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2021-08-29 20:07:10 -07:00
6a02a89e5e
Merge pull request #135 from 10on/master
Fix path for constants after renaming it
2021-06-15 09:38:40 -07:00
Denis Pushkarev
fbf5b5ccf3 Fix path for constants after renaming it 2021-06-08 20:48:30 +03:00
093cdc0c00
Merge pull request #130 from sciguy16/patch-1
Rename events enum from AlertPayload to Event
2021-06-04 10:35:37 -07:00
David Young
88ace0f66f
Rename events enum from AlertPayload to Event 2021-05-09 19:43:59 +01:00
dbe7f1999b Updated version with latest PRs
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2021-04-05 21:30:51 -07:00
7e8eaf6598
Merge pull request #121 from Debenben/patch-2
possible fix for #118, always return resolve
2021-04-05 21:12:33 -07:00
08489819ec Fixed Mario initializer, Technic and Mindstorms angular motors
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2021-04-05 21:08:37 -07:00
debenben
a51aac1066 possible fix for #118, always return resolve
* changed _finished pointer to array to not overwrite callbacks
* all completed and discarded commands get resolved
* 0x10 bitset exists in documentation only? -> not implemented
2020-12-30 20:54:24 +01:00
a3f66d5df0 Updated docs
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2020-12-29 22:35:23 -08:00
04e8798c6a Bumped package 2020-12-29 22:30:13 -08:00
e6a174e53a
Merge pull request #119 from Debenben/patch-1
fix issue #118 (partially)
2020-12-29 22:28:18 -08:00
Debenben
01d229823e
fix issue #118 (partially)
fix wrong constant, should be 0x82 like in previous version.
2020-12-29 16:31:45 +01:00
51edf0b933 Updated docs, bumped version
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2020-12-23 13:38:40 -08:00
42dae48639 Restructured build flow
All checks were successful
continuous-integration/drone/push Build is passing
2020-12-23 10:25:10 -08:00
df4ea5dd86 Mario gesture support 2020-12-23 10:24:59 -08:00
5094c8269f Mario accelerometer support 2020-12-23 10:15:57 -08:00
e88cec2635 Added buffer shim to webpack
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2020-12-22 17:35:48 -08:00
4f1e48a6b0 Updated docs
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2020-12-22 17:07:59 -08:00
1193df20df Updated README, bumped version 2020-12-22 17:07:00 -08:00
e016f14059 Removed ancient temperature subscription
All checks were successful
continuous-integration/drone/push Build is passing
2020-12-22 16:42:41 -08:00
be8495a2f2
Support for Super Mario 2020-12-22 16:06:56 -08:00
7d0c4f73ba Added example
All checks were successful
continuous-integration/drone/push Build is passing
2020-12-22 16:05:57 -08:00
38bdea2642 Merge branch 'master' of https://gitea.kellenicki.com/nkellenicki/node-poweredup into feature/mario
All checks were successful
continuous-integration/drone/push Build is passing
2020-12-22 15:44:25 -08:00
2dec413e94
Merge pull request #111 from jncraton/lpf2hub-consts
All checks were successful
continuous-integration/drone/push Build is passing
Replace magic numbers with constants
2020-12-22 15:20:02 -08:00
d1fe3a49e4 Fixed Typescript defs
All checks were successful
continuous-integration/drone/push Build is passing
2020-12-22 15:17:59 -08:00
224415801f Updated dependencies, fixed vulns
Some checks failed
continuous-integration/drone/push Build is failing
2020-12-22 15:03:40 -08:00
Jon Craton
7bc9603952 Replace magic numbers with constants
This replaces several magic numbers in the lpf2hub implementation with constants that were already present in src/consts.ts. This should enhance readability and maintainability. Comments that were made redundant by including the constant names have been removed.

There are still quite a few magic numbers in here that could be replaced, particularly in the byte arrays used to build messages, but I didn't attempt to clean those up.
2020-10-16 15:05:01 -04:00
7852fa5823 Updated packages 2020-10-02 10:39:07 -07:00
7b0e46e645 Merge branch 'master' of github.com:nathankellenicki/node-poweredup 2020-10-02 10:35:51 -07:00
34ffc7816c
Merge pull request #106 from nathankellenicki/dependabot/npm_and_yarn/bl-4.0.3
Bump bl from 4.0.2 to 4.0.3
2020-10-02 10:35:42 -07:00
7bd7d3ce6d Mario support 2020-10-02 10:14:00 -07:00
f64b141227 Updated Control+ motors 2020-10-01 17:34:09 -07:00
dependabot[bot]
15c3f4defc
Bump bl from 4.0.2 to 4.0.3
Bumps [bl](https://github.com/rvagg/bl) from 4.0.2 to 4.0.3.
- [Release notes](https://github.com/rvagg/bl/releases)
- [Commits](https://github.com/rvagg/bl/compare/v4.0.2...v4.0.3)

Signed-off-by: dependabot[bot] <support@github.com>
2020-09-02 16:16:41 +00:00
d86c3f69f8
Merge pull request #99 from aileo/lpf2hub-message-size
Fix message length comparison
2020-07-30 14:03:58 -07:00
6e29cb9914
Merge pull request #101 from nathankellenicki/dependabot/npm_and_yarn/lodash-4.17.19
Bump lodash from 4.17.15 to 4.17.19
2020-07-30 13:43:43 -07:00
8d5a3438a3
Merge pull request #102 from nathankellenicki/dependabot/npm_and_yarn/elliptic-6.5.3
Bump elliptic from 6.5.2 to 6.5.3
2020-07-30 13:43:31 -07:00
dependabot[bot]
8401297b3f
Bump elliptic from 6.5.2 to 6.5.3
Bumps [elliptic](https://github.com/indutny/elliptic) from 6.5.2 to 6.5.3.
- [Release notes](https://github.com/indutny/elliptic/releases)
- [Commits](https://github.com/indutny/elliptic/compare/v6.5.2...v6.5.3)

Signed-off-by: dependabot[bot] <support@github.com>
2020-07-30 13:29:10 +00:00
dependabot[bot]
b2eebfa442
Bump lodash from 4.17.15 to 4.17.19
Bumps [lodash](https://github.com/lodash/lodash) from 4.17.15 to 4.17.19.
- [Release notes](https://github.com/lodash/lodash/releases)
- [Commits](https://github.com/lodash/lodash/compare/4.17.15...4.17.19)

Signed-off-by: dependabot[bot] <support@github.com>
2020-07-16 11:29:47 +00:00
Léo Bonnargent
4394030f6b Fix message length comparison 2020-06-28 17:48:13 +02:00
db492be169
Merge pull request #96 from aileo/abandonware-noble
Change doc link to abandonware/noble
2020-06-23 20:17:58 -07:00
89a47944a5
Update README.md 2020-06-23 20:17:23 -07:00
Léo Bonnargent
511f503912 Change doc link to abandonware/noble
- also add root permisions note to the readme
2020-06-22 13:53:54 +02:00
6bdd454772 Fix for scanStop on Raspberry Pis
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2020-06-12 13:48:20 -07:00
9b4d496f34 Updated deps, added exports
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2020-06-12 12:52:57 -07:00
afe4eadf08 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
2020-06-12 12:37:07 -07:00
8cbd0b8879 Bumped packages
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2020-06-04 22:24:25 -07:00
dee732c8ca More error handling around manuallyAttachDevice
Some checks failed
continuous-integration/drone/tag Build is failing
continuous-integration/drone/push Build is passing
2020-06-03 20:24:03 -07:00
e6c6a3c18f Method for manually attaching devices as a workaround for connection issues
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2020-06-03 09:05:41 -07:00
1b2c988409 Added support for the leds on the Technic color sensor
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2020-05-31 13:31:53 -07:00
2e2f565ed7
Merge pull request #86 from aileo/mailbox
Improve web ble mailbox
2020-05-30 17:36:56 -07:00
Léo Bonnargent
93d6a9e45a Improve web ble mailbox 2020-05-25 23:19:04 +02:00
bce589a751 Bumped package
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2020-05-24 15:54:12 -07:00
6decc7139b gotoPhysicalZero fix
All checks were successful
continuous-integration/drone/push Build is passing
2020-05-24 15:53:18 -07:00
bcc59ce81c Added maxpower
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2020-05-24 10:15:30 -07:00
9234e9af34 Bumped version
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2020-05-23 19:31:25 -07:00
974b32e98c Updated docs
All checks were successful
continuous-integration/drone/push Build is passing
2020-05-23 19:30:38 -07:00
a7992bf20e Added gotoRealZero
Some checks failed
continuous-integration/drone/push Build is failing
2020-05-23 19:28:54 -07:00
0a9f200e97 Added docs 2020-05-23 18:37:19 -07:00
b219dcf60b Added acceleration/deceleraiton setters for tacho motors 2020-05-23 18:33:04 -07:00
e526e32146 Added resetAngle 2020-05-23 14:22:35 -07:00
a8126b2f3e
Merge pull request #84 from p8nut/master
add Lego constant to consts.ts
2020-05-23 10:24:15 -07:00
andrey_j
b24946ca43 fix hex typo 2020-05-16 16:38:46 +02:00
andrey_j
7ad17ccfcf add Lego missing constant 2020-05-16 16:32:00 +02:00
be7490cc9f Downgraded Noble
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2020-04-04 17:38:25 -07:00
6305662d38 Downgraded Noble 2020-04-04 17:38:14 -07:00
b66eb5befa Updated docs
Some checks failed
continuous-integration/drone/tag Build is failing
continuous-integration/drone/push Build is failing
2020-04-04 17:27:36 -07:00
b9972b0527 Bumped version 2020-04-04 17:17:34 -07:00
6343c97175
Merge pull request #80 from nathankellenicki/feature/power-functions-ir
[feat] Power Functions IR
2020-04-04 17:16:17 -07:00
4bf26cf158 Fixed bugs, updated packages 2020-04-04 17:14:48 -07:00
48532ab56f Power Functions fixes 2020-04-04 17:05:53 -07:00
45670f57c7
Update src/devices/colordistancesensor.ts
Co-Authored-By: Michał Szafrański <szafranski@gmail.com>
2020-03-25 10:00:31 -07:00
04313c746d
Update src/devices/colordistancesensor.ts
Co-Authored-By: Michał Szafrański <szafranski@gmail.com>
2020-03-25 10:00:22 -07:00
97d0c407cf
Update src/devices/colordistancesensor.ts
Co-Authored-By: Michał Szafrański <szafranski@gmail.com>
2020-03-25 09:57:25 -07:00
3145fec599
Update src/devices/colordistancesensor.ts
Co-Authored-By: Michał Szafrański <szafranski@gmail.com>
2020-03-25 09:54:56 -07:00
232ef6835e
Update src/devices/colordistancesensor.ts
Co-Authored-By: Michał Szafrański <szafranski@gmail.com>
2020-03-25 09:54:27 -07:00
0ec0692aad PF extended channel mode 2020-03-24 19:09:48 -07:00
32b7ba3d45 Single and combo PWM 2020-03-24 14:16:59 -07:00
a2cee6566d
Merge pull request #77 from nathankellenicki/dependabot/npm_and_yarn/acorn-6.4.1
Bump acorn from 6.4.0 to 6.4.1
2020-03-14 11:29:20 -07:00
dependabot[bot]
74418453d3
Bump acorn from 6.4.0 to 6.4.1
Bumps [acorn](https://github.com/acornjs/acorn) from 6.4.0 to 6.4.1.
- [Release notes](https://github.com/acornjs/acorn/releases)
- [Commits](https://github.com/acornjs/acorn/compare/6.4.0...6.4.1)

Signed-off-by: dependabot[bot] <support@github.com>
2020-03-14 06:07:33 +00:00
854666fd06
Merge pull request #76 from highflying/feature/return-promises
Feature/return promises
2020-03-09 11:05:54 -07:00
Ben Rogers
232edb2ffb Moves away from callbacks, towards more promises
Allows more use of await
Removed some unnecessary awaits, some unnecessary Promise wrappers
2020-03-03 21:29:52 +00:00
Ben Rogers
78d769a269
Merge pull request #2 from nathankellenicki/master
Update fork
2020-03-01 15:03:09 +00:00
8b16d1012b Bumped to 6.1.0
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2020-02-24 21:47:06 -08:00
7b0d981327 Added comment 2020-02-24 21:44:57 -08:00
28fd0b5578 Added support for Duplo color sensor RGB values, reflectivity, and Duplo train system sounds 2020-02-24 21:43:52 -08:00
ecbf489148 Fixed problems with sample code, braking consts
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2020-02-11 08:44:48 -08:00
d98af00775 Fixed merge conflicts
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2020-02-10 11:33:14 -08:00
91a0c02972 Merge branch 'feature/devices' 2020-02-10 11:30:18 -08:00
a34c4223fb Added announement to readme 2020-02-10 11:22:15 -08:00
e721e0f5bf Updated docs, readme, version 2020-02-10 11:17:43 -08:00
c0009f8f08 Updated vernie sample, added braking style 2020-02-07 14:28:32 -08:00
e34eea98ba Removed examples with old API 2020-01-29 14:57:03 -08:00
c6f8015154 Added example of slow speed train control with a Medium Linear Motor (Boost Motor) 2020-01-29 14:54:14 -08:00
407accedc8 Added Technic Force Sensor (Spike Prime)
Some checks failed
continuous-integration/drone/push Build is failing
2020-01-14 16:57:36 -08:00
ef315676b0 Added support for Technic Color Sensor and Technic Distance Sensor (Spike Prime)
Some checks failed
continuous-integration/drone/push Build is failing
2020-01-14 16:40:48 -08:00
d329ce6191 Added support for Spike Prime motors
Some checks failed
continuous-integration/drone/push Build is failing
2020-01-13 14:30:43 -08:00
225b60f752 Devices now cache notified values for easy retrieval without events
Some checks failed
continuous-integration/drone/push Build is failing
2020-01-13 12:59:43 -08:00
0c3ff8b00a Devices now cache notified values for easy retrieval without events
Some checks failed
continuous-integration/drone/push Build is failing
2020-01-13 12:56:58 -08:00
dfd22b1d3d Can not retrieve human readable device type from devices. Updated web bluetooth example
Some checks failed
continuous-integration/drone/push Build is failing
2020-01-13 12:18:00 -08:00
ea20b1bee0 Can not retrieve human readable device type from devices. Updated web bluetooth example 2020-01-13 12:17:51 -08:00
5fde49c0c2 Adding power and brightness ramping back in
Some checks failed
continuous-integration/drone/push Build is failing
2020-01-13 10:58:57 -08:00
63f1c10fcc Servo calibration and reset
Some checks failed
continuous-integration/drone/push Build is failing
2020-01-10 12:27:23 -08:00
56eaa7ca49 Fixed parts of absolute angle 2020-01-09 22:50:44 -08:00
74be8a752b Initial absolute motor support 2020-01-09 16:01:57 -08:00
f7e86d32cf Added setSpeed, virtual port multiparam options
Some checks failed
continuous-integration/drone/push Build is failing
2020-01-09 12:05:05 -08:00
b43b59e526 Virtual ports tested
Some checks failed
continuous-integration/drone/push Build is failing
2020-01-09 10:56:59 -08:00
bf721eddf6 Virtual port attachment and detachment
Some checks failed
continuous-integration/drone/push Build is failing
2020-01-08 15:37:07 -08:00
875293a742 Fixed linting errors and removed namespaces 2020-01-08 15:10:54 -08:00
afa7c74f82 Merge branch 'feature/devices' of github.com:nathankellenicki/node-poweredup into feature/devices
Some checks failed
continuous-integration/drone/push Build is failing
2020-01-08 14:38:57 -08:00
673f5ffcb6 Start of port combining 2020-01-08 14:38:51 -08:00
9f087e3e1a Merge branch 'feature/devices' of github.com:nathankellenicki/node-poweredup into feature/devices 2020-01-06 22:17:27 -08:00
077a7376c0 WeDo 2.0 unsubscribing 2020-01-06 09:49:38 -08:00
290f469b47 Device events emit value objects 2019-12-26 18:18:55 -08:00
c5146bd315 Renamed button to remoteButton on RC 2019-12-23 20:32:12 -08:00
9113d22766 Named internal ports on hubs
Some checks failed
continuous-integration/drone/push Build is failing
2019-12-22 19:02:35 -08:00
579f82334c Device events now emit on hub too
Some checks failed
continuous-integration/drone/push Build is failing
2019-12-22 18:39:19 -08:00
2dabeddbab More WeDo 2.0 devices 2019-12-20 12:35:09 -08:00
035017617e Bug fixes, hubs now wait for hub properties before being connected 2019-12-19 15:44:35 -08:00
bc644c85b2 Duplo motors and sensors 2019-12-19 12:07:05 -08:00
705fbd341a writeDirect function on device
Some checks failed
continuous-integration/drone/push Build is failing
2019-12-19 10:46:38 -08:00
a5a9b2e880 Control+ (Technic Medium Hub) devices, renamed hubs to be more inline with official naming convention
Some checks failed
continuous-integration/drone/push Build is failing
2019-12-18 17:13:21 -08:00
6e77d697fc Control+ (Technic Medium Hub) sensors
Some checks failed
continuous-integration/drone/push Build is failing
2019-12-18 16:51:32 -08:00
195c0d5123 HubLED and MoveHubTiltSensor
Some checks failed
continuous-integration/drone/push Build is failing
2019-12-18 15:20:20 -08:00
6d23179be6 PUPRemoteButton
Some checks failed
continuous-integration/drone/push Build is failing
2019-12-18 13:21:32 -08:00
2e06a17e5d CurrentSensor
Some checks failed
continuous-integration/drone/push Build is failing
2019-12-18 12:04:39 -08:00
c1b8697a56 VoltageSensor
Some checks failed
continuous-integration/drone/push Build is failing
2019-12-18 11:45:12 -08:00
de4feb0b89 Added functions to wait for port attachments
Some checks failed
continuous-integration/drone/push Build is failing
2019-12-18 10:24:39 -08:00
364089b703 Power to speed when rotating by angle
Some checks failed
continuous-integration/drone/push Build is failing
2019-12-17 17:23:27 -08:00
ffd3cceab8 Exported hub PortMap 2019-12-17 14:44:48 -08:00
36c34a9743 Exported device ModeMap
Some checks failed
continuous-integration/drone/push Build is failing
2019-12-17 14:29:14 -08:00
388bce170c Mapping of events to modes
Some checks failed
continuous-integration/drone/push Build is failing
2019-12-17 14:03:37 -08:00
04b79ade47 Renamed devices
Some checks failed
continuous-integration/drone/push Build is failing
2019-12-16 21:21:25 -08:00
df70d8a8a4 Renamed devices 2019-12-16 21:19:56 -08:00
225f331811 Better directory structure 2019-12-16 17:31:22 -08:00
406e9e99bc Rename again
All checks were successful
continuous-integration/drone/push Build is passing
2019-12-16 17:11:30 -08:00
37be7f85b6 Rename 2019-12-16 17:10:50 -08:00
023b141c4d Better handling of device initialisation, implemented more modes
Some checks failed
continuous-integration/drone/push Build is failing
2019-12-16 17:07:43 -08:00
2a67242f34 Removed some commented code from hubs 2019-12-16 12:13:41 -08:00
31ac93275c Motion and tilt sensor 2019-12-16 11:48:09 -08:00
81cbdac591 Merge branch 'feature/devices' of github.com:nathankellenicki/node-poweredup into feature/devices 2019-12-16 10:44:12 -08:00
198d637ef9 Renamed devices
Some checks failed
continuous-integration/drone/push Build is failing
2019-12-16 08:42:40 -08:00
6a7c4899b4 Added more motor types
All checks were successful
continuous-integration/drone/push Build is passing
2019-12-15 14:07:43 -08:00
77d99f6b39 More debug, ports property
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2019-12-13 22:41:03 +09:00
6beeda5df7 Implemented methods for retrieving hubs and devices 2019-12-11 17:20:35 +09:00
59179652dd Added more debug to investigate webbluetooth device attachment issues
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2019-12-11 13:28:39 +09:00
1793eb05e0 Removing commented code 2019-12-10 08:21:56 +09:00
5c03e5c3b6 More refactoring 2019-12-10 08:15:21 +09:00
7fdc754084 Start of hub refactor 2019-12-10 07:23:33 +09:00
e624efd067 Updated to fix security vulnerability in dependency 2019-12-08 23:03:51 -08:00
f9cea9a6bf Yay, port object is no longer a thing 2019-12-08 22:59:25 -08:00
a02249f696 Implemented basic lights, device busy-ness 2019-12-08 22:57:44 -08:00
d382c3d9f2 Basic ColorDistanceSensor and TachoMotor handling 2019-12-08 22:06:26 -08:00
93a1369e84 Basic code for passing messages through to the device 2019-12-08 18:07:46 -08:00
8ffc60b924 attachedDevices now a map 2019-12-07 13:19:16 -08:00
4af1d3d69b Added autosubscribe when adding eventlisteners 2019-12-06 17:31:12 -08:00
d453fe52fb Basic implementation of BasicMotor types 2019-12-06 11:31:56 -08:00
eb6b20adbb Version 5.0.0
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2019-12-03 23:13:27 -08:00
138e1cc041
Merge pull request #57 from nutki/pr-11
Control+ hub improvements
2019-12-03 22:57:40 -08:00
5a3211a560
Merge pull request #54 from aileo/attach
Emit attach event any case
2019-12-03 09:57:56 -08:00
0d076aa7e1
Merge pull request #52 from aileo/hub-disconnect
Add doc to hub's disconnect event
2019-12-03 09:56:56 -08:00
396765c8ea
Merge pull request #50 from nutki/pr-9
fixed address readout
2019-12-03 09:56:23 -08:00
Michal Szafranski
0e121a4f92 Control+ hub improvements 2019-11-24 10:53:16 +01:00
Leo Bonnargent
55bcafa637 Emit attach event any case 2019-11-20 14:42:23 +01:00
Leo Bonnargent
abd21a88b2 Add doc to hub's disconnect event 2019-11-18 09:14:32 +01:00
Michal Szafranski
31b8eb6ec8 fixed mac readout 2019-11-15 19:56:30 +01:00
Ben Rogers
0ebaecd1b4
Merge pull request #1 from nathankellenicki/master
Update local fork
2019-11-15 09:13:51 +00:00
984ae53213 Version 4.3.0
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2019-11-13 16:19:24 -08:00
1d885ff244
Merge pull request #48 from aileo/gethubbymac
Add PoweredUP#getConnectedHubByPrimaryMACAddress
2019-11-13 16:08:28 -08:00
e96b7bd47d Added RSSI back in, as reported by the hub 2019-11-13 16:05:23 -08:00
Leo Bonnargent
b88d282ae2 Add PoweredUP#getConnectedHubByPrimaryMACAddress 2019-11-14 00:26:43 +01:00
3a816b9f11 Refactered connection on lpf2hub 2019-11-13 15:04:05 -08:00
2482422302
Merge pull request #47 from aileo/macaddress
Add mac address to hub/lpf2hub
2019-11-13 14:41:59 -08:00
Leo Bonnargent
89ad6fe39b Use primaryMACAddress naming for consistency 2019-11-13 23:30:45 +01:00
Leo Bonnargent
655b21c0e9 Merge branch 'master' into macaddress 2019-11-13 23:26:02 +01:00
64e5743893
Merge pull request #45 from nutki/pr-8
Extended port information requests
2019-11-13 14:16:02 -08:00
70beaad4fa
Merge pull request #44 from nutki/pr-7
Voltage and current readout improvements
2019-11-13 14:14:54 -08:00
Michal Szafranski
49f43f5dff Unified 9.6 max voltage values 2019-11-13 22:49:29 +01:00
Michal Szafranski
e72f3f72f5 improved port information switching 2019-11-13 22:47:42 +01:00
Léo Bonnargent
1d575cf63c
code optimization from @nutki
Co-Authored-By: Michał Szafrański <szafranski@gmail.com>
2019-11-13 22:13:49 +01:00
Leo Bonnargent
7c23bd437f Better MAC address paring
- as per @dlech suggestion
2019-11-13 21:38:59 +01:00
Leo Bonnargent
e65c8eb71e Merge branch 'master' into macaddress 2019-11-13 21:27:04 +01:00
Leo Bonnargent
abbbd218ee Add mac address to hub/lpf2hub
- should close nathankellenicki/node-poweredup/issues/46
2019-11-13 20:58:20 +01:00
Michal Szafranski
5f13c98529 Moved toBin and toHex to utils 2019-11-12 20:41:18 +01:00
Michal Szafranski
3ab3f97122 report hw/sw versions for discovered devices 2019-11-12 09:09:02 +01:00
Michal Szafranski
a9fe059b3c Added missing device types 2019-11-12 09:08:37 +01:00
Michal Szafranski
8346988604 fix device type read regression 2019-11-12 09:07:46 +01:00
Michal Szafranski
522a8c2e23 Simplify enum name maps 2019-11-12 09:07:00 +01:00
Michal Szafranski
8e144c8311 more verbose port information output 2019-11-12 09:06:42 +01:00
Michal Szafranski
243d65699f Extended port information requests 2019-11-12 09:03:38 +01:00
Michal Szafranski
f43863bd51 typo in voltage value 2019-11-12 08:47:34 +01:00
Michal Szafranski
545e8ee177 remove unused _padMessage 2019-11-12 08:47:24 +01:00
Michal Szafranski
d2f71aa993 Voltage readout added for duplo train and fixed for PUP remote 2019-11-12 08:47:05 +01:00
0fbd27d41f Fixed bug with retrieving hardware versions
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2019-11-11 17:03:54 -08:00
7255c83ae9 Bumped version
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2019-11-11 11:28:30 -08:00
8ff0664641 Made Control+ tilt and accelerometer behave like normal devices 2019-11-11 11:16:49 -08:00
6315f54a23 Fixed double disconnect bug, added hardware versions
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2019-11-10 20:40:59 -08:00
fedc2bd6e4 Removed extraneous dependencies
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2019-11-10 17:44:03 -08:00
892d8bf37e Updated dependencies
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2019-11-10 16:56:47 -08:00
01cd067460 Bumped version
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2019-11-10 12:39:33 -08:00
4135f6e427 Merge branch 'master' of github.com:nathankellenicki/node-poweredup
All checks were successful
continuous-integration/drone/push Build is passing
2019-11-10 12:31:03 -08:00
c383f53025
Merge pull request #37 from nutki/pr-5
Fix ts 3.6.3 error
2019-11-10 12:30:57 -08:00
3dc1076a88
Merge pull request #36 from nutki/pr-4
allow switching to mode 0 in Hub.subscribe()
2019-11-10 12:30:40 -08:00
4e91e0d5a1 Merge branch 'master' of github.com:nathankellenicki/node-poweredup 2019-11-10 12:30:13 -08:00
73dd34449a
Merge pull request #35 from nutki/pr-3
Fix and simplify tilt sensor reading
2019-11-10 12:30:05 -08:00
491a8ab340 Merge branch 'pr-3' of github.com:nutki/node-poweredup 2019-11-10 12:26:57 -08:00
be132bd9e8
Merge pull request #34 from nutki/pr-2
allow case insensitive port names
2019-11-10 12:23:43 -08:00
2797081091
Merge pull request #33 from nutki/pr-1
allow RGB led control for the duplo train hub
2019-11-10 12:19:48 -08:00
e179be89fb Merge branch 'master' of github.com:nathankellenicki/node-poweredup
All checks were successful
continuous-integration/drone/push Build is passing
2019-11-10 12:15:31 -08:00
e3b65c07b6 Removed noble-mac dependency, fixed connection issues when manufacturerData doesn't exist 2019-11-10 12:15:26 -08:00
77c470f616
Merge pull request #31 from churchs19/master
Updating noble dependency to @abandonware/noble for Node >= 10.0 support
2019-11-10 12:14:39 -08:00
dc360be318 Merge branch 'master' of github.com:churchs19/node-poweredup 2019-11-10 11:36:44 -08:00
a610d0a35a
Merge pull request #40 from aileo/lmotor-42100
Add 42100 to Control+ Large Motor availability sets
2019-11-10 11:29:12 -08:00
a85b3d6ad2
Merge pull request #41 from nutki/pr-6
LPF2 firmware versions should be decoded with BCD
2019-11-10 11:28:57 -08:00
6d3aa19663
Merge pull request #42 from aileo/allow-import
Remove sources from npmignore
2019-11-10 11:26:57 -08:00
Leo Bonnargent
63e2552604 Remove sources from npmignore
allow to import the sources to be bundled with main app if needed
2019-11-09 11:41:16 +01:00
Michal Szafranski
172c1b826c Firmware version is encoded with BCD 2019-11-05 22:08:33 +01:00
Leo Bonnargent
ef73b3bde2 Add 42100 to Control+ Large Motor availability sets 2019-11-04 23:34:44 +01:00
Michal Szafranski
1e40bdd537 Fix setLEDColor regression 2019-11-03 14:44:44 +01:00
Michal Szafranski
00e6840c32 fix tilt sensor readout in wedo hub as well 2019-11-03 10:18:54 +01:00
Michal Szafranski
822d3da5d9 Fix ts error 2019-11-02 17:59:22 +01:00
Michal Szafranski
98f1ca84b0 allow switching to mode 0 2019-11-02 17:57:04 +01:00
Michal Szafranski
c7a5efcc78 Fix and simplify tilt sensor reading 2019-11-02 17:41:11 +01:00
Michal Szafranski
0b1c5008f3 allow case insensitive port names 2019-11-02 17:39:50 +01:00
Michal Szafranski
3bbca30296 undo version bump in package lock 2019-11-02 17:37:55 +01:00
Michal Szafranski
05daa648cb allow RGB led control for the duplo train hub 2019-11-02 17:29:46 +01:00
Shane Church
a1026547cf Reverted accidental formatting changes to wedo2smarthub.ts 2019-10-13 08:45:55 -05:00
Shane Church
e5bba46b80 Updated references to @abandonware/noble since noble is no longer maintained
Allows building on Node.js >= 10
2019-10-13 08:38:58 -05:00
Shane Church
41ca97e31a
Merge pull request #3 from nathankellenicki/master
Merge from base
2019-10-12 17:48:51 -05:00
9a9d3ee4d5 Fixed Technic Control+ hub when used with web bluetooth
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2019-08-09 10:18:20 -07:00
17a64c51dd Fixed web bluetooth
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2019-08-07 22:00:49 -07:00
732c3626b5 Added ability to reset absolute zero
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2019-08-07 13:22:57 -07:00
348037a2ab setAbsolutePosition on Control+ motors
All checks were successful
continuous-integration/drone/push Build is passing
2019-08-07 12:52:56 -07:00
6651b79188 Support for tilt, accel, temp on Control+ Hub
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2019-08-07 11:04:51 -07:00
373737ddaf Port info debug reporting
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2019-08-06 17:48:53 -07:00
cc1571dc26 Added initial support for LEGO Technic CONTROL+
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2019-08-06 14:52:14 -07:00
7b61b6981a Updated for latest Boost Move Hub firmware
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2019-08-02 21:11:31 -07:00
ac4bcbaca0 Security fixes
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2019-07-19 14:52:35 -07:00
46c4b4dacb Security fixes 2019-07-19 14:52:03 -07:00
e5bca563f7
Merge pull request #25 from nathankellenicki/dependabot/npm_and_yarn/lodash.mergewith-4.6.2
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
Bump lodash.mergewith from 4.6.1 to 4.6.2
2019-07-19 13:45:57 -07:00
dependabot[bot]
37d5ccc2e7
Bump lodash.mergewith from 4.6.1 to 4.6.2
Bumps [lodash.mergewith](https://github.com/lodash/lodash) from 4.6.1 to 4.6.2.
- [Release notes](https://github.com/lodash/lodash/releases)
- [Commits](https://github.com/lodash/lodash/commits)

Signed-off-by: dependabot[bot] <support@github.com>
2019-07-19 20:44:17 +00:00
b82ce97259 Updated dependencies, docs 2019-07-19 13:39:37 -07:00
b80023bb7f Bumped version
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone Build is passing
2019-04-25 21:57:48 -07:00
2c08e8b3ee Fixed typescript errors 2019-04-25 21:57:16 -07:00
a394882dcc Bumped version
Some checks failed
continuous-integration/drone Build is failing
continuous-integration/drone/push Build is failing
2019-04-25 21:49:41 -07:00
e959230a22 Correct voltage and current readings 2019-04-25 21:48:10 -07:00
7a647da798 Fixed disconnect bug
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone Build is passing
2019-04-25 15:32:07 -07:00
1dc583e5f2 Added current back
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone Build is passing
2019-04-25 14:25:10 -07:00
2e6d2b0dbc Library will now throw error if your firmware is too old
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone Build is passing
2019-04-15 10:46:32 -07:00
5ad9bc5748 Now supports PUP Hub firmware 1.1.00.0004 - rotation works on Boost tacho motor. Also manual setup of virtual ports.
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone Build is passing
2019-04-12 15:14:00 -07:00
8066824f90 Updated example
All checks were successful
continuous-integration/drone/push Build is passing
2019-04-04 14:39:14 -07:00
42f34269f2 Improved scanning in browser, added DualShock 4 browser example
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone Build is passing
2019-04-04 14:09:04 -07:00
Shane Church
4f21d3f63b
Merge pull request #2 from nathankellenicki/master
Merge from nathankellenicki/master
2019-02-05 09:39:29 -06:00
256 changed files with 98071 additions and 178241 deletions

View File

@ -1,14 +1,15 @@
pipeline: pipeline:
install: install:
image: node:10.15.1 image: node:20.12.2
commands: commands:
- apt-get update - apt-get update
- apt-get install -y bluetooth bluez libbluetooth-dev libudev-dev - apt-get install -y bluetooth bluez libbluetooth-dev libudev-dev
- git submodule update --init --recursive
- npm install - npm install
build: build:
image: node:10.15.1 image: node:20.12.2
commands: commands:
- npm run all - npm run all

1
.gitignore vendored
View File

@ -2,3 +2,4 @@ node_modules/
dist/ dist/
.vscode/ .vscode/
*.tgz *.tgz
**/.DS_store

0
.gitmodules vendored Normal file
View File

View File

@ -1,9 +1,15 @@
{ {
"tags": { "tags": {
"allowUnknownTags": true "allowUnknownTags": true,
"dictionaries": ["jsdoc"]
},
"source": {
"include": [ "README.md", "dist/node" ],
"includePattern": ".js$"
}, },
"plugins": ["plugins/markdown"], "plugins": ["plugins/markdown"],
"templates": { "templates": {
"referenceTitle": "node-poweredup Reference",
"logoFile": "", "logoFile": "",
"cleverLinks": false, "cleverLinks": false,
"monospaceLinks": false, "monospaceLinks": false,
@ -24,5 +30,11 @@
"markdown": { "markdown": {
"parser": "gfm", "parser": "gfm",
"hardwrap": true "hardwrap": true
},
"opts": {
"destination": "./docs/",
"encoding": "utf8",
"private": true,
"recurse": true
} }
} }

View File

@ -1,17 +1,5 @@
boostmovehub.ts
consts.ts
duplotrainbase.ts
hub.ts
index.ts
lpf2hub.ts
port.ts
poweredup.ts
puphub.ts
pupremote.ts
package-lock.json package-lock.json
tsconfig.json tsconfig.json
tslint.json tslint.json
utils.ts
wedo2smarthub.ts
.vscode/ .vscode/
examples/ examples/

152
README.md
View File

@ -1,66 +1,30 @@
[![Drone](https://drone.kellenicki.com/api/badges/nkellenicki/node-poweredup/status.svg)](https://drone.kellenicki.com/nkellenicki/node-poweredup) [![Drone](https://drone.kellenicki.com/api/badges/nkellenicki/node-poweredup/status.svg)](https://drone.kellenicki.com/nkellenicki/node-poweredup)
[![NPM Version](https://img.shields.io/npm/v/node-poweredup.svg?style=flat)](https://www.npmjs.com/package/node-poweredup) [![NPM Version](https://img.shields.io/npm/v/node-poweredup.svg?style=flat)](https://www.npmjs.com/package/node-poweredup)
[![Docs](https://img.shields.io/badge/docs-start%20here-yellowgreen.svg)](https://nathan.kellenicki.com/node-poweredup/)
# **node-poweredup** - A Javascript module to interface with LEGO Powered UP components. # **node-poweredup** - A Javascript module to interface with LEGO Powered Up components.
### Announcements
* v7.1.0 adds support for SPIKE Essential, including the Technic Small Hub, Technic Small Angular Motor, and Technic 3x3 Color Matrix.
### Introduction ### Introduction
LEGO Powered UP is the successor to Power Functions, the system for adding electronics to LEGO models. Powered UP is a collection of ranges - starting with LEGO WeDo 2.0 released in 2016, LEGO Boost released in 2017, and LEGO Powered UP released in 2018. It also includes the 2018 Duplo App-Controlled Train sets. LEGO Powered Up is the successor to Power Functions, the system for adding electronics to LEGO models. Powered Up is a collection of ranges, all of which are compatible with each other:
This library allows communication and control of Powered UP devices and peripherals via Javascript, both from Node.js and from the browser using Web Bluetooth. * LEGO Education WeDo 2.0
* LEGO Boost
* LEGO Powered Up
* LEGO Technic CONTROL+
* LEGO Education SPIKE Prime
* LEGO Education SPIKE Essential
* LEGO Mindstorms Robot Inventor
### Node.js Installation Other products that speak the Powered Up protocol include the Duplo App-Controlled trains and LEGO Super Mario, both of which are compatible with this library.
Node.js v8.0 required. This library allows communication and control of Powered Up devices and peripherals via Javascript, both from Node.js and from the browser using Web Bluetooth.
```javascript ### Sample Usage
npm install node-poweredup --save
```
node-poweredup uses the Noble BLE library by Sandeep Mistry. On macOS everything should function out of the box. On Linux and Windows there are [certain dependencies which may need installed first](https://github.com/noble/noble#prerequisites).
Note: node-poweredup has been tested on macOS 10.13 and Debian/Raspbian on the Raspberry Pi 3 Model B.
### Compatibility
While most Powered UP components and Hubs are compatible with each other, there are exceptions. For example, there is limited backwards compatibility between newer components and the WeDo 2.0 Smart Hub. However WeDo 2.0 components are fully forwards compatible with newer Hubs.
| Device Name | Product Code | Type | WeDo 2.0 Smart Hub | Boost Move Hub | Powered UP Hub | Availability |
| ------------------------------- | ------------ | ------------- | ------------------ | -------------- | -------------- | ------------ |
| WeDo 2.0 Tilt Sensor | <a href="https://brickset.com/sets/45305-1/">45305</a> | Sensor | Yes | Yes | Yes | <a href="https://brickset.com/sets/45300-1/">45300</a> |
| WeDo 2.0 Motion Sensor | <a href="https://brickset.com/sets/45304-1/">45304</a> | Sensor | Yes | Yes | Yes | <a href="https://brickset.com/sets/45300-1/">45300</a> |
| WeDo 2.0 Medium Motor | <a href="https://brickset.com/sets/45303-1/">45303</a> | Motor | Yes | Yes | Yes | <a href="https://brickset.com/sets/45300-1/">45300</a><br /> <a href="https://brickset.com/sets/76112-1/">76112</a> |
| Boost Color and Distance Sensor | <a href="https://brickset.com/sets/88007-1/">88007</a> | Sensor | *Partial* | Yes | Yes | <a href="https://brickset.com/sets/17101-1/">17101</a> |
| Boost Tacho Motor | <a href="https://brickset.com/sets/88008-1/">88008</a> | Motor/Sensor | *Partial* | Yes | *Partial* | <a href="https://brickset.com/sets/17101-1/">17101</a> |
| Powered UP Train Motor | <a href="https://brickset.com/sets/88011-1/">88011</a> | Motor | Yes | Yes | Yes | <a href="https://brickset.com/sets/60197-1/">60197</a><br /><a href="https://brickset.com/sets/60198-1/">60198</a> |
| Powered UP LED Lights | <a href="https://brickset.com/sets/88005-1/">88005</a> | Light | Yes | Yes | Yes | <a href="https://brickset.com/sets/88005-1/">88005</a> |
In addition, the Hubs themselves have certain built-in features which this library exposes.
| Hub Name | Product Code | Built-In Features | Availability |
| ------------------ | ------------ | ---------------------- | ------------ |
| WeDo 2.0 Smart hub | <a href="https://brickset.com/sets/45301-1/">45301</a> | RGB LED<br />Piezo Buzzer<br />Button | <a href="https://brickset.com/sets/45300-1/">45300</a> |
| Boost Move Hub | <a href="https://brickset.com/sets/88006-1/">88006</a> | RGB LED<br />Tilt Sensor<br />2x Tacho Motors<br />Button | <a href="https://brickset.com/sets/17101-1/">17101</a> |
| Powered UP Hub | <a href="https://brickset.com/sets/88009-1/">88009</a> | RGB LED<br />Button | <a href="https://brickset.com/sets/60197-1/">60197</a><br /><a href="https://brickset.com/sets/60198-1/">60198</a><br /><a href="https://brickset.com/sets/76112-1/">76112</a> |
| Powered UP Remote | <a href="https://brickset.com/sets/88010-1/">88010</a> | RGB LED<br />Left and Right Control Buttons<br />Button | <a href="https://brickset.com/sets/60197-1/">60197</a><br /><a href="https://brickset.com/sets/60198-1/">60198</a> |
| Duplo Train Base | 28743 | RGB LED/Headlights<br />Speaker<br />Speedometer<br />Motor<br />Color and Distance Sensor<br />Button | <a href="https://brickset.com/sets/10874-1/">10874</a><br /><a href="https://brickset.com/sets/10875-1/">10875</a> |
### Known Issues and Limitations
* The Boost Color and Distance sensor only works in color mode with the WeDo 2.0 Smart Hub.
* When used with the WeDo 2.0 Smart Hub, the Boost Tacho Motor does not support rotating the motor by angle.
* When used with the Powered UP Hub, the Boost Tacho Motor does not support rotating the motor by angle. It also does not support rotation detection.
* Plugging two Boost Tacho Motors into the Powered UP Hub will crash the Hub (This requires a firmware update from LEGO to fix).
### Documentation
[Full documentation is available here.](https://nathankellenicki.github.io/node-poweredup/)
### Node.js Sample Usage
```javascript ```javascript
const PoweredUP = require("node-poweredup"); const PoweredUP = require("node-poweredup");
@ -69,17 +33,22 @@ const poweredUP = new PoweredUP.PoweredUP();
poweredUP.on("discover", async (hub) => { // Wait to discover a Hub poweredUP.on("discover", async (hub) => { // Wait to discover a Hub
console.log(`Discovered ${hub.name}!`); console.log(`Discovered ${hub.name}!`);
await hub.connect(); // Connect to the Hub await hub.connect(); // Connect to the Hub
const motorA = await hub.waitForDeviceAtPort("A"); // Make sure a motor is plugged into port A
const motorB = await hub.waitForDeviceAtPort("B"); // Make sure a motor is plugged into port B
console.log("Connected"); console.log("Connected");
await hub.sleep(3000); // Sleep for 3 seconds before starting
while (true) { // Repeat indefinitely while (true) { // Repeat indefinitely
console.log("Running motor B at speed 75"); console.log("Running motor B at speed 50");
hub.setMotorSpeed("B", 75); // Start a motor attached to port B to run a 3/4 speed (75) indefinitely motorB.setPower(50); // Start a motor attached to port B to run a 3/4 speed (75) indefinitely
console.log("Running motor A at speed 100 for 2 seconds"); console.log("Running motor A at speed 100 for 2 seconds");
await hub.setMotorSpeed("A", 100, 2000); // Run a motor attached to port A for 2 seconds at maximum speed (100) then stop motorA.setPower(100); // Run a motor attached to port A for 2 seconds at maximum speed (100) then stop
await hub.sleep(2000);
motorA.brake();
await hub.sleep(1000); // Do nothing for 1 second await hub.sleep(1000); // Do nothing for 1 second
console.log("Running motor A at speed -50 for 1 seconds"); console.log("Running motor A at speed -30 for 1 second");
await hub.setMotorSpeed("A", -50, 1000); // Run a motor attached to port A for 1 second at 1/2 speed in reverse (-50) then stop motorA.setPower(-30); // Run a motor attached to port A for 2 seconds at 1/2 speed in reverse (-50) then stop
await hub.sleep(2000);
motorA.brake();
await hub.sleep(1000); // Do nothing for 1 second await hub.sleep(1000); // Do nothing for 1 second
} }
}); });
@ -90,7 +59,70 @@ console.log("Scanning for Hubs...");
More examples are available in the "examples" directory. More examples are available in the "examples" directory.
### Documentation
[Full documentation is available here.](https://nathankellenicki.github.io/node-poweredup/)
### Node.js Installation
Node.js v12.0+ required.
```javascript
npm install node-poweredup --save
```
node-poweredup uses the Noble BLE library by Sandeep Mistry. On macOS everything should function out of the box. On Linux and Windows there are [certain dependencies which may need installed first](https://github.com/abandonware/noble#prerequisites).
Note: node-poweredup has been tested on macOS 11.0 and Debian/Raspbian on the Raspberry Pi 3 Model B.
### Compatibility
While most Powered Up components and Hubs are compatible with each other, there are exceptions. For example, there is limited backwards compatibility between newer components and the WeDo 2.0 Smart Hub. However WeDo 2.0 components are fully forwards compatible with newer Hubs.
| Device Name | Product Code | Type | WeDo 2.0 Smart Hub | Boost Move Hub | Powered Up Hub | Control+ Hub | Availability |
| ------------------------------- | ------------ | ------------- | ------------------ | -------------- | -------------- | ------------ | ----- |
| WeDo 2.0 Tilt Sensor | <a href="https://brickset.com/sets/45305-1/">45305</a> | Sensor | Yes | Yes | Yes | Yes | <a href="https://brickset.com/sets/45300-1/">45300</a> |
| WeDo 2.0 Motion Sensor | <a href="https://brickset.com/sets/45304-1/">45304</a> | Sensor | Yes | Yes | Yes | Yes | <a href="https://brickset.com/sets/45300-1/">45300</a> |
| WeDo 2.0 Medium Motor | <a href="https://brickset.com/sets/45303-1/">45303</a> | Motor | Yes | Yes | Yes | Yes | <a href="https://brickset.com/sets/45300-1/">45300</a><br /> <a href="https://brickset.com/sets/76112-1/">76112</a> |
| Boost Color and Distance Sensor | <a href="https://brickset.com/sets/88007-1/">88007</a> | Sensor | *Partial* | Yes | Yes | Yes | <a href="https://brickset.com/sets/17101-1/">17101</a> |
| Boost Tacho Motor | <a href="https://brickset.com/sets/88008-1/">88008</a> | Motor/Sensor | *Partial* | Yes | Yes | Yes | <a href="https://brickset.com/sets/17101-1/">17101</a> |
| Powered Up Train Motor | <a href="https://brickset.com/sets/88011-1/">88011</a> | Motor | Yes | Yes | Yes | Yes | <a href="https://brickset.com/sets/60197-1/">60197</a><br /><a href="https://brickset.com/sets/60198-1/">60198</a> |
| 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* | 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> |
| SPIKE Essential Small Motor | 45607 | Motor/Sensor | *Partial* | No | Yes | Yes | <a href="https://brickset.com/sets/45345-1/">45345</a> |
| SPIKE Essential 3x3 Color Matrix | 45608 | Motor/Sensor | *Partial* | No | Yes | Yes | <a href="https://brickset.com/sets/45345-1/">45345</a> |
In addition, the Hubs themselves have certain built-in features which this library exposes.
| Hub Name | Product Code | Built-In Features | Availability |
| ------------------ | ------------ | ---------------------- | ------------ |
| WeDo 2.0 Smart hub | <a href="https://brickset.com/sets/45301-1/">45301</a> | RGB LED<br />Piezo Buzzer<br />Button | <a href="https://brickset.com/sets/45300-1/">45300</a> |
| Boost Move Hub | <a href="https://brickset.com/sets/88006-1/">88006</a> | RGB LED<br />Tilt Sensor<br />2x Tacho Motors<br />Button | <a href="https://brickset.com/sets/17101-1/">17101</a> |
| Powered Up Hub | <a href="https://brickset.com/sets/88009-1/">88009</a> | RGB LED<br />Button | <a href="https://brickset.com/sets/60197-1/">60197</a><br /><a href="https://brickset.com/sets/60198-1/">60198</a><br /><a href="https://brickset.com/sets/76112-1/">76112</a> |
| Powered Up Remote | <a href="https://brickset.com/sets/88010-1/">88010</a> | RGB LED<br />Left and Right Control Buttons<br />Button | <a href="https://brickset.com/sets/60197-1/">60197</a><br /><a href="https://brickset.com/sets/60198-1/">60198</a> |
| Duplo Train Base | 28743 | RGB LED/Headlights<br />Speaker<br />Speedometer<br />Motor<br />Color and Distance Sensor<br />Button | <a href="https://brickset.com/sets/10874-1/">10874</a><br /><a href="https://brickset.com/sets/10875-1/">10875</a> |
| Control+ Hub | 22127 | RGB LED<br />Button<br />Tilt Sensor<br />Accelerometer | <a href="https://brickset.com/sets/42099-1/">42099</a><br /><a href="https://brickset.com/sets/42100-1/">42100</a> |
| Super Mario | 71360 | Pants Sensor<br />Barcode and Color Sensor | <a href="https://brickset.com/sets/71360-1/">71360</a> |
| SPIKE Essential Hub | 45609 | RGB LED<br />Button<br />Tilt Sensor<br />Accelerometer | <a href="https://brickset.com/sets/45345-1/">45345</a> |
### Known Issues and Limitations
* 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 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 to develop for this Hub using the officially provided tools and software. The SPIKE Essential Hub however is supported, as it uses Bluetooth Low Energy.
* On most Unix systems, you need root permissions to access Bluetooth devices. You may want to [grant the node executable access to the Bluetooth adapter](https://github.com/abandonware/noble#running-without-rootsudo-linux-specific)
### Credits ### Credits
Thanks go to Jorge Pereira ([@JorgePe](https://github.com/JorgePe)), Sebastian Raff ([@hobbyquaker](https://github.com/hobbyquaker)), Valentin Heun ([@vheun](https://github.com/vheun)), Johan Korten ([@jakorten](https://github.com/jakorten)), and Andrey Pokhilko ([@undera](https://github.com/undera)) for their various works, contributions, and assistance on figuring out the LEGO Boost, WeDo 2.0, and Powered UP protocols. Thanks go to Jorge Pereira ([@JorgePe](https://github.com/JorgePe)), Sebastian Raff ([@hobbyquaker](https://github.com/hobbyquaker)), Valentin Heun ([@vheun](https://github.com/vheun)), Johan Korten ([@jakorten](https://github.com/jakorten)), and Andrey Pokhilko ([@undera](https://github.com/undera)) for their various works, contributions, and assistance on figuring out the LEGO Boost, WeDo 2.0, and Powered Up protocols.

129
abandonware-noble.d.ts vendored Normal file
View File

@ -0,0 +1,129 @@
declare module "@abandonware/noble" {
// Type definitions for noble
// Project: https://github.com/sandeepmistry/noble
// Definitions by: Seon-Wook Park <https://github.com/swook>
// Shantanu Bhadoria <https://github.com/shantanubhadoria>
// Luke Libraro <https://github.com/lukel99>
// Dan Chao <https://github.com/bioball>
// Michal Lower <https://github.com/keton>
// Rob Moran <https://github.com/thegecko>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference types="node" />
import events = require("events");
export function startScanning(callback?: (error?: Error) => void): void;
export function startScanning(serviceUUIDs: string[], callback?: (error?: Error) => void): void;
export function startScanning(serviceUUIDs: string[], allowDuplicates: boolean, callback?: (error?: Error) => void): void;
export function stopScanning(callback?: () => void): void;
export function on(event: "stateChange", listener: (state: string) => void): events.EventEmitter;
export function on(event: "scanStart", listener: () => void): events.EventEmitter;
export function on(event: "scanStop", listener: () => void): events.EventEmitter;
export function on(event: "discover", listener: (peripheral: Peripheral) => void): events.EventEmitter;
export function on(event: string, listener: Function): events.EventEmitter;
export function removeListener(event: "stateChange", listener: (state: string) => void): events.EventEmitter;
export function removeListener(event: "scanStart", listener: () => void): events.EventEmitter;
export function removeListener(event: "scanStop", listener: () => void): events.EventEmitter;
export function removeListener(event: "discover", listener: (peripheral: Peripheral) => void): events.EventEmitter;
export function removeListener(event: string, listener: Function): events.EventEmitter;
export var state:string;
export class Peripheral extends events.EventEmitter {
id: string;
uuid: string;
address: string;
addressType: string;
connectable: boolean;
advertisement: Advertisement;
rssi: number;
services: Service[];
state: 'error' | 'connecting' | 'connected' | 'disconnecting' | 'disconnected';
connect(callback?: (error: string) => void): void;
disconnect(callback?: () => void): void;
updateRssi(callback?: (error: string, rssi: number) => void): void;
discoverServices(serviceUUIDs: string[], callback?: (error: string, services: Service[]) => void): void;
discoverAllServicesAndCharacteristics(callback?: (error: string, services: Service[], characteristics: Characteristic[]) => void): void;
discoverSomeServicesAndCharacteristics(serviceUUIDs: string[], characteristicUUIDs: string[], callback?: (error: string, services: Service[], characteristics: Characteristic[]) => void): void;
readHandle(handle: Buffer, callback: (error: string, data: Buffer) => void): void;
writeHandle(handle: Buffer, data: Buffer, withoutResponse: boolean, callback: (error: string) => void): void;
toString(): string;
on(event: "connect", listener: (error: string) => void): this;
on(event: "disconnect", listener: (error: string) => void): this;
on(event: "rssiUpdate", listener: (rssi: number) => void): this;
on(event: "servicesDiscover", listener: (services: Service[]) => void): this;
on(event: string, listener: Function): this;
}
export interface Advertisement {
localName: string;
serviceData: {
uuid: string,
data: Buffer
};
txPowerLevel: number;
manufacturerData: Buffer;
serviceUuids: string[];
}
export class Service extends events.EventEmitter {
uuid: string;
name: string;
type: string;
includedServiceUuids: string[];
characteristics: Characteristic[];
discoverIncludedServices(serviceUUIDs: string[], callback?: (error: string, includedServiceUuids: string[]) => void): void;
discoverCharacteristics(characteristicUUIDs: string[], callback?: (error: string, characteristics: Characteristic[]) => void): void;
toString(): string;
on(event: "includedServicesDiscover", listener: (includedServiceUuids: string[]) => void): this;
on(event: "characteristicsDiscover", listener: (characteristics: Characteristic[]) => void): this;
on(event: string, listener: Function): this;
}
export class Characteristic extends events.EventEmitter {
uuid: string;
name: string;
type: string;
properties: string[];
descriptors: Descriptor[];
read(callback?: (error: string, data: Buffer) => void): void;
write(data: Buffer, notify: boolean, callback?: (error: string) => void): void;
broadcast(broadcast: boolean, callback?: (error: string) => void): void;
notify(notify: boolean, callback?: (error: string) => void): void;
discoverDescriptors(callback?: (error: string, descriptors: Descriptor[]) => void): void;
toString(): string;
subscribe(callback?: (error: string) => void): void;
unsubscribe(callback?: (error: string) => void): void;
on(event: "read", listener: (data: Buffer, isNotification: boolean) => void): this;
on(event: "write", withoutResponse: boolean, listener: (error: string) => void): this;
on(event: "broadcast", listener: (state: string) => void): this;
on(event: "notify", listener: (state: string) => void): this;
on(event: "descriptorsDiscover", listener: (descriptors: Descriptor[]) => void): this;
on(event: string, listener: Function): this;
on(event: string, option: boolean, listener: Function): this;
}
export class Descriptor extends events.EventEmitter {
uuid: string;
name: string;
type: string;
readValue(callback?: (error: string, data: Buffer) => void): void;
writeValue(data: Buffer, callback?: (error: string) => void): void;
toString(): string;
on(event: "valueRead", listener: (error: string, data: Buffer) => void): this;
on(event: "valueWrite", listener: (error: string) => void): this;
on(event: string, listener: Function): this;
}
}

2008
docs/AbsoluteMotor.html Normal file

File diff suppressed because one or more lines are too long

1391
docs/BaseHub.html Normal file

File diff suppressed because one or more lines are too long

1459
docs/BasicMotor.html Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

1022
docs/CurrentSensor.html Normal file

File diff suppressed because one or more lines are too long

841
docs/Device.html Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

1239
docs/HubLED.html Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

1239
docs/Light.html Normal file

File diff suppressed because one or more lines are too long

2092
docs/Mario.html Normal file

File diff suppressed because one or more lines are too long

1215
docs/MarioAccelerometer.html Normal file

File diff suppressed because one or more lines are too long

1215
docs/MarioBarcodeSensor.html Normal file

File diff suppressed because one or more lines are too long

1022
docs/MarioPantsSensor.html Normal file

File diff suppressed because one or more lines are too long

1357
docs/MediumLinearMotor.html Normal file

File diff suppressed because one or more lines are too long

1022
docs/MotionSensor.html Normal file

File diff suppressed because one or more lines are too long

2092
docs/MoveHub.html Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

1045
docs/MoveHubTiltSensor.html Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

1057
docs/PiezoBuzzer.html Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

2092
docs/RemoteControl.html Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

2620
docs/TachoMotor.html Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

1525
docs/TechnicColorSensor.html Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

1316
docs/TechnicForceSensor.html Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

2092
docs/TechnicMediumHub.html Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

1045
docs/TiltSensor.html Normal file

File diff suppressed because one or more lines are too long

1479
docs/TrainMotor.html Normal file

File diff suppressed because one or more lines are too long

1022
docs/VoltageSensor.html Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,445 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>node-poweredup Source: boostmovehub.js</title>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/sunlight.default.css">
<link type="text/css" rel="stylesheet" href="styles/site.simplex.css">
</head>
<body>
<div class="navbar navbar-default navbar-fixed-top navbar-inverse">
<div class="container">
<div class="navbar-header">
<a class="navbar-brand" href="index.html">node-poweredup</a>
<button class="navbar-toggle" type="button" data-toggle="collapse" data-target="#topNavigation">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<div class="navbar-collapse collapse" id="topNavigation">
<ul class="nav navbar-nav">
<li class="dropdown">
<a href="classes.list.html" class="dropdown-toggle" data-toggle="dropdown">Classes<b class="caret"></b></a>
<ul class="dropdown-menu ">
<li><a href="BoostMoveHub.html">BoostMoveHub</a></li><li><a href="DuploTrainBase.html">DuploTrainBase</a></li><li><a href="Hub.html">Hub</a></li><li><a href="LPF2Hub.html">LPF2Hub</a></li><li><a href="PoweredUP.html">PoweredUP</a></li><li><a href="PUPHub.html">PUPHub</a></li><li><a href="PUPRemote.html">PUPRemote</a></li><li><a href="WeDo2SmartHub.html">WeDo2SmartHub</a></li>
</ul>
</li>
<li class="dropdown">
<a href="events.list.html" class="dropdown-toggle" data-toggle="dropdown">Events<b class="caret"></b></a>
<ul class="dropdown-menu ">
<li><a href="BoostMoveHub.html#event:attach">BoostMoveHub#event:attach</a></li><li><a href="BoostMoveHub.html#event:button">BoostMoveHub#event:button</a></li><li><a href="BoostMoveHub.html#event:color">BoostMoveHub#event:color</a></li><li><a href="BoostMoveHub.html#event:colorAndDistance">BoostMoveHub#event:colorAndDistance</a></li><li><a href="BoostMoveHub.html#event:detach">BoostMoveHub#event:detach</a></li><li><a href="BoostMoveHub.html#event:distance">BoostMoveHub#event:distance</a></li><li><a href="BoostMoveHub.html#event:rotate">BoostMoveHub#event:rotate</a></li><li><a href="BoostMoveHub.html#event:tilt">BoostMoveHub#event:tilt</a></li><li><a href="DuploTrainBase.html#event:color">DuploTrainBase#event:color</a></li><li><a href="DuploTrainBase.html#event:speed">DuploTrainBase#event:speed</a></li><li><a href="Hub.html#event:attach">Hub#event:attach</a></li><li><a href="Hub.html#event:detach">Hub#event:detach</a></li><li><a href="LPF2Hub.html#event:attach">LPF2Hub#event:attach</a></li><li><a href="LPF2Hub.html#event:button">LPF2Hub#event:button</a></li><li><a href="LPF2Hub.html#event:color">LPF2Hub#event:color</a></li><li><a href="LPF2Hub.html#event:colorAndDistance">LPF2Hub#event:colorAndDistance</a></li><li><a href="LPF2Hub.html#event:detach">LPF2Hub#event:detach</a></li><li><a href="LPF2Hub.html#event:distance">LPF2Hub#event:distance</a></li><li><a href="LPF2Hub.html#event:rotate">LPF2Hub#event:rotate</a></li><li><a href="LPF2Hub.html#event:speed">LPF2Hub#event:speed</a></li><li><a href="LPF2Hub.html#event:tilt">LPF2Hub#event:tilt</a></li><li><a href="PoweredUP.html#event:discover">PoweredUP#event:discover</a></li><li><a href="PUPHub.html#event:attach">PUPHub#event:attach</a></li><li><a href="PUPHub.html#event:button">PUPHub#event:button</a></li><li><a href="PUPHub.html#event:color">PUPHub#event:color</a></li><li><a href="PUPHub.html#event:colorAndDistance">PUPHub#event:colorAndDistance</a></li><li><a href="PUPHub.html#event:detach">PUPHub#event:detach</a></li><li><a href="PUPHub.html#event:distance">PUPHub#event:distance</a></li><li><a href="PUPHub.html#event:tilt">PUPHub#event:tilt</a></li><li><a href="PUPRemote.html#event:button">PUPRemote#event:button</a></li><li><a href="PUPRemote.html#event:colorAndDistance">PUPRemote#event:colorAndDistance</a></li><li><a href="WeDo2SmartHub.html#event:attach">WeDo2SmartHub#event:attach</a></li><li><a href="WeDo2SmartHub.html#event:button">WeDo2SmartHub#event:button</a></li><li><a href="WeDo2SmartHub.html#event:color">WeDo2SmartHub#event:color</a></li><li><a href="WeDo2SmartHub.html#event:detach">WeDo2SmartHub#event:detach</a></li><li><a href="WeDo2SmartHub.html#event:distance">WeDo2SmartHub#event:distance</a></li><li><a href="WeDo2SmartHub.html#event:rotate">WeDo2SmartHub#event:rotate</a></li><li><a href="WeDo2SmartHub.html#event:tilt">WeDo2SmartHub#event:tilt</a></li>
</ul>
</li>
<li class="dropdown">
<a href="global.html" class="dropdown-toggle" data-toggle="dropdown">Global<b class="caret"></b></a>
<ul class="dropdown-menu ">
<li><a href="global.html">Global</a></li>
</ul>
</li>
</ul>
<div class="col-sm-3 col-md-3">
<form class="navbar-form" role="search">
<div class="input-group">
<input type="text" class="form-control" placeholder="Search" name="q" id="search-input">
<div class="input-group-btn">
<button class="btn btn-default" id="search-submit"><i class="glyphicon glyphicon-search"></i></button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
<div class="container" id="toc-content">
<div class="row">
<div class="col-md-12">
<div id="main">
<h1 class="page-title">Source: boostmovehub.js</h1>
<section>
<article>
<pre
class="sunlight-highlight-javascript linenums">"use strict";
var __importStar = (this &amp;&amp; this.__importStar) || function (mod) {
if (mod &amp;&amp; mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const lpf2hub_1 = require("./lpf2hub");
const port_1 = require("./port");
const Consts = __importStar(require("./consts"));
const Debug = require("debug");
const debug = Debug("boostmovehub");
/**
* The BoostMoveHub is emitted if the discovered device is a Boost Move Hub.
* @class BoostMoveHub
* @extends LPF2Hub
* @extends Hub
*/
class BoostMoveHub extends lpf2hub_1.LPF2Hub {
// We set JSDoc to ignore these events as a Boost Move Hub will never emit them.
/**
* @event BoostMoveHub#speed
* @ignore
*/
static IsBoostMoveHub(peripheral) {
return (peripheral.advertisement &amp;&amp;
peripheral.advertisement.serviceUuids &amp;&amp;
peripheral.advertisement.serviceUuids.indexOf(Consts.BLEService.LPF2_HUB.replace(/-/g, "")) >= 0 &amp;&amp; peripheral.advertisement.manufacturerData[3] === Consts.BLEManufacturerData.BOOST_MOVE_HUB_ID);
}
constructor(device, autoSubscribe = true) {
super(device, autoSubscribe);
this.type = Consts.HubType.BOOST_MOVE_HUB;
this._ports = {
"A": new port_1.Port("A", 55),
"B": new port_1.Port("B", 56),
"AB": new port_1.Port("AB", 57),
"TILT": new port_1.Port("TILT", 58),
"C": new port_1.Port("C", 1),
"D": new port_1.Port("D", 2)
};
debug("Discovered Boost Move Hub");
}
connect() {
return new Promise(async (resolve, reject) => {
debug("Connecting to Boost Move Hub");
await super.connect();
debug("Connect completed");
return resolve();
});
}
/**
* Set the motor speed on a given port.
* @method BoostMoveHub#setMotorSpeed
* @param {string} port
* @param {number | Array.&lt;number>} speed For forward, a value between 1 - 100 should be set. For reverse, a value between -1 to -100. Stop is 0. If you are specifying port AB to control both motors, you can optionally supply a tuple of speeds.
* @param {number} [time] How long to activate the motor for (in milliseconds). Leave empty to turn the motor on indefinitely.
* @returns {Promise} Resolved upon successful completion of command. If time is specified, this is once the motor is finished.
*/
setMotorSpeed(port, speed, time) {
const portObj = this._portLookup(port);
if (portObj.id !== "AB" &amp;&amp; speed instanceof Array) {
throw new Error(`Port ${portObj.id} can only accept a single speed`);
}
let cancelEventTimer = true;
if (typeof time === "boolean") {
if (time === true) {
cancelEventTimer = false;
}
time = undefined;
}
if (cancelEventTimer) {
portObj.cancelEventTimer();
}
return new Promise((resolve, reject) => {
if (time &amp;&amp; typeof time === "number") {
if (portObj.type === Consts.DeviceType.BOOST_TACHO_MOTOR || portObj.type === Consts.DeviceType.BOOST_MOVE_HUB_MOTOR) {
portObj.busy = true;
let data = null;
if (portObj.id === "AB") {
data = Buffer.from([0x81, portObj.value, 0x11, 0x0a, 0x00, 0x00, this._mapSpeed(speed instanceof Array ? speed[0] : speed), this._mapSpeed(speed instanceof Array ? speed[1] : speed), 0x64, 0x7f, 0x03]);
}
else {
// @ts-ignore: The type of speed is properly checked at the start
data = Buffer.from([0x81, portObj.value, 0x11, 0x09, 0x00, 0x00, this._mapSpeed(speed), 0x64, 0x7f, 0x03]);
}
data.writeUInt16LE(time > 65535 ? 65535 : time, 4);
this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, data);
portObj.finished = () => {
return resolve();
};
}
else {
// @ts-ignore: The type of speed is properly checked at the start
const data = Buffer.from([0x81, portObj.value, 0x11, 0x51, 0x00, this._mapSpeed(speed)]);
this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, data);
const timeout = global.setTimeout(() => {
const data = Buffer.from([0x81, portObj.value, 0x11, 0x51, 0x00, 0x00]);
this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, data);
return resolve();
// @ts-ignore: The type of time is properly checked at the start
}, time);
portObj.setEventTimer(timeout);
}
}
else {
if (portObj.type === Consts.DeviceType.BOOST_TACHO_MOTOR || portObj.type === Consts.DeviceType.BOOST_MOVE_HUB_MOTOR) {
portObj.busy = true;
let data = null;
if (portObj.id === "AB") {
data = Buffer.from([0x81, portObj.value, 0x11, 0x02, this._mapSpeed(speed instanceof Array ? speed[0] : speed), this._mapSpeed(speed instanceof Array ? speed[1] : speed), 0x64, 0x7f, 0x03]);
}
else {
// @ts-ignore: The type of speed is properly checked at the start
data = Buffer.from([0x81, portObj.value, 0x11, 0x01, this._mapSpeed(speed), 0x64, 0x7f, 0x03]);
}
this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, data);
portObj.finished = () => {
return resolve();
};
}
else {
// @ts-ignore: The type of speed is properly checked at the start
const data = Buffer.from([0x81, portObj.value, 0x11, 0x51, 0x00, this._mapSpeed(speed)]);
this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, data);
}
}
});
}
/**
* Ramp the motor speed on a given port.
* @method BoostMoveHub#rampMotorSpeed
* @param {string} port
* @param {number} fromSpeed For forward, a value between 1 - 100 should be set. For reverse, a value between -1 to -100. Stop is 0.
* @param {number} toSpeed For forward, a value between 1 - 100 should be set. For reverse, a value between -1 to -100. Stop is 0.
* @param {number} time How long the ramp should last (in milliseconds).
* @returns {Promise} Resolved upon successful completion of command.
*/
rampMotorSpeed(port, fromSpeed, toSpeed, time) {
const portObj = this._portLookup(port);
portObj.cancelEventTimer();
return new Promise((resolve, reject) => {
this._calculateRamp(fromSpeed, toSpeed, time, portObj)
.on("changeSpeed", (speed) => {
this.setMotorSpeed(port, speed, true);
})
.on("finished", resolve);
});
}
/**
* Rotate a motor by a given angle.
* @method BoostMoveHub#setMotorAngle
* @param {string} port
* @param {number} angle How much the motor should be rotated (in degrees).
* @param {number | Array.&lt;number>} [speed=100] For forward, a value between 1 - 100 should be set. For reverse, a value between -1 to -100. Stop is 0. If you are specifying port AB to control both motors, you can optionally supply a tuple of speeds.
* @returns {Promise} Resolved upon successful completion of command (ie. once the motor is finished).
*/
setMotorAngle(port, angle, speed = 100) {
const portObj = this._portLookup(port);
if (!(portObj.type === Consts.DeviceType.BOOST_TACHO_MOTOR || portObj.type === Consts.DeviceType.BOOST_MOVE_HUB_MOTOR)) {
throw new Error("Angle rotation is only available when using a Boost Tacho Motor or Boost Move Hub Motor");
}
if (portObj.id !== "AB" &amp;&amp; speed instanceof Array) {
throw new Error(`Port ${portObj.id} can only accept a single speed`);
}
portObj.cancelEventTimer();
return new Promise((resolve, reject) => {
portObj.busy = true;
let data = null;
if (portObj.id === "AB") {
data = Buffer.from([0x81, portObj.value, 0x11, 0x0c, 0x00, 0x00, 0x00, 0x00, this._mapSpeed(speed instanceof Array ? speed[0] : speed), this._mapSpeed(speed instanceof Array ? speed[1] : speed), 0x64, 0x7f, 0x03]);
}
else {
// @ts-ignore: The type of speed is properly checked at the start
data = Buffer.from([0x81, portObj.value, 0x11, 0x0b, 0x00, 0x00, 0x00, 0x00, this._mapSpeed(speed), 0x64, 0x7f, 0x03]);
}
data.writeUInt32LE(angle, 4);
this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, data);
portObj.finished = () => {
return resolve();
};
});
}
/**
* Fully (hard) stop the motor on a given port.
* @method BoostMoveHub#brakeMotor
* @param {string} port
* @returns {Promise} Resolved upon successful completion of command.
*/
brakeMotor(port) {
return this.setMotorSpeed(port, 127);
}
/**
* Set the light brightness on a given port.
* @method BoostMoveHub#setLightBrightness
* @param {string} port
* @param {number} brightness Brightness value between 0-100 (0 is off)
* @param {number} [time] How long to turn the light on (in milliseconds). Leave empty to turn the light on indefinitely.
* @returns {Promise} Resolved upon successful completion of command. If time is specified, this is once the light is turned off.
*/
setLightBrightness(port, brightness, time) {
const portObj = this._portLookup(port);
portObj.cancelEventTimer();
return new Promise((resolve, reject) => {
const data = Buffer.from([0x81, portObj.value, 0x11, 0x51, 0x00, brightness]);
this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, data);
if (time) {
const timeout = global.setTimeout(() => {
const data = Buffer.from([0x81, portObj.value, 0x11, 0x51, 0x00, 0x00]);
this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, data);
return resolve();
}, time);
portObj.setEventTimer(timeout);
}
else {
return resolve();
}
});
}
}
exports.BoostMoveHub = BoostMoveHub;
//# sourceMappingURL=boostmovehub.js.map</pre>
</article>
</section>
</div>
</div>
<div class="clearfix"></div>
</div>
</div>
<div class="modal fade" id="searchResults">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title">Search results</h4>
</div>
<div class="modal-body"></div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div>
<footer>
<span class="copyright">
node-poweredup by Nathan Kellenicki licensed under the MIT license.
</span>
<span class="jsdoc-message">
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a>
on Wed Mar 20th 2019
using the <a href="https://github.com/docstrap/docstrap">DocStrap template</a>.
</span>
</footer>
<script src="scripts/docstrap.lib.js"></script>
<script src="scripts/toc.js"></script>
<script type="text/javascript" src="scripts/fulltext-search-ui.js"></script>
<script>
$( function () {
$( "[id*='$']" ).each( function () {
var $this = $( this );
$this.attr( "id", $this.attr( "id" ).replace( "$", "__" ) );
} );
$( ".tutorial-section pre, .readme-section pre, pre.prettyprint.source" ).each( function () {
var $this = $( this );
var example = $this.find( "code" );
exampleText = example.html();
var lang = /{@lang (.*?)}/.exec( exampleText );
if ( lang && lang[1] ) {
exampleText = exampleText.replace( lang[0], "" );
example.html( exampleText );
lang = lang[1];
} else {
var langClassMatch = example.parent()[0].className.match(/lang\-(\S+)/);
lang = langClassMatch ? langClassMatch[1] : "javascript";
}
if ( lang ) {
$this
.addClass( "sunlight-highlight-" + lang )
.addClass( "linenums" )
.html( example.html() );
}
} );
Sunlight.highlightAll( {
lineNumbers : true,
showMenu : true,
enableDoclinks : true
} );
$.catchAnchorLinks( {
navbarOffset: 10
} );
$( "#toc" ).toc( {
anchorName : function ( i, heading, prefix ) {
return $( heading ).attr( "id" ) || ( prefix + i );
},
selectors : "#toc-content h1,#toc-content h2,#toc-content h3,#toc-content h4",
showAndHide : false,
smoothScrolling: true
} );
$( "#main span[id^='toc']" ).addClass( "toc-shim" );
$( '.dropdown-toggle' ).dropdown();
$( "table" ).each( function () {
var $this = $( this );
$this.addClass('table');
} );
} );
</script>
<!--Navigation and Symbol Display-->
<!--Google Analytics-->
<script type="text/javascript">
$(document).ready(function() {
SearcherDisplay.init();
});
</script>
</body>
</html>

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

239
docs/devices_device.js.html Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

137
docs/devices_hubled.js.html Normal file

File diff suppressed because one or more lines are too long

123
docs/devices_light.js.html Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,394 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>node-poweredup Source: duplotrainbase.js</title>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/sunlight.default.css">
<link type="text/css" rel="stylesheet" href="styles/site.simplex.css">
</head>
<body>
<div class="navbar navbar-default navbar-fixed-top navbar-inverse">
<div class="container">
<div class="navbar-header">
<a class="navbar-brand" href="index.html">node-poweredup</a>
<button class="navbar-toggle" type="button" data-toggle="collapse" data-target="#topNavigation">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<div class="navbar-collapse collapse" id="topNavigation">
<ul class="nav navbar-nav">
<li class="dropdown">
<a href="classes.list.html" class="dropdown-toggle" data-toggle="dropdown">Classes<b class="caret"></b></a>
<ul class="dropdown-menu ">
<li><a href="BoostMoveHub.html">BoostMoveHub</a></li><li><a href="DuploTrainBase.html">DuploTrainBase</a></li><li><a href="Hub.html">Hub</a></li><li><a href="LPF2Hub.html">LPF2Hub</a></li><li><a href="PoweredUP.html">PoweredUP</a></li><li><a href="PUPHub.html">PUPHub</a></li><li><a href="PUPRemote.html">PUPRemote</a></li><li><a href="WeDo2SmartHub.html">WeDo2SmartHub</a></li>
</ul>
</li>
<li class="dropdown">
<a href="events.list.html" class="dropdown-toggle" data-toggle="dropdown">Events<b class="caret"></b></a>
<ul class="dropdown-menu ">
<li><a href="BoostMoveHub.html#event:attach">BoostMoveHub#event:attach</a></li><li><a href="BoostMoveHub.html#event:button">BoostMoveHub#event:button</a></li><li><a href="BoostMoveHub.html#event:color">BoostMoveHub#event:color</a></li><li><a href="BoostMoveHub.html#event:colorAndDistance">BoostMoveHub#event:colorAndDistance</a></li><li><a href="BoostMoveHub.html#event:detach">BoostMoveHub#event:detach</a></li><li><a href="BoostMoveHub.html#event:distance">BoostMoveHub#event:distance</a></li><li><a href="BoostMoveHub.html#event:rotate">BoostMoveHub#event:rotate</a></li><li><a href="BoostMoveHub.html#event:tilt">BoostMoveHub#event:tilt</a></li><li><a href="DuploTrainBase.html#event:color">DuploTrainBase#event:color</a></li><li><a href="DuploTrainBase.html#event:speed">DuploTrainBase#event:speed</a></li><li><a href="Hub.html#event:attach">Hub#event:attach</a></li><li><a href="Hub.html#event:detach">Hub#event:detach</a></li><li><a href="LPF2Hub.html#event:attach">LPF2Hub#event:attach</a></li><li><a href="LPF2Hub.html#event:button">LPF2Hub#event:button</a></li><li><a href="LPF2Hub.html#event:color">LPF2Hub#event:color</a></li><li><a href="LPF2Hub.html#event:colorAndDistance">LPF2Hub#event:colorAndDistance</a></li><li><a href="LPF2Hub.html#event:detach">LPF2Hub#event:detach</a></li><li><a href="LPF2Hub.html#event:distance">LPF2Hub#event:distance</a></li><li><a href="LPF2Hub.html#event:rotate">LPF2Hub#event:rotate</a></li><li><a href="LPF2Hub.html#event:speed">LPF2Hub#event:speed</a></li><li><a href="LPF2Hub.html#event:tilt">LPF2Hub#event:tilt</a></li><li><a href="PoweredUP.html#event:discover">PoweredUP#event:discover</a></li><li><a href="PUPHub.html#event:attach">PUPHub#event:attach</a></li><li><a href="PUPHub.html#event:button">PUPHub#event:button</a></li><li><a href="PUPHub.html#event:color">PUPHub#event:color</a></li><li><a href="PUPHub.html#event:colorAndDistance">PUPHub#event:colorAndDistance</a></li><li><a href="PUPHub.html#event:detach">PUPHub#event:detach</a></li><li><a href="PUPHub.html#event:distance">PUPHub#event:distance</a></li><li><a href="PUPHub.html#event:tilt">PUPHub#event:tilt</a></li><li><a href="PUPRemote.html#event:button">PUPRemote#event:button</a></li><li><a href="PUPRemote.html#event:colorAndDistance">PUPRemote#event:colorAndDistance</a></li><li><a href="WeDo2SmartHub.html#event:attach">WeDo2SmartHub#event:attach</a></li><li><a href="WeDo2SmartHub.html#event:button">WeDo2SmartHub#event:button</a></li><li><a href="WeDo2SmartHub.html#event:color">WeDo2SmartHub#event:color</a></li><li><a href="WeDo2SmartHub.html#event:detach">WeDo2SmartHub#event:detach</a></li><li><a href="WeDo2SmartHub.html#event:distance">WeDo2SmartHub#event:distance</a></li><li><a href="WeDo2SmartHub.html#event:rotate">WeDo2SmartHub#event:rotate</a></li><li><a href="WeDo2SmartHub.html#event:tilt">WeDo2SmartHub#event:tilt</a></li>
</ul>
</li>
<li class="dropdown">
<a href="global.html" class="dropdown-toggle" data-toggle="dropdown">Global<b class="caret"></b></a>
<ul class="dropdown-menu ">
<li><a href="global.html">Global</a></li>
</ul>
</li>
</ul>
<div class="col-sm-3 col-md-3">
<form class="navbar-form" role="search">
<div class="input-group">
<input type="text" class="form-control" placeholder="Search" name="q" id="search-input">
<div class="input-group-btn">
<button class="btn btn-default" id="search-submit"><i class="glyphicon glyphicon-search"></i></button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
<div class="container" id="toc-content">
<div class="row">
<div class="col-md-12">
<div id="main">
<h1 class="page-title">Source: duplotrainbase.js</h1>
<section>
<article>
<pre
class="sunlight-highlight-javascript linenums">"use strict";
var __importStar = (this &amp;&amp; this.__importStar) || function (mod) {
if (mod &amp;&amp; mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const lpf2hub_1 = require("./lpf2hub");
const port_1 = require("./port");
const Consts = __importStar(require("./consts"));
const Debug = require("debug");
const debug = Debug("duplotrainbase");
/**
* The DuploTrainBase is emitted if the discovered device is a Duplo Train Base.
* @class DuploTrainBase
* @extends LPF2Hub
* @extends Hub
*/
class DuploTrainBase extends lpf2hub_1.LPF2Hub {
// We set JSDoc to ignore these events as a Duplo Train Base will never emit them.
/**
* @event DuploTrainBase#distance
* @ignore
*/
/**
* @event DuploTrainBase#colorAndDistance
* @ignore
*/
/**
* @event DuploTrainBase#tilt
* @ignore
*/
/**
* @event DuploTrainBase#rotate
* @ignore
*/
/**
* @event DuploTrainBase#button
* @ignore
*/
/**
* @event DuploTrainBase#attach
* @ignore
*/
/**
* @event DuploTrainBase#detach
* @ignore
*/
static IsDuploTrainBase(peripheral) {
return (peripheral.advertisement &amp;&amp;
peripheral.advertisement.serviceUuids &amp;&amp;
peripheral.advertisement.serviceUuids.indexOf(Consts.BLEService.LPF2_HUB.replace(/-/g, "")) >= 0 &amp;&amp; peripheral.advertisement.manufacturerData[3] === Consts.BLEManufacturerData.DUPLO_TRAIN_HUB_ID);
}
constructor(device, autoSubscribe = true) {
super(device, autoSubscribe);
this.type = Consts.HubType.DUPLO_TRAIN_HUB;
this._ports = {
"MOTOR": new port_1.Port("MOTOR", 0),
"COLOR": new port_1.Port("COLOR", 18),
"SPEEDOMETER": new port_1.Port("SPEEDOMETER", 19)
};
debug("Discovered Duplo Train Base");
}
connect() {
return new Promise(async (resolve, reject) => {
debug("Connecting to Duplo Train Base");
await super.connect();
debug("Connect completed");
return resolve();
});
}
/**
* Set the color of the LED on the train via a color value.
* @method DuploTrainBase#setLEDColor
* @param {Color} color
* @returns {Promise} Resolved upon successful issuance of command.
*/
setLEDColor(color) {
return new Promise((resolve, reject) => {
if (color === false) {
color = 0;
}
const data = Buffer.from([0x81, 0x11, 0x11, 0x51, 0x00, color]);
this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, data);
return resolve();
});
}
/**
* Set the motor speed on a given port.
* @method DuploTrainBase#setMotorSpeed
* @param {string} port
* @param {number | Array.&lt;number>} speed For forward, a value between 1 - 100 should be set. For reverse, a value between -1 to -100. Stop is 0. If you are specifying port AB to control both motors, you can optionally supply a tuple of speeds.
* @param {number} [time] How long to activate the motor for (in milliseconds). Leave empty to turn the motor on indefinitely.
* @returns {Promise} Resolved upon successful completion of command. If time is specified, this is once the motor is finished.
*/
setMotorSpeed(port, speed, time) {
const portObj = this._portLookup(port);
let cancelEventTimer = true;
if (typeof time === "boolean") {
if (time === true) {
cancelEventTimer = false;
}
time = undefined;
}
if (cancelEventTimer) {
portObj.cancelEventTimer();
}
return new Promise((resolve, reject) => {
if (time &amp;&amp; typeof time === "number") {
const data = Buffer.from([0x81, portObj.value, 0x11, 0x51, 0x00, this._mapSpeed(speed)]);
this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, data);
const timeout = global.setTimeout(() => {
const data = Buffer.from([0x81, portObj.value, 0x11, 0x51, 0x00, 0x00]);
this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, data);
return resolve();
}, time);
portObj.setEventTimer(timeout);
}
else {
const data = Buffer.from([0x81, portObj.value, 0x11, 0x51, 0x00, this._mapSpeed(speed)]);
this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, data);
return resolve();
}
});
}
/**
* Ramp the motor speed on a given port.
* @method DuploTrainBase#rampMotorSpeed
* @param {string} port
* @param {number} fromSpeed For forward, a value between 1 - 100 should be set. For reverse, a value between -1 to -100. Stop is 0.
* @param {number} toSpeed For forward, a value between 1 - 100 should be set. For reverse, a value between -1 to -100. Stop is 0.
* @param {number} time How long the ramp should last (in milliseconds).
* @returns {Promise} Resolved upon successful completion of command.
*/
rampMotorSpeed(port, fromSpeed, toSpeed, time) {
const portObj = this._portLookup(port);
portObj.cancelEventTimer();
return new Promise((resolve, reject) => {
this._calculateRamp(fromSpeed, toSpeed, time, portObj)
.on("changeSpeed", (speed) => {
this.setMotorSpeed(port, speed, true);
})
.on("finished", resolve);
});
}
/**
* Fully (hard) stop the motor on a given port.
* @method DuploTrainBase#brakeMotor
* @param {string} port
* @returns {Promise} Resolved upon successful completion of command.
*/
brakeMotor(port) {
return this.setMotorSpeed(port, 127);
}
/**
* Play a built-in train sound.
* @method DuploTrainBase#playSound
* @param {DuploTrainBaseSound} sound
* @returns {Promise} Resolved upon successful issuance of command.
*/
playSound(sound) {
return new Promise((resolve, reject) => {
const data = Buffer.from([0x81, 0x01, 0x11, 0x51, 0x01, sound]);
this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, data);
return resolve();
});
}
}
exports.DuploTrainBase = DuploTrainBase;
//# sourceMappingURL=duplotrainbase.js.map</pre>
</article>
</section>
</div>
</div>
<div class="clearfix"></div>
</div>
</div>
<div class="modal fade" id="searchResults">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title">Search results</h4>
</div>
<div class="modal-body"></div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div>
<footer>
<span class="copyright">
node-poweredup by Nathan Kellenicki licensed under the MIT license.
</span>
<span class="jsdoc-message">
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a>
on Wed Mar 20th 2019
using the <a href="https://github.com/docstrap/docstrap">DocStrap template</a>.
</span>
</footer>
<script src="scripts/docstrap.lib.js"></script>
<script src="scripts/toc.js"></script>
<script type="text/javascript" src="scripts/fulltext-search-ui.js"></script>
<script>
$( function () {
$( "[id*='$']" ).each( function () {
var $this = $( this );
$this.attr( "id", $this.attr( "id" ).replace( "$", "__" ) );
} );
$( ".tutorial-section pre, .readme-section pre, pre.prettyprint.source" ).each( function () {
var $this = $( this );
var example = $this.find( "code" );
exampleText = example.html();
var lang = /{@lang (.*?)}/.exec( exampleText );
if ( lang && lang[1] ) {
exampleText = exampleText.replace( lang[0], "" );
example.html( exampleText );
lang = lang[1];
} else {
var langClassMatch = example.parent()[0].className.match(/lang\-(\S+)/);
lang = langClassMatch ? langClassMatch[1] : "javascript";
}
if ( lang ) {
$this
.addClass( "sunlight-highlight-" + lang )
.addClass( "linenums" )
.html( example.html() );
}
} );
Sunlight.highlightAll( {
lineNumbers : true,
showMenu : true,
enableDoclinks : true
} );
$.catchAnchorLinks( {
navbarOffset: 10
} );
$( "#toc" ).toc( {
anchorName : function ( i, heading, prefix ) {
return $( heading ).attr( "id" ) || ( prefix + i );
},
selectors : "#toc-content h1,#toc-content h2,#toc-content h3,#toc-content h4",
showAndHide : false,
smoothScrolling: true
} );
$( "#main span[id^='toc']" ).addClass( "toc-shim" );
$( '.dropdown-toggle' ).dropdown();
$( "table" ).each( function () {
var $this = $( this );
$this.addClass('table');
} );
} );
</script>
<!--Navigation and Symbol Display-->
<!--Google Analytics-->
<script type="text/javascript">
$(document).ready(function() {
SearcherDisplay.init();
});
</script>
</body>
</html>

Binary file not shown.

File diff suppressed because it is too large Load Diff

After

Width:  |  Height:  |  Size: 116 KiB

Some files were not shown because too many files have changed in this diff Show More