-
Notifications
You must be signed in to change notification settings - Fork 0
/
bbcopter.js
85 lines (73 loc) · 2.21 KB
/
bbcopter.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
//load node module requirements
var fs = global.fs = require('fs');
var util = require('util');
var async = require('async');
global.log = require('./tools/logger.js');
//load configuration file
//var config = global.config = JSON.parse(fs.readFileSync('./config/config.json'));
var config = global.config = require('./config/config.json');
//load global variables informations
require("./config/global.js")(config);
/**
* Initialize variables
*/
var plugins = [];
/**
* Initialize Modules
*/
log.init();
var SensorsController = require('./controller/sensor_controller.js');
// we load web server
if (config.webserver) {
try {
var WebServer = require("bbcopterWebServer");
} catch(err) {
log.error("Cannot load webserver module!\nPlease do npm install before launching the code.");
}
}
var sensor = new SensorsController();
sensor.on('statusChanged', function(status) {
console.log("status changed");
console.log(status);
if (status == SensorsController.Status.OK) {
sensor.init();
}
if (status == SensorsController.Status.READY) {
sensor.start();
}
});
sensor.load();
// We load motor module
/*
try {
var motor = global.motor = require(config.motor);
} catch(err) {
log.error("Cannot load motor module!\nPlease check your config.json file and you need to have the same name for your module under node_module folder");
global.motorOK = false;
}
// We load receiver module
try {
var receiver = global.receiver = require(config.receiver);
} catch(err) {
log.error("Cannot load receiver module!\nPlease check your config.json file and you need to have the same name for your module under node_module folder");
}
*/
/**
* Plugins must be under plugins folder. Each plugin must have its own folder.
* Config file must contain the folder name in the plugin parameter.
* All plugin must have main.js in its folder to make the quad recognize it.
*/
/*
if (config.plugins.length > 0) {
for (var i = 0; i < config.plugins.length; i++) {
try {
var plugin = new require('./plugins/' + config.plugins[i] + "/main.js")();
console.log(plugin.name);
plugins.push(plugin);
} catch(err) {
log.error("Cannot load plugin " + config.plugins[i] + ". Error during the load of the plugin. Error : " + err);
}
};
}
console.log(plugins[0]);
*/