iobroker.vis-2-widget-snapmaker-u1 0.0.0-stage → 0.0.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/LICENSE +21 -0
- package/README-de.md +49 -0
- package/README.md +48 -2
- package/admin/icon.svg +1 -0
- package/admin/webcomponents/entry.js +11 -0
- package/admin/webcomponents/media-element.js +64 -0
- package/admin/webcomponents/media-preview.svg +1 -0
- package/admin/webcomponents/media.json +302 -0
- package/admin/webcomponents/overview-element.js +56 -0
- package/admin/webcomponents/overview-preview.svg +1 -0
- package/admin/webcomponents/overview.json +251 -0
- package/admin/webcomponents/spool-element.js +94 -0
- package/admin/webcomponents/spool-model.js +26 -0
- package/admin/webcomponents/spool-view.js +92 -0
- package/admin/webcomponents/spools-preview.svg +18 -0
- package/admin/webcomponents/spools.json +41 -0
- package/io-package.json +93 -0
- package/package.json +39 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Negalein <negalein@gmail.com>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README-de.md
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# Snapmaker-U1-Widgets für VIS 2
|
|
2
|
+
|
|
3
|
+
[English](README.md)
|
|
4
|
+
|
|
5
|
+
Beta 0.0.6 für VIS 2. Druckerübersicht, Kameras und Spoolman sind enthalten; Kamerastreams und Einstellungen bitte auf dem eigenen Testsystem prüfen.
|
|
6
|
+
|
|
7
|
+
[Snapmaker U1 – Herstellerinformationen](https://www.snapmaker.com/en/snapmaker-u1)
|
|
8
|
+
|
|
9
|
+
## Voraussetzungen
|
|
10
|
+
|
|
11
|
+
VIS 2.20.13, js-controller 7.2.5 und Snapmaker-U1-Adapter 0.0.14; Spoolman muss im Hauptadapter eingerichtet sein. Das Widget liest nur native Zustände und schreibt keine Daten. Ein Browser mit ES-Modulen und Web Components ist erforderlich.
|
|
12
|
+
|
|
13
|
+
## Testinstallation
|
|
14
|
+
|
|
15
|
+
Sobald der Adapter im ioBroker-Latest-Repository verfügbar ist, kann er über den ioBroker Admin installiert werden. Eine Instanz dieses Widget-Adapters anlegen, falls sie nicht automatisch angelegt wird; VIS 2 neu starten. Im VIS-2-Editor das Widget im Adapter-Set hinzufügen und die Snapmaker-U1-Instanz wählen. Auf einer Testansicht zunächst mit mehreren Widget-Instanzen, Ansichtswechsel und Neustart prüfen.
|
|
16
|
+
|
|
17
|
+
Das Widget zeigt bei nicht verfügbarer Verbindung einen Hinweis auf möglicherweise veraltete Werte. Bei fehlender Nennkapazität wird kein Füllstand erfunden. Schwellen: unter 300 g gelb, unter 100 g rot. Die optionale Rotation zeigt Druckstatus und gewählte AFC-Lane an, sie misst keinen tatsächlichen Filamentvorschub. Die Lane-Zuordnung ist am echten Drucker noch zu bestätigen. Radius und 3D-Ansicht sind Näherungen mit einheitlicher Spulengeometrie.
|
|
18
|
+
|
|
19
|
+
Filamentfarben werden als sechsstelliger RGB- oder achtstelliger RGBA-Hexcode mit oder ohne `#` akzeptiert. Das Widget zeigt den RGB-Anteil deckend und passend zur AFC-Farbe; die Transparenz des Filaments wird nicht dargestellt.
|
|
20
|
+
|
|
21
|
+
## Druckerübersicht und Kameras
|
|
22
|
+
|
|
23
|
+
Die Übersicht zeigt Druckauftrag, Fortschritt (der Adapter liefert bereits Prozentwerte), Layer, Z-Position, vier Extrudertemperaturen, Bett- und Kammertemperatur, geschätzte Restzeit und Verbindungsstatus. Optional kann der Datenpunkt eines Akkus über die Datenpunktauswahl gewählt werden. Fehlende Schätzungen werden als unbekannt angezeigt. Das Widget ist schreibgeschützt.
|
|
24
|
+
|
|
25
|
+
Das Medien-Widget zeigt die native Druckvorschau und bis zu zwei Kamerastreams. Snapmaker-Instanz wählen und den Stream-Datenpunkt jeder Kamera über die Datenpunktauswahl auswählen, beispielsweise `snapmaker-u1.0.cameras.<kamera-id>.streamUrl`. Für jede Kamera **WebRTC / HTML** oder **MJPEG** auswählen. Nicht benötigte Kamerafelder leer lassen. Vollbild hängt vom Browser ab. Kamera- und Vorschauladressen müssen vom Anzeigegerät erreichbar sein; HTTPS-Mixed-Content oder iframe-Regeln des Streamservers können die Anzeige verhindern. Die Kompatibilität der Kameradienste und echte Streams müssen getestet werden. Die automatische Auflösungsumschaltung ist noch nicht implementiert.
|
|
26
|
+
|
|
27
|
+
Kamera-Stream-Datenpunkte können aus beliebigen Adaptern stammen; der gewählte Datenpunkt muss eine HTTP(S)-URL enthalten.
|
|
28
|
+
|
|
29
|
+
## Darstellung
|
|
30
|
+
|
|
31
|
+
Jedes Widget besitzt eigene Einstellungen: automatisches, helles oder dunkles Grunddesign; Farben für Panel, Karten, Text, Nebentext, Warnung und Alarm; Schriftauswahl oder eigene Schriftart, Schriftgröße, Schriftstärke, Kursiv und Unterstreichung. Leere Farbfelder verwenden das Grunddesign. Eine eigene Schriftart hat Vorrang vor der Auswahl; die Schrift muss auf dem Anzeigegerät installiert oder anderweitig verfügbar sein. Die Filamentfarben stammen weiterhin aus Spoolman. Bei eigenen Farben auf ausreichenden Kontrast achten. Die Editor-Einstellungen müssen noch in VIS 2.20.13 praktisch geprüft werden.
|
|
32
|
+
|
|
33
|
+
## Migration vom Testadapter
|
|
34
|
+
|
|
35
|
+
Das bisherige Testpaket hieß `iobroker.vis-2-snapmaker-u1`; dieses Paket heißt `iobroker.vis-2-widget-snapmaker-u1`. Vor der Migration das VIS-Projekt exportieren, das neue Paket installieren und den alten Testadapter erst nach Prüfung der Widgets entfernen. Die Komponenten-Tags bleiben gleich; bestehende Ansichten und Einstellungen müssen nach der Migration geprüft werden.
|
|
36
|
+
|
|
37
|
+
## Entwicklung
|
|
38
|
+
|
|
39
|
+
`npm ci` und `npm test` im Repository. Das Paket ist eigenständig; die VIS-1-Version ist nicht erforderlich. Quellcode MIT, siehe LICENSE.
|
|
40
|
+
|
|
41
|
+
## Änderungen
|
|
42
|
+
|
|
43
|
+
### 0.0.6
|
|
44
|
+
|
|
45
|
+
- Erste öffentliche Beta mit Druckerübersicht, Kamera- und Spoolman-Widgets vorbereitet.
|
|
46
|
+
|
|
47
|
+
## Lizenz
|
|
48
|
+
|
|
49
|
+
MIT; siehe [LICENSE](LICENSE).
|
package/README.md
CHANGED
|
@@ -1,3 +1,49 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Snapmaker U1 widgets for VIS 2
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[Deutsch](README-de.md)
|
|
4
|
+
|
|
5
|
+
Beta 0.0.6 for VIS 2. Printer overview, cameras and Spoolman are included; verify camera streams and settings on your own test system.
|
|
6
|
+
|
|
7
|
+
[Snapmaker U1 product information](https://www.snapmaker.com/en/snapmaker-u1)
|
|
8
|
+
|
|
9
|
+
## Requirements
|
|
10
|
+
|
|
11
|
+
VIS 2.20.13, js-controller 7.2.5 and Snapmaker U1 adapter 0.0.14; Spoolman must be configured in the main adapter. The widget reads native states and does not write data. A browser with ES modules and Web Components is required.
|
|
12
|
+
|
|
13
|
+
## Test installation
|
|
14
|
+
|
|
15
|
+
When the adapter is available in the ioBroker latest repository, install it through ioBroker Admin. Create an instance of this widget adapter if one is not created automatically, then restart VIS 2. In the VIS 2 editor, add the widget from the adapter's set and select the Snapmaker U1 instance. Start with a test view and check multiple widget instances, view changes and restarts.
|
|
16
|
+
|
|
17
|
+
The widget warns that displayed values may be stale when the connection is unavailable. If nominal capacity is missing, it does not invent a fill level. The warning thresholds are below 300 g (yellow) and below 100 g (red). Optional rotation indicates a print in progress and the selected AFC lane; it does not measure actual filament movement. Lane selection still needs confirmation on the printer. The radius and 3D view are approximations using uniform spool geometry.
|
|
18
|
+
|
|
19
|
+
Filament colors accept six-digit RGB and eight-digit RGBA hex codes, with or without `#`. The widget displays the RGB part opaquely to match the AFC color; it does not visualize filament transparency.
|
|
20
|
+
|
|
21
|
+
## Printer overview and cameras
|
|
22
|
+
|
|
23
|
+
The overview shows the print job, progress (already supplied as percent), layers, Z position, four tool temperatures, bed and chamber temperatures, estimated remaining time and connectivity. Optionally select a battery state with the object picker. Missing estimates are shown as unknown. The widget is read-only.
|
|
24
|
+
|
|
25
|
+
The media widget shows the native print preview and up to two camera streams. Select the Snapmaker instance, then select each camera stream state with the object picker, for example `snapmaker-u1.0.cameras.<camera-id>.streamUrl`, and choose **WebRTC / HTML** or **MJPEG** for that camera. Leave a camera field blank if unused. Fullscreen depends on browser support. Cameras and preview URLs must be reachable by the display device; HTTPS mixed-content restrictions or stream server iframe policies may prevent display. Camera service compatibility and actual streams require testing. Automatic resolution switching is not implemented.
|
|
26
|
+
|
|
27
|
+
Camera stream states may come from any adapter; the selected state must contain an HTTP(S) URL.
|
|
28
|
+
|
|
29
|
+
## Appearance
|
|
30
|
+
|
|
31
|
+
Each widget has its own appearance settings: automatic, light or dark base theme; panel, card, text, secondary text, warning and alarm colors; font selection or a custom font family, size, weight, italic and underline. Empty color fields use the base theme. A custom font family overrides the selection; the font must be installed or otherwise available on the display device. Filament colors continue to come from Spoolman. Check contrast when choosing custom colors. These editor settings still require testing in VIS 2.20.13.
|
|
32
|
+
|
|
33
|
+
## Migration from the test adapter
|
|
34
|
+
|
|
35
|
+
The previous test package was `iobroker.vis-2-snapmaker-u1`; this package is `iobroker.vis-2-widget-snapmaker-u1`. Export your VIS project before migration, install the new package, and remove the old test adapter only after verifying the widgets. The component tags are unchanged, but existing views and settings must be tested after migration.
|
|
36
|
+
|
|
37
|
+
## Development
|
|
38
|
+
|
|
39
|
+
Run `npm ci` and `npm test` in this repository. This package is independent and does not require the VIS 1 version. The source code is MIT licensed; see [LICENSE](LICENSE).
|
|
40
|
+
|
|
41
|
+
## Changelog
|
|
42
|
+
|
|
43
|
+
### 0.0.6
|
|
44
|
+
|
|
45
|
+
- Prepare the first public beta with printer overview, camera and Spoolman widgets.
|
|
46
|
+
|
|
47
|
+
## License
|
|
48
|
+
|
|
49
|
+
Copyright (c) 2026 Negalein <negalein@gmail.com>. MIT; see [LICENSE](LICENSE).
|
package/admin/icon.svg
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64"><circle cx="32" cy="32" r="29" fill="#273847"/><circle cx="32" cy="32" r="22" fill="#42b7a3"/><circle cx="32" cy="32" r="13" fill="#273847"/><circle cx="32" cy="32" r="5" fill="#b9ccd4"/></svg>
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { SpoolElement } from './spool-element.js';
|
|
2
|
+
class Vis2SpoolElement extends SpoolElement {}
|
|
3
|
+
if (!customElements.get('snapmaker-u1-vis2-spools')) customElements.define('snapmaker-u1-vis2-spools', Vis2SpoolElement);
|
|
4
|
+
|
|
5
|
+
import { OverviewElement } from './overview-element.js';
|
|
6
|
+
class Vis2OverviewElement extends OverviewElement {}
|
|
7
|
+
if (!customElements.get('snapmaker-u1-vis2-overview')) customElements.define('snapmaker-u1-vis2-overview', Vis2OverviewElement);
|
|
8
|
+
|
|
9
|
+
import { MediaElement } from './media-element.js';
|
|
10
|
+
class Vis2MediaElement extends MediaElement {}
|
|
11
|
+
if (!customElements.get('snapmaker-u1-vis2-media')) customElements.define('snapmaker-u1-vis2-media', Vis2MediaElement);
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { SpoolElement } from './spool-element.js';
|
|
2
|
+
|
|
3
|
+
const messages={de:{title:'Druckvorschau & Kameras',thumbnail:'Druckvorschau',camera:'Kamera',missing:'Keine Quelle ausgewählt',noPreview:'Keine Druckvorschau',fullscreen:'Vollbild',failed:'Vollbild nicht verfügbar'},en:{title:'Print preview & cameras',thumbnail:'Print preview',camera:'Camera',missing:'No source selected',noPreview:'No print preview',fullscreen:'Fullscreen',failed:'Fullscreen unavailable'}};
|
|
4
|
+
const make=(tag,cls,text)=>{const n=document.createElement(tag);if(cls)n.className=cls;if(text!==undefined)n.textContent=text;return n;};
|
|
5
|
+
export function cameraState(_instance,id){
|
|
6
|
+
if(typeof id!=='string')return '';
|
|
7
|
+
const value=id.trim();
|
|
8
|
+
// The editor chooses any ioBroker state; never subscribe to a wildcard pattern.
|
|
9
|
+
return value && value !== 'nothing_selected' && value.length <= 512 && !/[\x00-\x1f*?]/.test(value) ? value : '';
|
|
10
|
+
}
|
|
11
|
+
export function mediaUrl(raw){
|
|
12
|
+
if(typeof raw!=='string' || !raw.trim())return '';
|
|
13
|
+
try {const u=new URL(raw.trim(),document.baseURI);return ['http:','https:'].includes(u.protocol) ? u.href : '';} catch {return '';}
|
|
14
|
+
}
|
|
15
|
+
/** State updates only change matching media sources; other feeds keep playing. */
|
|
16
|
+
export class MediaElement extends SpoolElement {
|
|
17
|
+
_sync(){
|
|
18
|
+
const instance=this._settings.instance;
|
|
19
|
+
if(!this.isConnected || !this._socket || !/^snapmaker-u1\.\d+$/.test(instance||'')){this.render();return;}
|
|
20
|
+
const a=cameraState(instance,this._settings.camera1State),b=cameraState(instance,this._settings.camera2State);
|
|
21
|
+
const ids=[`${instance}.printer.job.previewUrl`,...new Set([a,b].filter(Boolean))];
|
|
22
|
+
const key=JSON.stringify(ids);
|
|
23
|
+
if(this._subscription && this._subscription.key===key){this.render();return;}
|
|
24
|
+
if(this._subscription)this._stop();
|
|
25
|
+
const sub={socket:this._socket,instance,ids,key,seen:new Set()};
|
|
26
|
+
sub.handler=(id,state)=>{if(this._subscription!==sub||!ids.includes(id))return;sub.seen.add(id);this._values.set(id,state?.val??null);this._draw();};
|
|
27
|
+
this._subscription=sub;
|
|
28
|
+
try{
|
|
29
|
+
Promise.resolve(sub.socket.subscribeState(ids,sub.handler)).catch(()=>{});
|
|
30
|
+
for(const id of ids)Promise.resolve(sub.socket.getState(id)).then(state=>{if(this._subscription===sub&&!sub.seen.has(id)){this._values.set(id,state?.val??null);this._draw();}}).catch(()=>{});
|
|
31
|
+
}catch{this._stop();}
|
|
32
|
+
this.render();
|
|
33
|
+
}
|
|
34
|
+
_draw(){this.render();}
|
|
35
|
+
render(){
|
|
36
|
+
if(!this.shadowRoot||!this.isConnected)return;
|
|
37
|
+
const t=messages[String(this._socket?.systemLang||'en').toLowerCase().startsWith('de')?'de':'en'];
|
|
38
|
+
if(!this._mediaNodes){
|
|
39
|
+
const style=make('style');style.textContent=`:host{display:block;width:100%;height:100%;font-family:var(--u1-font-family,Arial,sans-serif);font-size:var(--u1-font-size,14px);font-weight:var(--u1-font-weight,400);font-style:var(--u1-font-style,normal);text-decoration:var(--u1-text-decoration,none);color:var(--u1-text-color,#eaf0f5);--panel:var(--u1-panel-color,#17202a);--card:var(--u1-card-color,#202b36);--muted:var(--u1-muted-color,#aab8c5)}:host([theme=light]){color:var(--u1-text-color,#182432);--panel:var(--u1-panel-color,#edf2f6);--card:var(--u1-card-color,#fff);--muted:var(--u1-muted-color,#586878)}*{box-sizing:border-box}.panel{height:100%;overflow:auto;background:var(--panel);border-radius:12px;padding:12px}.title{margin:0 0 10px;font-size:1.07em;font-weight:inherit}.grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(210px,1fr));gap:8px}.card{background:var(--card);border-radius:10px;padding:8px;min-width:0}.heading{display:flex;justify-content:space-between;align-items:center;margin-bottom:6px;gap:4px}.frame{position:relative;aspect-ratio:16/9;background:#10151c;border-radius:6px;overflow:hidden}.frame img,.frame iframe{display:block;width:100%;height:100%;object-fit:contain;border:0}.placeholder{position:absolute;inset:0;display:grid;place-items:center;color:#ddd;padding:8px;text-align:center}.button{color:inherit;background:var(--panel);border:0;border-radius:5px;padding:5px 8px;cursor:pointer}.frame:fullscreen{background:#000}.frame:fullscreen img,.frame:fullscreen iframe{height:100%;width:100%}`;
|
|
40
|
+
const panel=make('section','panel'),title=make('h2','title'),grid=make('div','grid');panel.append(title,grid);const cards=[];
|
|
41
|
+
for(let i=0;i<3;i++){
|
|
42
|
+
const card=make('article','card'),heading=make('div','heading'),label=make('span'),button=make('button','button');button.type='button';heading.append(label);
|
|
43
|
+
const frame=make('div','frame'),placeholder=make('div','placeholder');frame.append(placeholder,button);card.append(heading,frame);grid.append(card);
|
|
44
|
+
button.addEventListener('click',()=>{if(this.shadowRoot.fullscreenElement===frame || document.fullscreenElement===frame){document.exitFullscreen?.();return;}const request=frame.requestFullscreen?.();if(request?.catch)request.catch(()=>{placeholder.textContent=t.failed;placeholder.hidden=false;});});
|
|
45
|
+
cards.push({label,button,frame,placeholder,media:null,mode:'',url:''});
|
|
46
|
+
}
|
|
47
|
+
style.textContent += '.placeholder[hidden]{display:none}.frame .button{position:absolute;z-index:2;right:6px;top:6px}';
|
|
48
|
+
this.shadowRoot.replaceChildren(style,panel);this._mediaNodes={title,cards};
|
|
49
|
+
}
|
|
50
|
+
this._mediaNodes.title.textContent=t.title;
|
|
51
|
+
const prefix=this._subscription?.instance;const keys=[prefix?`${prefix}.printer.job.previewUrl`:'',cameraState(prefix||'',this._settings.camera1State),cameraState(prefix||'',this._settings.camera2State)];
|
|
52
|
+
const modes=['image',this._settings.camera1Mode==='mjpeg'?'image':'iframe',this._settings.camera2Mode==='iframe'?'iframe':'image'];
|
|
53
|
+
this._mediaNodes.cards.forEach((card,i)=>{
|
|
54
|
+
card.label.textContent=i===0?t.thumbnail:`${t.camera} ${i}`;card.button.textContent='⛶';card.button.title=t.fullscreen;card.button.setAttribute('aria-label',`${t.fullscreen}: ${card.label.textContent}`);
|
|
55
|
+
const url=mediaUrl(keys[i]?this._values.get(keys[i]):'');const mode=modes[i];
|
|
56
|
+
if(mode!==card.mode || url!==card.url){
|
|
57
|
+
if(card.media)card.media.remove();card.media=null;card.mode=mode;card.url=url;
|
|
58
|
+
if(url){const media=make(mode==='iframe'?'iframe':'img');media.setAttribute('title',card.label.textContent);if(mode==='iframe'){media.setAttribute('allow','autoplay; fullscreen');media.setAttribute('allowfullscreen','');}else media.alt=card.label.textContent;media.addEventListener('error',()=>{card.placeholder.hidden=false;});media.src=url;card.frame.prepend(media);card.media=media;}
|
|
59
|
+
}
|
|
60
|
+
card.placeholder.textContent=i===0?t.noPreview:t.missing;card.placeholder.hidden=!!url;card.button.disabled=!url;
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
disconnectedCallback(){super.disconnectedCallback();if(this._mediaNodes){for(const card of this._mediaNodes.cards){card.media?.remove();card.media=null;card.url='';}}}
|
|
64
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 120"><rect width="320" height="120" rx="12" fill="#17202a"/><text x="14" y="23" fill="#eaf0f5" font-family="Arial" font-size="13">Print preview & cameras</text><g fill="#273847"><rect x="12" y="34" width="94" height="74" rx="7"/><rect x="113" y="34" width="94" height="74" rx="7"/><rect x="214" y="34" width="94" height="74" rx="7"/></g><g fill="#d5e0e9" font-family="Arial" font-size="9"><text x="22" y="51">Preview</text><text x="123" y="51">Camera 1</text><text x="224" y="51">Camera 2</text></g><g stroke="#6da5c4" stroke-width="3" fill="none"><rect x="32" y="64" width="54" height="30" rx="2"/><rect x="133" y="64" width="54" height="30" rx="2"/><circle cx="160" cy="79" r="8"/><rect x="234" y="64" width="54" height="30" rx="2"/><circle cx="261" cy="79" r="8"/></g></svg>
|
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
{
|
|
2
|
+
"manifestVersion": 1,
|
|
3
|
+
"tag": "snapmaker-u1-vis2-media",
|
|
4
|
+
"module": "./entry.js",
|
|
5
|
+
"name": {
|
|
6
|
+
"en": "Snapmaker U1 Preview & cameras",
|
|
7
|
+
"de": "Snapmaker U1 Druckvorschau & Kameras"
|
|
8
|
+
},
|
|
9
|
+
"description": {
|
|
10
|
+
"en": "Print preview and two camera streams",
|
|
11
|
+
"de": "Druckvorschau und zwei Kamerastreams"
|
|
12
|
+
},
|
|
13
|
+
"icon": "media-preview.svg",
|
|
14
|
+
"size": {
|
|
15
|
+
"width": 900,
|
|
16
|
+
"height": 300
|
|
17
|
+
},
|
|
18
|
+
"settings": {
|
|
19
|
+
"type": "panel",
|
|
20
|
+
"items": {
|
|
21
|
+
"instance": {
|
|
22
|
+
"type": "instance",
|
|
23
|
+
"adapter": "snapmaker-u1",
|
|
24
|
+
"label": {
|
|
25
|
+
"en": "Snapmaker U1 instance",
|
|
26
|
+
"de": "Snapmaker-U1-Instanz"
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"camera1State": {
|
|
30
|
+
"type": "objectId",
|
|
31
|
+
"label": {
|
|
32
|
+
"en": "Camera 1 stream state ID",
|
|
33
|
+
"de": "Kamera 1 Stream-Datenpunkt"
|
|
34
|
+
},
|
|
35
|
+
"help": {
|
|
36
|
+
"en": "Choose a state containing a camera stream URL",
|
|
37
|
+
"de": "Datenpunkt mit einer Kamera-Stream-URL auswählen"
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
"camera1Mode": {
|
|
41
|
+
"type": "select",
|
|
42
|
+
"default": "iframe",
|
|
43
|
+
"label": {
|
|
44
|
+
"en": "Camera 1 format",
|
|
45
|
+
"de": "Kamera 1 Format"
|
|
46
|
+
},
|
|
47
|
+
"options": [
|
|
48
|
+
{
|
|
49
|
+
"value": "iframe",
|
|
50
|
+
"label": "WebRTC / HTML"
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
"value": "mjpeg",
|
|
54
|
+
"label": "MJPEG"
|
|
55
|
+
}
|
|
56
|
+
]
|
|
57
|
+
},
|
|
58
|
+
"camera2State": {
|
|
59
|
+
"type": "objectId",
|
|
60
|
+
"label": {
|
|
61
|
+
"en": "Camera 2 stream state ID",
|
|
62
|
+
"de": "Kamera 2 Stream-Datenpunkt"
|
|
63
|
+
},
|
|
64
|
+
"help": {
|
|
65
|
+
"en": "Choose a state containing a camera stream URL",
|
|
66
|
+
"de": "Datenpunkt mit einer Kamera-Stream-URL auswählen"
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
"camera2Mode": {
|
|
70
|
+
"type": "select",
|
|
71
|
+
"default": "mjpeg",
|
|
72
|
+
"label": {
|
|
73
|
+
"en": "Camera 2 format",
|
|
74
|
+
"de": "Kamera 2 Format"
|
|
75
|
+
},
|
|
76
|
+
"options": [
|
|
77
|
+
{
|
|
78
|
+
"value": "iframe",
|
|
79
|
+
"label": "WebRTC / HTML"
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
"value": "mjpeg",
|
|
83
|
+
"label": "MJPEG"
|
|
84
|
+
}
|
|
85
|
+
]
|
|
86
|
+
},
|
|
87
|
+
"appearance": {
|
|
88
|
+
"type": "header",
|
|
89
|
+
"text": {
|
|
90
|
+
"en": "Appearance",
|
|
91
|
+
"de": "Darstellung"
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
"appearanceTheme": {
|
|
95
|
+
"type": "select",
|
|
96
|
+
"default": "auto",
|
|
97
|
+
"label": {
|
|
98
|
+
"en": "Base theme",
|
|
99
|
+
"de": "Grunddesign"
|
|
100
|
+
},
|
|
101
|
+
"options": [
|
|
102
|
+
{
|
|
103
|
+
"value": "auto",
|
|
104
|
+
"label": {
|
|
105
|
+
"en": "Automatic",
|
|
106
|
+
"de": "Automatisch"
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
"value": "light",
|
|
111
|
+
"label": {
|
|
112
|
+
"en": "Light",
|
|
113
|
+
"de": "Hell"
|
|
114
|
+
}
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
"value": "dark",
|
|
118
|
+
"label": {
|
|
119
|
+
"en": "Dark",
|
|
120
|
+
"de": "Dunkel"
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
]
|
|
124
|
+
},
|
|
125
|
+
"panelColor": {
|
|
126
|
+
"type": "color",
|
|
127
|
+
"label": {
|
|
128
|
+
"en": "Panel background",
|
|
129
|
+
"de": "Panel-Hintergrund"
|
|
130
|
+
},
|
|
131
|
+
"help": {
|
|
132
|
+
"en": "Empty uses the base theme",
|
|
133
|
+
"de": "Leer verwendet das Grunddesign"
|
|
134
|
+
}
|
|
135
|
+
},
|
|
136
|
+
"cardColor": {
|
|
137
|
+
"type": "color",
|
|
138
|
+
"label": {
|
|
139
|
+
"en": "Spool card background",
|
|
140
|
+
"de": "Spulenkarten-Hintergrund"
|
|
141
|
+
},
|
|
142
|
+
"help": {
|
|
143
|
+
"en": "Empty uses the base theme",
|
|
144
|
+
"de": "Leer verwendet das Grunddesign"
|
|
145
|
+
}
|
|
146
|
+
},
|
|
147
|
+
"textColor": {
|
|
148
|
+
"type": "color",
|
|
149
|
+
"label": {
|
|
150
|
+
"en": "Text color",
|
|
151
|
+
"de": "Textfarbe"
|
|
152
|
+
},
|
|
153
|
+
"help": {
|
|
154
|
+
"en": "Empty uses the base theme",
|
|
155
|
+
"de": "Leer verwendet das Grunddesign"
|
|
156
|
+
}
|
|
157
|
+
},
|
|
158
|
+
"mutedColor": {
|
|
159
|
+
"type": "color",
|
|
160
|
+
"label": {
|
|
161
|
+
"en": "Secondary text color",
|
|
162
|
+
"de": "Farbe für Nebentexte"
|
|
163
|
+
},
|
|
164
|
+
"help": {
|
|
165
|
+
"en": "Empty uses the base theme",
|
|
166
|
+
"de": "Leer verwendet das Grunddesign"
|
|
167
|
+
}
|
|
168
|
+
},
|
|
169
|
+
"fontPreset": {
|
|
170
|
+
"type": "select",
|
|
171
|
+
"default": "default",
|
|
172
|
+
"label": {
|
|
173
|
+
"en": "Font",
|
|
174
|
+
"de": "Schriftart"
|
|
175
|
+
},
|
|
176
|
+
"options": [
|
|
177
|
+
{
|
|
178
|
+
"value": "default",
|
|
179
|
+
"label": {
|
|
180
|
+
"en": "Default (Arial)",
|
|
181
|
+
"de": "Standard (Arial)"
|
|
182
|
+
}
|
|
183
|
+
},
|
|
184
|
+
{
|
|
185
|
+
"value": "arial",
|
|
186
|
+
"label": "Arial"
|
|
187
|
+
},
|
|
188
|
+
{
|
|
189
|
+
"value": "verdana",
|
|
190
|
+
"label": "Verdana"
|
|
191
|
+
},
|
|
192
|
+
{
|
|
193
|
+
"value": "trebuchet",
|
|
194
|
+
"label": "Trebuchet MS"
|
|
195
|
+
},
|
|
196
|
+
{
|
|
197
|
+
"value": "georgia",
|
|
198
|
+
"label": "Georgia"
|
|
199
|
+
},
|
|
200
|
+
{
|
|
201
|
+
"value": "times",
|
|
202
|
+
"label": "Times New Roman"
|
|
203
|
+
},
|
|
204
|
+
{
|
|
205
|
+
"value": "courier",
|
|
206
|
+
"label": "Courier New"
|
|
207
|
+
},
|
|
208
|
+
{
|
|
209
|
+
"value": "system",
|
|
210
|
+
"label": {
|
|
211
|
+
"en": "System font",
|
|
212
|
+
"de": "Systemschrift"
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
]
|
|
216
|
+
},
|
|
217
|
+
"fontFamily": {
|
|
218
|
+
"type": "text",
|
|
219
|
+
"label": {
|
|
220
|
+
"en": "Custom font family",
|
|
221
|
+
"de": "Eigene Schriftart"
|
|
222
|
+
},
|
|
223
|
+
"help": {
|
|
224
|
+
"en": "Optional font name or CSS font-family list; overrides the font selection. The font must be available on the display device.",
|
|
225
|
+
"de": "Optionaler Schriftname oder CSS-Schriftliste; hat Vorrang vor der Schriftauswahl. Die Schrift muss auf dem Anzeigegerät verfügbar sein."
|
|
226
|
+
}
|
|
227
|
+
},
|
|
228
|
+
"fontSize": {
|
|
229
|
+
"type": "number",
|
|
230
|
+
"min": 8,
|
|
231
|
+
"max": 60,
|
|
232
|
+
"step": 1,
|
|
233
|
+
"default": 14,
|
|
234
|
+
"label": {
|
|
235
|
+
"en": "Font size (px)",
|
|
236
|
+
"de": "Schriftgröße (px)"
|
|
237
|
+
}
|
|
238
|
+
},
|
|
239
|
+
"fontWeight": {
|
|
240
|
+
"type": "select",
|
|
241
|
+
"default": "400",
|
|
242
|
+
"label": {
|
|
243
|
+
"en": "Font weight",
|
|
244
|
+
"de": "Schriftstärke"
|
|
245
|
+
},
|
|
246
|
+
"options": [
|
|
247
|
+
{
|
|
248
|
+
"value": "400",
|
|
249
|
+
"label": {
|
|
250
|
+
"en": "Normal",
|
|
251
|
+
"de": "Normal"
|
|
252
|
+
}
|
|
253
|
+
},
|
|
254
|
+
{
|
|
255
|
+
"value": "500",
|
|
256
|
+
"label": {
|
|
257
|
+
"en": "Medium",
|
|
258
|
+
"de": "Mittel"
|
|
259
|
+
}
|
|
260
|
+
},
|
|
261
|
+
{
|
|
262
|
+
"value": "600",
|
|
263
|
+
"label": {
|
|
264
|
+
"en": "Semi-bold",
|
|
265
|
+
"de": "Halbfett"
|
|
266
|
+
}
|
|
267
|
+
},
|
|
268
|
+
{
|
|
269
|
+
"value": "700",
|
|
270
|
+
"label": {
|
|
271
|
+
"en": "Bold",
|
|
272
|
+
"de": "Fett"
|
|
273
|
+
}
|
|
274
|
+
},
|
|
275
|
+
{
|
|
276
|
+
"value": "800",
|
|
277
|
+
"label": {
|
|
278
|
+
"en": "Extra bold",
|
|
279
|
+
"de": "Extrafett"
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
]
|
|
283
|
+
},
|
|
284
|
+
"fontItalic": {
|
|
285
|
+
"type": "checkbox",
|
|
286
|
+
"default": false,
|
|
287
|
+
"label": {
|
|
288
|
+
"en": "Italic",
|
|
289
|
+
"de": "Kursiv"
|
|
290
|
+
}
|
|
291
|
+
},
|
|
292
|
+
"fontUnderline": {
|
|
293
|
+
"type": "checkbox",
|
|
294
|
+
"default": false,
|
|
295
|
+
"label": {
|
|
296
|
+
"en": "Underline",
|
|
297
|
+
"de": "Unterstrichen"
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { SpoolElement } from './spool-element.js';
|
|
2
|
+
|
|
3
|
+
const paths = ['info.connection','printer.info.ready','spoolman.apiConnected','printer.job.state','printer.job.filename','printer.job.progress','printer.job.remaining','printer.job.estimatedEnd','printer.job.estimateAvailable','printer.job.layer.current','printer.job.layer.total','printer.motion.position.z','printer.bed.temperature','printer.bed.target','printer.chamber.temperature',...Array.from({length:4},(_,i)=>[`printer.tools.tool${i}.temperature`,`printer.tools.tool${i}.target`]).flat()];
|
|
4
|
+
const labels = {
|
|
5
|
+
de:{title:'Snapmaker U1',job:'Druckauftrag',none:'Kein Druckauftrag',unknown:'Unbekannt',temps:'Temperaturen',information:'Informationen',layer:'Layer',height:'Höhe',remaining:'Restzeit',end:'Endzeit',bed:'Bett',chamber:'Kammer',connection:'Verbindung',online:'Verbunden',offline:'Offline',spoolman:'Spoolman',battery:'Batterie',printing:'Druckt',paused:'Pausiert',complete:'Abgeschlossen',standby:'Bereit',error:'Fehler'},
|
|
6
|
+
en:{title:'Snapmaker U1',job:'Print job',none:'No print job',unknown:'Unknown',temps:'Temperatures',information:'Information',layer:'Layer',height:'Height',remaining:'Remaining',end:'Estimated end',bed:'Bed',chamber:'Chamber',connection:'Connection',online:'Connected',offline:'Offline',spoolman:'Spoolman',battery:'Battery',printing:'Printing',paused:'Paused',complete:'Complete',standby:'Ready',error:'Error'}
|
|
7
|
+
};
|
|
8
|
+
const finite = value => typeof value === 'number' && Number.isFinite(value);
|
|
9
|
+
export const percent = value => finite(value) && value >= 0 && value <= 100 ? value : null;
|
|
10
|
+
export function duration(value) {
|
|
11
|
+
if (!finite(value) || value < 0) return '–';
|
|
12
|
+
const minutes = Math.floor(value / 60);
|
|
13
|
+
return `${Math.floor(minutes / 60)}h ${String(minutes % 60).padStart(2,'0')}m`;
|
|
14
|
+
}
|
|
15
|
+
function node(tag, name, value) { const result=document.createElement(tag); if (name) result.className=name; if (value !== undefined) result.textContent=value; return result; }
|
|
16
|
+
function value(value, suffix='', digits=0) { return finite(value) ? `${value.toFixed(digits)}${suffix}` : '–'; }
|
|
17
|
+
|
|
18
|
+
/** Read-only overview: independent subscriptions and isolated styles per widget. */
|
|
19
|
+
export class OverviewElement extends SpoolElement {
|
|
20
|
+
_sync() {
|
|
21
|
+
const instance = this._settings.instance;
|
|
22
|
+
const battery = typeof this._settings.batteryOid === 'string' ? this._settings.batteryOid.trim() : '';
|
|
23
|
+
if (!this.isConnected || !this._socket || !/^snapmaker-u1\.\d+$/.test(instance || '')) { this.render(); return; }
|
|
24
|
+
if (this._subscription && this._subscription.battery === battery) { this.render(); return; }
|
|
25
|
+
if (this._subscription) this._stop();
|
|
26
|
+
const ids = paths.map(p=>`${instance}.${p}`);
|
|
27
|
+
if (battery && !ids.includes(battery)) ids.push(battery);
|
|
28
|
+
const sub = {socket:this._socket, instance, battery, ids, seen:new Set()};
|
|
29
|
+
sub.handler = (id,state) => { if (this._subscription !== sub || !ids.includes(id)) return; sub.seen.add(id); this._values.set(id,state?.val ?? null); this.render(); };
|
|
30
|
+
this._subscription = sub;
|
|
31
|
+
try {
|
|
32
|
+
Promise.resolve(sub.socket.subscribeState(ids,sub.handler)).catch(()=>{});
|
|
33
|
+
for (const id of ids) Promise.resolve(sub.socket.getState(id)).then(state=>{if(this._subscription===sub && !sub.seen.has(id)){this._values.set(id,state?.val ?? null);this.render();}}).catch(()=>{});
|
|
34
|
+
} catch { this._stop(); }
|
|
35
|
+
this.render();
|
|
36
|
+
}
|
|
37
|
+
_draw() { this.render(); }
|
|
38
|
+
render() {
|
|
39
|
+
if (!this.shadowRoot || !this.isConnected) return;
|
|
40
|
+
const t = labels[String(this._socket?.systemLang || 'en').toLowerCase().startsWith('de') ? 'de' : 'en'];
|
|
41
|
+
const base=this._subscription?.instance; const get=path=>base ? this._values.get(`${base}.${path}`) : undefined;
|
|
42
|
+
const style=node('style'); style.textContent=`:host{display:block;width:100%;height:100%;font-family:var(--u1-font-family,Arial,sans-serif);font-size:var(--u1-font-size,14px);font-weight:var(--u1-font-weight,400);font-style:var(--u1-font-style,normal);text-decoration:var(--u1-text-decoration,none);color:var(--u1-text-color,#eaf0f5);--panel:var(--u1-panel-color,#17202a);--card:var(--u1-card-color,#202b36);--muted:var(--u1-muted-color,#aab8c5)}:host([theme=light]){color:var(--u1-text-color,#182432);--panel:var(--u1-panel-color,#edf2f6);--card:var(--u1-card-color,#fff);--muted:var(--u1-muted-color,#586878)}*{box-sizing:border-box}.panel{height:100%;overflow:auto;background:var(--panel);border-radius:12px;padding:12px}.header,.row{display:flex;align-items:center;justify-content:space-between;gap:8px}.header{margin-bottom:10px}.header strong{font-size:1.15em}.muted{color:var(--muted);font-size:.85em}.grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(230px,1fr));gap:8px}.card{background:var(--card);border-radius:10px;padding:10px;min-width:0}.card h2{font-size:1em;font-weight:inherit;margin:0 0 8px}.job{font-weight:bold;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.progress{height:8px;border-radius:8px;background:var(--panel);overflow:hidden;margin:8px 0}.bar{height:100%;background:#42a5f5}.numbers{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:8px;margin-top:8px}.metric{background:var(--panel);border-radius:7px;padding:6px;min-width:0}.metric strong{display:block;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.status{border-radius:12px;padding:4px 8px;background:var(--card)}.online{color:#4caf70}.offline{color:#e67171}`;
|
|
43
|
+
const panel=node('section','panel'); const head=node('header','header'); head.append(node('strong','',t.title));
|
|
44
|
+
const state=String(get('printer.job.state') || '').toLowerCase(); const states={printing:t.printing,paused:t.paused,complete:t.complete,standby:t.standby,error:t.error}; head.append(node('span','status',states[state] || state || t.unknown)); panel.append(head);
|
|
45
|
+
const grid=node('div','grid'); panel.append(grid);
|
|
46
|
+
const card=(title)=>{const a=node('article','card');a.append(node('h2','',title));grid.append(a);return a;};
|
|
47
|
+
const metric=(container,label,text)=>{const a=node('div','metric');a.append(node('span','muted',label),node('strong','',text));container.append(a);};
|
|
48
|
+
const job=card(t.job); job.append(node('div','job',String(get('printer.job.filename') || t.none)));
|
|
49
|
+
const p=percent(get('printer.job.progress')); const track=node('div','progress');const bar=node('div','bar');bar.style.width=`${p ?? 0}%`;track.append(bar);job.append(track,node('div','muted',p===null?'–':`${p.toFixed(1)} %`));
|
|
50
|
+
const jobNums=node('div','numbers');metric(jobNums,t.layer,`${value(get('printer.job.layer.current'))} / ${value(get('printer.job.layer.total'))}`);metric(jobNums,t.height,value(get('printer.motion.position.z'),' mm',2));job.append(jobNums);
|
|
51
|
+
const temp=card(t.temps);const tempNums=node('div','numbers');for(let i=0;i<4;i++){const actual=get(`printer.tools.tool${i}.temperature`),target=get(`printer.tools.tool${i}.target`);metric(tempNums,`Extruder ${i+1}`,`${value(actual,' °C',1)}${finite(target) ? ` / ${value(target,' °C',0)}` : ''}`);}temp.append(tempNums);
|
|
52
|
+
const info=card(t.information);const infoNums=node('div','numbers');const available=get('printer.job.estimateAvailable')===true;const end=get('printer.job.estimatedEnd');metric(infoNums,t.remaining,available?duration(get('printer.job.remaining')):'–');metric(infoNums,t.end,available && finite(end) && end>0 ? new Date(end).toLocaleTimeString(undefined,{hour:'2-digit',minute:'2-digit'}) : '–');metric(infoNums,t.bed,value(get('printer.bed.temperature'),' °C',1));metric(infoNums,t.chamber,value(get('printer.chamber.temperature'),' °C',1));if(this._subscription?.battery)metric(infoNums,t.battery,value(this._values.get(this._subscription.battery),' %'));info.append(infoNums);
|
|
53
|
+
for(const [label,connected] of [[t.connection,get('info.connection')],['Klipper',get('printer.info.ready')],[t.spoolman,get('spoolman.apiConnected')]]){const row=node('div','row muted');const status=connected===true?t.online:connected===false?t.offline:t.unknown;row.append(node('span','',label),node('span',connected===true?'online':connected===false?'offline':'',status));info.append(row);}
|
|
54
|
+
this.shadowRoot.replaceChildren(style,panel);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 120"><rect width="320" height="120" rx="12" fill="#17202a"/><text x="14" y="23" fill="#eaf0f5" font-family="Arial" font-size="13">Snapmaker U1</text><g fill="#273847"><rect x="12" y="34" width="94" height="74" rx="7"/><rect x="113" y="34" width="94" height="74" rx="7"/><rect x="214" y="34" width="94" height="74" rx="7"/></g><g fill="#eaf0f5" font-family="Arial" font-size="9"><text x="20" y="50">Print job</text><text x="121" y="50">Temperatures</text><text x="222" y="50">Information</text><text x="20" y="76">68 %</text><text x="121" y="76">215 °C</text><text x="222" y="76">1h 24m</text></g><rect x="20" y="86" width="76" height="5" rx="2" fill="#17202a"/><rect x="20" y="86" width="52" height="5" rx="2" fill="#42a5f5"/></svg>
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
{
|
|
2
|
+
"manifestVersion": 1,
|
|
3
|
+
"tag": "snapmaker-u1-vis2-overview",
|
|
4
|
+
"module": "./entry.js",
|
|
5
|
+
"name": {
|
|
6
|
+
"en": "Snapmaker U1 Printer overview",
|
|
7
|
+
"de": "Snapmaker U1 Druckerübersicht"
|
|
8
|
+
},
|
|
9
|
+
"description": {
|
|
10
|
+
"en": "Print progress, temperatures and connectivity",
|
|
11
|
+
"de": "Druckfortschritt, Temperaturen und Verbindungsstatus"
|
|
12
|
+
},
|
|
13
|
+
"icon": "overview-preview.svg",
|
|
14
|
+
"size": {
|
|
15
|
+
"width": 800,
|
|
16
|
+
"height": 310
|
|
17
|
+
},
|
|
18
|
+
"settings": {
|
|
19
|
+
"type": "panel",
|
|
20
|
+
"items": {
|
|
21
|
+
"instance": {
|
|
22
|
+
"type": "instance",
|
|
23
|
+
"adapter": "snapmaker-u1",
|
|
24
|
+
"label": {
|
|
25
|
+
"en": "Snapmaker U1 instance",
|
|
26
|
+
"de": "Snapmaker-U1-Instanz"
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"batteryOid": {
|
|
30
|
+
"type": "objectId",
|
|
31
|
+
"label": {
|
|
32
|
+
"en": "Optional battery state ID",
|
|
33
|
+
"de": "Optionaler Batterie-Datenpunkt"
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
"appearance": {
|
|
37
|
+
"type": "header",
|
|
38
|
+
"text": {
|
|
39
|
+
"en": "Appearance",
|
|
40
|
+
"de": "Darstellung"
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
"appearanceTheme": {
|
|
44
|
+
"type": "select",
|
|
45
|
+
"default": "auto",
|
|
46
|
+
"label": {
|
|
47
|
+
"en": "Base theme",
|
|
48
|
+
"de": "Grunddesign"
|
|
49
|
+
},
|
|
50
|
+
"options": [
|
|
51
|
+
{
|
|
52
|
+
"value": "auto",
|
|
53
|
+
"label": {
|
|
54
|
+
"en": "Automatic",
|
|
55
|
+
"de": "Automatisch"
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
"value": "light",
|
|
60
|
+
"label": {
|
|
61
|
+
"en": "Light",
|
|
62
|
+
"de": "Hell"
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
"value": "dark",
|
|
67
|
+
"label": {
|
|
68
|
+
"en": "Dark",
|
|
69
|
+
"de": "Dunkel"
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
]
|
|
73
|
+
},
|
|
74
|
+
"panelColor": {
|
|
75
|
+
"type": "color",
|
|
76
|
+
"label": {
|
|
77
|
+
"en": "Panel background",
|
|
78
|
+
"de": "Panel-Hintergrund"
|
|
79
|
+
},
|
|
80
|
+
"help": {
|
|
81
|
+
"en": "Empty uses the base theme",
|
|
82
|
+
"de": "Leer verwendet das Grunddesign"
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
"cardColor": {
|
|
86
|
+
"type": "color",
|
|
87
|
+
"label": {
|
|
88
|
+
"en": "Spool card background",
|
|
89
|
+
"de": "Spulenkarten-Hintergrund"
|
|
90
|
+
},
|
|
91
|
+
"help": {
|
|
92
|
+
"en": "Empty uses the base theme",
|
|
93
|
+
"de": "Leer verwendet das Grunddesign"
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
"textColor": {
|
|
97
|
+
"type": "color",
|
|
98
|
+
"label": {
|
|
99
|
+
"en": "Text color",
|
|
100
|
+
"de": "Textfarbe"
|
|
101
|
+
},
|
|
102
|
+
"help": {
|
|
103
|
+
"en": "Empty uses the base theme",
|
|
104
|
+
"de": "Leer verwendet das Grunddesign"
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
"mutedColor": {
|
|
108
|
+
"type": "color",
|
|
109
|
+
"label": {
|
|
110
|
+
"en": "Secondary text color",
|
|
111
|
+
"de": "Farbe für Nebentexte"
|
|
112
|
+
},
|
|
113
|
+
"help": {
|
|
114
|
+
"en": "Empty uses the base theme",
|
|
115
|
+
"de": "Leer verwendet das Grunddesign"
|
|
116
|
+
}
|
|
117
|
+
},
|
|
118
|
+
"fontPreset": {
|
|
119
|
+
"type": "select",
|
|
120
|
+
"default": "default",
|
|
121
|
+
"label": {
|
|
122
|
+
"en": "Font",
|
|
123
|
+
"de": "Schriftart"
|
|
124
|
+
},
|
|
125
|
+
"options": [
|
|
126
|
+
{
|
|
127
|
+
"value": "default",
|
|
128
|
+
"label": {
|
|
129
|
+
"en": "Default (Arial)",
|
|
130
|
+
"de": "Standard (Arial)"
|
|
131
|
+
}
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
"value": "arial",
|
|
135
|
+
"label": "Arial"
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
"value": "verdana",
|
|
139
|
+
"label": "Verdana"
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
"value": "trebuchet",
|
|
143
|
+
"label": "Trebuchet MS"
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
"value": "georgia",
|
|
147
|
+
"label": "Georgia"
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
"value": "times",
|
|
151
|
+
"label": "Times New Roman"
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
"value": "courier",
|
|
155
|
+
"label": "Courier New"
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
"value": "system",
|
|
159
|
+
"label": {
|
|
160
|
+
"en": "System font",
|
|
161
|
+
"de": "Systemschrift"
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
]
|
|
165
|
+
},
|
|
166
|
+
"fontFamily": {
|
|
167
|
+
"type": "text",
|
|
168
|
+
"label": {
|
|
169
|
+
"en": "Custom font family",
|
|
170
|
+
"de": "Eigene Schriftart"
|
|
171
|
+
},
|
|
172
|
+
"help": {
|
|
173
|
+
"en": "Optional font name or CSS font-family list; overrides the font selection. The font must be available on the display device.",
|
|
174
|
+
"de": "Optionaler Schriftname oder CSS-Schriftliste; hat Vorrang vor der Schriftauswahl. Die Schrift muss auf dem Anzeigegerät verfügbar sein."
|
|
175
|
+
}
|
|
176
|
+
},
|
|
177
|
+
"fontSize": {
|
|
178
|
+
"type": "number",
|
|
179
|
+
"min": 8,
|
|
180
|
+
"max": 60,
|
|
181
|
+
"step": 1,
|
|
182
|
+
"default": 14,
|
|
183
|
+
"label": {
|
|
184
|
+
"en": "Font size (px)",
|
|
185
|
+
"de": "Schriftgröße (px)"
|
|
186
|
+
}
|
|
187
|
+
},
|
|
188
|
+
"fontWeight": {
|
|
189
|
+
"type": "select",
|
|
190
|
+
"default": "400",
|
|
191
|
+
"label": {
|
|
192
|
+
"en": "Font weight",
|
|
193
|
+
"de": "Schriftstärke"
|
|
194
|
+
},
|
|
195
|
+
"options": [
|
|
196
|
+
{
|
|
197
|
+
"value": "400",
|
|
198
|
+
"label": {
|
|
199
|
+
"en": "Normal",
|
|
200
|
+
"de": "Normal"
|
|
201
|
+
}
|
|
202
|
+
},
|
|
203
|
+
{
|
|
204
|
+
"value": "500",
|
|
205
|
+
"label": {
|
|
206
|
+
"en": "Medium",
|
|
207
|
+
"de": "Mittel"
|
|
208
|
+
}
|
|
209
|
+
},
|
|
210
|
+
{
|
|
211
|
+
"value": "600",
|
|
212
|
+
"label": {
|
|
213
|
+
"en": "Semi-bold",
|
|
214
|
+
"de": "Halbfett"
|
|
215
|
+
}
|
|
216
|
+
},
|
|
217
|
+
{
|
|
218
|
+
"value": "700",
|
|
219
|
+
"label": {
|
|
220
|
+
"en": "Bold",
|
|
221
|
+
"de": "Fett"
|
|
222
|
+
}
|
|
223
|
+
},
|
|
224
|
+
{
|
|
225
|
+
"value": "800",
|
|
226
|
+
"label": {
|
|
227
|
+
"en": "Extra bold",
|
|
228
|
+
"de": "Extrafett"
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
]
|
|
232
|
+
},
|
|
233
|
+
"fontItalic": {
|
|
234
|
+
"type": "checkbox",
|
|
235
|
+
"default": false,
|
|
236
|
+
"label": {
|
|
237
|
+
"en": "Italic",
|
|
238
|
+
"de": "Kursiv"
|
|
239
|
+
}
|
|
240
|
+
},
|
|
241
|
+
"fontUnderline": {
|
|
242
|
+
"type": "checkbox",
|
|
243
|
+
"default": false,
|
|
244
|
+
"label": {
|
|
245
|
+
"en": "Underline",
|
|
246
|
+
"de": "Unterstrichen"
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { SpoolView } from './spool-view.js';
|
|
2
|
+
import { stateIds } from './spool-model.js';
|
|
3
|
+
|
|
4
|
+
/** Host-specific elements extend this class and register a unique tag. */
|
|
5
|
+
export class SpoolElement extends SpoolView {
|
|
6
|
+
constructor() {
|
|
7
|
+
super();
|
|
8
|
+
this._socket = null;
|
|
9
|
+
this._settings = {};
|
|
10
|
+
this._theme = {};
|
|
11
|
+
this._subscription = null;
|
|
12
|
+
this._values = new Map();
|
|
13
|
+
}
|
|
14
|
+
set socket(value) { if (this._socket !== value) { this._stop(); this._socket = value; this._sync(); } }
|
|
15
|
+
get socket() { return this._socket; }
|
|
16
|
+
set settings(value) {
|
|
17
|
+
const old = this._settings.instance;
|
|
18
|
+
this._settings = value || {};
|
|
19
|
+
this._applyAppearance();
|
|
20
|
+
if (old !== this._settings.instance) this._stop();
|
|
21
|
+
this._sync();
|
|
22
|
+
}
|
|
23
|
+
get settings() { return this._settings; }
|
|
24
|
+
set theme(value) { this._theme = value || {}; this._applyAppearance(); }
|
|
25
|
+
get theme() { return this._theme; }
|
|
26
|
+
_applyAppearance() {
|
|
27
|
+
const settings = this._settings;
|
|
28
|
+
const selected = settings.appearanceTheme;
|
|
29
|
+
this.setAttribute('theme', selected === 'light' || selected === 'dark' ? selected : this._theme.type === 'light' ? 'light' : 'dark');
|
|
30
|
+
for (const [setting, variable] of Object.entries({panelColor:'--u1-panel-color', cardColor:'--u1-card-color', textColor:'--u1-text-color', mutedColor:'--u1-muted-color', warningColor:'--u1-warning-color', alarmColor:'--u1-alarm-color'})) {
|
|
31
|
+
// Validate with the browser's color parser before using a value as a CSS variable.
|
|
32
|
+
const probe = document.createElement('span').style;
|
|
33
|
+
probe.color = typeof settings[setting] === 'string' ? settings[setting].trim() : '';
|
|
34
|
+
if (probe.color) this.style.setProperty(variable, probe.color);
|
|
35
|
+
else this.style.removeProperty(variable);
|
|
36
|
+
}
|
|
37
|
+
const presets = {arial:'Arial, sans-serif',verdana:'Verdana, sans-serif',trebuchet:'"Trebuchet MS", sans-serif',georgia:'Georgia, serif',times:'"Times New Roman", serif',courier:'"Courier New", monospace',system:'system-ui, sans-serif'};
|
|
38
|
+
const custom = typeof settings.fontFamily === 'string' ? settings.fontFamily.trim() : '';
|
|
39
|
+
const family = custom && custom.length <= 200 && !/[;{}\\]/.test(custom) ? custom : presets[settings.fontPreset] || '';
|
|
40
|
+
if (family) this.style.setProperty('--u1-font-family', family);
|
|
41
|
+
else this.style.removeProperty('--u1-font-family');
|
|
42
|
+
const size = Number(settings.fontSize);
|
|
43
|
+
this.style.setProperty('--u1-font-size', `${Number.isFinite(size) && size >= 8 && size <= 60 ? size : 14}px`);
|
|
44
|
+
const weight = String(settings.fontWeight || '400');
|
|
45
|
+
this.style.setProperty('--u1-font-weight', ['400','500','600','700','800'].includes(weight) ? weight : '400');
|
|
46
|
+
this.style.setProperty('--u1-font-style', settings.fontItalic === true ? 'italic' : 'normal');
|
|
47
|
+
this.style.setProperty('--u1-text-decoration', settings.fontUnderline === true ? 'underline' : 'none');
|
|
48
|
+
}
|
|
49
|
+
connectedCallback() { super.connectedCallback(); this._sync(); }
|
|
50
|
+
disconnectedCallback() { this._stop(); }
|
|
51
|
+
_sync() {
|
|
52
|
+
const instance = this._settings.instance;
|
|
53
|
+
if (!this.isConnected || !this._socket || !/^snapmaker-u1\.\d+$/.test(instance || '')) { this._draw(); return; }
|
|
54
|
+
if (this._subscription) { this._draw(); return; }
|
|
55
|
+
const ids = stateIds(instance);
|
|
56
|
+
const sub = { socket: this._socket, instance, ids, seen: new Set() };
|
|
57
|
+
sub.handler = (id, state) => {
|
|
58
|
+
if (this._subscription !== sub || !ids.includes(id)) return;
|
|
59
|
+
sub.seen.add(id);
|
|
60
|
+
this._values.set(id, state?.val ?? null);
|
|
61
|
+
this._draw();
|
|
62
|
+
};
|
|
63
|
+
this._subscription = sub;
|
|
64
|
+
try {
|
|
65
|
+
Promise.resolve(sub.socket.subscribeState(ids, sub.handler)).catch(error => {
|
|
66
|
+
if (this._subscription === sub) console.warn('Snapmaker widget subscription failed', error);
|
|
67
|
+
});
|
|
68
|
+
for (const id of ids) {
|
|
69
|
+
Promise.resolve(sub.socket.getState(id)).then(state => {
|
|
70
|
+
if (this._subscription === sub && !sub.seen.has(id)) {
|
|
71
|
+
this._values.set(id, state?.val ?? null);
|
|
72
|
+
this._draw();
|
|
73
|
+
}
|
|
74
|
+
}).catch(() => {});
|
|
75
|
+
}
|
|
76
|
+
} catch (error) { console.warn('Snapmaker widget connection failed', error); this._stop(); }
|
|
77
|
+
this._draw();
|
|
78
|
+
}
|
|
79
|
+
_stop() {
|
|
80
|
+
const sub = this._subscription;
|
|
81
|
+
this._subscription = null;
|
|
82
|
+
this._values.clear();
|
|
83
|
+
if (sub) {
|
|
84
|
+
try { Promise.resolve(sub.socket.unsubscribeState(sub.ids, sub.handler)).catch(() => {}); } catch { /* host disconnected */ }
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
_draw() {
|
|
88
|
+
const base = this._subscription?.instance;
|
|
89
|
+
const get = suffix => base ? this._values.get(`${base}.${suffix}`) : undefined;
|
|
90
|
+
const fields = ['active', 'color', 'material', 'name', 'remaining_weight', 'initial_weight', 'spool_id', 'lane'];
|
|
91
|
+
const slots = Array.from({ length: 4 }, (_, i) => Object.fromEntries(fields.map(f => [f, get(`spoolman.aktiv.${i+1}.${f}`)])));
|
|
92
|
+
this.data = { slots, connected: get('info.connection'), apiConnected: get('spoolman.apiConnected'), currentLane: get('printer.afc.currentLane'), printing: get('spoolman.druck_laeuft'), animate: this._settings.animate === true };
|
|
93
|
+
}
|
|
94
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/** Return the cross-sectionally correct radius for a constant-width winding. */
|
|
2
|
+
export function windingRadius(remaining, capacity, hub = 28, full = 70) {
|
|
3
|
+
if (![remaining, capacity, hub, full].every(Number.isFinite) || capacity <= 0 || remaining < 0 || hub < 0 || full < hub) return null;
|
|
4
|
+
const fraction = Math.min(1, remaining / capacity);
|
|
5
|
+
return Math.sqrt(hub * hub + fraction * (full * full - hub * hub));
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function weightStatus(remaining) {
|
|
9
|
+
if (!Number.isFinite(remaining) || remaining < 0) return 'unknown';
|
|
10
|
+
if (remaining < 100) return 'alarm';
|
|
11
|
+
if (remaining < 300) return 'warning';
|
|
12
|
+
return 'normal';
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function normalizeColor(value) {
|
|
16
|
+
if (typeof value !== 'string') return '#78909c';
|
|
17
|
+
const s = value.trim().replace(/^#/, '');
|
|
18
|
+
// Spoolman may send RRGGBBAA. Use its RGB hue opaquely so it matches the AFC color.
|
|
19
|
+
return /^[\da-f]{6}(?:[\da-f]{2})?$/i.test(s) ? `#${s.slice(0, 6)}` : '#78909c';
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function stateIds(instance) {
|
|
23
|
+
if (!/^snapmaker-u1\.\d+$/.test(instance)) throw new TypeError('Expected snapmaker-u1.<instance>');
|
|
24
|
+
const fields = ['active', 'color', 'material', 'name', 'remaining_weight', 'initial_weight', 'spool_id', 'lane'];
|
|
25
|
+
return [ `${instance}.info.connection`, `${instance}.spoolman.apiConnected`, `${instance}.spoolman.druck_laeuft`, `${instance}.printer.afc.currentLane`, ...Array.from({ length: 4 }, (_, i) => fields.map(f => `${instance}.spoolman.aktiv.${i + 1}.${f}`)).flat() ];
|
|
26
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { windingRadius, normalizeColor, weightStatus } from './spool-model.js';
|
|
2
|
+
|
|
3
|
+
const NS = 'http://www.w3.org/2000/svg';
|
|
4
|
+
function svg(tag, attrs = {}) {
|
|
5
|
+
const node = document.createElementNS(NS, tag);
|
|
6
|
+
for (const [key, value] of Object.entries(attrs)) node.setAttribute(key, String(value));
|
|
7
|
+
return node;
|
|
8
|
+
}
|
|
9
|
+
function ellipse(parent, cx, cy, rx, ry, fill, extra = {}) {
|
|
10
|
+
parent.append(svg('ellipse', { cx, cy, rx, ry, fill, ...extra }));
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// Anchoring the phase to the page clock prevents state updates from restarting the rotation.
|
|
14
|
+
export function rotationDelay(now) {
|
|
15
|
+
return `-${Math.max(0, now) % 8000}ms`;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** Host supplies the latest four slot records and print state. No global IDs or styles. */
|
|
19
|
+
export class SpoolView extends HTMLElement {
|
|
20
|
+
constructor() {
|
|
21
|
+
super();
|
|
22
|
+
this.attachShadow({ mode: 'open' });
|
|
23
|
+
this._data = {};
|
|
24
|
+
}
|
|
25
|
+
connectedCallback() { this.render(); }
|
|
26
|
+
set data(value) { this._data = value || {}; if (this.isConnected) this.render(); }
|
|
27
|
+
get data() { return this._data; }
|
|
28
|
+
render() {
|
|
29
|
+
const style = document.createElement('style');
|
|
30
|
+
style.textContent = `
|
|
31
|
+
:host {display:block;width:100%;height:100%;font-family:var(--u1-font-family,Arial,sans-serif);font-size:var(--u1-font-size,14px);font-weight:var(--u1-font-weight,400);font-style:var(--u1-font-style,normal);text-decoration:var(--u1-text-decoration,none);color:var(--u1-text-color,#eaf0f5);--panel:var(--u1-panel-color,#17202a);--card:var(--u1-card-color,#202b36);--muted:var(--u1-muted-color,#aab8c5)}
|
|
32
|
+
:host([theme=light]) {color:var(--u1-text-color,#182432);--panel:var(--u1-panel-color,#edf2f6);--card:var(--u1-card-color,#fff);--muted:var(--u1-muted-color,#586878)}
|
|
33
|
+
* {box-sizing:border-box} .panel {background:var(--panel);border-radius:12px;padding:12px;height:100%;overflow:auto}
|
|
34
|
+
h2 {font-size:1.07em;font-weight:inherit;margin:0 0 10px} strong {font-weight:inherit} .grid {display:grid;grid-template-columns:repeat(auto-fit,minmax(150px,1fr));gap:8px}
|
|
35
|
+
article {background:var(--card);border:1px solid transparent;border-radius:10px;padding:9px;min-width:0}
|
|
36
|
+
article.warning {border-color:var(--u1-warning-color,#e4b329)} article.alarm {border-color:var(--u1-alarm-color,#df5148)} article.active {box-shadow:inset 0 0 0 2px var(--filament)}
|
|
37
|
+
.top,.weight {display:flex;justify-content:space-between;gap:4px} .name {overflow:hidden;text-overflow:ellipsis;white-space:nowrap;color:var(--muted)}
|
|
38
|
+
svg {display:block;width:100%;height:120px} .spin {transform-box:view-box;transform-origin:0 0;animation:rotate 8s linear infinite}
|
|
39
|
+
@keyframes rotate {to {transform:rotate(360deg)}} @media (prefers-reduced-motion:reduce) {.spin {animation:none}}
|
|
40
|
+
.weight {font-weight:inherit} .meta {font-size:.86em;color:var(--muted);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
41
|
+
`;
|
|
42
|
+
const panel = document.createElement('div'); panel.className = 'panel';
|
|
43
|
+
const title = document.createElement('h2'); title.textContent = 'Spoolman · AFC'; panel.append(title);
|
|
44
|
+
const connection = document.createElement('div'); connection.className = 'meta';
|
|
45
|
+
connection.textContent = this._data.connected === true && this._data.apiConnected === true ? 'Verbunden' : this._data.connected === false || this._data.apiConnected === false ? 'Offline – Werte möglicherweise veraltet' : 'Verbindung unbekannt';
|
|
46
|
+
panel.append(connection);
|
|
47
|
+
const grid = document.createElement('div'); grid.className = 'grid'; panel.append(grid);
|
|
48
|
+
for (let i = 0; i < 4; i++) {
|
|
49
|
+
const s = this._data.slots?.[i] || {};
|
|
50
|
+
// v0.0.14 `active` means a slot contains a spool, not that it is the selected tool.
|
|
51
|
+
const present = s.active === true;
|
|
52
|
+
const selected = present && typeof s.lane === 'string' && s.lane !== '' && s.lane === this._data.currentLane;
|
|
53
|
+
const color = normalizeColor(s.color);
|
|
54
|
+
const radius = present ? windingRadius(s.remaining_weight, s.initial_weight) : null;
|
|
55
|
+
const card = document.createElement('article');
|
|
56
|
+
card.className = `${present ? weightStatus(s.remaining_weight) : 'unknown'}${selected ? ' active' : ''}`;
|
|
57
|
+
card.style.setProperty('--filament', color);
|
|
58
|
+
const top = document.createElement('div'); top.className = 'top';
|
|
59
|
+
const label = document.createElement('strong'); label.textContent = `Extruder ${i + 1}`;
|
|
60
|
+
const state = document.createElement('span'); state.textContent = selected ? 'Aktiv' : present ? 'Bereit' : '–'; top.append(label, state); card.append(top);
|
|
61
|
+
const name = document.createElement('div'); name.className = 'name'; name.textContent = present ? (s.name || 'Unbekannt') : s.active === false ? 'Keine Spule' : 'Keine Daten'; card.append(name);
|
|
62
|
+
const picture = svg('svg', { viewBox:'0 0 210 180', role:'img', 'aria-label': `Spule ${i + 1}` });
|
|
63
|
+
ellipse(picture, 112, 150, 73, 11, '#000', { opacity:'.2' });
|
|
64
|
+
ellipse(picture, 128, 88, 59, 70, '#303943');
|
|
65
|
+
picture.append(svg('path', { d:'M105 18 H128 V158 H105 Z', fill:'#333d47' }));
|
|
66
|
+
if (radius !== null && radius > 28) {
|
|
67
|
+
const ry = radius; const rx = radius * .76;
|
|
68
|
+
picture.append(svg('path', { d:`M105 ${90-ry} H128 V${90+ry} H105 Z`, fill:color }));
|
|
69
|
+
for (let x = 108; x <= 128; x += 4) picture.append(svg('line', { x1:x, x2:x, y1:90-ry, y2:90+ry, stroke:'#000', 'stroke-opacity':'.18', 'stroke-width':'1' }));
|
|
70
|
+
ellipse(picture, 105, 90, rx, ry, color);
|
|
71
|
+
for (let r = 30; r < radius; r += 4) ellipse(picture, 105, 90, r*.76, r, 'none', { stroke:'#fff', 'stroke-opacity':'.20', 'stroke-width':'1' });
|
|
72
|
+
}
|
|
73
|
+
// Rotate the circular spokes before projecting them into the fixed elliptical face.
|
|
74
|
+
const face = svg('g', { transform:'translate(105 90) scale(0.79 1)', class:'spool-face' });
|
|
75
|
+
const spinning = this._data.animate && this._data.printing === true && this._data.connected === true && this._data.apiConnected === true && selected;
|
|
76
|
+
const spokes = svg('g', { class: spinning ? 'spokes spin' : 'spokes' });
|
|
77
|
+
if (spinning) spokes.style.animationDelay = rotationDelay(performance.now());
|
|
78
|
+
for (let a = 0; a < 360; a += 90) spokes.append(svg('path', { d:'M-5 -24 L-10 -64 L10 -64 L5 -24 Z', fill:'#3b4651', transform:`rotate(${a})` }));
|
|
79
|
+
face.append(spokes);
|
|
80
|
+
ellipse(face, 0, 0, 72, 72, 'none', {stroke:'#48525e','stroke-width':'8'});
|
|
81
|
+
ellipse(face, 0, 0, 29, 29, '#3b4651');
|
|
82
|
+
ellipse(face, 0, 0, 13, 13, '#151c23'); picture.append(face); card.append(picture);
|
|
83
|
+
const material = document.createElement('div'); material.textContent = present ? (s.material || 'Material unbekannt') : '–'; card.append(material);
|
|
84
|
+
const weight = document.createElement('div'); weight.className = 'weight';
|
|
85
|
+
const w = document.createElement('span'); w.textContent = present && Number.isFinite(s.remaining_weight) && s.remaining_weight >= 0 ? `${Math.round(s.remaining_weight)} g` : 'Gewicht unbekannt';
|
|
86
|
+
const pct = document.createElement('span'); pct.textContent = radius === null ? '–' : `${Math.round(Math.min(1,s.remaining_weight/s.initial_weight)*100)} %`;
|
|
87
|
+
weight.append(w,pct); card.append(weight);
|
|
88
|
+
const meta = document.createElement('div'); meta.className='meta'; meta.textContent = s.lane || ''; card.append(meta); grid.append(card);
|
|
89
|
+
}
|
|
90
|
+
this.shadowRoot.replaceChildren(style, panel);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="400" height="160" viewBox="0 0 400 160">
|
|
2
|
+
<rect x="2" y="2" width="396" height="156" rx="15" fill="#17232e"/>
|
|
3
|
+
<text x="14" y="25" font-family="Arial,sans-serif" font-size="14" font-weight="bold" fill="#eef4f7">Spoolman · AFC</text>
|
|
4
|
+
<g font-family="Arial,sans-serif" font-size="10" fill="#d5e0e6">
|
|
5
|
+
<rect x="12" y="36" width="89" height="111" rx="8" fill="#273743"/><text x="19" y="51">Extruder 1</text>
|
|
6
|
+
<rect x="107" y="36" width="89" height="111" rx="8" fill="#273743"/><text x="114" y="51">Extruder 2</text>
|
|
7
|
+
<rect x="202" y="36" width="89" height="111" rx="8" fill="#273743"/><text x="209" y="51">Extruder 3</text>
|
|
8
|
+
<rect x="297" y="36" width="91" height="111" rx="8" fill="#273743"/><text x="304" y="51">Extruder 4</text>
|
|
9
|
+
</g>
|
|
10
|
+
<g stroke="#91a3ae" stroke-width="3">
|
|
11
|
+
<ellipse cx="57" cy="94" rx="24" ry="34" fill="#4ba8cd"/><ellipse cx="152" cy="94" rx="24" ry="34" fill="#d88545"/>
|
|
12
|
+
<ellipse cx="247" cy="94" rx="24" ry="34" fill="#84af66"/><ellipse cx="343" cy="94" rx="24" ry="34" fill="#c66576"/>
|
|
13
|
+
</g>
|
|
14
|
+
<g fill="#273743" stroke="#273743" stroke-width="5">
|
|
15
|
+
<path d="M57 62v64M34 94h46M152 62v64M129 94h46M247 62v64M224 94h46M343 62v64M320 94h46"/>
|
|
16
|
+
<ellipse cx="57" cy="94" rx="7" ry="10"/><ellipse cx="152" cy="94" rx="7" ry="10"/><ellipse cx="247" cy="94" rx="7" ry="10"/><ellipse cx="343" cy="94" rx="7" ry="10"/>
|
|
17
|
+
</g>
|
|
18
|
+
</svg>
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"manifestVersion": 1, "tag": "snapmaker-u1-vis2-spools", "module": "./entry.js",
|
|
3
|
+
"name": { "en": "Snapmaker U1 Spoolman / AFC", "de": "Snapmaker U1 Spoolman / AFC" },
|
|
4
|
+
"description": { "en": "Four native Spoolman slots", "de": "Vier native Spoolman-Spulen" },
|
|
5
|
+
"icon": "spools-preview.svg",
|
|
6
|
+
"size": { "width": 800, "height": 300 },
|
|
7
|
+
"settings": { "type": "panel", "items": {
|
|
8
|
+
"instance": { "type": "instance", "adapter": "snapmaker-u1", "label": { "en": "Snapmaker U1 instance", "de": "Snapmaker-U1-Instanz" } },
|
|
9
|
+
"animate": { "type": "checkbox", "default": false, "label": { "en": "Animate selected spool while printing", "de": "Aktive Spule während des Drucks drehen" } },
|
|
10
|
+
"appearance": { "type": "header", "text": { "en": "Appearance", "de": "Darstellung" } },
|
|
11
|
+
"appearanceTheme": { "type": "select", "default": "auto", "label": { "en": "Base theme", "de": "Grunddesign" }, "options": [
|
|
12
|
+
{ "value": "auto", "label": { "en": "Automatic", "de": "Automatisch" } },
|
|
13
|
+
{ "value": "light", "label": { "en": "Light", "de": "Hell" } },
|
|
14
|
+
{ "value": "dark", "label": { "en": "Dark", "de": "Dunkel" } }
|
|
15
|
+
] },
|
|
16
|
+
"panelColor": { "type": "color", "label": { "en": "Panel background", "de": "Panel-Hintergrund" }, "help": { "en": "Empty uses the base theme", "de": "Leer verwendet das Grunddesign" } },
|
|
17
|
+
"cardColor": { "type": "color", "label": { "en": "Spool card background", "de": "Spulenkarten-Hintergrund" }, "help": { "en": "Empty uses the base theme", "de": "Leer verwendet das Grunddesign" } },
|
|
18
|
+
"textColor": { "type": "color", "label": { "en": "Text color", "de": "Textfarbe" }, "help": { "en": "Empty uses the base theme", "de": "Leer verwendet das Grunddesign" } },
|
|
19
|
+
"mutedColor": { "type": "color", "label": { "en": "Secondary text color", "de": "Farbe für Nebentexte" }, "help": { "en": "Empty uses the base theme", "de": "Leer verwendet das Grunddesign" } },
|
|
20
|
+
"warningColor": { "type": "color", "label": { "en": "Warning border color", "de": "Rahmenfarbe Warnung" } },
|
|
21
|
+
"alarmColor": { "type": "color", "label": { "en": "Alarm border color", "de": "Rahmenfarbe Alarm" } },
|
|
22
|
+
"fontPreset": { "type": "select", "default": "default", "label": { "en": "Font", "de": "Schriftart" }, "options": [
|
|
23
|
+
{ "value": "default", "label": { "en": "Default (Arial)", "de": "Standard (Arial)" } },
|
|
24
|
+
{ "value": "arial", "label": "Arial" }, { "value": "verdana", "label": "Verdana" },
|
|
25
|
+
{ "value": "trebuchet", "label": "Trebuchet MS" }, { "value": "georgia", "label": "Georgia" },
|
|
26
|
+
{ "value": "times", "label": "Times New Roman" }, { "value": "courier", "label": "Courier New" },
|
|
27
|
+
{ "value": "system", "label": { "en": "System font", "de": "Systemschrift" } }
|
|
28
|
+
] },
|
|
29
|
+
"fontFamily": { "type": "text", "label": { "en": "Custom font family", "de": "Eigene Schriftart" }, "help": { "en": "Optional font name or CSS font-family list; overrides the font selection. The font must be available on the display device.", "de": "Optionaler Schriftname oder CSS-Schriftliste; hat Vorrang vor der Schriftauswahl. Die Schrift muss auf dem Anzeigegerät verfügbar sein." } },
|
|
30
|
+
"fontSize": { "type": "number", "min": 8, "max": 60, "step": 1, "default": 14, "label": { "en": "Font size (px)", "de": "Schriftgröße (px)" } },
|
|
31
|
+
"fontWeight": { "type": "select", "default": "400", "label": { "en": "Font weight", "de": "Schriftstärke" }, "options": [
|
|
32
|
+
{ "value": "400", "label": { "en": "Normal", "de": "Normal" } },
|
|
33
|
+
{ "value": "500", "label": { "en": "Medium", "de": "Mittel" } },
|
|
34
|
+
{ "value": "600", "label": { "en": "Semi-bold", "de": "Halbfett" } },
|
|
35
|
+
{ "value": "700", "label": { "en": "Bold", "de": "Fett" } },
|
|
36
|
+
{ "value": "800", "label": { "en": "Extra bold", "de": "Extrafett" } }
|
|
37
|
+
] },
|
|
38
|
+
"fontItalic": { "type": "checkbox", "default": false, "label": { "en": "Italic", "de": "Kursiv" } },
|
|
39
|
+
"fontUnderline": { "type": "checkbox", "default": false, "label": { "en": "Underline", "de": "Unterstrichen" } }
|
|
40
|
+
} }
|
|
41
|
+
}
|
package/io-package.json
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
{
|
|
2
|
+
"common": {
|
|
3
|
+
"name": "vis-2-widget-snapmaker-u1",
|
|
4
|
+
"version": "0.0.6",
|
|
5
|
+
"news": {
|
|
6
|
+
"0.0.6": {
|
|
7
|
+
"en": "Beta with printer overview, cameras and Spoolman.",
|
|
8
|
+
"de": "Beta mit Druckerübersicht, Kameras und Spoolman.",
|
|
9
|
+
"ru": "Бета-версия: обзор принтера, камеры и Spoolman.",
|
|
10
|
+
"pt": "Beta com visão da impressora, câmeras e Spoolman.",
|
|
11
|
+
"nl": "Bèta met printeroverzicht, camera’s en Spoolman.",
|
|
12
|
+
"fr": "Bêta avec aperçu de l’imprimante, caméras et Spoolman.",
|
|
13
|
+
"it": "Beta con panoramica della stampante, telecamere e Spoolman.",
|
|
14
|
+
"es": "Beta con resumen de impresora, cámaras y Spoolman.",
|
|
15
|
+
"pl": "Beta z podglądem drukarki, kamerami i Spoolman.",
|
|
16
|
+
"uk": "Бета: огляд принтера, камери та Spoolman.",
|
|
17
|
+
"zh-cn": "测试版:打印机概览、摄像头和 Spoolman。"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"titleLang": {
|
|
21
|
+
"en": "Snapmaker U1 Widgets · VIS 2",
|
|
22
|
+
"de": "Snapmaker-U1-Widgets · VIS 2",
|
|
23
|
+
"ru": "Виджеты Snapmaker U1 · VIS 2",
|
|
24
|
+
"pt": "Widgets Snapmaker U1 · VIS 2",
|
|
25
|
+
"nl": "Snapmaker U1-widgets · VIS 2",
|
|
26
|
+
"fr": "Widgets Snapmaker U1 · VIS 2",
|
|
27
|
+
"it": "Widget Snapmaker U1 · VIS 2",
|
|
28
|
+
"es": "Widgets de Snapmaker U1 · VIS 2",
|
|
29
|
+
"pl": "Widżety Snapmaker U1 · VIS 2",
|
|
30
|
+
"uk": "Віджети Snapmaker U1 · VIS 2",
|
|
31
|
+
"zh-cn": "Snapmaker U1 组件 · VIS 2"
|
|
32
|
+
},
|
|
33
|
+
"desc": {
|
|
34
|
+
"en": "Snapmaker U1 Widgets · VIS 2",
|
|
35
|
+
"de": "Snapmaker-U1-Widgets · VIS 2",
|
|
36
|
+
"ru": "Виджеты Snapmaker U1 · VIS 2",
|
|
37
|
+
"pt": "Widgets Snapmaker U1 · VIS 2",
|
|
38
|
+
"nl": "Snapmaker U1-widgets · VIS 2",
|
|
39
|
+
"fr": "Widgets Snapmaker U1 · VIS 2",
|
|
40
|
+
"it": "Widget Snapmaker U1 · VIS 2",
|
|
41
|
+
"es": "Widgets de Snapmaker U1 · VIS 2",
|
|
42
|
+
"pl": "Widżety Snapmaker U1 · VIS 2",
|
|
43
|
+
"uk": "Віджети Snapmaker U1 · VIS 2",
|
|
44
|
+
"zh-cn": "Snapmaker U1 组件 · VIS 2"
|
|
45
|
+
},
|
|
46
|
+
"authors": [
|
|
47
|
+
"Negalein <negalein@gmail.com>"
|
|
48
|
+
],
|
|
49
|
+
"licenseInformation": {
|
|
50
|
+
"license": "MIT",
|
|
51
|
+
"type": "free"
|
|
52
|
+
},
|
|
53
|
+
"platform": "Javascript/Node.js",
|
|
54
|
+
"mode": "none",
|
|
55
|
+
"enabled": true,
|
|
56
|
+
"onlyWWW": true,
|
|
57
|
+
"singleton": true,
|
|
58
|
+
"type": "visualization-widgets",
|
|
59
|
+
"connectionType": "local",
|
|
60
|
+
"dataSource": "push",
|
|
61
|
+
"adminUI": {
|
|
62
|
+
"config": "none"
|
|
63
|
+
},
|
|
64
|
+
"tier": 3,
|
|
65
|
+
"icon": "icon.svg",
|
|
66
|
+
"extIcon": "https://raw.githubusercontent.com/Negalein/ioBroker.vis-2-widget-snapmaker-u1/main/admin/icon.svg",
|
|
67
|
+
"readme": "https://github.com/Negalein/ioBroker.vis-2-widget-snapmaker-u1/blob/main/README.md",
|
|
68
|
+
"dependencies": [
|
|
69
|
+
{
|
|
70
|
+
"js-controller": ">=7.2.5"
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
"vis-2": ">=2.20.13"
|
|
74
|
+
}
|
|
75
|
+
],
|
|
76
|
+
"restartAdapters": [
|
|
77
|
+
"vis-2"
|
|
78
|
+
],
|
|
79
|
+
"webComponents": [
|
|
80
|
+
"webcomponents/spools.json",
|
|
81
|
+
"webcomponents/overview.json",
|
|
82
|
+
"webcomponents/media.json"
|
|
83
|
+
],
|
|
84
|
+
"keywords": [
|
|
85
|
+
"visualization",
|
|
86
|
+
"snapmaker",
|
|
87
|
+
"widgets",
|
|
88
|
+
"spoolman"
|
|
89
|
+
]
|
|
90
|
+
},
|
|
91
|
+
"native": {},
|
|
92
|
+
"instanceObjects": []
|
|
93
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,41 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "iobroker.vis-2-widget-snapmaker-u1",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
6
|
-
|
|
3
|
+
"version": "0.0.6",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Snapmaker U1 widgets for ioBroker VIS 2",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"author": "Negalein <negalein@gmail.com>",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "https://github.com/Negalein/ioBroker.vis-2-widget-snapmaker-u1.git"
|
|
11
|
+
},
|
|
12
|
+
"keywords": [
|
|
13
|
+
"iobroker",
|
|
14
|
+
"vis-2",
|
|
15
|
+
"snapmaker",
|
|
16
|
+
"spoolman",
|
|
17
|
+
"ioBroker"
|
|
18
|
+
],
|
|
19
|
+
"files": [
|
|
20
|
+
"admin/",
|
|
21
|
+
"io-package.json",
|
|
22
|
+
"LICENSE",
|
|
23
|
+
"README.md",
|
|
24
|
+
"README-de.md"
|
|
25
|
+
],
|
|
26
|
+
"scripts": {
|
|
27
|
+
"test": "node --test test/*.test.mjs",
|
|
28
|
+
"test:package": "mocha test/package.cjs --exit"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@iobroker/testing": "^6.3.4",
|
|
32
|
+
"jsdom": "^26.1.0"
|
|
33
|
+
},
|
|
34
|
+
"engines": {
|
|
35
|
+
"node": ">=20"
|
|
36
|
+
},
|
|
37
|
+
"homepage": "https://github.com/Negalein/ioBroker.vis-2-widget-snapmaker-u1",
|
|
38
|
+
"bugs": {
|
|
39
|
+
"url": "https://github.com/Negalein/ioBroker.vis-2-widget-snapmaker-u1/issues"
|
|
40
|
+
}
|
|
41
|
+
}
|