From c9675b902a3b7431870fcad3e858e2911ed84419 Mon Sep 17 00:00:00 2001 From: Chris Fetherston Date: Tue, 15 Aug 2017 21:16:52 -0400 Subject: [PATCH 1/6] I think this kinda works --- .eslintrc | 4 +-- examples/keyboard/drone.js | 9 ++++++ lib/Drone.js | 9 ++++++ lib/MiniDroneBtAdapter.js | 57 +++++++++++++++++++++++++++++++++----- 4 files changed, 70 insertions(+), 9 deletions(-) diff --git a/.eslintrc b/.eslintrc index 79bfef3..d946b4c 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,8 +1,8 @@ { "extends": "airbnb-base", "rules": { - "indent": ["error", 4], - "no-unused-expressions": ["error", { "allowTernary": true }], + "indent": [2, 4], + "no-unused-expressions": [2, { "allowTernary": true }], // specify the maximum length of a line in your program // http://eslint.org/docs/rules/max-len "max-len": [2, 150, 2, { diff --git a/examples/keyboard/drone.js b/examples/keyboard/drone.js index 776c445..906f564 100644 --- a/examples/keyboard/drone.js +++ b/examples/keyboard/drone.js @@ -56,6 +56,15 @@ process.stdin.on('keypress', (ch, key) => { case 'f': drone.trim(); break; + case 'l': + drone.animateHeadlights(); + break; + case 'k': + drone.animateHeadlights('blink'); + break; + case 'o': + drone.animateHeadlights('oscillate'); + break; case 'escape': drone.emergency(); break; diff --git a/lib/Drone.js b/lib/Drone.js index b2ba675..cf26f29 100644 --- a/lib/Drone.js +++ b/lib/Drone.js @@ -184,6 +184,15 @@ class Drone extends EventEmitter { this.network.writeTakePicture(); } + /** + * Sets the drone's light state + * @param {string} state The desired light state, can be flash, blink, or oscillate + * @return {undefined} + */ + animateHeadlights(animation) { + this.network.writeHeadlightAnimation(animation); + } + /** * Perform the drone's emergency landing, kills the rotors * @return {undefined} diff --git a/lib/MiniDroneBtAdapter.js b/lib/MiniDroneBtAdapter.js index 3704115..c28f289 100644 --- a/lib/MiniDroneBtAdapter.js +++ b/lib/MiniDroneBtAdapter.js @@ -2,14 +2,14 @@ const Logger = require('winston'); const EventEmitter = require('events'); // MiniDrone Command classes and class methods -// https://github.com/Parrot-Developers/libARCommands/blob/master/Xml/MiniDrone_commands.xml +// https://github.com/Parrot-Developers/arsdk-xml/blob/master/xml/minidrone.xml +// https://github.com/Parrot-Developers/arsdk-xml/blob/ab28dab91845cd36c4d7002b55f70805deaff3c8/xml/common.xml const MD_CLASSES = { PILOTING: 0x00, SPEED_SETTINGS: 0x01, ANIMATION: 0x04, MEDIA_RECORD: 0x06, PILOTING_SETTINGS: 0x08, - NAVIGATION_DATA_STATE: 0x18, }; const MD_METHODS = { TRIM: 0x00, @@ -23,6 +23,7 @@ const MD_METHODS = { MAX_VERTICAL_SPEED: 0x00, MAX_ROTATION_SPEED: 0x01, DRONE_POSITION: 0x00, + LIGHT_STATE: 0x00, }; const MD_DATA_TYPES = { ACK: 0x01, @@ -47,6 +48,7 @@ const MANUFACTURER_SERIALS = ['4300cf1900090100', '4300cf1909090100', '4300cf190 const DRONE_PREFIXES = ['RS_', 'Mars_', 'Travis_', 'Maclan_', 'Mambo_', 'Blaze_', 'NewZ_']; const MD_DEVICE_TYPE = 0x02; +const MD_COMMON = 0x00; const FLIGHT_STATUSES = ['landed', 'taking off', 'hovering', 'flying', 'landing', 'emergency', 'rolling', 'initializing']; @@ -138,10 +140,11 @@ class MiniDroneBtAdapter extends EventEmitter { * Creates a buffer with the common values needed to write to the drone * @param {String} uuid The characteristic UUID * @param {Array} args The buffer arguments, usually the above command constants + * @param {String} deviceType Optional project class to write to * @return {buffer} A freshly created Buffer stream */ - createBuffer(uuid, args = []) { - const buffArray = [MD_DATA_TYPES.DATA, ++this.steps[uuid] & 0xFF, MD_DEVICE_TYPE]; + createBuffer(uuid, args = [], deviceType = MD_DEVICE_TYPE) { + const buffArray = [MD_DATA_TYPES.DATA, ++this.steps[uuid] & 0xFF, deviceType]; return new Buffer(buffArray.concat(args)); } @@ -251,7 +254,17 @@ class MiniDroneBtAdapter extends EventEmitter { } // this one is a little weird, don't understand the extra // argument after the flip class constant ¯\_(ツ)_/¯ - const buffer = this.createBuffer(COMMAND_KEY, [MD_CLASSES.ANIMATION, MD_METHODS.FLIP, 0x00, animations[animation], 0x00, 0x00, 0x00]); + const buffer = this.createBuffer( + COMMAND_KEY, [ + MD_CLASSES.ANIMATION, + MD_METHODS.FLIP, + 0x00, + animations[animation], + 0x00, + 0x00, + 0x00 + ] + ); this.write(COMMAND_KEY, buffer); Logger.info(`Animation command called with ${animation} argument`); } @@ -294,7 +307,7 @@ class MiniDroneBtAdapter extends EventEmitter { /** * Convenience method for setting the drone's max rotation speed limitation - * @param {integer} tilt The max rotation speed from (50°-360° for Airborne Cargo / 50° - 180° for Mambo) + * @param {integer} rotationSpeed The max rotation speed from (50°-360° for Airborne Cargo / 50° - 180° for Mambo) * @return {undefined} */ writeMaxRotationSpeed(rotationSpeed) { @@ -304,6 +317,35 @@ class MiniDroneBtAdapter extends EventEmitter { Logger.info(`Setting max rotation speed to ${rotationSpeed} °/s`); } + /** + * Convenience method for setting the USB light accessory's state + * Can be fixed, blinking, or oscillated + * @param {string} animation The desired headlight animation, can be 'fixed', 'blink' or 'oscillate' + * @return {undefined} + */ + writeHeadlightAnimation(animation = 'flash') { + const lightAnimation = { + flash: 0x00, + blink: 0x01, + oscillate: 0x02, + }; + + const buffer = this.createBuffer( + COMMAND_KEY, [ + 0x18, // class + 0x00, // method + 0x00, // argument? + lightAnimation[animation], + 0x00, + 0x00, + 0x00, + ], 0x00 + ); + this.write(COMMAND_KEY, buffer); + + Logger.info(`Headlight animation command called with ${animation} argument.`); + } + /** * Event handler for when noble discovers a peripheral * Validates it is a drone and attempts to connect. @@ -396,9 +438,10 @@ class MiniDroneBtAdapter extends EventEmitter { * @return {boolean} If the peripheral is a drone */ validatePeripheral(peripheral) { - if (!peripheral) { + if (!peripheral || !peripheral.advertisement.localName) { return false; } + const localName = peripheral.advertisement.localName; const manufacturer = peripheral.advertisement.manufacturerData; const matchesFilter = localName === this.options.droneFilter; From bed55422ccba7ec036863856ab9c8fbd81280a7c Mon Sep 17 00:00:00 2001 From: Chris Fetherston Date: Tue, 15 Aug 2017 21:31:26 -0400 Subject: [PATCH 2/6] use the common class constant --- lib/MiniDroneBtAdapter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/MiniDroneBtAdapter.js b/lib/MiniDroneBtAdapter.js index c28f289..b4394ed 100644 --- a/lib/MiniDroneBtAdapter.js +++ b/lib/MiniDroneBtAdapter.js @@ -339,7 +339,7 @@ class MiniDroneBtAdapter extends EventEmitter { 0x00, 0x00, 0x00, - ], 0x00 + ], MD_COMMON ); this.write(COMMAND_KEY, buffer); From af0cb5a931b8a94a10be72a785884a5c5af15db0 Mon Sep 17 00:00:00 2001 From: Chris Fetherston Date: Tue, 15 Aug 2017 21:38:19 -0400 Subject: [PATCH 3/6] Clean up a couple things --- lib/Drone.js | 4 ++-- lib/MiniDroneBtAdapter.js | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/Drone.js b/lib/Drone.js index cf26f29..ff17807 100644 --- a/lib/Drone.js +++ b/lib/Drone.js @@ -185,8 +185,8 @@ class Drone extends EventEmitter { } /** - * Sets the drone's light state - * @param {string} state The desired light state, can be flash, blink, or oscillate + * Sets the drone's headlight animation + * @param {string} animation The desired light state, can be flash, blink, or oscillate * @return {undefined} */ animateHeadlights(animation) { diff --git a/lib/MiniDroneBtAdapter.js b/lib/MiniDroneBtAdapter.js index b4394ed..5abde76 100644 --- a/lib/MiniDroneBtAdapter.js +++ b/lib/MiniDroneBtAdapter.js @@ -318,7 +318,7 @@ class MiniDroneBtAdapter extends EventEmitter { } /** - * Convenience method for setting the USB light accessory's state + * Convenience method for sending the headlight animation command * Can be fixed, blinking, or oscillated * @param {string} animation The desired headlight animation, can be 'fixed', 'blink' or 'oscillate' * @return {undefined} @@ -333,9 +333,9 @@ class MiniDroneBtAdapter extends EventEmitter { const buffer = this.createBuffer( COMMAND_KEY, [ 0x18, // class - 0x00, // method - 0x00, // argument? - lightAnimation[animation], + MD_METHODS.LIGHT_STATE, // method + 0x00, // ? + lightAnimation[animation], // argument 0x00, 0x00, 0x00, From f1c50dcf7978017b8dc18ff6673acbe7b21af669 Mon Sep 17 00:00:00 2001 From: Chris Fetherston Date: Mon, 21 Aug 2017 11:33:11 -0400 Subject: [PATCH 4/6] clean up docs and write unit tests --- lib/Drone.js | 2 +- lib/MiniDroneBtAdapter.js | 2 +- tests/lib/MiniDroneBtAdapter-test.js | 36 ++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/lib/Drone.js b/lib/Drone.js index ff17807..1f94d3f 100644 --- a/lib/Drone.js +++ b/lib/Drone.js @@ -186,7 +186,7 @@ class Drone extends EventEmitter { /** * Sets the drone's headlight animation - * @param {string} animation The desired light state, can be flash, blink, or oscillate + * @param {string} animation The desired light state, can be 'flash', 'blink', or 'oscillate' * @return {undefined} */ animateHeadlights(animation) { diff --git a/lib/MiniDroneBtAdapter.js b/lib/MiniDroneBtAdapter.js index 5abde76..184ace7 100644 --- a/lib/MiniDroneBtAdapter.js +++ b/lib/MiniDroneBtAdapter.js @@ -320,7 +320,7 @@ class MiniDroneBtAdapter extends EventEmitter { /** * Convenience method for sending the headlight animation command * Can be fixed, blinking, or oscillated - * @param {string} animation The desired headlight animation, can be 'fixed', 'blink' or 'oscillate' + * @param {string} animation The desired headlight animation, can be 'flash', 'blink' or 'oscillate' * @return {undefined} */ writeHeadlightAnimation(animation = 'flash') { diff --git a/tests/lib/MiniDroneBtAdapter-test.js b/tests/lib/MiniDroneBtAdapter-test.js index 3ce7ecd..9a42421 100644 --- a/tests/lib/MiniDroneBtAdapter-test.js +++ b/tests/lib/MiniDroneBtAdapter-test.js @@ -186,4 +186,40 @@ describe('MiniDroneBtAdapter', () => { expect(isDrone).to.equal(true); expect(isNotDrone).to.equal(true); }); + + it('should write the correct flash headlight animation buffer', () => { + const adapter = new MiniDroneBtAdapter(); + const buff = new Buffer([0x02, 1 & 0xFF, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]); + adapter.characteristics = mockCharacteristics; + + adapter.writeHeadlightAnimation(); + const spy = adapter.characteristics[1].write; + expect(spy).to.have.been.calledWith(sinon.match((value) => + bufferEqual(value, buff), + 'did not match expected flash headlight buffer'), true); + }); + + it('should write the correct blink headlight animation buffer', () => { + const adapter = new MiniDroneBtAdapter(); + const buff = new Buffer([0x02, 1 & 0xFF, 0x00, 0x18, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00]); + adapter.characteristics = mockCharacteristics; + + adapter.writeHeadlightAnimation('blink'); + const spy = adapter.characteristics[1].write; + expect(spy).to.have.been.calledWith(sinon.match((value) => + bufferEqual(value, buff), + 'did not match expected flash headlight buffer'), true); + }); + + it('should write the correct oscillate headlight animation buffer', () => { + const adapter = new MiniDroneBtAdapter(); + const buff = new Buffer([0x02, 1 & 0xFF, 0x00, 0x18, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00]); + adapter.characteristics = mockCharacteristics; + + adapter.writeHeadlightAnimation('oscillate'); + const spy = adapter.characteristics[1].write; + expect(spy).to.have.been.calledWith(sinon.match((value) => + bufferEqual(value, buff), + 'did not match expected flash headlight buffer'), true); + }); }); From 3aa5dd3acbb914d7001173e1049afc4bbaa259d2 Mon Sep 17 00:00:00 2001 From: Chris Fetherston Date: Mon, 21 Aug 2017 11:37:08 -0400 Subject: [PATCH 5/6] more docs --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index dd44561..b31a581 100644 --- a/README.md +++ b/README.md @@ -74,6 +74,9 @@ To fly with the keyboard follow the below instructions. **d** | Yaw right **t** | Toggle takeoff & land **f** | Flattrim +**l** | Flash the headlights (if equipped) +**k** | Blink the headlights (if equipped) +**o** | Oscillate the headlights (if equipped) **Escape** | Emergency land ## Tests @@ -81,6 +84,10 @@ To run the test runner execute `npm test`. ## Changelog +### 1.2.0 +- Added support for animating the headlights on equipped drones +- Fixed a bug with saturated Bluetooth environments + ### 1.1.0 - Added support for Mambo, Blaze and New Z minidrones - Added support for setting max tilt, altitude, vertical speed, rotation speed and defining a drone type to connect to From c76ce178a41ca9a1f6921fc588078dcb2c863372 Mon Sep 17 00:00:00 2001 From: Chris Fetherston Date: Mon, 21 Aug 2017 11:38:02 -0400 Subject: [PATCH 6/6] update docs --- docs/Drone.html | 303 ++++++++++++++++++++++++++-- docs/Drone.js.html | 11 +- docs/MiniDroneBtAdapter.html | 337 +++++++++++++++++++++++++++++--- docs/MiniDroneBtAdapter.js.html | 59 +++++- docs/index.html | 20 +- docs/styles/jsdoc-default.css | 8 +- package.json | 2 +- 7 files changed, 679 insertions(+), 61 deletions(-) diff --git a/docs/Drone.html b/docs/Drone.html index 27d5b2a..f2d2c9f 100644 --- a/docs/Drone.html +++ b/docs/Drone.html @@ -28,7 +28,7 @@

Class: Drone

-

Drone

+

Drone(options)

Drone Class @@ -47,7 +47,9 @@

Drone

Constructor

+

new Drone(options)

+ @@ -386,6 +388,8 @@
Fires:
+ +
@@ -395,7 +399,9 @@
Fires:
- + + + @@ -409,7 +415,9 @@

Methods

+

animate(animation) → {undefined}

+ @@ -510,7 +518,7 @@
Parameters:
Source:
@@ -554,12 +562,169 @@
Returns:
+ + + + + + + + +

animateHeadlights(animation) → {undefined}

+ + + + + + +
+ Sets the drone's headlight animation +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
animation + + +string + + + The desired light state, can be 'flash', 'blink', or 'oscillate'
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +undefined + + +
+
+ + + + + + + + + + + + +

connect() → {undefined}

+ @@ -610,7 +775,7 @@

connectSource:
@@ -654,12 +819,16 @@
Returns:
+ + +

emergency() → {undefined}

+ @@ -710,7 +879,7 @@

emergencySource:
@@ -754,12 +923,16 @@
Returns:
+ + +

eventLoop() → {undefined}

+ @@ -810,7 +983,7 @@

eventLoopSource:
@@ -854,12 +1027,16 @@
Returns:
+ + +

getBatteryLevel() → {integer}

+ @@ -910,7 +1087,7 @@

getBat
Source:
@@ -958,12 +1135,16 @@

Returns:
+ + +

getRssi() → {interger}

+ @@ -1014,7 +1195,7 @@

getRssiSource:
@@ -1062,12 +1243,16 @@
Returns:
+ + +

isFlying() → {Boolean}

+ @@ -1166,12 +1351,16 @@
Returns:
+ + +

land() → {undefined}

+ @@ -1266,12 +1455,16 @@
Returns:
+ + +

onConnected() → {undefined}

+ @@ -1322,7 +1515,7 @@

onConnecte
Source:
@@ -1366,12 +1559,16 @@

Returns:
+ + +

setDroneFilter(name) → {undefined}

+ @@ -1515,12 +1712,16 @@
Returns:
+ + +

setFlightParams(flightParams) → {undefined}

+ @@ -1782,12 +1983,16 @@
Returns:
+ + +

setMaxAltitude(altitude) → {undefined}

+ @@ -1931,12 +2136,16 @@
Returns:
+ + +

setMaxRotationSpeed(speed) → {undefined}

+ @@ -2080,12 +2289,16 @@
Returns:
+ + +

setMaxTilt(tilt) → {undefined}

+ @@ -2229,12 +2442,16 @@
Returns:
+ + +

setMaxVerticalSpeed(speed) → {undefined}

+ @@ -2378,12 +2595,16 @@
Returns:
+ + +

takeOff() → {undefined}

+ @@ -2478,12 +2699,16 @@
Returns:
+ + +

takeoffOrLand() → {undefined}

+ @@ -2578,12 +2803,16 @@
Returns:
+ + +

takePicture() → {undefined}

+ @@ -2678,12 +2907,16 @@
Returns:
+ + +

trim() → {undefined}

+ @@ -2778,6 +3011,8 @@
Returns:
+ + @@ -2791,7 +3026,9 @@

Events

+

batteryStatusChange

+ @@ -2852,7 +3089,7 @@
Type:
Source:
@@ -2878,12 +3115,16 @@
Type:
+ + +

connected

+ @@ -2944,7 +3185,7 @@
Type:
Source:
@@ -2970,12 +3211,16 @@
Type:
+ + +

flightParamChange

+ @@ -3036,7 +3281,7 @@
Type:
Source:
@@ -3062,12 +3307,16 @@
Type:
+ + +

flightStatusChange

+ @@ -3128,7 +3377,7 @@
Type:
Source:
@@ -3154,12 +3403,16 @@
Type:
+ + +

maxAltitudeChange

+ @@ -3220,7 +3473,7 @@
Type:
Source:
@@ -3246,12 +3499,16 @@
Type:
+ + +

maxRotationSpeed

+ @@ -3312,7 +3569,7 @@
Type:
Source:
@@ -3338,12 +3595,16 @@
Type:
+ + +

maxTiltChange

+ @@ -3404,7 +3665,7 @@
Type:
Source:
@@ -3430,12 +3691,16 @@
Type:
+ + +

maxVerticalSpeed

+ @@ -3496,7 +3761,7 @@
Type:
Source:
@@ -3522,6 +3787,8 @@
Type:
+ + @@ -3540,7 +3807,7 @@

Home

Classes

  • diff --git a/docs/Drone.js.html b/docs/Drone.js.html index 45c1d26..e6d32ad 100644 --- a/docs/Drone.js.html +++ b/docs/Drone.js.html @@ -212,6 +212,15 @@

    Source: Drone.js

    this.network.writeTakePicture(); } + /** + * Sets the drone's headlight animation + * @param {string} animation The desired light state, can be 'flash', 'blink', or 'oscillate' + * @return {undefined} + */ + animateHeadlights(animation) { + this.network.writeHeadlightAnimation(animation); + } + /** * Perform the drone's emergency landing, kills the rotors * @return {undefined} @@ -371,7 +380,7 @@

    Home

    Classes

    • diff --git a/docs/MiniDroneBtAdapter.html b/docs/MiniDroneBtAdapter.html index f1bcf79..9a59d3a 100644 --- a/docs/MiniDroneBtAdapter.html +++ b/docs/MiniDroneBtAdapter.html @@ -28,7 +28,7 @@

      Class: MiniDroneBtAdapter

      -

      MiniDroneBtAdapter

      +

      MiniDroneBtAdapter(options)

      Network adapter between drone and Noble BTLE Abstracts away all the characteristics, buffers @@ -46,7 +46,9 @@

      MiniDroneBtAdapter

      Constructor

      +

      new MiniDroneBtAdapter(options)

      + @@ -202,7 +204,7 @@
      Properties
      Source:
      @@ -228,6 +230,8 @@
      Properties
      + +
      @@ -237,7 +241,9 @@
      Properties
      - + + + @@ -251,7 +257,9 @@

      Methods

      -

      createBuffer(uuid, args) → {buffer}

      + +

      createBuffer(uuid, args, deviceType) → {buffer}

      + @@ -337,6 +345,29 @@
      Parameters:
      + + + + deviceType + + + + + +String + + + + + + + + + + Optional project class to write to + + + @@ -374,7 +405,7 @@
      Parameters:
      Source:
      @@ -422,12 +453,16 @@
      Returns:
      + + +

      getCharacteristic(uuid) → {Characteristic}

      + @@ -527,7 +562,7 @@
      Parameters:
      Source:
      @@ -575,12 +610,16 @@
      Returns:
      + + +

      onBatteryStatusChange(data, isNotification) → {undefined}

      + @@ -703,7 +742,7 @@
      Parameters:
      Source:
      @@ -747,12 +786,16 @@
      Returns:
      + + +

      onDisconnect() → {undefined}

      + @@ -804,7 +847,7 @@

      onDisconn
      Source:
      @@ -848,12 +891,16 @@

      Returns:
      + + +

      onFlightStatusChange(data, isNotification) → {undefined}

      + @@ -976,7 +1023,7 @@
      Parameters:
      Source:
      @@ -1020,12 +1067,16 @@
      Returns:
      + + +

      onNobleStateChange(state) → {undefined}

      + @@ -1125,7 +1176,7 @@
      Parameters:
      Source:
      @@ -1169,12 +1220,16 @@
      Returns:
      + + +

      onPeripheralDiscovery(peripheral) → {undefined}

      + @@ -1275,7 +1330,7 @@
      Parameters:
      Source:
      @@ -1319,12 +1374,16 @@
      Returns:
      + + +

      setupPeripheral() → {undefined}

      + @@ -1375,7 +1434,7 @@

      setupP
      Source:
      @@ -1419,12 +1478,16 @@

      Returns:
      + + +

      updateRssi()

      + @@ -1475,7 +1538,7 @@

      updateRssi<
      Source:
      @@ -1501,12 +1564,16 @@

      updateRssi< + + +

      validatePeripheral(peripheral) → {boolean}

      + @@ -1606,7 +1673,7 @@
      Parameters:
      Source:
      @@ -1654,12 +1721,16 @@
      Returns:
      + + +

      write(uuid, buffer) → {undefined}

      + @@ -1783,7 +1854,7 @@
      Parameters:
      Source:
      @@ -1827,12 +1898,16 @@
      Returns:
      + + +

      writeAnimation(animation) → {undefined}

      + @@ -1932,7 +2007,7 @@
      Parameters:
      Source:
      @@ -1976,12 +2051,16 @@
      Returns:
      + + +

      writeEmergency() → {undefined}

      + @@ -2032,7 +2111,7 @@

      writeEm
      Source:
      @@ -2076,12 +2155,16 @@

      Returns:
      + + +

      writeFlightParams(flightParams) → {undefined}

      + @@ -2182,7 +2265,7 @@
      Parameters:
      Source:
      @@ -2226,12 +2309,178 @@
      Returns:
      + + + +

      writeHeadlightAnimation(animation) → {undefined}

      + + + + + + +
      + Convenience method for sending the headlight animation command +Can be fixed, blinking, or oscillated +
      + + + + + + + + + +
      Parameters:
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeDefaultDescription
      animation + + +string + + + + + + flash + + The desired headlight animation, can be 'flash', 'blink' or 'oscillate'
      + + + + + + +
      + + + + + + + + + + + + + + + + + + + + + + + + + + +
      Source:
      +
      + + + + + + + +
      + + + + + + + + + + + + + +
      Returns:
      + + + + +
      +
      + Type +
      +
      + +undefined + + +
      +
      + + + + + + + + + + + + +

      writeLand() → {undefined}

      + @@ -2282,7 +2531,7 @@

      writeLandSource:
      @@ -2326,12 +2575,16 @@
      Returns:
      + + +

      writeMaxAltitude(altitude) → {undefined}

      + @@ -2431,7 +2684,7 @@
      Parameters:
      Source:
      @@ -2475,12 +2728,16 @@
      Returns:
      + + -

      writeMaxRotationSpeed(tilt) → {undefined}

      + +

      writeMaxRotationSpeed(rotationSpeed) → {undefined}

      + @@ -2523,7 +2780,7 @@
      Parameters:
      - tilt + rotationSpeed @@ -2580,7 +2837,7 @@
      Parameters:
      Source:
      @@ -2624,12 +2881,16 @@
      Returns:
      + + +

      writeMaxTilt(tilt) → {undefined}

      + @@ -2729,7 +2990,7 @@
      Parameters:
      Source:
      @@ -2773,12 +3034,16 @@
      Returns:
      + + +

      writeMaxVerticalSpeed(verticalSpeed) → {undefined}

      + @@ -2878,7 +3143,7 @@
      Parameters:
      Source:
      @@ -2922,12 +3187,16 @@
      Returns:
      + + +

      writeTakeoff() → {undefined}

      + @@ -2978,7 +3247,7 @@

      writeTake
      Source:
      @@ -3022,12 +3291,16 @@

      Returns:
      + + +

      writeTakePicture() → {undefined}

      + @@ -3078,7 +3351,7 @@

      write
      Source:
      @@ -3122,12 +3395,16 @@

      Returns:
      + + +

      writeTrim() → {undefined}

      + @@ -3178,7 +3455,7 @@

      writeTrimSource:
      @@ -3222,6 +3499,8 @@
      Returns:
      + + @@ -3244,7 +3523,7 @@

      Home

      Classes

      • diff --git a/docs/MiniDroneBtAdapter.js.html b/docs/MiniDroneBtAdapter.js.html index 10a4d23..e762989 100644 --- a/docs/MiniDroneBtAdapter.js.html +++ b/docs/MiniDroneBtAdapter.js.html @@ -30,14 +30,14 @@

        Source: MiniDroneBtAdapter.js

        const EventEmitter = require('events'); // MiniDrone Command classes and class methods -// https://github.com/Parrot-Developers/libARCommands/blob/master/Xml/MiniDrone_commands.xml +// https://github.com/Parrot-Developers/arsdk-xml/blob/master/xml/minidrone.xml +// https://github.com/Parrot-Developers/arsdk-xml/blob/ab28dab91845cd36c4d7002b55f70805deaff3c8/xml/common.xml const MD_CLASSES = { PILOTING: 0x00, SPEED_SETTINGS: 0x01, ANIMATION: 0x04, MEDIA_RECORD: 0x06, PILOTING_SETTINGS: 0x08, - NAVIGATION_DATA_STATE: 0x18, }; const MD_METHODS = { TRIM: 0x00, @@ -51,6 +51,7 @@

        Source: MiniDroneBtAdapter.js

        MAX_VERTICAL_SPEED: 0x00, MAX_ROTATION_SPEED: 0x01, DRONE_POSITION: 0x00, + LIGHT_STATE: 0x00, }; const MD_DATA_TYPES = { ACK: 0x01, @@ -75,6 +76,7 @@

        Source: MiniDroneBtAdapter.js

        const DRONE_PREFIXES = ['RS_', 'Mars_', 'Travis_', 'Maclan_', 'Mambo_', 'Blaze_', 'NewZ_']; const MD_DEVICE_TYPE = 0x02; +const MD_COMMON = 0x00; const FLIGHT_STATUSES = ['landed', 'taking off', 'hovering', 'flying', 'landing', 'emergency', 'rolling', 'initializing']; @@ -166,10 +168,11 @@

        Source: MiniDroneBtAdapter.js

        * Creates a buffer with the common values needed to write to the drone * @param {String} uuid The characteristic UUID * @param {Array} args The buffer arguments, usually the above command constants + * @param {String} deviceType Optional project class to write to * @return {buffer} A freshly created Buffer stream */ - createBuffer(uuid, args = []) { - const buffArray = [MD_DATA_TYPES.DATA, ++this.steps[uuid] & 0xFF, MD_DEVICE_TYPE]; + createBuffer(uuid, args = [], deviceType = MD_DEVICE_TYPE) { + const buffArray = [MD_DATA_TYPES.DATA, ++this.steps[uuid] & 0xFF, deviceType]; return new Buffer(buffArray.concat(args)); } @@ -279,7 +282,17 @@

        Source: MiniDroneBtAdapter.js

        } // this one is a little weird, don't understand the extra // argument after the flip class constant ¯\_(ツ)_/¯ - const buffer = this.createBuffer(COMMAND_KEY, [MD_CLASSES.ANIMATION, MD_METHODS.FLIP, 0x00, animations[animation], 0x00, 0x00, 0x00]); + const buffer = this.createBuffer( + COMMAND_KEY, [ + MD_CLASSES.ANIMATION, + MD_METHODS.FLIP, + 0x00, + animations[animation], + 0x00, + 0x00, + 0x00 + ] + ); this.write(COMMAND_KEY, buffer); Logger.info(`Animation command called with ${animation} argument`); } @@ -322,7 +335,7 @@

        Source: MiniDroneBtAdapter.js

        /** * Convenience method for setting the drone's max rotation speed limitation - * @param {integer} tilt The max rotation speed from (50°-360° for Airborne Cargo / 50° - 180° for Mambo) + * @param {integer} rotationSpeed The max rotation speed from (50°-360° for Airborne Cargo / 50° - 180° for Mambo) * @return {undefined} */ writeMaxRotationSpeed(rotationSpeed) { @@ -332,6 +345,35 @@

        Source: MiniDroneBtAdapter.js

        Logger.info(`Setting max rotation speed to ${rotationSpeed} °/s`); } + /** + * Convenience method for sending the headlight animation command + * Can be fixed, blinking, or oscillated + * @param {string} animation The desired headlight animation, can be 'flash', 'blink' or 'oscillate' + * @return {undefined} + */ + writeHeadlightAnimation(animation = 'flash') { + const lightAnimation = { + flash: 0x00, + blink: 0x01, + oscillate: 0x02, + }; + + const buffer = this.createBuffer( + COMMAND_KEY, [ + 0x18, // class + MD_METHODS.LIGHT_STATE, // method + 0x00, // ? + lightAnimation[animation], // argument + 0x00, + 0x00, + 0x00, + ], MD_COMMON + ); + this.write(COMMAND_KEY, buffer); + + Logger.info(`Headlight animation command called with ${animation} argument.`); + } + /** * Event handler for when noble discovers a peripheral * Validates it is a drone and attempts to connect. @@ -424,9 +466,10 @@

        Source: MiniDroneBtAdapter.js

        * @return {boolean} If the peripheral is a drone */ validatePeripheral(peripheral) { - if (!peripheral) { + if (!peripheral || !peripheral.advertisement.localName) { return false; } + const localName = peripheral.advertisement.localName; const manufacturer = peripheral.advertisement.manufacturerData; const matchesFilter = localName === this.options.droneFilter; @@ -499,7 +542,7 @@

        Home

        Classes

        • diff --git a/docs/index.html b/docs/index.html index d87d180..b35c9d9 100644 --- a/docs/index.html +++ b/docs/index.html @@ -178,13 +178,29 @@

          Control Layout

          + + + + + + + + + + + +
          Flattrim
          lFlash the headlights (if equipped)
          kBlink the headlights (if equipped)
          oOscillate the headlights (if equipped)
          Escape Emergency land

          Tests

          To run the test runner execute npm test.

          -

          Changelog

          1.1.0

            +

            Changelog

            1.2.0

              +
            • Added support for animating the headlights on equipped drones
            • +
            • Fixed a bug with saturated Bluetooth environments
            • +
            +

            1.1.0

            • Added support for Mambo, Blaze and New Z minidrones
            • Added support for setting max tilt, altitude, vertical speed, rotation speed and defining a drone type to connect to
            @@ -214,7 +230,7 @@

            Home

            Classes

            • diff --git a/docs/styles/jsdoc-default.css b/docs/styles/jsdoc-default.css index ede1919..9207bc8 100644 --- a/docs/styles/jsdoc-default.css +++ b/docs/styles/jsdoc-default.css @@ -78,6 +78,10 @@ article dl { margin-bottom: 40px; } +article img { + max-width: 100%; +} + section { display: block; @@ -218,8 +222,8 @@ thead tr th { border-right: 1px solid #aaa; } tr > th:last-child { border-right: 1px solid #ddd; } -.ancestors { color: #999; } -.ancestors a +.ancestors, .attribs { color: #999; } +.ancestors a, .attribs a { color: #999 !important; text-decoration: none; diff --git a/package.json b/package.json index 96069c7..d1b3256 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "parrot-minidrone", - "version": "1.1.1", + "version": "1.2.0", "description": "Node package that exposes a simple API for flying Parrot MiniDrones such as Rolling Spider, Airborne Cargo, Night and Hydrofoil.", "main": "drone.js", "scripts": {