loupedeck-commander 1.2.5 → 1.2.6
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/common/touchbuttons.mjs +4 -2
- package/interfaces/opcuaif.mjs +64 -16
- package/package.json +1 -1
package/common/touchbuttons.mjs
CHANGED
|
@@ -212,8 +212,8 @@ export class Button {
|
|
|
212
212
|
text = ''
|
|
213
213
|
font = '16px Arial'
|
|
214
214
|
|
|
215
|
-
#x
|
|
216
|
-
#y
|
|
215
|
+
#x = 0
|
|
216
|
+
#y = 0
|
|
217
217
|
#moveLeft
|
|
218
218
|
#moveRight
|
|
219
219
|
#moveUp
|
|
@@ -500,6 +500,8 @@ export class Button {
|
|
|
500
500
|
state: this.#keys[this.#index],
|
|
501
501
|
min: this.#min,
|
|
502
502
|
max: this.#max,
|
|
503
|
+
x: (this.#x %100),
|
|
504
|
+
y: (this.#y %100)
|
|
503
505
|
}
|
|
504
506
|
|
|
505
507
|
if (!params.value)
|
package/interfaces/opcuaif.mjs
CHANGED
|
@@ -23,7 +23,6 @@ const subscriptionParameters = {
|
|
|
23
23
|
requestedPublishingInterval: 1000
|
|
24
24
|
};
|
|
25
25
|
|
|
26
|
-
|
|
27
26
|
/**
|
|
28
27
|
* Our Special-Handler just used the Default - and adds Vibration after triggers through Button-Releases
|
|
29
28
|
*/
|
|
@@ -35,6 +34,7 @@ export class OPCUAIf extends BaseIf {
|
|
|
35
34
|
#connected
|
|
36
35
|
#endpointurl
|
|
37
36
|
monitoreditems
|
|
37
|
+
types
|
|
38
38
|
buttons
|
|
39
39
|
#callback
|
|
40
40
|
constructor() {
|
|
@@ -64,28 +64,68 @@ export class OPCUAIf extends BaseIf {
|
|
|
64
64
|
this.#endpointurl = this.formatString(options.endpointurl,options)
|
|
65
65
|
this.#callback = callbackFunction
|
|
66
66
|
this.monitoreditems = {}
|
|
67
|
+
this.types = {}
|
|
67
68
|
this.buttons = {}
|
|
68
69
|
this.LogInfo(`OPCUAIf init ${this.#endpointurl}\n`);
|
|
69
70
|
|
|
70
71
|
await this.Connect(this.#endpointurl);
|
|
71
72
|
|
|
72
|
-
let
|
|
73
|
-
const
|
|
74
|
-
for (let
|
|
75
|
-
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
73
|
+
let fields = [config.touch.center, config.knobs]
|
|
74
|
+
const fieldKeys = Object.keys(fields)
|
|
75
|
+
for (let f = 0; f < fieldKeys.length; f++) {
|
|
76
|
+
let field=fields[f]
|
|
77
|
+
const keys = Object.keys(field)
|
|
78
|
+
for (let i = 0; i < keys.length; i++) {
|
|
79
|
+
const key = keys[i]
|
|
80
|
+
const elem = field[key]
|
|
81
|
+
if (elem.nodeid){
|
|
82
|
+
let format = this.formatString(elem.nodeid,options)
|
|
83
|
+
let monitoredItemId = await this.Subscribe(format)
|
|
84
|
+
this.buttons[monitoredItemId] = i
|
|
85
|
+
}
|
|
86
|
+
await this.monitorStates(elem,options)
|
|
81
87
|
}
|
|
82
|
-
|
|
83
88
|
}
|
|
84
89
|
} catch (error) {
|
|
85
90
|
this.LogError(`OPCUAIf: Error $error\n`)
|
|
86
91
|
}
|
|
87
92
|
}
|
|
88
93
|
|
|
94
|
+
async monitorStates(elem,options){
|
|
95
|
+
const stateKeys = Object.keys(elem.states)
|
|
96
|
+
for (let i = 0; i < stateKeys.length; i++) {
|
|
97
|
+
const key2 = stateKeys[i]
|
|
98
|
+
const state = elem.states[key2]
|
|
99
|
+
if (state.opcua){
|
|
100
|
+
let format = this.formatString(state.opcua,options)
|
|
101
|
+
let monitoredItemId = await this.Subscribe(format)
|
|
102
|
+
this.buttons[monitoredItemId] = i
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
convert(value,type){
|
|
108
|
+
switch(type){
|
|
109
|
+
case DataType.Int16:
|
|
110
|
+
case DataType.Int32:
|
|
111
|
+
if (typeof value == "number"){
|
|
112
|
+
if (Number.isInteger(value))
|
|
113
|
+
return value
|
|
114
|
+
else
|
|
115
|
+
return Math.trunc(value)
|
|
116
|
+
}
|
|
117
|
+
return parseInt(value,10)
|
|
118
|
+
break
|
|
119
|
+
case DataType.Float:
|
|
120
|
+
if (typeof value == "number")
|
|
121
|
+
return value
|
|
122
|
+
return parseFloat(value)
|
|
123
|
+
break;
|
|
124
|
+
default:
|
|
125
|
+
return value
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
89
129
|
async call (opcuaNode, options = {}) {
|
|
90
130
|
var res = this.Check(options)
|
|
91
131
|
if (res<0){
|
|
@@ -94,10 +134,15 @@ export class OPCUAIf extends BaseIf {
|
|
|
94
134
|
}
|
|
95
135
|
|
|
96
136
|
var nodeId = super.formatString(opcuaNode, options)
|
|
97
|
-
var value = super.formatString(options.value, options)
|
|
98
137
|
|
|
138
|
+
var type = this.types[opcuaNode]
|
|
139
|
+
var value = options.value
|
|
140
|
+
if (typeof value == "string")
|
|
141
|
+
value = super.formatString(options.value, options)
|
|
142
|
+
|
|
143
|
+
var convertedValue = this.convert(value,type)
|
|
99
144
|
//this.LogInfo(`OPCUAIf: write ${nodeId} => ${value}\n`)
|
|
100
|
-
await this.Write(nodeId,
|
|
145
|
+
await this.Write(nodeId,convertedValue,type)
|
|
101
146
|
|
|
102
147
|
var NewState = "waiting"
|
|
103
148
|
return NewState
|
|
@@ -109,13 +154,13 @@ export class OPCUAIf extends BaseIf {
|
|
|
109
154
|
this.LogError(`OPCUAIf: mandatory parameter missing\n`)
|
|
110
155
|
return res
|
|
111
156
|
}
|
|
112
|
-
if (!options
|
|
157
|
+
if (!"endpointurl" in options){
|
|
113
158
|
this.LogError(`OPCUAIf: mandatory parameter endpointurl missing\n`)
|
|
114
159
|
return -11}
|
|
115
|
-
if (!options
|
|
160
|
+
if (!"nodeid" in options){
|
|
116
161
|
this.LogError(`OPCUAIf: mandatory parameter nodeid missing\n`)
|
|
117
162
|
return -12}
|
|
118
|
-
if (!options
|
|
163
|
+
if (!"value" in options){
|
|
119
164
|
this.LogError(`OPCUAIf: mandatory parameter value missing\n`)
|
|
120
165
|
return -13}
|
|
121
166
|
return 0
|
|
@@ -242,6 +287,9 @@ export class OPCUAIf extends BaseIf {
|
|
|
242
287
|
monitoredItem.on("changed", function (dataValue) {
|
|
243
288
|
var nodeId = self.monitoreditems[this.monitoredItemId]
|
|
244
289
|
var buttonID = self.buttons[this.monitoredItemId]
|
|
290
|
+
// store the type of a nodeid in local dictionary
|
|
291
|
+
self.types[nodeId] = dataValue.value.dataType
|
|
292
|
+
// publish the value to subscribers:
|
|
245
293
|
self.LogInfo(`OPCUAIf: monitored item changed: ${nodeId} => ${dataValue.value.value}\n`);
|
|
246
294
|
self.emit('monitored item changed',buttonID,nodeId, dataValue.value.value)
|
|
247
295
|
});
|