loupedeck-commander 1.2.4 → 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.
@@ -138,6 +138,7 @@ export class BaseLoupeDeckHandler {
138
138
  this.screens.center = new ButtonField('center', this.device.rows, this.device.columns, dCenter.width, dCenter.height, profile.touch.center,profile)
139
139
  this.screens.left = new ButtonField('left', 1, 1, dLeft.width, dLeft.height, profile.touch.left,profile)
140
140
  this.screens.right = new ButtonField('right', 1, 1, dRight.width, dRight.height, profile.touch.right,profile)
141
+
141
142
  // knobs are only available in the CT-version:
142
143
  if (this.device.knobs) {
143
144
  this.knobs = new ButtonField('knob', 1, 1, 0, 0, profile.knobs,profile)
@@ -151,10 +152,11 @@ export class BaseLoupeDeckHandler {
151
152
  await this.buttons.load()
152
153
  await this.knobs.load()
153
154
 
154
- await this.screens.center.draw(this.device)
155
-
156
- //this.buttons.setState(this.currentProfile+1,1)
157
- //this.buttons.setState(oldProfile+1,1)
155
+ // Force a screen Update on all screens:
156
+ this.screenUpdate["center"] = true
157
+ this.screenUpdate["left"] = true
158
+ this.screenUpdate["right"] = true
159
+ await this.updateScreens()
158
160
 
159
161
  await this.buttons.draw(this.device)
160
162
 
@@ -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)
@@ -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() {
@@ -47,7 +47,7 @@ export class OPCUAIf extends BaseIf {
47
47
  if (!this.#client)
48
48
  return
49
49
 
50
- this.LogInfo(`OPCUAIf Stopping`)
50
+ this.LogInfo(`OPCUAIf Stopping\n`)
51
51
  await this.#client.closeSession(this.#session,true)
52
52
  await this.#client.disconnect()
53
53
  this.#connected = false
@@ -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 field=config.touch.center
73
- const keys = Object.keys(field)
74
- for (let i = 0; i < keys.length; i++) {
75
- const key = keys[i]
76
- const elem = config.touch.center[key]
77
- if (elem.nodeid){
78
- let format = this.formatString(elem.nodeid,options)
79
- let monitoredItemId = await this.Subscribe(format)
80
- this.buttons[monitoredItemId] = i
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,value)
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.endpointurl){
157
+ if (!"endpointurl" in options){
113
158
  this.LogError(`OPCUAIf: mandatory parameter endpointurl missing\n`)
114
159
  return -11}
115
- if (!options.nodeid){
160
+ if (!"nodeid" in options){
116
161
  this.LogError(`OPCUAIf: mandatory parameter nodeid missing\n`)
117
162
  return -12}
118
- if (!options.value){
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
  });
package/package.json CHANGED
@@ -1,10 +1,12 @@
1
1
  {
2
2
  "name": "loupedeck-commander",
3
- "version": "1.2.4",
3
+ "version": "1.2.6",
4
4
  "description": "A system to ease working with LoupeDeck devices using CMD-line, OPC/UA or HTTP-client interfaces",
5
5
  "main": "index.mjs",
6
6
  "scripts": {
7
- "test": "node test.mjs",
7
+ "test": "echo \"INFO: no test specified\" && exit 0",
8
+ "lint": "echo \"INFO: no linter specified\" && exit 0",
9
+ "format": "echo \"INFO: no format rule specified\" && exit 0",
8
10
  "start": "node index.mjs"
9
11
  },
10
12
  "dependencies": {