@operato/scene-mpi 1.3.7
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/CHANGELOG.md +11 -0
- package/README.md +31 -0
- package/assets/favicon.ico +0 -0
- package/assets/images/spinner.png +0 -0
- package/dist/auto-clicker.d.ts +10 -0
- package/dist/auto-clicker.js +84 -0
- package/dist/auto-clicker.js.map +1 -0
- package/dist/boot-button.d.ts +20 -0
- package/dist/boot-button.js +90 -0
- package/dist/boot-button.js.map +1 -0
- package/dist/gateway-on-button.d.ts +7 -0
- package/dist/gateway-on-button.js +88 -0
- package/dist/gateway-on-button.js.map +1 -0
- package/dist/gateway-on-message.d.ts +3 -0
- package/dist/gateway-on-message.js +375 -0
- package/dist/gateway-on-message.js.map +1 -0
- package/dist/gateway.d.ts +58 -0
- package/dist/gateway.js +396 -0
- package/dist/gateway.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/indicator-on-message.d.ts +2 -0
- package/dist/indicator-on-message.js +5 -0
- package/dist/indicator-on-message.js.map +1 -0
- package/dist/indicator-user-action.d.ts +5 -0
- package/dist/indicator-user-action.js +263 -0
- package/dist/indicator-user-action.js.map +1 -0
- package/dist/indicator.d.ts +83 -0
- package/dist/indicator.js +544 -0
- package/dist/indicator.js.map +1 -0
- package/dist/reply-button.d.ts +20 -0
- package/dist/reply-button.js +67 -0
- package/dist/reply-button.js.map +1 -0
- package/dist/segment-display.d.ts +41 -0
- package/dist/segment-display.js +521 -0
- package/dist/segment-display.js.map +1 -0
- package/dist/seven-segment.d.ts +7 -0
- package/dist/seven-segment.js +137 -0
- package/dist/seven-segment.js.map +1 -0
- package/dist/templates/auto-clicker.d.ts +17 -0
- package/dist/templates/auto-clicker.js +19 -0
- package/dist/templates/auto-clicker.js.map +1 -0
- package/dist/templates/boot-button.d.ts +16 -0
- package/dist/templates/boot-button.js +18 -0
- package/dist/templates/boot-button.js.map +1 -0
- package/dist/templates/gateway.d.ts +16 -0
- package/dist/templates/gateway.js +18 -0
- package/dist/templates/gateway.js.map +1 -0
- package/dist/templates/index.d.ts +16 -0
- package/dist/templates/index.js +15 -0
- package/dist/templates/index.js.map +1 -0
- package/dist/templates/indicator.d.ts +16 -0
- package/dist/templates/indicator.js +18 -0
- package/dist/templates/indicator.js.map +1 -0
- package/dist/templates/reply-button.d.ts +16 -0
- package/dist/templates/reply-button.js +18 -0
- package/dist/templates/reply-button.js.map +1 -0
- package/dist/templates/seven-segment.d.ts +28 -0
- package/dist/templates/seven-segment.js +30 -0
- package/dist/templates/seven-segment.js.map +1 -0
- package/dist/uuid.d.ts +1 -0
- package/dist/uuid.js +21 -0
- package/dist/uuid.js.map +1 -0
- package/helps/scene/component/auto-clicker.ko.md +3 -0
- package/helps/scene/component/auto-clicker.md +3 -0
- package/helps/scene/component/auto-clicker.zh.md +3 -0
- package/helps/scene/component/boot-button.ko.md +3 -0
- package/helps/scene/component/boot-button.md +3 -0
- package/helps/scene/component/boot-button.zh.md +3 -0
- package/helps/scene/component/gateway.ko.md +3 -0
- package/helps/scene/component/gateway.md +3 -0
- package/helps/scene/component/gateway.zh.md +3 -0
- package/helps/scene/component/indicator.ko.md +3 -0
- package/helps/scene/component/indicator.md +3 -0
- package/helps/scene/component/indicator.zh.md +3 -0
- package/helps/scene/component/reply-button.ko.md +3 -0
- package/helps/scene/component/reply-button.md +3 -0
- package/helps/scene/component/reply-button.zh.md +3 -0
- package/helps/scene/component/seven-segment.ko.md +3 -0
- package/helps/scene/component/seven-segment.md +3 -0
- package/helps/scene/component/seven-segment.zh.md +3 -0
- package/icons/boot-button.png +0 -0
- package/icons/button-error.png +0 -0
- package/icons/button-start.png +0 -0
- package/icons/button-status.png +0 -0
- package/icons/button-stop.png +0 -0
- package/icons/gateway.png +0 -0
- package/icons/icon-boot-button.png +0 -0
- package/icons/icon-gateway.png +0 -0
- package/icons/icon-indicator.png +0 -0
- package/icons/icon-reply-button.png +0 -0
- package/icons/icon-seven-segment.png +0 -0
- package/icons/indicator.png +0 -0
- package/icons/no-image.png +0 -0
- package/icons/reply-button.png +0 -0
- package/package.json +61 -0
- package/src/auto-clicker.ts +97 -0
- package/src/boot-button.ts +112 -0
- package/src/gateway-on-button.ts +97 -0
- package/src/gateway-on-message.ts +405 -0
- package/src/gateway.ts +484 -0
- package/src/index.ts +6 -0
- package/src/indicator-on-message.ts +6 -0
- package/src/indicator-user-action.ts +292 -0
- package/src/indicator.ts +638 -0
- package/src/reply-button.ts +88 -0
- package/src/segment-display.ts +608 -0
- package/src/seven-segment.ts +162 -0
- package/src/templates/auto-clicker.ts +19 -0
- package/src/templates/boot-button.ts +18 -0
- package/src/templates/gateway.ts +18 -0
- package/src/templates/index.ts +15 -0
- package/src/templates/indicator.ts +18 -0
- package/src/templates/reply-button.ts +18 -0
- package/src/templates/seven-segment.ts +30 -0
- package/src/uuid.ts +20 -0
- package/things-scene.config.js +5 -0
- package/translations/en.json +26 -0
- package/translations/ja.json +26 -0
- package/translations/ko.json +26 -0
- package/translations/ms.json +23 -0
- package/translations/zh.json +23 -0
- package/tsconfig.json +22 -0
- package/tsconfig.tsbuildinfo +1 -0
package/src/gateway.ts
ADDED
|
@@ -0,0 +1,484 @@
|
|
|
1
|
+
const IMAGE = new URL('../../icons/gateway.png', import.meta.url).href
|
|
2
|
+
|
|
3
|
+
import { Component, ComponentNature, Container, Properties } from '@hatiolab/things-scene'
|
|
4
|
+
import { uuid } from './uuid'
|
|
5
|
+
|
|
6
|
+
import { buttons } from './gateway-on-button'
|
|
7
|
+
|
|
8
|
+
import { onmessage, consoleLogger } from './gateway-on-message'
|
|
9
|
+
import Indicator from './indicator'
|
|
10
|
+
|
|
11
|
+
const BUTTONS_MARGIN = 0
|
|
12
|
+
const BUTTONS_GAP = 0
|
|
13
|
+
const BUTTONS_RADIUS = 0
|
|
14
|
+
const BUTTOMS_ICON_SIZE = 0
|
|
15
|
+
|
|
16
|
+
const NATURE: ComponentNature = {
|
|
17
|
+
mutable: false,
|
|
18
|
+
resizable: true,
|
|
19
|
+
rotatable: true,
|
|
20
|
+
properties: [
|
|
21
|
+
{
|
|
22
|
+
type: 'string',
|
|
23
|
+
name: 'replyPublisher',
|
|
24
|
+
label: 'reply_publisher',
|
|
25
|
+
placeholder: ''
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
type: 'string',
|
|
29
|
+
name: 'reqPublisher',
|
|
30
|
+
label: 'req_publisher',
|
|
31
|
+
placeholder: ''
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
type: 'select',
|
|
35
|
+
label: 'power_flag',
|
|
36
|
+
name: 'power_flag',
|
|
37
|
+
property: {
|
|
38
|
+
options: [
|
|
39
|
+
{
|
|
40
|
+
display: 'true',
|
|
41
|
+
value: 'true'
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
display: 'false',
|
|
45
|
+
value: 'false'
|
|
46
|
+
}
|
|
47
|
+
]
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
type: 'select',
|
|
52
|
+
label: 'boot_flag',
|
|
53
|
+
name: 'boot_flag',
|
|
54
|
+
property: {
|
|
55
|
+
options: [
|
|
56
|
+
{
|
|
57
|
+
display: 'true',
|
|
58
|
+
value: 'true'
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
display: 'false',
|
|
62
|
+
value: 'false'
|
|
63
|
+
}
|
|
64
|
+
]
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
type: 'string',
|
|
69
|
+
name: 'pubTopic',
|
|
70
|
+
label: 'pub_topic',
|
|
71
|
+
placeholder: ''
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
type: 'string',
|
|
75
|
+
name: 'subTopic',
|
|
76
|
+
label: 'sub_topic',
|
|
77
|
+
placeholder: ''
|
|
78
|
+
}
|
|
79
|
+
],
|
|
80
|
+
help: 'scene/component/gateway'
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export default class Gateway extends Container {
|
|
84
|
+
static _image?: HTMLImageElement
|
|
85
|
+
static _buttonImages: HTMLImageElement[] = []
|
|
86
|
+
|
|
87
|
+
private timeflow?: any
|
|
88
|
+
private ledBlinker?: any
|
|
89
|
+
private ledBarBlinker?: any
|
|
90
|
+
|
|
91
|
+
private _focusedButton?: any
|
|
92
|
+
|
|
93
|
+
public version?: any
|
|
94
|
+
public publisher?: any
|
|
95
|
+
public time?: any
|
|
96
|
+
|
|
97
|
+
static get image() {
|
|
98
|
+
if (!Gateway._image) {
|
|
99
|
+
Gateway._image = new Image()
|
|
100
|
+
Gateway._image.src = IMAGE
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return Gateway._image
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
static get buttonImages() {
|
|
107
|
+
if (!Gateway._buttonImages) {
|
|
108
|
+
Gateway._buttonImages = []
|
|
109
|
+
|
|
110
|
+
buttons.forEach(button => {
|
|
111
|
+
let image = new Image()
|
|
112
|
+
image.src = button.icon
|
|
113
|
+
|
|
114
|
+
Gateway._buttonImages.push(image)
|
|
115
|
+
})
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return Gateway._buttonImages
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
dispose() {
|
|
122
|
+
this.timerOff()
|
|
123
|
+
|
|
124
|
+
delete this.timeflow
|
|
125
|
+
delete this.ledBlinker
|
|
126
|
+
delete this.ledBarBlinker
|
|
127
|
+
|
|
128
|
+
super.dispose()
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
buttonContains(x: number, y: number) {
|
|
132
|
+
var rx = BUTTONS_RADIUS
|
|
133
|
+
var ry = BUTTONS_RADIUS
|
|
134
|
+
|
|
135
|
+
return buttons.find((button, idx) => {
|
|
136
|
+
let cx = idx * BUTTONS_GAP + BUTTONS_RADIUS / 2
|
|
137
|
+
let cy = BUTTONS_RADIUS
|
|
138
|
+
|
|
139
|
+
let normx = (x - cx) / (rx * 2 - 0.5)
|
|
140
|
+
let normy = (y - cy) / (ry * 2 - 0.5)
|
|
141
|
+
|
|
142
|
+
return normx * normx + normy * normy < 0.25
|
|
143
|
+
})
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
passIndicatorsMessage(indicatorMessage: any) {
|
|
147
|
+
if (!this.state.power_flag || !this.state.boot_flag) return
|
|
148
|
+
if (indicatorMessage.action == 'IND_ON_RES') {
|
|
149
|
+
this.reqPublisher!.data = {
|
|
150
|
+
properties: this.generateMessageProperties(),
|
|
151
|
+
body: indicatorMessage
|
|
152
|
+
}
|
|
153
|
+
consoleLogger(
|
|
154
|
+
'sent ' + (indicatorMessage.action ? indicatorMessage.action : 'indicator message'),
|
|
155
|
+
this.reqPublisher!.data
|
|
156
|
+
)
|
|
157
|
+
} else {
|
|
158
|
+
this.replyPublisher!.data = {
|
|
159
|
+
properties: this.generateMessageProperties(),
|
|
160
|
+
body: indicatorMessage
|
|
161
|
+
}
|
|
162
|
+
consoleLogger(
|
|
163
|
+
'sent ' + (indicatorMessage.action ? indicatorMessage.action : 'indicator message'),
|
|
164
|
+
this.replyPublisher!.data
|
|
165
|
+
)
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
generateMessageProperties() {
|
|
170
|
+
return {
|
|
171
|
+
id: uuid(),
|
|
172
|
+
time: Date.now(),
|
|
173
|
+
dest_id: this.getState('subTopic'),
|
|
174
|
+
source_id: this.getState('pubTopic'),
|
|
175
|
+
is_reply: false
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
generateReplyMessage(messageId: string, destId: string, action: string, body: any) {
|
|
180
|
+
var msg = {
|
|
181
|
+
properties: {
|
|
182
|
+
id: messageId,
|
|
183
|
+
time: Date.now(),
|
|
184
|
+
dest_id: this.getState('pubTopic'),
|
|
185
|
+
source_id: this.getState('subTopic'),
|
|
186
|
+
is_reply: true
|
|
187
|
+
},
|
|
188
|
+
body: {
|
|
189
|
+
action: action + '_ACK'
|
|
190
|
+
} as any
|
|
191
|
+
}
|
|
192
|
+
switch (action) {
|
|
193
|
+
case 'IND_ON_REQ':
|
|
194
|
+
msg.body = {
|
|
195
|
+
action: 'IND_ON_REQ_ACK',
|
|
196
|
+
biz_type: body.biz_type,
|
|
197
|
+
action_type: body.action_type,
|
|
198
|
+
ret_args: body.ret_args,
|
|
199
|
+
read_only: body.read_only,
|
|
200
|
+
ind_on: body.ind_on.map((ind: any) => {
|
|
201
|
+
let indOn = {} as any
|
|
202
|
+
indOn.id = ind.id
|
|
203
|
+
indOn.biz_id = ind.biz_id
|
|
204
|
+
if (ind.stock_taking_id) indOn.stock_taking_id = ind.stock_taking_id
|
|
205
|
+
return indOn
|
|
206
|
+
})
|
|
207
|
+
}
|
|
208
|
+
break
|
|
209
|
+
case 'LED_ON_REQ':
|
|
210
|
+
case 'LED_OFF_REQ':
|
|
211
|
+
msg.body = {
|
|
212
|
+
action: action + '_ACK',
|
|
213
|
+
id: body.id
|
|
214
|
+
}
|
|
215
|
+
break
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
return msg
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
render(context: CanvasRenderingContext2D) {
|
|
222
|
+
var { left, top, width, height } = this.bounds
|
|
223
|
+
|
|
224
|
+
context.beginPath()
|
|
225
|
+
|
|
226
|
+
context.rect(left, top, width, height)
|
|
227
|
+
|
|
228
|
+
this.drawFill(context)
|
|
229
|
+
this.drawStroke(context)
|
|
230
|
+
|
|
231
|
+
// this.drawImage(context, Gateway.image, left + width - 62 - 5, top + 5, 62, 32)
|
|
232
|
+
|
|
233
|
+
Gateway.buttonImages.forEach((image, idx) => {
|
|
234
|
+
context.beginPath()
|
|
235
|
+
|
|
236
|
+
if (buttons[idx] === this._focusedButton) {
|
|
237
|
+
context.ellipse(
|
|
238
|
+
BUTTONS_MARGIN + left + idx * BUTTONS_GAP + BUTTOMS_ICON_SIZE / 2,
|
|
239
|
+
BUTTONS_MARGIN + top + BUTTOMS_ICON_SIZE / 2,
|
|
240
|
+
BUTTONS_RADIUS,
|
|
241
|
+
BUTTONS_RADIUS,
|
|
242
|
+
0,
|
|
243
|
+
0,
|
|
244
|
+
2 * Math.PI
|
|
245
|
+
)
|
|
246
|
+
context.fillStyle = 'lightgray'
|
|
247
|
+
context.fill()
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
this.drawImage(
|
|
251
|
+
context,
|
|
252
|
+
image,
|
|
253
|
+
BUTTONS_MARGIN + left + idx * BUTTONS_GAP,
|
|
254
|
+
BUTTONS_MARGIN + top,
|
|
255
|
+
BUTTOMS_ICON_SIZE,
|
|
256
|
+
BUTTOMS_ICON_SIZE
|
|
257
|
+
)
|
|
258
|
+
})
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
get indicators(): Indicator[] {
|
|
262
|
+
var groups = this.findAll('group') as Component[]
|
|
263
|
+
|
|
264
|
+
if (groups.length == 0) {
|
|
265
|
+
return this.findAll('indicator') as Indicator[]
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
var indicators = groups.map(function (group: Component, index: number) {
|
|
269
|
+
var indicator = group.findFirst('indicator') as Indicator
|
|
270
|
+
return indicator
|
|
271
|
+
})
|
|
272
|
+
|
|
273
|
+
return indicators
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
get replyPublisher() {
|
|
277
|
+
if (this.state.replyPublisher) {
|
|
278
|
+
return this.findById(this.state.replyPublisher)
|
|
279
|
+
} else {
|
|
280
|
+
return this.findFirst('mqtt')
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
get replyGraphQl() {
|
|
285
|
+
if (this.state.replyPublisher) {
|
|
286
|
+
return this.findById(this.state.replyPublisher)
|
|
287
|
+
} else {
|
|
288
|
+
return this.findFirst('graphql-client')
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
get reqPublisher() {
|
|
293
|
+
if (this.state.reqPublisher) {
|
|
294
|
+
return this.findById(this.state.reqPublisher)
|
|
295
|
+
} else {
|
|
296
|
+
return this.findFirst('mqtt')
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
get timer() {
|
|
301
|
+
return this.findFirst('seven-segment')
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
startBlinkingLed() {
|
|
305
|
+
this.ledBlinker = setTimeout(() => {
|
|
306
|
+
this.indicators.forEach((indicator, index) => {
|
|
307
|
+
// 인디케이터가 켜져있고,
|
|
308
|
+
var isLightOn = indicator.state.boot_flag == 'true' && indicator.lit
|
|
309
|
+
// 버튼 모드가 BLINK이고,
|
|
310
|
+
var isBtnModeBlink = indicator.getConf.btn_mode === indicator.btnModes.BLINK
|
|
311
|
+
// display 상태가 아닐 때
|
|
312
|
+
var isNotDisplay = indicator.currentTask !== indicator.tasks.DISPLAY
|
|
313
|
+
// 또는 인디케이터가 FULL 상태이며 이 상태에서 깜박임 옵션이 true일 때
|
|
314
|
+
var isFullState = indicator.currentTask == indicator.tasks.FULL
|
|
315
|
+
if (isLightOn && ((isBtnModeBlink && isNotDisplay) || (indicator.getConf.blink_if_full && isFullState))) {
|
|
316
|
+
indicator.getState('buttonColor') === '#0000'
|
|
317
|
+
? indicator.setState('buttonColor', String(indicator.colors[indicator.store.color]) || '#0000')
|
|
318
|
+
: indicator.setState('buttonColor', String('#0000'))
|
|
319
|
+
}
|
|
320
|
+
})
|
|
321
|
+
if (this.ledBlinker) this.startBlinkingLed()
|
|
322
|
+
}, this.indicators[0].getConf.btn_intvl * 100)
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
stopBlinkingLed() {
|
|
326
|
+
clearTimeout(this.ledBlinker)
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
startBlinkingLedBar() {
|
|
330
|
+
this.ledBarBlinker = setTimeout(() => {
|
|
331
|
+
this.indicators.forEach((indicator, index) => {
|
|
332
|
+
if (indicator.ledLit && indicator.getConf.led_bar_mode === indicator.btnModes.BLINK) {
|
|
333
|
+
if (indicator.ledRect.strokeStyle === '#0000') {
|
|
334
|
+
indicator.ledRect.strokeStyle =
|
|
335
|
+
'#f00' + Math.round((indicator.getConf.led_bar_brtns * 15) / 10).toString(16)
|
|
336
|
+
} else {
|
|
337
|
+
indicator.ledRect.strokeStyle = '#0000'
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
})
|
|
341
|
+
if (this.ledBarBlinker) this.startBlinkingLedBar()
|
|
342
|
+
}, this.indicators[0].getConf.led_bar_intvl * 100)
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
stopBlinkingLedBar() {
|
|
346
|
+
clearTimeout(this.ledBarBlinker)
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
boot() {
|
|
350
|
+
if (this.state.boot_flag == 'true') return
|
|
351
|
+
var { indicators, publisher } = this
|
|
352
|
+
|
|
353
|
+
consoleLogger('onclickStart')
|
|
354
|
+
|
|
355
|
+
// 2.1 indicator ready
|
|
356
|
+
this.indicators.forEach(indicator => {
|
|
357
|
+
var segLen = indicator.displays.length * indicator.displays[0].pattern.length
|
|
358
|
+
// 2.2 indicater ID 점등
|
|
359
|
+
if (indicator.model.id) {
|
|
360
|
+
// id가 있으면 점등
|
|
361
|
+
indicator.displayMessage(indicator.model.id)
|
|
362
|
+
} else {
|
|
363
|
+
// id가 없으면 무작위값 점등
|
|
364
|
+
indicator.displayMessage(
|
|
365
|
+
('0'.repeat(segLen - 1) + Math.floor(Math.random() * parseInt(1 + '0'.repeat(segLen)))).substr(-segLen)
|
|
366
|
+
)
|
|
367
|
+
}
|
|
368
|
+
})
|
|
369
|
+
|
|
370
|
+
// 2.3 gateway ready
|
|
371
|
+
this.setState('power_flag', 'true')
|
|
372
|
+
|
|
373
|
+
// 2.4 boot request to M/W
|
|
374
|
+
if (publisher) {
|
|
375
|
+
publisher.data = {
|
|
376
|
+
properties: this.generateMessageProperties(),
|
|
377
|
+
body: {
|
|
378
|
+
action: 'GW_INIT_REQ',
|
|
379
|
+
id: this.model.id //.split('/')[this.model.id.split('/').length - 1]
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
consoleLogger('sent GW_INIT_REQ', publisher.data)
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
off() {
|
|
387
|
+
if (this.state.power_flag == 'false') return
|
|
388
|
+
|
|
389
|
+
this.timerOff()
|
|
390
|
+
this.stopBlinkingLed()
|
|
391
|
+
this.stopBlinkingLedBar()
|
|
392
|
+
|
|
393
|
+
this.setState('power_flag', String('false'))
|
|
394
|
+
this.setState('boot_flag', String('false'))
|
|
395
|
+
|
|
396
|
+
this.indicators.forEach((indicator: Indicator) => {
|
|
397
|
+
indicator.setState('boot_flag', String('false'))
|
|
398
|
+
indicator.ledRect.strokeStyle = '#0000'
|
|
399
|
+
indicator.lightOff()
|
|
400
|
+
})
|
|
401
|
+
consoleLogger('turned off ' + this.model.id)
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
setTimer(timestamp: number) {
|
|
405
|
+
if (!this.timer) return
|
|
406
|
+
var digitalClock =
|
|
407
|
+
('0' + new Date(timestamp).getHours()).substr(-2) +
|
|
408
|
+
':' +
|
|
409
|
+
('0' + new Date(timestamp).getMinutes()).substr(-2) +
|
|
410
|
+
':' +
|
|
411
|
+
('0' + new Date(timestamp).getSeconds()).substr(-2)
|
|
412
|
+
this.timer.value = digitalClock
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
timerOn() {
|
|
416
|
+
// if (this.timer) {
|
|
417
|
+
// consoleLogger(this.model.id, "timer on");
|
|
418
|
+
// let hms = this.timer.value.split(':').map(t => {
|
|
419
|
+
// return parseInt(t);
|
|
420
|
+
// });
|
|
421
|
+
// this.timeflow = setInterval(() => {
|
|
422
|
+
// if (!this.root || !this.timer) { this.timerOff(); delete this.timeflow; return; }
|
|
423
|
+
// hms[2]++;
|
|
424
|
+
// if (hms[2] >= 60) {
|
|
425
|
+
// hms[2] = 0;
|
|
426
|
+
// hms[1]++;
|
|
427
|
+
// if (hms[1] >= 60) {
|
|
428
|
+
// hms[1] = 0;
|
|
429
|
+
// hms[0]++;
|
|
430
|
+
// if (hms[0] >= 24) {
|
|
431
|
+
// hms[0] = 0;
|
|
432
|
+
// }
|
|
433
|
+
// }
|
|
434
|
+
// }
|
|
435
|
+
// this.timer.value = ("0" + hms[0]).substr(-2) + ":" + ("0" + hms[1]).substr(-2) + ":" + ("0" + hms[2]).substr(-2);
|
|
436
|
+
// }, 990);
|
|
437
|
+
// }
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
timerOff() {
|
|
441
|
+
consoleLogger(this.model.id, 'timer off')
|
|
442
|
+
|
|
443
|
+
clearInterval(this.timeflow)
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
onchangeData(after: Properties, before: Properties) {
|
|
447
|
+
super.onchangeData(after, before)
|
|
448
|
+
|
|
449
|
+
onmessage(this, after.data)
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
onmousedown(e: MouseEvent, hint: any) {
|
|
453
|
+
var { left, top, width, height } = this.bounds
|
|
454
|
+
|
|
455
|
+
var { x, y } = this.transcoordC2S(e.offsetX, e.offsetY)
|
|
456
|
+
|
|
457
|
+
var button = this.buttonContains(x - left - BUTTONS_MARGIN, y - top - BUTTONS_MARGIN)
|
|
458
|
+
if (button) {
|
|
459
|
+
button.handler(this)
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
onmousemove(e: MouseEvent, hint: any) {
|
|
464
|
+
var { left, top, width, height } = this.bounds
|
|
465
|
+
|
|
466
|
+
var { x, y } = this.transcoordC2S(e.offsetX, e.offsetY)
|
|
467
|
+
|
|
468
|
+
var old = this._focusedButton
|
|
469
|
+
this._focusedButton = this.buttonContains(x - left - BUTTONS_MARGIN, y - top - BUTTONS_MARGIN)
|
|
470
|
+
if (this._focusedButton !== old) {
|
|
471
|
+
this.invalidate()
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
get hasTextProperty() {
|
|
476
|
+
return false
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
get nature() {
|
|
480
|
+
return NATURE
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
Component.register('gateway', Gateway)
|
package/src/index.ts
ADDED