| 'use strict'; | ||
| var WiFli = require('../index') | ||
| , MockConnection = require('../lib/mock-connection') | ||
| ; | ||
| var kopter = new WiFli(); | ||
| // replace this with a real connect() call to send to real copter | ||
| kopter.connection = new MockConnection(); | ||
| kopter.once('launch', function () { | ||
| kopter.runQueue(function (q) { | ||
| q.on('end', function () { kopter.land(); }); | ||
| q.enqueue({hover : true}, 1000); | ||
| q.enqueue({hover : true, trim : -8}, 500); | ||
| q.enqueue({hover : true, trim : 8}, 1000); | ||
| }); | ||
| }); | ||
| kopter.once('land', function () { kopter.end(); }); | ||
| kopter.once('end', function () { console.log("all done!"); }); | ||
| kopter.launch(); |
| 'use strict'; | ||
| function MockConnection() { | ||
| } | ||
| MockConnection.prototype.write = function (buffer) { | ||
| console.dir(buffer); | ||
| }; | ||
| MockConnection.prototype.end = function () { | ||
| console.log('connection shut down'); | ||
| }; | ||
| module.exports = MockConnection; |
| 'use strict'; | ||
| var WiFli = require('../index'); | ||
| var WiFli = require('../index') | ||
| , MockConnection = require('../lib/mock-connection') | ||
| ; | ||
| function MockConnection() { | ||
| } | ||
| MockConnection.prototype.write = function (buffer) { | ||
| console.dir(buffer); | ||
| }; | ||
| MockConnection.prototype.end = function () { | ||
| console.log('connection shut down'); | ||
| }; | ||
| var kopter = new WiFli(); | ||
@@ -17,0 +9,0 @@ // replace this with a real connect() call to send to real copter |
+55
-6
@@ -14,4 +14,5 @@ 'use strict'; | ||
| */ | ||
| var HELIADDRESS = '192.168.11.123' | ||
| , HELIPORT = 2000 | ||
| var HELIADDRESS = '192.168.11.123' | ||
| , HELIPORT = 2000 | ||
| , HOVER_SPEED = 30 // FIXME: SWAG | ||
| ; | ||
@@ -32,6 +33,9 @@ | ||
| function WiFli () { | ||
| function WiFli (options) { | ||
| EventEmitter.call(this); | ||
| this.writable = true; | ||
| if (!options) options = {}; | ||
| this.hoverSpeed = options.hoverSpeed || HOVER_SPEED; | ||
| // make it easy to stream commands to copter | ||
@@ -87,5 +91,13 @@ this.on('data', function (command) { | ||
| if (command.reset) { | ||
| this.sendReset(); | ||
| return true; | ||
| return this.sendReset(); | ||
| } | ||
| else if (command.hover) { | ||
| return this.hover(command); | ||
| } | ||
| else if (command.launch) { | ||
| return this.launch(); | ||
| } | ||
| else if (command.land) { | ||
| return this.land(); | ||
| } | ||
| else { | ||
@@ -116,6 +128,43 @@ var b = new Command(command).toBuffer(); | ||
| WiFli.prototype.sendReset = function () { | ||
| this.sendCommand(); | ||
| var status = this.sendCommand(); | ||
| this.emit('reset'); | ||
| return status; | ||
| }; | ||
| WiFli.prototype.hover = function (command) { | ||
| if (command) { | ||
| delete command.hover; | ||
| } | ||
| else { | ||
| command = {}; | ||
| } | ||
| command.rotorSpeed = this.hoverSpeed; | ||
| this.sendCommand(command); | ||
| this.emit('hover'); | ||
| }; | ||
| WiFli.prototype.launch = function () { | ||
| var self = this; | ||
| var launchSpeed = Math.floor(this.hoverSpeed * 1.1); | ||
| this.runQueue(function (q) { | ||
| q.once('end', function () { self.emit('launch'); }); | ||
| q.enqueue({rotorSpeed : launchSpeed}, 1000); | ||
| q.enqueue({hover : true}, 0); | ||
| }); | ||
| }; | ||
| WiFli.prototype.land = function () { | ||
| var self = this; | ||
| Math.floor(self.hoverSpeed * 1.1); | ||
| this.runQueue(function (q) { | ||
| q.once('end', function () { self.emit('land'); }); | ||
| q.enqueue({rotorSpeed : Math.floor(self.hoverSpeed * 0.8)}, 400); | ||
| q.enqueue({rotorSpeed : Math.floor(self.hoverSpeed * 0.95)}, 1000); | ||
| q.enqueue({hover : true}, 300); | ||
| q.enqueue({reset : true}, 0); | ||
| }); | ||
| }; | ||
| module.exports = WiFli; |
+2
-2
| { | ||
| "name": "wifli", | ||
| "version": "0.3.1", | ||
| "version": "0.4.0", | ||
| "author": { | ||
@@ -19,3 +19,3 @@ "name": "Forrest L Norvell", | ||
| "scripts": { | ||
| "test": "echo \"Error: no test specified\" && exit 1" | ||
| "test": "tap test" | ||
| }, | ||
@@ -22,0 +22,0 @@ "repository": { |
+0
-5
| ## Pending work | ||
| * Test streaming interface for use with joystick controller. | ||
| * Add high-level commands: | ||
| * launch | ||
| * hover | ||
| * land | ||
| * make hover point configurable |
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
11579
19.82%14
16.67%356
22.34%2
-33.33%