1 | (function () { |
||
2 | function NavigationData(name, deps) { |
||
3 | deps.logger.debug('Navigation Data plugin loaded'); |
||
4 | var navdata = { |
||
5 | roll: 0, |
||
6 | pitch: 0, |
||
7 | yaw: 0, |
||
8 | thrust: 0, |
||
9 | depth: 0, |
||
10 | heading: 0 |
||
11 | }; |
||
12 | this.state = {imuMode: 'gyro'} |
||
0 ignored issues
–
show
|
|||
13 | var self=this; |
||
14 | |||
15 | // Encoding helper functions |
||
16 | function encode( floatIn ) |
||
17 | { |
||
18 | return parseInt( floatIn * 1000 ); |
||
19 | } |
||
20 | |||
21 | function decode( intIn ) |
||
22 | { |
||
23 | return ( intIn * 0.001 ); |
||
24 | } |
||
25 | |||
26 | // IMU state provided by IMU plugin |
||
27 | deps.globalEventLoop.on('plugin.imu.roll', function (value) |
||
28 | { |
||
29 | navdata.roll = value; |
||
30 | }); |
||
31 | |||
32 | deps.globalEventLoop.on('plugin.imu.pitch', function (value) |
||
33 | { |
||
34 | navdata.pitch = value; |
||
35 | }); |
||
36 | |||
37 | deps.globalEventLoop.on('plugin.imu.yaw', function (value) |
||
38 | { |
||
39 | navdata.yaw = value; |
||
40 | navdata.heading = value; |
||
41 | }); |
||
42 | |||
43 | deps.globalEventLoop.on('plugin.diveProfile.depth', function (value) |
||
44 | { |
||
45 | navdata.depth = value; |
||
46 | }); |
||
47 | |||
48 | deps.globalEventLoop.on('mcu.status', function (status) |
||
49 | { |
||
50 | // TODO: Move to IMU plugin |
||
51 | if ('imu_mode' in status) |
||
52 | { |
||
53 | self.state.imuMode = status.imu_mode==0?'gyro':'compass'; |
||
0 ignored issues
–
show
It is recommended to use
=== to compare with 0 .
Generally, it is recommended to use strict comparison whenever possible and not to rely on the weaker type-juggling comparison operator. ![]() |
|||
54 | deps.cockpit.emit('plugin.navigationData.state', self.state); |
||
55 | } |
||
56 | |||
57 | if ('fthr' in status) |
||
58 | { |
||
59 | navdata.thrust = status.fthr; |
||
60 | } |
||
61 | }); |
||
62 | |||
63 | // TODO: Move to IMU plugin |
||
64 | deps.cockpit.on('plugin.navigationData.setState', function (state) |
||
65 | { |
||
66 | if (state.imuMode) |
||
67 | { |
||
68 | var mode = 0; //gyro |
||
69 | if (state.imuMode=="compass") |
||
70 | { |
||
71 | mode = 1 |
||
0 ignored issues
–
show
There should be a semicolon.
Requirement of semicolons purely is a coding style issue since JavaScript has specific rules about semicolons which are followed by all browsers. Further Readings: ![]() |
|||
72 | } |
||
73 | deps.globalEventLoop.emit('mcu.SendCommand', `imu_mode(${mode})`); |
||
0 ignored issues
–
show
'template literal syntax' is only available in ES6 (use 'esversion: 6').
Generally using ECMAScript 6 specific syntax is fine if you are sure that it is already supported by all engines which are supposed to run this code. Further Reading: ![]() |
|||
74 | } |
||
75 | }); |
||
76 | |||
77 | // Emit navdata at 10Hz rate |
||
78 | setInterval(function () |
||
79 | { |
||
80 | deps.cockpit.emit('plugin.navigationData.data', navdata); |
||
81 | }, 100); |
||
82 | } |
||
83 | |||
84 | module.exports = function (name, deps) { |
||
85 | return new NavigationData(name, deps); |
||
86 | }; |
||
87 | }()); |
Requirement of semicolons purely is a coding style issue since JavaScript has specific rules about semicolons which are followed by all browsers.
Further Readings: