tello-api-client
Version:
Tello API Client for Node.js.
83 lines • 2.93 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var dgram = require("dgram");
var FlipCommand;
(function (FlipCommand) {
FlipCommand["Left"] = "l";
FlipCommand["Right"] = "r";
FlipCommand["Forward"] = "f";
FlipCommand["Back"] = "b";
FlipCommand["BackLeft"] = "bl";
FlipCommand["BackRight"] = "rb";
FlipCommand["FrontLeft"] = "fl";
FlipCommand["FrontRight"] = "fr";
})(FlipCommand = exports.FlipCommand || (exports.FlipCommand = {}));
var TelloClient = /** @class */ (function () {
function TelloClient(ipAddress, port) {
if (ipAddress === void 0) { ipAddress = '192.168.10.1'; }
if (port === void 0) { port = 8889; }
this.socket = dgram.createSocket('udp4');
this.config = {
address: ipAddress,
port: port
};
}
TelloClient.prototype.command = function (cb) {
this.sendCommand("command", cb);
};
TelloClient.prototype.takeoff = function (cb) {
this.sendCommand("takeoff", cb);
};
TelloClient.prototype.land = function (cb) {
this.sendCommand("land", cb);
};
TelloClient.prototype.up = function (cm, cb) {
this.sendCommand("up " + cm, cb);
};
TelloClient.prototype.down = function (cm, cb) {
this.sendCommand("down " + cm, cb);
};
TelloClient.prototype.left = function (cm, cb) {
this.sendCommand("left " + cm, cb);
};
TelloClient.prototype.right = function (cm, cb) {
this.sendCommand("right " + cm, cb);
};
TelloClient.prototype.forward = function (cm, cb) {
this.sendCommand("forward " + cm, cb);
};
TelloClient.prototype.back = function (cm, cb) {
this.sendCommand("back " + cm, cb);
};
TelloClient.prototype.cw = function (rotate, cb) {
this.sendCommand("cw " + rotate, cb);
};
TelloClient.prototype.ccw = function (rotate, cb) {
this.sendCommand("ccw " + rotate, cb);
};
TelloClient.prototype.flip = function (command, cb) {
this.sendCommand("flip " + command, cb);
};
TelloClient.prototype.setSpeed = function (cmPerSecond, cb) {
this.sendCommand("speed " + cmPerSecond, cb);
};
TelloClient.prototype.getSpeed = function (cb) {
this.sendCommand("Speed?", cb);
};
TelloClient.prototype.getBattery = function (cb) {
this.sendCommand("Battery?", cb);
};
TelloClient.prototype.getFlightTime = function (cb) {
this.sendCommand("Time?", cb);
};
TelloClient.prototype.sendCommand = function (command, callback) {
var _this = this;
var msg = new Buffer(command);
setTimeout(function () {
_this.socket.send(msg, 0, msg.length, _this.config.port, _this.config.address, callback);
}, 500);
};
return TelloClient;
}());
exports.TelloClient = TelloClient;
//# sourceMappingURL=tello.js.map