Commit 5e57abdf authored by Léo-Paul Géneau's avatar Léo-Paul Géneau 👾

Comply to JSLint

parent 5c0b63f0
/*jslint indent2 */ /*jslint nomen: true, indent: 2, maxerr: 3, maxlen: 80 */
/*global console, std */ /*global console, me*/
const EPSILON_YAW = 6;
const EPSILON_ALTITUDE = 5;
const TARGET_YAW = 0;
var running = false;
const wrongParameters = displayMessage.bind(null, "Wrong parameters");
function displayDronePositions() {
if(!pubsubRunning)
console.log("You must start pubsub first !");
else {
for (const [id, drone] of Object.entries(droneDict)) {
console.log(id, drone.latitude, drone.longitude, drone.altitudeAbs, drone.altitudeRel);
}
}
return 0;
}
function land() { (function (console, me) {
var yaw; "use strict";
while(true) { function displayMessage(message) {
yaw = getYaw(); console.log(message);
console.log(`[DEMO] Waiting for yaw... (${yaw} , ${TARGET_YAW})`); return 0;
if(Math.abs(yaw - TARGET_YAW) < EPSILON_YAW) {
break;
}
sleep(250);
} }
console.log("[DEMO] Deploying parachute..."); var help = ["altitude(altitude)", "exit",
exit_on_fail(doParachute(2), "Failed to deploy parachute"); "goto(latitude, longitude, altitude)", "help", "land", "loiter",
} "positions", "speed(speed)"].join("\n"),
wrongParameters = displayMessage.bind(null, "Wrong parameters");
function waitForAltitude(target_altitude) { function checkNumber(value, toExecute) {
var altitude = getAltitude(); return (
while(Math.abs(altitude - target_altitude) > EPSILON_ALTITUDE) { Number.isNaN(value)
console.log( ? wrongParameters
`[DEMO] Waiting for altitude... (${altitude} , ${target_altitude})`); : toExecute.bind(null, value)
sleep(1000); );
altitude = getAltitude();
} }
}
function goToAltitude(target_altitude, wait, go) { function displayDronePositions() {
if(go) { Object.entries(me.droneDict).forEach(function ([id, drone]) {
exit_on_fail( console.log(
setAltitude(target_altitude), id,
`Failed to go to altitude ${target_altitude} m` drone.latitude,
drone.longitude,
drone.altitudeAbs,
drone.altitudeRel
); );
});
return 0;
} }
if(wait) { function exit() {
waitForAltitude(target_altitude); try {
me.f.close();
} catch (error) {
console.error(error);
}
me.exit(0);
} }
}
function checkNumber(value, toExecute) { me.onStart = function () {
return ( me.f = me.fdopen(me.in, "r");
Number.isNaN(value) console.log(help);
? wrongParameters };
: toExecute.bind(null, value)
);
}
function displayMessage(message) { me.onUpdate = function () {
console.log(message); var altitude,
return 0; latitude,
} longitude,
speed,
user_input,
undefined_cmd = false,
cmd,
ret;
function exit() { console.log("> ");
running = false; user_input = me.f.getline();
return 0;
} switch (user_input) {
function getInput() {
let undefined_cmd;
let altitude;
let cmd;
let latitude;
let longitude;
let s;
let speed;
const help = `
land
goto(point)
gotoCoord(latitude, longitude)
altitude(altitude)
speed(speed)
positions
reboot
exit
help
`;
const f = std.fdopen(std.in, "r");
running = true;
while (running) {
std.printf("> ");
s = f.getline();
undefined_cmd = false;
switch (s) {
case "altitude": case "altitude":
std.printf("Altitude: "); console.log("Altitude: ");
altitude = parseFloat(f.getline()); altitude = parseFloat(me.f.getline());
cmd = checkNumber(altitude, setAltitude); cmd = checkNumber(altitude, me.setAltitude);
break; break;
case "exit": case "exit":
cmd = exit; cmd = exit;
break; break;
/* case "gotoCoord": case "goto":
std.printf("Latitude: "); console.log("Latitude: ");
latitude = parseFloat(f.getline()); latitude = parseFloat(me.f.getline());
std.printf("Longitude: "); console.log("Longitude: ");
longitude = parseFloat(f.getline()); longitude = parseFloat(me.f.getline());
cmd = checkNumber(longitude, checkNumber(latitude, setTargetLatLong)); console.log("Altitude: ");
break;*/ altitude = parseFloat(me.f.getline());
cmd = checkNumber(
altitude,
checkNumber(longitude, checkNumber(latitude, me.setTargetCoordinates))
);
break;
case "help": case "help":
cmd = displayMessage.bind(null, help); cmd = displayMessage.bind(null, help);
break; break;
case "land": case "land":
cmd = land; cmd = me.triggerParachute;
break; break;
case "loiter": case "loiter":
cmd = loiter; cmd = me.loiter;
break; break;
case "positions": case "positions":
cmd = displayDronePositions; cmd = displayDronePositions;
break; break;
case "reboot":
cmd = reboot;
break;
case "speed": case "speed":
std.printf("Speed: "); console.log("Speed: ");
speed = parseFloat(f.getline()); speed = parseFloat(me.f.getline());
cmd = checkNumber(speed, setAirspeed); cmd = checkNumber(speed, me.setAirspeed);
break; break;
default: default:
...@@ -154,18 +113,12 @@ function getInput() { ...@@ -154,18 +113,12 @@ function getInput() {
cmd = displayMessage.bind(null, " Undefined command"); cmd = displayMessage.bind(null, " Undefined command");
} }
let ret = cmd(); ret = cmd();
if (ret) { if (ret) {
console.log(" [ERROR] function:\n", cmd, "\nreturn value:", ret); console.log(" [ERROR] function:\n", cmd, "\nreturn value:", ret);
} } else if (user_input !== "help" && !undefined_cmd) {
else if (s !== "help" && !undefined_cmd) {
console.log(" Command successful"); console.log(" Command successful");
} }
}; };
}(console, me));
\ No newline at end of file
f.close();
}
me.onUpdate = function() {
getInput();
};
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment