1 | const Periodic = require( "Periodic" ); |
||
0 ignored issues
–
show
Backwards Compatibility
introduced
by
![]() |
|||
2 | const Listener = require( "Listener" ); |
||
0 ignored issues
–
show
|
|||
3 | |||
4 | class SystemGreeting |
||
0 ignored issues
–
show
|
|||
5 | { |
||
6 | constructor( name, deps ) |
||
7 | { |
||
8 | console.log( "SystemGreeting plugin loaded" ); |
||
9 | |||
10 | this.globalBus = deps.globalEventLoop; |
||
11 | this.cockpitBus = deps.cockpit; |
||
12 | |||
13 | var wakeAttempts = 0; |
||
14 | var maxWakeAttempts = 10; |
||
15 | |||
16 | this.mcuStatusListener = new Listener( this.globalBus, 'mcu.status', false, ( data ) => |
||
0 ignored issues
–
show
'arrow function 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: ![]() |
|||
17 | { |
||
18 | // Listen for awake response |
||
19 | if( 'awake' in data ) |
||
20 | { |
||
21 | // Stop wakeup |
||
22 | this.wakeMCU.stop(); |
||
23 | this.mcuStatusListener.disable(); |
||
24 | } |
||
25 | }); |
||
26 | |||
27 | this.mcuResetListener = new Listener( this.globalBus, 'mcu.ResetMCU', false, () => |
||
0 ignored issues
–
show
'arrow function 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: ![]() |
|||
28 | { |
||
29 | // Perform another system greeting to show that the MCU has been updated/reset |
||
30 | wakeAttempts = 0; |
||
31 | this.mcuStatusListener.enable(); |
||
32 | this.wakeMCU.start(); |
||
33 | }); |
||
34 | |||
35 | this.wakeMCU = new Periodic( 1000, "timeout", () => |
||
0 ignored issues
–
show
'arrow function 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: ![]() |
|||
36 | { |
||
37 | if( wakeAttempts < maxWakeAttempts ) |
||
38 | { |
||
39 | // Emit wake command to mcu |
||
40 | this.globalBus.emit( 'mcu.SendCommand', "wake()" ); |
||
41 | wakeAttempts++; |
||
42 | } |
||
43 | else |
||
44 | { |
||
45 | // Stop wakeup |
||
46 | this.wakeMCU.stop(); |
||
47 | this.mcuStatusListener.disable(); |
||
48 | } |
||
49 | }); |
||
50 | } |
||
51 | |||
52 | start() |
||
53 | { |
||
54 | this.mcuResetListener.enable(); |
||
55 | this.mcuStatusListener.enable(); |
||
56 | this.wakeMCU.start(); |
||
57 | } |
||
58 | |||
59 | stop() |
||
60 | { |
||
61 | this.wakeMCU.stop(); |
||
62 | this.mcuStatusListener.disable(); |
||
63 | this.mcuResetListener.disable(); |
||
64 | } |
||
65 | |||
66 | getSettingSchema() |
||
67 | { |
||
68 | //from http://json-schema.org/examples.html |
||
69 | return [{ |
||
70 | 'title': 'System Greeting', |
||
71 | 'type': 'object', |
||
72 | 'managedBy': '_hidden', |
||
73 | 'id': 'system-greeting', |
||
74 | 'properties': {}, |
||
75 | 'required': [] |
||
76 | }]; |
||
77 | } |
||
78 | } |
||
79 | |||
80 | module.exports = (name, deps) => |
||
0 ignored issues
–
show
'arrow function 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: ![]() |
|||
81 | { |
||
82 | return new SystemGreeting( name, deps ); |
||
83 | } |
||
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: ![]() |