@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.
Files changed (125) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/README.md +31 -0
  3. package/assets/favicon.ico +0 -0
  4. package/assets/images/spinner.png +0 -0
  5. package/dist/auto-clicker.d.ts +10 -0
  6. package/dist/auto-clicker.js +84 -0
  7. package/dist/auto-clicker.js.map +1 -0
  8. package/dist/boot-button.d.ts +20 -0
  9. package/dist/boot-button.js +90 -0
  10. package/dist/boot-button.js.map +1 -0
  11. package/dist/gateway-on-button.d.ts +7 -0
  12. package/dist/gateway-on-button.js +88 -0
  13. package/dist/gateway-on-button.js.map +1 -0
  14. package/dist/gateway-on-message.d.ts +3 -0
  15. package/dist/gateway-on-message.js +375 -0
  16. package/dist/gateway-on-message.js.map +1 -0
  17. package/dist/gateway.d.ts +58 -0
  18. package/dist/gateway.js +396 -0
  19. package/dist/gateway.js.map +1 -0
  20. package/dist/index.d.ts +5 -0
  21. package/dist/index.js +7 -0
  22. package/dist/index.js.map +1 -0
  23. package/dist/indicator-on-message.d.ts +2 -0
  24. package/dist/indicator-on-message.js +5 -0
  25. package/dist/indicator-on-message.js.map +1 -0
  26. package/dist/indicator-user-action.d.ts +5 -0
  27. package/dist/indicator-user-action.js +263 -0
  28. package/dist/indicator-user-action.js.map +1 -0
  29. package/dist/indicator.d.ts +83 -0
  30. package/dist/indicator.js +544 -0
  31. package/dist/indicator.js.map +1 -0
  32. package/dist/reply-button.d.ts +20 -0
  33. package/dist/reply-button.js +67 -0
  34. package/dist/reply-button.js.map +1 -0
  35. package/dist/segment-display.d.ts +41 -0
  36. package/dist/segment-display.js +521 -0
  37. package/dist/segment-display.js.map +1 -0
  38. package/dist/seven-segment.d.ts +7 -0
  39. package/dist/seven-segment.js +137 -0
  40. package/dist/seven-segment.js.map +1 -0
  41. package/dist/templates/auto-clicker.d.ts +17 -0
  42. package/dist/templates/auto-clicker.js +19 -0
  43. package/dist/templates/auto-clicker.js.map +1 -0
  44. package/dist/templates/boot-button.d.ts +16 -0
  45. package/dist/templates/boot-button.js +18 -0
  46. package/dist/templates/boot-button.js.map +1 -0
  47. package/dist/templates/gateway.d.ts +16 -0
  48. package/dist/templates/gateway.js +18 -0
  49. package/dist/templates/gateway.js.map +1 -0
  50. package/dist/templates/index.d.ts +16 -0
  51. package/dist/templates/index.js +15 -0
  52. package/dist/templates/index.js.map +1 -0
  53. package/dist/templates/indicator.d.ts +16 -0
  54. package/dist/templates/indicator.js +18 -0
  55. package/dist/templates/indicator.js.map +1 -0
  56. package/dist/templates/reply-button.d.ts +16 -0
  57. package/dist/templates/reply-button.js +18 -0
  58. package/dist/templates/reply-button.js.map +1 -0
  59. package/dist/templates/seven-segment.d.ts +28 -0
  60. package/dist/templates/seven-segment.js +30 -0
  61. package/dist/templates/seven-segment.js.map +1 -0
  62. package/dist/uuid.d.ts +1 -0
  63. package/dist/uuid.js +21 -0
  64. package/dist/uuid.js.map +1 -0
  65. package/helps/scene/component/auto-clicker.ko.md +3 -0
  66. package/helps/scene/component/auto-clicker.md +3 -0
  67. package/helps/scene/component/auto-clicker.zh.md +3 -0
  68. package/helps/scene/component/boot-button.ko.md +3 -0
  69. package/helps/scene/component/boot-button.md +3 -0
  70. package/helps/scene/component/boot-button.zh.md +3 -0
  71. package/helps/scene/component/gateway.ko.md +3 -0
  72. package/helps/scene/component/gateway.md +3 -0
  73. package/helps/scene/component/gateway.zh.md +3 -0
  74. package/helps/scene/component/indicator.ko.md +3 -0
  75. package/helps/scene/component/indicator.md +3 -0
  76. package/helps/scene/component/indicator.zh.md +3 -0
  77. package/helps/scene/component/reply-button.ko.md +3 -0
  78. package/helps/scene/component/reply-button.md +3 -0
  79. package/helps/scene/component/reply-button.zh.md +3 -0
  80. package/helps/scene/component/seven-segment.ko.md +3 -0
  81. package/helps/scene/component/seven-segment.md +3 -0
  82. package/helps/scene/component/seven-segment.zh.md +3 -0
  83. package/icons/boot-button.png +0 -0
  84. package/icons/button-error.png +0 -0
  85. package/icons/button-start.png +0 -0
  86. package/icons/button-status.png +0 -0
  87. package/icons/button-stop.png +0 -0
  88. package/icons/gateway.png +0 -0
  89. package/icons/icon-boot-button.png +0 -0
  90. package/icons/icon-gateway.png +0 -0
  91. package/icons/icon-indicator.png +0 -0
  92. package/icons/icon-reply-button.png +0 -0
  93. package/icons/icon-seven-segment.png +0 -0
  94. package/icons/indicator.png +0 -0
  95. package/icons/no-image.png +0 -0
  96. package/icons/reply-button.png +0 -0
  97. package/package.json +61 -0
  98. package/src/auto-clicker.ts +97 -0
  99. package/src/boot-button.ts +112 -0
  100. package/src/gateway-on-button.ts +97 -0
  101. package/src/gateway-on-message.ts +405 -0
  102. package/src/gateway.ts +484 -0
  103. package/src/index.ts +6 -0
  104. package/src/indicator-on-message.ts +6 -0
  105. package/src/indicator-user-action.ts +292 -0
  106. package/src/indicator.ts +638 -0
  107. package/src/reply-button.ts +88 -0
  108. package/src/segment-display.ts +608 -0
  109. package/src/seven-segment.ts +162 -0
  110. package/src/templates/auto-clicker.ts +19 -0
  111. package/src/templates/boot-button.ts +18 -0
  112. package/src/templates/gateway.ts +18 -0
  113. package/src/templates/index.ts +15 -0
  114. package/src/templates/indicator.ts +18 -0
  115. package/src/templates/reply-button.ts +18 -0
  116. package/src/templates/seven-segment.ts +30 -0
  117. package/src/uuid.ts +20 -0
  118. package/things-scene.config.js +5 -0
  119. package/translations/en.json +26 -0
  120. package/translations/ja.json +26 -0
  121. package/translations/ko.json +26 -0
  122. package/translations/ms.json +23 -0
  123. package/translations/zh.json +23 -0
  124. package/tsconfig.json +22 -0
  125. package/tsconfig.tsbuildinfo +1 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"uuid.js","sourceRoot":"","sources":["../src/uuid.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,IAAI;IAClB,MAAM,KAAK,GAAG,kBAAkB,CAAA;IAChC,MAAM,IAAI,GAAG,EAAE,CAAA;IACf,IAAI,MAAM,CAAA;IAEV,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC;QAC5B,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,EAAE,CAAC;YAChD,IAAI,CAAC,CAAC,CAAC,GAAG,GAAG,CAAA;QACf,CAAC;aAAM,IAAI,CAAC,KAAK,EAAE,EAAE,CAAC;YACpB,IAAI,CAAC,CAAC,CAAC,GAAG,GAAG,CAAA;QACf,CAAC;aAAM,CAAC;YACN,IAAI,MAAM,KAAK,SAAS,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;gBACxC,MAAM,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,CAAA;YACnC,CAAC;YACD,IAAI,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,MAAM,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,CAAA;QAC3D,CAAC;IACH,CAAC;IAED,OAAO,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;AACtB,CAAC","sourcesContent":["export function uuid() {\n const chars = '0123456789abcdef'\n const uuid = []\n let random\n\n for (let i = 0; i < 36; i++) {\n if (i === 8 || i === 13 || i === 18 || i === 23) {\n uuid[i] = '-'\n } else if (i === 14) {\n uuid[i] = '4'\n } else {\n if (random === undefined || i % 6 === 0) {\n random = (Math.random() * 16) | 0\n }\n uuid[i] = chars[i === 19 ? (random & 0x3) | 0x8 : random]\n }\n }\n\n return uuid.join('')\n}\n"]}
@@ -0,0 +1,3 @@
1
+ # legend[ko]
2
+
3
+ ## properties
@@ -0,0 +1,3 @@
1
+ # legend[en]
2
+
3
+ ## properties
@@ -0,0 +1,3 @@
1
+ # legend[zh]
2
+
3
+ ## properties
@@ -0,0 +1,3 @@
1
+ # legend[ko]
2
+
3
+ ## properties
@@ -0,0 +1,3 @@
1
+ # legend[en]
2
+
3
+ ## properties
@@ -0,0 +1,3 @@
1
+ # legend[zh]
2
+
3
+ ## properties
@@ -0,0 +1,3 @@
1
+ # legend[ko]
2
+
3
+ ## properties
@@ -0,0 +1,3 @@
1
+ # legend[en]
2
+
3
+ ## properties
@@ -0,0 +1,3 @@
1
+ # legend[zh]
2
+
3
+ ## properties
@@ -0,0 +1,3 @@
1
+ # legend[ko]
2
+
3
+ ## properties
@@ -0,0 +1,3 @@
1
+ # legend[en]
2
+
3
+ ## properties
@@ -0,0 +1,3 @@
1
+ # legend[zh]
2
+
3
+ ## properties
@@ -0,0 +1,3 @@
1
+ # legend[ko]
2
+
3
+ ## properties
@@ -0,0 +1,3 @@
1
+ # legend[en]
2
+
3
+ ## properties
@@ -0,0 +1,3 @@
1
+ # legend[zh]
2
+
3
+ ## properties
@@ -0,0 +1,3 @@
1
+ # legend[ko]
2
+
3
+ ## properties
@@ -0,0 +1,3 @@
1
+ # legend[en]
2
+
3
+ ## properties
@@ -0,0 +1,3 @@
1
+ # legend[zh]
2
+
3
+ ## properties
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
package/package.json ADDED
@@ -0,0 +1,61 @@
1
+ {
2
+ "name": "@operato/scene-mpi",
3
+ "description": "Multi-purpose indicator integration component for things-scene",
4
+ "author": "heartyoh",
5
+ "version": "1.3.7",
6
+ "main": "dist/index.js",
7
+ "module": "dist/index.js",
8
+ "license": "MIT",
9
+ "things-scene": true,
10
+ "publishConfig": {
11
+ "access": "public",
12
+ "@oprato:registry": "https://registry.npmjs.org"
13
+ },
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "git+https://github.com/things-scene/operato-scene.git",
17
+ "directory": "packages/mpi"
18
+ },
19
+ "scripts": {
20
+ "serve": "tsc && concurrently -k -r \"tsc --watch --preserveWatchOutput\" \"things-factory-dev\"",
21
+ "serve:dev": "npm run serve",
22
+ "start": "tsc && concurrently -k -r \"tsc --watch --preserveWatchOutput\" \"wds\"",
23
+ "build": "tsc",
24
+ "prepublish": "tsc",
25
+ "lint": "eslint --ext .ts,.html . --ignore-path .gitignore && prettier \"**/*.ts\" --check --ignore-path .gitignore",
26
+ "format": "eslint --ext .ts,.html . --fix --ignore-path .gitignore && prettier \"**/*.ts\" --write --ignore-path .gitignore",
27
+ "migration": "things-factory-migration"
28
+ },
29
+ "dependencies": {
30
+ "@hatiolab/things-scene": "^3.2.0"
31
+ },
32
+ "devDependencies": {
33
+ "@hatiolab/prettier-config": "^1.0.0",
34
+ "@things-factory/builder": "^6.0.0",
35
+ "@things-factory/operato-board": "^6.0.0",
36
+ "@typescript-eslint/eslint-plugin": "^4.33.0",
37
+ "@typescript-eslint/parser": "^4.33.0",
38
+ "@web/dev-server": "^0.1.28",
39
+ "concurrently": "^8.0.1",
40
+ "eslint": "^8.39.0",
41
+ "eslint-config-prettier": "^8.3.0",
42
+ "husky": "^8.0.3",
43
+ "lint-staged": "^13.2.2",
44
+ "prettier": "^2.4.1",
45
+ "tslib": "^2.3.1",
46
+ "typescript": "^5.0.4"
47
+ },
48
+ "prettier": "@hatiolab/prettier-config",
49
+ "husky": {
50
+ "hooks": {
51
+ "pre-commit": "lint-staged"
52
+ }
53
+ },
54
+ "lint-staged": {
55
+ "*.ts": [
56
+ "eslint --fix",
57
+ "prettier --write"
58
+ ]
59
+ },
60
+ "gitHead": "1a9537c359f06a220491b213794c9747ab6e5a24"
61
+ }
@@ -0,0 +1,97 @@
1
+ import { Component, ComponentNature, RectPath, Shape } from '@hatiolab/things-scene'
2
+ import { consoleLogger } from './gateway-on-message'
3
+
4
+ const NATURE: ComponentNature = {
5
+ mutable: false,
6
+ resizable: true,
7
+ rotatable: true,
8
+ properties: [
9
+ {
10
+ type: 'select',
11
+ name: 'switch',
12
+ label: 'switch',
13
+ placeholder: 'false',
14
+ property: {
15
+ options: [
16
+ {
17
+ display: 'OFF',
18
+ value: 'false'
19
+ },
20
+ {
21
+ display: 'ON',
22
+ value: 'true'
23
+ }
24
+ ]
25
+ }
26
+ },
27
+ {
28
+ type: 'string',
29
+ name: 'target',
30
+ label: 'target',
31
+ placeholder: ''
32
+ },
33
+ {
34
+ type: 'number',
35
+ name: 'interval',
36
+ label: 'interval',
37
+ placeholder: '0'
38
+ }
39
+ ],
40
+ help: 'scene/component/auto-clicker'
41
+ }
42
+
43
+ export default class AutoClicker extends RectPath(Shape) {
44
+ autoClicker: any
45
+
46
+ dispose() {
47
+ clearInterval(this.autoClicker)
48
+ delete this.autoClicker
49
+ super.dispose()
50
+ }
51
+
52
+ render(context: CanvasRenderingContext2D) {
53
+ var { left, top, width, height } = this.bounds
54
+
55
+ context.beginPath()
56
+
57
+ context.rect(left, top, width, height)
58
+
59
+ this.drawFill(context)
60
+ this.drawStroke(context)
61
+ }
62
+
63
+ onmousedown(e: Event, hint: any) {
64
+ var autoClicker = () => {
65
+ this.autoClicker = setTimeout(() => {
66
+ //@ts-ignore
67
+ target?.onmousedown.call(target, e, hint)
68
+ autoClicker()
69
+ }, interval)
70
+ }
71
+
72
+ var pp = { true: true, false: false }
73
+ //@ts-ignore
74
+ var currentSwitchState = pp[this.getState('switch')]
75
+ var interval = this.getState('interval')
76
+ var target = this.root.findById(this.getState('target'))
77
+
78
+ this.setState('switch', !currentSwitchState)
79
+ currentSwitchState = !currentSwitchState
80
+
81
+ this.text = currentSwitchState ? 'ON' : 'OFF'
82
+ this.setState('fontColor', currentSwitchState ? 'rgb(0, 173, 31)' : 'rgb(254, 3, 3)')
83
+ consoleLogger('Auto response:', currentSwitchState)
84
+
85
+ if (currentSwitchState && target && interval >= 1000) {
86
+ autoClicker()
87
+ } else {
88
+ clearTimeout(this.autoClicker)
89
+ }
90
+ }
91
+
92
+ get nature() {
93
+ return NATURE
94
+ }
95
+ }
96
+
97
+ Component.register('auto-clicker', AutoClicker)
@@ -0,0 +1,112 @@
1
+ const boot = new URL('../../icons/boot-button.png', import.meta.url).href
2
+ import { Component, ComponentNature, RectPath, Shape } from '@hatiolab/things-scene'
3
+
4
+ import { uuid } from './uuid'
5
+
6
+ import { consoleLogger } from './gateway-on-message'
7
+
8
+ export const buttons = [
9
+ {
10
+ icon: boot,
11
+ handler: onclickBoot
12
+ }
13
+ ]
14
+
15
+ const BUTTONS_MARGIN = 10
16
+
17
+ const NATURE: ComponentNature = {
18
+ mutable: false,
19
+ resizable: true,
20
+ rotatable: true,
21
+ properties: [
22
+ {
23
+ type: 'string',
24
+ name: 'publisher',
25
+ label: 'publisher'
26
+ }
27
+ ],
28
+ help: 'scene/component/boot-button'
29
+ }
30
+
31
+ export default class BootButton extends RectPath(Shape) {
32
+ static _image: HTMLImageElement
33
+
34
+ static get image() {
35
+ if (!BootButton._image) {
36
+ BootButton._image = new Image()
37
+ BootButton._image.src = boot
38
+ }
39
+
40
+ return BootButton._image
41
+ }
42
+
43
+ get publisher() {
44
+ if (this.state.publisher) {
45
+ return this.root.findById(this.state.publisher)
46
+ }
47
+ }
48
+
49
+ render(context: CanvasRenderingContext2D) {
50
+ var { left, top, width, height } = this.bounds
51
+
52
+ context.beginPath()
53
+
54
+ context.rect(left, top, width, height)
55
+
56
+ this.drawFill(context)
57
+ this.drawStroke(context)
58
+
59
+ this.drawImage(context, BootButton.image, left, top, width, height)
60
+ }
61
+
62
+ onmousedown(e: MouseEvent, hint: any) {
63
+ var { left, top, width, height } = this.bounds
64
+
65
+ var { x, y } = this.transcoordC2S(e.offsetX, e.offsetY)
66
+
67
+ var button = this.buttonContains(x - left - BUTTONS_MARGIN, y - top - BUTTONS_MARGIN)
68
+ if (button) {
69
+ button.handler(this)
70
+ }
71
+ }
72
+
73
+ buttonContains(x: number, y: number) {
74
+ return buttons[0]
75
+ }
76
+
77
+ get nature() {
78
+ return NATURE
79
+ }
80
+ }
81
+
82
+ function onclickBoot(button: BootButton) {
83
+ consoleLogger('onclickBoot')
84
+ if (!button.data) return
85
+ var gateways = button.data
86
+ for (let i = 0; i < gateways.length; i++) {
87
+ // var gatewayObjects = gateways.map((value, index) => {
88
+ // return this.root.findById(value);
89
+ // }, this);
90
+
91
+ // gatewayObjects.forEach((gateway, index) => {
92
+ // gateway.boot();
93
+ // });
94
+ button.publisher!.data = {
95
+ properties: {
96
+ id: uuid(),
97
+ time: Date.now(),
98
+ dest_id: 'mps_server',
99
+ source_id: gateways[i],
100
+ is_reply: false
101
+ },
102
+ body: {
103
+ action: 'GW_INIT_REQ',
104
+ id: gateways[i]
105
+ }
106
+ }
107
+
108
+ consoleLogger('sent GW_INIT_REQ', button.publisher!.data)
109
+ }
110
+ }
111
+
112
+ Component.register('boot-button', BootButton)
@@ -0,0 +1,97 @@
1
+ const start = new URL('../../icons/button-start.png', import.meta.url).href
2
+ const stop = new URL('../../icons/button-stop.png', import.meta.url).href
3
+ const status = new URL('../../icons/button-status.png', import.meta.url).href
4
+ const error = new URL('../../icons/button-error.png', import.meta.url).href
5
+
6
+ import Gateway from './gateway'
7
+ import { consoleLogger } from './gateway-on-message'
8
+
9
+ export const buttons = [
10
+ {
11
+ icon: start,
12
+ handler: onclickStart
13
+ },
14
+ {
15
+ icon: stop,
16
+ handler: onclickStop
17
+ },
18
+ {
19
+ icon: status,
20
+ handler: onclickStatus
21
+ },
22
+ {
23
+ icon: error,
24
+ handler: onclickError
25
+ },
26
+ {
27
+ icon: status,
28
+ handler: onclickTimesync
29
+ }
30
+ ]
31
+
32
+ function onclickStart(gateway: Gateway) {
33
+ // Boot
34
+ // 전원 ON
35
+ consoleLogger('onclickStart')
36
+ gateway.boot()
37
+ }
38
+
39
+ function onclickStop(gateway: Gateway) {
40
+ // 전원 OFF
41
+ consoleLogger('onclickStop')
42
+ gateway.off()
43
+ }
44
+
45
+ function onclickStatus(gateway: Gateway) {
46
+ consoleLogger('onclickStatus')
47
+ if (gateway.state.power_flag == 'false') return
48
+
49
+ ////////random indicator////////
50
+ var indicator = gateway.indicators[Math.floor(Math.random() * gateway.indicators.length)]
51
+
52
+ gateway.replyPublisher!.data = {
53
+ properties: gateway.generateMessageProperties(),
54
+ body: {
55
+ action: 'IND_STATUS_RPT',
56
+ id: indicator.model.id,
57
+ version: indicator.version,
58
+ status: Math.random() > 0.5 ? 'ok' : 'offline', // random status
59
+ rssi: Math.floor(Math.random() * 100).toString(),
60
+ battery: Math.floor(Math.random() * 100).toString()
61
+ // status: (indicator.state.boot_flag == "true") ? "ok" : "offline"
62
+ }
63
+ }
64
+ consoleLogger('sent IND_STATUS_RPT', gateway.replyPublisher!.data)
65
+ ////////////////////////////////
66
+ }
67
+
68
+ function onclickError(gateway: Gateway) {
69
+ consoleLogger('onclickError')
70
+ if (gateway.state.power_flag == 'false') return
71
+
72
+ let hwgb = Math.random()
73
+
74
+ gateway.replyPublisher!.data = {
75
+ properties: gateway.generateMessageProperties(),
76
+ body: {
77
+ action: 'ERR_RPT',
78
+ hw_gb: hwgb > 0.5 ? 'gw' : 'ind',
79
+ id: hwgb > 0.5 ? gateway.model.id : gateway.indicators[Math.floor(hwgb * gateway.indicators.length * 2)].model.id,
80
+ message: ['ERR001', 'ERR002', 'ERR003', 'ERR004', 'ERR005', 'ERR006'][Math.floor(Math.random() * 6)]
81
+ }
82
+ }
83
+ consoleLogger('sent ERR_RPT', gateway.replyPublisher!.data)
84
+ }
85
+
86
+ function onclickTimesync(gateway: Gateway) {
87
+ consoleLogger('onclickTimesync')
88
+ if (gateway.state.power_flag == 'false') return
89
+
90
+ gateway.replyPublisher!.data = {
91
+ properties: gateway.generateMessageProperties(),
92
+ body: {
93
+ action: 'TIMESYNC_REQ'
94
+ }
95
+ }
96
+ consoleLogger('sent TIMESYNC_REQ', gateway.replyPublisher!.data)
97
+ }