remoterigs-raspberrypi 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +3 -0
- package/package.json +20 -0
- package/src/common/code.js +62 -0
- package/src/common/debug.js +77 -0
- package/src/common/signalr.js +189 -0
- package/src/common/webrtc-streamer-wrapper.js +483 -0
- package/src/component/component.js +358 -0
- package/src/component/input/input.js +26 -0
- package/src/component/pin/pin.js +92 -0
- package/src/component/property/property.js +32 -0
- package/src/component/status/status-number.js +7 -0
- package/src/component/status/status-state.js +27 -0
- package/src/component/status/status.js +41 -0
- package/src/config.json.default +8 -0
- package/src/models/models.js +1045 -0
- package/src/rig.js +65 -0
- package/src/server.js +87 -0
|
@@ -0,0 +1,358 @@
|
|
|
1
|
+
import Debug from '../common/debug.js';
|
|
2
|
+
import WebRTCStreamerWrapper from "../common/webrtc-streamer-wrapper.js";
|
|
3
|
+
import Code from "../common/code.js";
|
|
4
|
+
import StatusNumber from './status/status-number.js';
|
|
5
|
+
import StatusState from './status/status-state.js';
|
|
6
|
+
import Pin from './pin/pin.js';
|
|
7
|
+
import Property from './property/property.js';
|
|
8
|
+
import Input from './input/input.js';
|
|
9
|
+
import { CodeBlockType, ComponentType, HighScoreModel, LogSettingType, StatusType } from '../models/models.js';
|
|
10
|
+
import SignalR from '../common/signalr.js';
|
|
11
|
+
export default class Component {
|
|
12
|
+
constructor(rig, component, clientRTCConfigurationViewModel, parent) {
|
|
13
|
+
this.rig = rig;
|
|
14
|
+
this.child = {};
|
|
15
|
+
this.property = {};
|
|
16
|
+
this.input = {};
|
|
17
|
+
this.pin = {};
|
|
18
|
+
this.status = {};
|
|
19
|
+
this.boolean = {};
|
|
20
|
+
this.number = {};
|
|
21
|
+
this.string = {};
|
|
22
|
+
this.timeout = {};
|
|
23
|
+
this.streamer = null;
|
|
24
|
+
this.callback = null;
|
|
25
|
+
this.SandboxVars = {};
|
|
26
|
+
this.component = component;
|
|
27
|
+
this.parent = parent;
|
|
28
|
+
this.clientRTCConfigurationViewModel = clientRTCConfigurationViewModel;
|
|
29
|
+
this.Log("component: " + this.component.id + " " + this.component.name);
|
|
30
|
+
for (var i = 0; i < this.component.children.length; i++) {
|
|
31
|
+
try {
|
|
32
|
+
var child = new Component(this.rig, this.component.children[i], this.clientRTCConfigurationViewModel, this);
|
|
33
|
+
this.child[child.GetStorageName()] = child;
|
|
34
|
+
}
|
|
35
|
+
catch (ex) {
|
|
36
|
+
this.Error("FAILED TO CREATE CHILD COMPONENT: " + ex);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
for (var i = 0; i < this.component.properties.length; i++) {
|
|
40
|
+
this.property[this.component.properties[i].componentDefinitionPropertyName.toLowerCase()] = new Property(this.component.properties[i]);
|
|
41
|
+
this.Log(this.property[this.component.properties[i].componentDefinitionPropertyName.toLowerCase()].GetLogMessage());
|
|
42
|
+
}
|
|
43
|
+
for (var i = 0; i < this.component.inputs.length; i++) {
|
|
44
|
+
this.input[this.component.inputs[i].componentDefinitionInputName] = new Input(this.component.inputs[i]);
|
|
45
|
+
this.Log(this.input[this.component.inputs[i].componentDefinitionInputName].GetLogMessage());
|
|
46
|
+
}
|
|
47
|
+
for (var i = 0; i < this.component.pins.length; i++) {
|
|
48
|
+
this.pin[this.component.pins[i].componentDefinitionMicroControllerPinName] = new Pin(this, this.component.pins[i]);
|
|
49
|
+
this.Log(this.pin[this.component.pins[i].componentDefinitionMicroControllerPinName].GetLogMessage());
|
|
50
|
+
}
|
|
51
|
+
for (var i = 0; i < this.component.status.length; i++) {
|
|
52
|
+
switch (this.component.status[i].type) {
|
|
53
|
+
case StatusType.RigComponentStates:
|
|
54
|
+
this.status[this.component.status[i].name.toLowerCase()] = new StatusState(this.component.status[i], rig.rig.id, this.component.id);
|
|
55
|
+
break;
|
|
56
|
+
case StatusType.RigComponentNumber:
|
|
57
|
+
this.status[this.component.status[i].name.toLowerCase()] = new StatusNumber(this.component.status[i], rig.rig.id, this.component.id);
|
|
58
|
+
break;
|
|
59
|
+
default:
|
|
60
|
+
Debug.Error(this.GetName(), "UNKNOWN STATUS TYPE: '" + this.component.status[i].type + "'");
|
|
61
|
+
}
|
|
62
|
+
this.Log("status: '" + this.component.status[i].name.toLowerCase() + "'");
|
|
63
|
+
}
|
|
64
|
+
for (var i = 0; i < this.component.codeBlocks.length; i++) {
|
|
65
|
+
if (this.component.codeBlocks[i].type == CodeBlockType.Function) {
|
|
66
|
+
try {
|
|
67
|
+
switch (this.component.codeBlocks[i].parameters.length) {
|
|
68
|
+
case 1:
|
|
69
|
+
this[this.component.codeBlocks[i].name] = new Function(this.component.codeBlocks[i].parameters[0].name, this.component.codeBlocks[i].code);
|
|
70
|
+
break;
|
|
71
|
+
case 2:
|
|
72
|
+
this[this.component.codeBlocks[i].name] = new Function(this.component.codeBlocks[i].parameters[0].name, this.component.codeBlocks[i].parameters[1].name, this.component.codeBlocks[i].code);
|
|
73
|
+
break;
|
|
74
|
+
case 3:
|
|
75
|
+
this[this.component.codeBlocks[i].name] = new Function(this.component.codeBlocks[i].parameters[0].name, this.component.codeBlocks[i].parameters[1].name, this.component.codeBlocks[i].parameters[2].name, this.component.codeBlocks[i].code);
|
|
76
|
+
break;
|
|
77
|
+
case 4:
|
|
78
|
+
this[this.component.codeBlocks[i].name] = new Function(this.component.codeBlocks[i].parameters[0].name, this.component.codeBlocks[i].parameters[1].name, this.component.codeBlocks[i].parameters[2].name, this.component.codeBlocks[i].parameters[3].name, this.component.codeBlocks[i].code);
|
|
79
|
+
break;
|
|
80
|
+
case 5:
|
|
81
|
+
this[this.component.codeBlocks[i].name] = new Function(this.component.codeBlocks[i].parameters[0].name, this.component.codeBlocks[i].parameters[1].name, this.component.codeBlocks[i].parameters[2].name, this.component.codeBlocks[i].parameters[3].name, this.component.codeBlocks[i].parameters[4].name, this.component.codeBlocks[i].code);
|
|
82
|
+
break;
|
|
83
|
+
case 6:
|
|
84
|
+
this[this.component.codeBlocks[i].name] = new Function(this.component.codeBlocks[i].parameters[0].name, this.component.codeBlocks[i].parameters[1].name, this.component.codeBlocks[i].parameters[2].name, this.component.codeBlocks[i].parameters[3].name, this.component.codeBlocks[i].parameters[4].name, this.component.codeBlocks[i].parameters[5].name, this.component.codeBlocks[i].code);
|
|
85
|
+
break;
|
|
86
|
+
case 7:
|
|
87
|
+
this[this.component.codeBlocks[i].name] = new Function(this.component.codeBlocks[i].parameters[0].name, this.component.codeBlocks[i].parameters[1].name, this.component.codeBlocks[i].parameters[2].name, this.component.codeBlocks[i].parameters[3].name, this.component.codeBlocks[i].parameters[4].name, this.component.codeBlocks[i].parameters[5].name, this.component.codeBlocks[i].parameters[6].name, this.component.codeBlocks[i].code);
|
|
88
|
+
break;
|
|
89
|
+
default:
|
|
90
|
+
this[this.component.codeBlocks[i].name] = new Function(this.component.codeBlocks[i].code);
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
this.Log("codeblock: '" + this.component.codeBlocks[i].name.toLowerCase() + "'");
|
|
94
|
+
}
|
|
95
|
+
catch (ex) {
|
|
96
|
+
if (ex instanceof Error) {
|
|
97
|
+
this.LogAlways("Syntax error adding the function '" + this.component.codeBlocks[i].name + "' to component '" + this.component.name + "' (#" + this.component.id + ")");
|
|
98
|
+
this.LogAlways("Error:" + ex.message);
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
this.Error("UNKNOWN ERROR ADDING THE FUNCTION '" + this.component.codeBlocks[i].name + "' TO COMPONENT '" + this.component.name + "' (#" + this.component.id + "): " + ex);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
this.SandboxVars = Code.GetComponentContext(this);
|
|
107
|
+
var allFunctions = new Array();
|
|
108
|
+
this.GetFunctions(allFunctions);
|
|
109
|
+
for (const func of allFunctions) {
|
|
110
|
+
//this.Log("func added to SandboxVars: '" + func + "'");
|
|
111
|
+
this.SandboxVars[func] = this[func];
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
Init() {
|
|
115
|
+
for (const key in this.child) {
|
|
116
|
+
this.child[key].Init();
|
|
117
|
+
}
|
|
118
|
+
if (this.component.componentType == ComponentType.Camera) {
|
|
119
|
+
var devicePath = this.GetProperty("devicepath");
|
|
120
|
+
if (devicePath != undefined) {
|
|
121
|
+
if (this.clientRTCConfigurationViewModel != undefined) {
|
|
122
|
+
this.streamer = new WebRTCStreamerWrapper(this, this.clientRTCConfigurationViewModel, this.rig.rig.videoType);
|
|
123
|
+
this.streamer.Start().catch(console.error);
|
|
124
|
+
this.Log("init webcam streamer success: " + devicePath);
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
this.Log("init webcam FAILED; missing clientRTCConfigurationViewModel");
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
this.Log("init webcam FAILED; missing devicepath");
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
for (var i = 0; i < this.component.codeBlocks.length; i++) {
|
|
135
|
+
if (this.component.codeBlocks[i].type == CodeBlockType.Init) {
|
|
136
|
+
try {
|
|
137
|
+
eval(this.component.codeBlocks[i].code);
|
|
138
|
+
}
|
|
139
|
+
catch (ex_eval) {
|
|
140
|
+
try {
|
|
141
|
+
Code.runSandboxed(this.component.codeBlocks[i].code, this.SandboxVars);
|
|
142
|
+
}
|
|
143
|
+
catch (ex) {
|
|
144
|
+
this.Log("ERROR during execution of code block #" + this.component.codeBlocks[i].id + " '" + this.component.codeBlocks[i].name + "' - error: " + ex);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
Shutdown() {
|
|
151
|
+
for (const key in this.child) {
|
|
152
|
+
this.child[key].Shutdown();
|
|
153
|
+
}
|
|
154
|
+
for (var i = 0; i < this.component.codeBlocks.length; i++) {
|
|
155
|
+
if (this.component.codeBlocks[i].type == CodeBlockType.Shutdown) {
|
|
156
|
+
try {
|
|
157
|
+
eval(this.component.codeBlocks[i].code);
|
|
158
|
+
}
|
|
159
|
+
catch (ex_eval) {
|
|
160
|
+
try {
|
|
161
|
+
Code.runSandboxed(this.component.codeBlocks[i].code, this.SandboxVars);
|
|
162
|
+
}
|
|
163
|
+
catch (ex) {
|
|
164
|
+
this.Log("ERROR during execution of shutdown code block #" + this.component.codeBlocks[i].id + " '" + this.component.codeBlocks[i].name + "' - error: " + ex);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
ProcessKeyEvent(event) {
|
|
171
|
+
Debug.Log(LogSettingType.KeyEvents, undefined, this.GetName(), "ProcessKeyEvent: componentInputId=" + event.componentInputId + " type=" + event.type + " timestamp: " + event.timeStamp);
|
|
172
|
+
for (const key in this.child) {
|
|
173
|
+
this.child[key].ProcessKeyEvent(event);
|
|
174
|
+
}
|
|
175
|
+
for (var i = 0; i < this.component.codeBlocks.length; i++) {
|
|
176
|
+
if (this.component.codeBlocks[i].type == CodeBlockType.ProcessKeyEvent) {
|
|
177
|
+
try {
|
|
178
|
+
eval(this.component.codeBlocks[i].code);
|
|
179
|
+
}
|
|
180
|
+
catch (ex_eval) {
|
|
181
|
+
try {
|
|
182
|
+
Code.runSandboxed(this.component.codeBlocks[i].code, {
|
|
183
|
+
event: event,
|
|
184
|
+
...this.SandboxVars,
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
catch (ex) {
|
|
188
|
+
this.Log("ERROR during execution of ProcessKeyEvent code block #" + this.component.codeBlocks[i].id + " '" + this.component.codeBlocks[i].name + "' - error: " + ex);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
PutWebRTCMessage(message) {
|
|
195
|
+
if (this.component.id == message.componentId) {
|
|
196
|
+
this.Log("PutWebRTCMessage username: " + message.username + " rigOwnerUsername: " + message.rigOwnerUsername);
|
|
197
|
+
if (this.streamer != null) {
|
|
198
|
+
this.streamer.PutWebRTCMessage(message);
|
|
199
|
+
}
|
|
200
|
+
else {
|
|
201
|
+
this.Error("No streamer to put WebRTC message to.");
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
else {
|
|
205
|
+
for (const key in this.child) {
|
|
206
|
+
this.child[key].PutWebRTCMessage(message);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
SendCurrent() {
|
|
211
|
+
for (const key in this.child) {
|
|
212
|
+
this.child[key].SendCurrent();
|
|
213
|
+
}
|
|
214
|
+
for (const key in this.status) {
|
|
215
|
+
this.status[key].SendCurrent();
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
PinAlert(code, level, tick) {
|
|
219
|
+
try {
|
|
220
|
+
eval(code.code);
|
|
221
|
+
}
|
|
222
|
+
catch (ex_eval) {
|
|
223
|
+
try {
|
|
224
|
+
Code.runSandboxed(code.code, {
|
|
225
|
+
level: level,
|
|
226
|
+
tick: tick,
|
|
227
|
+
...this.SandboxVars,
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
catch (ex) {
|
|
231
|
+
this.Log("ERROR during execution of PinAlert code block #" + code.id + " '" + code.name + "' - error: " + ex);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
SetCallback(callback) {
|
|
236
|
+
this.callback = callback;
|
|
237
|
+
}
|
|
238
|
+
SetStatus(status, value) {
|
|
239
|
+
if (this.status.hasOwnProperty(status.toLowerCase())) {
|
|
240
|
+
this.status[status.toLowerCase()].UpdateStatus(value);
|
|
241
|
+
}
|
|
242
|
+
else {
|
|
243
|
+
this.Error("Status not found: '" + status + "'");
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
SetStatusState(status, value) {
|
|
247
|
+
if (this.status.hasOwnProperty(status.toLowerCase())) {
|
|
248
|
+
this.status[status.toLowerCase()].SelectState(value);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
GetStatus(status) {
|
|
252
|
+
if (this.status.hasOwnProperty(status.toLowerCase())) {
|
|
253
|
+
var value = this.status[status.toLowerCase()].GetValue();
|
|
254
|
+
if (value != null) {
|
|
255
|
+
return value;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
else {
|
|
259
|
+
this.Error("Status not found: '" + status + "'");
|
|
260
|
+
}
|
|
261
|
+
return 0;
|
|
262
|
+
}
|
|
263
|
+
GetStatusState(status) {
|
|
264
|
+
if (this.status.hasOwnProperty(status.toLowerCase())) {
|
|
265
|
+
this.status[status.toLowerCase()].GetValueStr();
|
|
266
|
+
}
|
|
267
|
+
return "";
|
|
268
|
+
}
|
|
269
|
+
GetName() {
|
|
270
|
+
var name = "";
|
|
271
|
+
if (this.parent != null) {
|
|
272
|
+
name = this.parent.GetName() + " > ";
|
|
273
|
+
}
|
|
274
|
+
name += "#" + this.component.id + " " + this.component.name;
|
|
275
|
+
return name;
|
|
276
|
+
}
|
|
277
|
+
GetStorageName() {
|
|
278
|
+
return this.component.componentDefinitionName.toLowerCase();
|
|
279
|
+
}
|
|
280
|
+
GetChild(name) {
|
|
281
|
+
if (this.child.hasOwnProperty(name.toLowerCase())) {
|
|
282
|
+
return this.child[name.toLowerCase()];
|
|
283
|
+
}
|
|
284
|
+
else {
|
|
285
|
+
this.Log("Child not found: '" + name + "'");
|
|
286
|
+
var av = "";
|
|
287
|
+
for (const key in this.child) {
|
|
288
|
+
if (av != "") {
|
|
289
|
+
av += ", ";
|
|
290
|
+
}
|
|
291
|
+
av += "'" + key + "'";
|
|
292
|
+
}
|
|
293
|
+
this.Log("Children names: " + av);
|
|
294
|
+
return this;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
Log(message) {
|
|
298
|
+
Debug.Log(LogSettingType.Component, this.component.id, this.GetName(), message);
|
|
299
|
+
}
|
|
300
|
+
LogAlways(message) {
|
|
301
|
+
Debug.LogAlways(this.GetName(), message, true);
|
|
302
|
+
}
|
|
303
|
+
Error(message) {
|
|
304
|
+
Debug.Error(this.GetName(), message);
|
|
305
|
+
}
|
|
306
|
+
GetProperty(name) {
|
|
307
|
+
if (!this.property.hasOwnProperty(name.toLowerCase())) {
|
|
308
|
+
this.Log("Property not found: '" + name + "'");
|
|
309
|
+
return "";
|
|
310
|
+
}
|
|
311
|
+
return this.property[name.toLowerCase()].value;
|
|
312
|
+
}
|
|
313
|
+
GetPropertyNumber(name) {
|
|
314
|
+
if (!this.property.hasOwnProperty(name.toLowerCase())) {
|
|
315
|
+
this.Log("Property not found: '" + name + "'");
|
|
316
|
+
return 0;
|
|
317
|
+
}
|
|
318
|
+
return parseInt(this.property[name.toLowerCase()].value);
|
|
319
|
+
}
|
|
320
|
+
SetTimeOut(name, callback, delay) {
|
|
321
|
+
this.ResetTimeOut(name);
|
|
322
|
+
this.timeout[name] = setTimeout(callback, delay);
|
|
323
|
+
}
|
|
324
|
+
ResetTimeOut(name) {
|
|
325
|
+
if (this.timeout[name] != undefined) {
|
|
326
|
+
clearTimeout(this.timeout[name]);
|
|
327
|
+
delete this.timeout[name];
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
IsEventInput(name, event) {
|
|
331
|
+
if (this.input[name] != undefined) {
|
|
332
|
+
if (this.input[name].componentInputId == event.componentInputId) {
|
|
333
|
+
return true;
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
else {
|
|
337
|
+
this.Error("Input not found: '" + name + "'");
|
|
338
|
+
}
|
|
339
|
+
return false;
|
|
340
|
+
}
|
|
341
|
+
GetFunctions(functions) {
|
|
342
|
+
//for (const key in this.child) {
|
|
343
|
+
// this.child[key].GetFunctions(functions);
|
|
344
|
+
//}
|
|
345
|
+
for (var i = 0; i < this.component.codeBlocks.length; i++) {
|
|
346
|
+
if (this.component.codeBlocks[i].type == CodeBlockType.Function) {
|
|
347
|
+
functions.push(this.component.codeBlocks[i].name);
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
AddPointsToCurrentSessionHighScore(points) {
|
|
352
|
+
var highScoreModel = new HighScoreModel();
|
|
353
|
+
highScoreModel.points = points;
|
|
354
|
+
this.Log("Adding " + points + " points to current session high score.");
|
|
355
|
+
SignalR.AddHighScorePoints(highScoreModel);
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
//# sourceMappingURL=component.js.map
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export default class Input {
|
|
2
|
+
constructor(componentInput) {
|
|
3
|
+
this.componentInput = componentInput;
|
|
4
|
+
this.componentInputId = this.componentInput.componentInputId;
|
|
5
|
+
}
|
|
6
|
+
GetLogMessage() {
|
|
7
|
+
//codeBlock ?: CodeBlockViewModel | undefined;
|
|
8
|
+
var tMessage = this.GetName();
|
|
9
|
+
tMessage += " - Input category: '" + this.componentInput.input.categoryName + "'";
|
|
10
|
+
tMessage += " - Input name: '" + this.componentInput.input.name + "'";
|
|
11
|
+
tMessage += " - Input componentDefinitionInputId: '" + this.componentInput.componentDefinitionInputId + "'";
|
|
12
|
+
//tMessage += " - Input componentDefinitionInputId: '" + this.input.componentDefinitionInputId + "'";
|
|
13
|
+
//tMessage += " - Input componentDefinitionInputName: '" + this.input.componentDefinitionInputName + "'";
|
|
14
|
+
//if (this.microcontrollerpin.componentMicroControllerPin.gpio != undefined) {
|
|
15
|
+
// tMessage += " - GPIO: '" + this.microcontrollerpin.componentMicroControllerPin.gpio + "'";
|
|
16
|
+
//}
|
|
17
|
+
//if (this.microcontrollerpin.codeBlock != undefined) {
|
|
18
|
+
// tMessage += " - AlertCode: '" + this.microcontrollerpin.componentMicroControllerPin.gpio + "'";
|
|
19
|
+
//}
|
|
20
|
+
return tMessage;
|
|
21
|
+
}
|
|
22
|
+
GetName() {
|
|
23
|
+
return "input '" + this.componentInput.componentDefinitionInputName + "'";
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=input.js.map
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { Gpio } from 'pigpio';
|
|
2
|
+
import { PinMode, PinPullUpDown } from '../../models/models.js';
|
|
3
|
+
import Debug from '../../common/debug.js';
|
|
4
|
+
export default class Pin {
|
|
5
|
+
constructor(component, pin) {
|
|
6
|
+
this.component = component;
|
|
7
|
+
this.microcontrollerpin = pin;
|
|
8
|
+
if (this.microcontrollerpin.componentMicroControllerPin.gpio != undefined) {
|
|
9
|
+
if (this.microcontrollerpin.pinMode == PinMode.INPUT) {
|
|
10
|
+
var pinPullUpDown = PinPullUpDown.PUD_OFF;
|
|
11
|
+
if (this.microcontrollerpin.pinPullUpDown == PinPullUpDown.PUD_UP) {
|
|
12
|
+
pinPullUpDown = Gpio.PUD_UP;
|
|
13
|
+
}
|
|
14
|
+
else if (this.microcontrollerpin.pinPullUpDown == PinPullUpDown.PUD_DOWN) {
|
|
15
|
+
pinPullUpDown = Gpio.PUD_DOWN;
|
|
16
|
+
}
|
|
17
|
+
this.pin = new Gpio(this.microcontrollerpin.componentMicroControllerPin.gpio, {
|
|
18
|
+
mode: Gpio.INPUT,
|
|
19
|
+
pullUpDown: pinPullUpDown,
|
|
20
|
+
alert: this.microcontrollerpin.codeBlock != undefined
|
|
21
|
+
});
|
|
22
|
+
if (this.microcontrollerpin.codeBlock != undefined) {
|
|
23
|
+
this.pin.enableAlert();
|
|
24
|
+
this.pin.on('alert', (level, tick) => {
|
|
25
|
+
if (this.microcontrollerpin.codeBlock != undefined) {
|
|
26
|
+
this.component.PinAlert(this.microcontrollerpin.codeBlock, level, tick);
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
this.pin = new Gpio(this.microcontrollerpin.componentMicroControllerPin.gpio, {
|
|
33
|
+
mode: Gpio.OUTPUT
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
Debug.Error(this.GetName(), "invalid pin");
|
|
39
|
+
this.pin = new Gpio(1, {
|
|
40
|
+
mode: Gpio.INPUT,
|
|
41
|
+
pullUpDown: Gpio.PUD_DOWN,
|
|
42
|
+
alert: true
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
servoWrite(value) {
|
|
47
|
+
this.pin.servoWrite(value);
|
|
48
|
+
}
|
|
49
|
+
GetEnablePullUp() {
|
|
50
|
+
return this.microcontrollerpin.pinPullUpDown == PinPullUpDown.PUD_UP;
|
|
51
|
+
}
|
|
52
|
+
Read() {
|
|
53
|
+
return this.pin.digitalRead();
|
|
54
|
+
}
|
|
55
|
+
GetLogMessage() {
|
|
56
|
+
//codeBlock ?: CodeBlockViewModel | undefined;
|
|
57
|
+
var tMessage = this.GetName();
|
|
58
|
+
tMessage += " - PinMode: '" + this.GetPinMode() + "'";
|
|
59
|
+
tMessage += " - PinPullUpDown: '" + this.GetPinPullUpDownStr() + "'";
|
|
60
|
+
if (this.microcontrollerpin.componentMicroControllerPin.gpio != undefined) {
|
|
61
|
+
tMessage += " - GPIO: '" + this.microcontrollerpin.componentMicroControllerPin.gpio + "'";
|
|
62
|
+
}
|
|
63
|
+
//if (this.microcontrollerpin.codeBlock != undefined) {
|
|
64
|
+
// tMessage += " - AlertCode: '" + this.microcontrollerpin.componentMicroControllerPin.gpio + "'";
|
|
65
|
+
//}
|
|
66
|
+
return tMessage;
|
|
67
|
+
}
|
|
68
|
+
GetPinPullUpDownStr() {
|
|
69
|
+
switch (this.microcontrollerpin.pinPullUpDown) {
|
|
70
|
+
case PinPullUpDown.PUD_DOWN:
|
|
71
|
+
return "PUD_DOWN";
|
|
72
|
+
case PinPullUpDown.PUD_OFF:
|
|
73
|
+
return "PUD_OFF";
|
|
74
|
+
case PinPullUpDown.PUD_UP:
|
|
75
|
+
return "PUD_UP";
|
|
76
|
+
}
|
|
77
|
+
return "";
|
|
78
|
+
}
|
|
79
|
+
GetPinMode() {
|
|
80
|
+
switch (this.microcontrollerpin.pinMode) {
|
|
81
|
+
case PinMode.INPUT:
|
|
82
|
+
return "INPUT";
|
|
83
|
+
case PinMode.OUTPUT:
|
|
84
|
+
return "OUTPUT";
|
|
85
|
+
}
|
|
86
|
+
return "";
|
|
87
|
+
}
|
|
88
|
+
GetName() {
|
|
89
|
+
return "pin '" + this.microcontrollerpin.componentDefinitionMicroControllerPinName + "'";
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=pin.js.map
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { ComponentDefinitionPropertyType } from '../../models/models.js';
|
|
2
|
+
export default class Property {
|
|
3
|
+
constructor(property) {
|
|
4
|
+
this.property = property;
|
|
5
|
+
if (this.property.componentPropertyValue != undefined) {
|
|
6
|
+
this.value = this.property.componentPropertyValue;
|
|
7
|
+
}
|
|
8
|
+
else {
|
|
9
|
+
this.value = this.property.componentDefinitionPropertyDefault;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
GetLogMessage() {
|
|
13
|
+
return this.GetName() + " - type: '" + this.GetType() + "' - value: '" + this.property.componentPropertyValue + "'";
|
|
14
|
+
}
|
|
15
|
+
GetType() {
|
|
16
|
+
switch (this.property.componentDefinitionPropertyType) {
|
|
17
|
+
case ComponentDefinitionPropertyType.String:
|
|
18
|
+
return "String";
|
|
19
|
+
case ComponentDefinitionPropertyType.Integer:
|
|
20
|
+
return "Integer";
|
|
21
|
+
case ComponentDefinitionPropertyType.Float:
|
|
22
|
+
return "Float";
|
|
23
|
+
case ComponentDefinitionPropertyType.Boolean:
|
|
24
|
+
return "Boolean";
|
|
25
|
+
}
|
|
26
|
+
return "";
|
|
27
|
+
}
|
|
28
|
+
GetName() {
|
|
29
|
+
return "property '" + this.property.componentDefinitionPropertyName + "'";
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=property.js.map
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import Debug from '../../common/debug.js';
|
|
2
|
+
import Status from './status.js';
|
|
3
|
+
export default class StatusState extends Status {
|
|
4
|
+
constructor(status, rig_id, component_id) {
|
|
5
|
+
super(status, rig_id, component_id);
|
|
6
|
+
}
|
|
7
|
+
SelectState(value) {
|
|
8
|
+
for (var i = 0; i < this.status.states.length; i++) {
|
|
9
|
+
if (this.status.states[i].name == value) {
|
|
10
|
+
this.UpdateStatus(this.status.states[i].id);
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
Debug.LogAlways(this.GetName(), "UNKNOWN STATE: '" + value + "'", true);
|
|
15
|
+
}
|
|
16
|
+
GetValueStr() {
|
|
17
|
+
if (this.last_value != null) {
|
|
18
|
+
for (var i = 0; i < this.status.states.length; i++) {
|
|
19
|
+
if (this.status.states[i].id == this.last_value) {
|
|
20
|
+
return this.status.states[i].name;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return "";
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=status-state.js.map
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import SignalR from '../../common/signalr.js';
|
|
2
|
+
import { StatusModel, RigComponentStatusModel } from '../../models/models.js';
|
|
3
|
+
export default class Status {
|
|
4
|
+
constructor(status, rig_id, component_id) {
|
|
5
|
+
this.last_value = null;
|
|
6
|
+
this.rig_id = rig_id;
|
|
7
|
+
this.component_id = component_id;
|
|
8
|
+
this.status = status;
|
|
9
|
+
}
|
|
10
|
+
UpdateStatus(value) {
|
|
11
|
+
if (this.last_value !== value) {
|
|
12
|
+
this.last_value = value;
|
|
13
|
+
this.SendUpdateStatus(value);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
SendCurrent() {
|
|
17
|
+
if (this.last_value != null) {
|
|
18
|
+
this.SendUpdateStatus(this.last_value);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
GetValue() {
|
|
22
|
+
return this.last_value;
|
|
23
|
+
}
|
|
24
|
+
GetName() {
|
|
25
|
+
return "status #" + this.status.id + " name: '" + this.status.name + "' component #" + this.component_id;
|
|
26
|
+
}
|
|
27
|
+
SendUpdateStatus(value) {
|
|
28
|
+
if (SignalR.IsConnected()) {
|
|
29
|
+
var tUpdateStatusModel = new StatusModel();
|
|
30
|
+
tUpdateStatusModel.type = this.status.type;
|
|
31
|
+
var tRigComponentStatusModel = new RigComponentStatusModel();
|
|
32
|
+
tRigComponentStatusModel.rigId = this.rig_id;
|
|
33
|
+
tRigComponentStatusModel.componentId = this.component_id;
|
|
34
|
+
tRigComponentStatusModel.statusId = this.status.id;
|
|
35
|
+
tRigComponentStatusModel.value = value;
|
|
36
|
+
tUpdateStatusModel.value = tRigComponentStatusModel;
|
|
37
|
+
SignalR.UpdateStatus(tUpdateStatusModel);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=status.js.map
|