1 | var sharedFunctions = require('./public/js/telemetryToSystemPower.js'); |
||
2 | var PREFERENCES_NS = 'plugins'; |
||
3 | |||
4 | class SystemEnvironment |
||
0 ignored issues
–
show
Backwards Compatibility
introduced
by
![]() |
|||
5 | { |
||
6 | constructor(name, deps) |
||
7 | { |
||
8 | deps.logger.debug('Controllerboard2x:SystemEnvironment plugin loaded'); |
||
9 | } |
||
10 | } |
||
11 | |||
12 | class SystemPower |
||
0 ignored issues
–
show
|
|||
13 | { |
||
14 | constructor(name, deps) |
||
15 | { |
||
16 | deps.logger.debug('Controllerboard2x:SystemPower plugin loaded'); |
||
17 | |||
18 | this.config = deps.config; |
||
19 | this.cockpit = deps.cockpit; |
||
20 | var self = this; |
||
21 | |||
22 | deps.cockpit.on('plugin.systemPower.powerESCs', function (enable) |
||
23 | { |
||
24 | if (enable) |
||
25 | { |
||
26 | deps.globalEventLoop.emit('mcu.SendCommand', 'escp(1)'); |
||
27 | } |
||
28 | else |
||
29 | { |
||
30 | deps.globalEventLoop.emit('mcu.SendCommand', 'escp(0)'); |
||
31 | } |
||
32 | }); |
||
33 | } |
||
34 | |||
35 | getSettingSchema() |
||
36 | { |
||
37 | // TODO: |
||
38 | // If settings already exist, new defaults aren't available. |
||
39 | // Do we have an idiomatic way for upgrading old settings so that |
||
40 | // renamed properties/values and new ones replace them? |
||
41 | |||
42 | var b = this.config.preferences.get(PREFERENCES_NS); |
||
43 | |||
44 | return [{ |
||
45 | id: 'batteryDefinitions', |
||
46 | title: 'Battery Formulas', |
||
47 | category: 'power', |
||
48 | type: 'object', |
||
49 | |||
50 | properties: |
||
51 | { |
||
52 | batteries: |
||
53 | { |
||
54 | title: "Batteries", |
||
55 | type: "array", |
||
56 | minItems: 1, |
||
57 | uniqueItems: true, |
||
58 | propertyOrder: 1, |
||
59 | |||
60 | items: |
||
61 | { |
||
62 | type: "object", |
||
63 | headerTemplate: "{{self.name}}", |
||
64 | properties: |
||
65 | { |
||
66 | name: { type: 'string', default: "New Battery" }, |
||
67 | minVoltage: { type: 'number', default: 8 }, |
||
68 | maxVoltage: { type: 'number', default: 12.6 } |
||
69 | }, |
||
70 | required: |
||
71 | [ |
||
72 | 'name', |
||
73 | 'minVoltage', |
||
74 | 'maxVoltage' |
||
75 | ] |
||
76 | }, |
||
77 | default: |
||
78 | [ |
||
79 | { |
||
80 | name: 'TrustFire', |
||
81 | minVoltage: 8, |
||
82 | maxVoltage: 13 |
||
83 | }, |
||
84 | { |
||
85 | name: 'LiFePO4 (OpenROV White)', |
||
86 | minVoltage: 7, |
||
87 | maxVoltage: 10 |
||
88 | }, |
||
89 | { |
||
90 | name: 'High-Capacity NMC (OpenROV Blue)', |
||
91 | minVoltage: 8, |
||
92 | maxVoltage: 12.6 |
||
93 | } |
||
94 | ] |
||
95 | }, |
||
96 | selectedBattery: |
||
97 | { |
||
98 | title: "Selected Battery", |
||
99 | type: 'string', |
||
100 | propertyOrder: 0, |
||
101 | |||
102 | enumSource: "possible_batteries", |
||
103 | enumValue: "{{item.name}}", |
||
104 | watch: |
||
105 | { |
||
106 | "possible_batteries": "root.batteryDefinitions.batteries" |
||
107 | }, |
||
108 | |||
109 | default: "LiFePO4 (OpenROV White)" |
||
110 | } |
||
111 | }, |
||
112 | |||
113 | required: |
||
114 | [ |
||
115 | 'batteries', |
||
116 | 'selectedBattery' |
||
117 | ] |
||
118 | }]; |
||
119 | } |
||
120 | }; |
||
0 ignored issues
–
show
|
|||
121 | |||
122 | // Controller Board 2X Plugin |
||
123 | class Controllerboard2x |
||
0 ignored issues
–
show
|
|||
124 | { |
||
125 | constructor(name, deps) |
||
126 | { |
||
127 | deps.logger.debug('Controllerboard2x plugin loaded'); |
||
128 | |||
129 | this.systempower = new SystemPower(name, deps); |
||
130 | this.systemenvironment = new SystemEnvironment(name, deps); |
||
131 | } |
||
132 | |||
133 | getSettingSchema() |
||
134 | { |
||
135 | var item = this.systempower.getSettingSchema(); |
||
136 | return item; |
||
137 | } |
||
138 | } |
||
139 | |||
140 | module.exports = function (name, deps) |
||
141 | { |
||
142 | if( process.env.PRODUCTID == "trident" ) |
||
143 | { |
||
144 | deps.logger.debug( "Not supported on trident" ); |
||
145 | return {}; |
||
146 | } |
||
147 | |||
148 | return new Controllerboard2x(name, deps); |
||
149 | }; |