From 95697a4e93eeddf75d19becb5d79acb720c22ecb Mon Sep 17 00:00:00 2001 From: David Carley Date: Thu, 4 Aug 2022 01:40:27 +0000 Subject: [PATCH 01/17] Firmware now builds in a VSCode "Remote Container" --- .devcontainer/Dockerfile | 15 +++++++++++++++ .devcontainer/devcontainer.json | 26 ++++++++++++++++++++++++++ docs/development.md | 18 ++++++++++++------ scripts/rpi-chroot.sh | 23 +++++++++++++---------- src/bbserial/Makefile | 6 ++++-- src/pug/templates/settings-view.pug | 2 +- 6 files changed, 71 insertions(+), 19 deletions(-) create mode 100644 .devcontainer/Dockerfile create mode 100644 .devcontainer/devcontainer.json diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 0000000..b8fa432 --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,15 @@ +# See here for image contents: https://github.com/microsoft/vscode-dev-containers/blob/v0.241.1/containers/debian/.devcontainer/base.Dockerfile + +# [Choice] Debian version (use bullseye on local arm64/Apple Silicon): bullseye, buster +ARG VARIANT=bullseye +FROM mcr.microsoft.com/vscode/devcontainers/base:${VARIANT} + +RUN apt update \ + && apt upgrade -y \ + && apt install -y \ + build-essential git wget binfmt-support qemu gcc-9 \ + parted gcc-avr avr-libc avrdude python3 python3-tornado curl \ + unzip python3-setuptools gcc-arm-linux-gnueabihf bc sudo \ + && update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 9 \ + && curl -fsSL https://deb.nodesource.com/setup_18.x | bash - \ + && apt install -y nodejs diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..62b154a --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,26 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at: +// https://github.com/microsoft/vscode-dev-containers/blob/v0.241.1/containers/debian +{ + "name": "Debian", + "build": { + "dockerfile": "Dockerfile", + // Update 'VARIANT' to pick an Debian version: bullseye, buster + // Use bullseye on local arm64/Apple Silicon. + "args": { "VARIANT": "bullseye" } + }, + + "runArgs": ["--privileged"], + + // Use 'forwardPorts' to make a list of ports inside the container available locally. + // "forwardPorts": [], + + // Uncomment to use the Docker CLI from inside the container. See https://aka.ms/vscode-remote/samples/docker-from-docker. + // "mounts": [ "source=/var/run/docker.sock,target=/var/run/docker.sock,type=bind" ], + + // Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root. + // "remoteUser": "vscode", + + "features": { + "sshd": "latest" + } +} diff --git a/docs/development.md b/docs/development.md index 6a82eb5..028d1b5 100644 --- a/docs/development.md +++ b/docs/development.md @@ -8,12 +8,18 @@ Debian Linux are not supported. On a Debian Linux (9.6.0 stable) system install the required packages: - sudo apt-get update - sudo apt-get install -y build-essential git wget binfmt-support qemu \ - parted gcc-avr avr-libc avrdude pylint3 python3 python3-tornado curl \ - unzip python3-setuptools gcc-arm-linux-gnueabihf bc sudo - curl -sL https://deb.nodesource.com/setup_13.x | sudo -E bash - - sudo apt-get install -y nodejs + apt update + apt upgrade -y + apt install -y \ + build-essential git wget binfmt-support qemu gcc-9 \ + parted gcc-avr avr-libc avrdude python3 python3-tornado curl \ + unzip python3-setuptools gcc-arm-linux-gnueabihf bc sudo + + update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 9 + + curl -fsSL https://deb.nodesource.com/setup_18.x | bash - + + apt install -y nodejs ## Getting the Source Code diff --git a/scripts/rpi-chroot.sh b/scripts/rpi-chroot.sh index 35e15be..ef52ca6 100755 --- a/scripts/rpi-chroot.sh +++ b/scripts/rpi-chroot.sh @@ -1,7 +1,6 @@ #!/bin/bash -ex ROOT="$PWD/rpi-root" -LOOP=12 if [ $# -lt 1 ]; then echo "Usage: $0 " @@ -9,7 +8,8 @@ if [ $# -lt 1 ]; then fi IMAGE="$1" -LOOP_DEV=/dev/loop${LOOP} +LOOP_BOOT= +LOOP_ROOT= EXEC= if [ $# -gt 1 ]; then @@ -26,25 +26,28 @@ fi # Clean up on EXIT function cleanup { umount "$ROOT"/{dev/pts,dev,sys,proc,boot,mnt/host,} 2>/dev/null || true - losetup -d $LOOP_DEV 2>/dev/null || true + losetup -d $LOOP_BOOT 2>/dev/null || true + losetup -d $LOOP_ROOT 2>/dev/null || true rmdir "$ROOT" 2>/dev/null || true } trap cleanup EXIT -# set up image as loop device -losetup $LOOP_DEV "$IMAGE" -partprobe $LOOP_DEV +LOOP_BOOT=`losetup -f` +losetup -o 4194304 $LOOP_BOOT "$IMAGE" + +LOOP_ROOT=`losetup -f` +losetup -o 48234496 $LOOP_ROOT "$IMAGE" # check and fix filesystems -fsck -f ${LOOP_DEV}p1 -fsck -f ${LOOP_DEV}p2 +fsck -f $LOOP_BOOT +fsck -f $LOOP_ROOT # make dir mkdir -p "$ROOT" # mount partition -mount -o rw ${LOOP_DEV}p2 -t ext4 "$ROOT" -mount -o rw ${LOOP_DEV}p1 "$ROOT/boot" +mount -o rw $LOOP_ROOT -t ext4 "$ROOT" +mount -o rw $LOOP_BOOT "$ROOT/boot" # mount binds mount --bind /dev "$ROOT/dev/" diff --git a/src/bbserial/Makefile b/src/bbserial/Makefile index 0b7bbc6..792ddfd 100644 --- a/src/bbserial/Makefile +++ b/src/bbserial/Makefile @@ -5,7 +5,7 @@ ccflags-y:=-std=gnu99 -Wno-declaration-after-statement KPKG=raspberrypi-kernel_1.20171029-1.tar.gz KURL=https://github.com/dbrgn/linux-rpi/archive/$(KPKG) -KDIR=linux-rpi-raspberrypi-kernel_1.20171029-1 +KDIR=/tmp/rpi-kernel export KERNEL=kernel7 KOPTS=ARCH=arm CROSS_COMPILE=$(CROSS) -C $(KDIR) @@ -14,7 +14,9 @@ all: $(KDIR) $(MAKE) $(KOPTS) M=$(DIR) modules $(KDIR): $(KPKG) - tar xf $(KPKG) + rm -rf $(KDIR) + mkdir -p $(KDIR) + tar xf $(KPKG) -C $(KDIR) --strip-components 1 $(MAKE) $(KOPTS) bcm2709_defconfig $(MAKE) $(KOPTS) modules_prepare diff --git a/src/pug/templates/settings-view.pug b/src/pug/templates/settings-view.pug index 8a0061f..4b6cf85 100644 --- a/src/pug/templates/settings-view.pug +++ b/src/pug/templates/settings-view.pug @@ -1,2 +1,2 @@ script#settings-view-template(type="text/x-template") - #settings \ No newline at end of file + #settings From 36f191a8dfea248b8731604830848e8e6bca27a1 Mon Sep 17 00:00:00 2001 From: David Carley Date: Mon, 8 Aug 2022 22:44:42 +0000 Subject: [PATCH 02/17] Bumped version number --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 8bccad7..ec44e54 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "bbctrl", - "version": "1.0.10b7", + "version": "1.0.10b8", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "bbctrl", - "version": "1.0.10b7", + "version": "1.0.10b8", "hasInstallScript": true, "license": "GPL-3.0+", "dependencies": { diff --git a/package.json b/package.json index f2f463a..aa4e8ad 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bbctrl", - "version": "1.0.10b7", + "version": "1.0.10b8", "homepage": "https://onefinitycnc.com/", "repository": "https://github.com/OneFinityCNC/onefinity", "license": "GPL-3.0+", From 5900632b283c563a6188f4662f33d2ab28d0f771 Mon Sep 17 00:00:00 2001 From: David Carley Date: Mon, 8 Aug 2022 22:45:12 +0000 Subject: [PATCH 03/17] Fixed a bug when uploading files with spaces or other special characters in the name. --- src/py/bbctrl/FileHandler.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/py/bbctrl/FileHandler.py b/src/py/bbctrl/FileHandler.py index 33d5eb3..7f2195c 100644 --- a/src/py/bbctrl/FileHandler.py +++ b/src/py/bbctrl/FileHandler.py @@ -5,7 +5,7 @@ import glob import tornado from tornado import gen from tornado.web import HTTPError - +from tornado.escape import url_unescape; def safe_remove(path): try: @@ -20,7 +20,8 @@ class FileHandler(bbctrl.APIHandler): if self.request.method == 'PUT': self.request.connection.set_max_body_size(2 ** 30) - self.uploadFilename = self.request.path.split('/')[-1] \ + filename = self.request.path.split('/')[-1] + self.uploadFilename = url_unescape(filename) \ .replace('\\', '/') \ .replace('#', '-') \ .replace('?', '-') From 2554f0ea752b390acabf7d15c38e5850de15327b Mon Sep 17 00:00:00 2001 From: David Carley Date: Tue, 16 Aug 2022 03:02:05 +0000 Subject: [PATCH 04/17] Rebuilt the shutdown/reboot dialog in Svelte --- .devcontainer/Dockerfile | 2 +- src/js/app.js | 22 +++++------ src/pug/index.pug | 12 +----- .../src/dialogs/DialogHost.svelte | 18 ++++++++- .../src/dialogs/ShutdownDialog.svelte | 38 +++++++++++++++++++ 5 files changed, 67 insertions(+), 25 deletions(-) create mode 100644 src/svelte-components/src/dialogs/ShutdownDialog.svelte diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index b8fa432..ee9848d 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -9,7 +9,7 @@ RUN apt update \ && apt install -y \ build-essential git wget binfmt-support qemu gcc-9 \ parted gcc-avr avr-libc avrdude python3 python3-tornado curl \ - unzip python3-setuptools gcc-arm-linux-gnueabihf bc sudo \ + unzip python3-setuptools gcc-arm-linux-gnueabihf bc vim sudo \ && update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 9 \ && curl -fsSL https://deb.nodesource.com/setup_18.x | bash - \ && apt install -y nodejs diff --git a/src/js/app.js b/src/js/app.js index 46a07ff..7210983 100644 --- a/src/js/app.js +++ b/src/js/app.js @@ -106,8 +106,7 @@ module.exports = new Vue({ firmwareUpgrading: false, checkedUpgrade: false, firmwareName: "", - latestVersion: "", - confirmShutdown: false, + latestVersion: "" }; }, @@ -283,10 +282,17 @@ module.exports = new Vue({ }, show_upgrade: function () { - if (!this.latestVersion) return false; + if (!this.latestVersion) { + return false; + } + return is_newer_version(this.config.version, this.latestVersion); }, + showShutdownDialog: function () { + SvelteComponents.showDialog("Shutdown"); + }, + update: async function () { const config = await api.get("config/load"); @@ -303,16 +309,6 @@ module.exports = new Vue({ SvelteComponents.handleConfigUpdate(this.config); }, - shutdown: function () { - this.confirmShutdown = false; - api.put("shutdown"); - }, - - reboot: function () { - this.confirmShutdown = false; - api.put("reboot"); - }, - connect: function () { this.sock = new Sock(`//${location.host}/sockjs`); diff --git a/src/pug/index.pug b/src/pug/index.pug index 3d65e50..89eb5a2 100644 --- a/src/pug/index.pug +++ b/src/pug/index.pug @@ -65,16 +65,8 @@ html(lang="en") li.pure-menu-heading a.pure-menu-link(href="#help") Help - button.pure-button.pure-button-primary(@click="confirmShutdown = true", style="width: 100%") - .fa.fa-power-off - message(:show.sync="confirmShutdown") - h3(slot="header") Confirm shutdown? - p(slot="body") Please wait for black screen before switching off power. - div(slot="footer") - button.pure-button(@click="confirmShutdown = false") Cancel - button.pure-button.button-success(@click="shutdown") Shutdown - button.pure-button.button-success(@click="reboot") Restart - + button.pure-button.pure-button-primary(@click="showShutdownDialog", style="width: 100%") + .fa.fa-power-off #main .header diff --git a/src/svelte-components/src/dialogs/DialogHost.svelte b/src/svelte-components/src/dialogs/DialogHost.svelte index a8765ec..129fd35 100644 --- a/src/svelte-components/src/dialogs/DialogHost.svelte +++ b/src/svelte-components/src/dialogs/DialogHost.svelte @@ -7,6 +7,7 @@ import SetTimeDialog from "./SetTimeDialog.svelte"; import ManualHomeAxisDialog from "./ManualHomeAxisDialog.svelte"; import SetAxisPositionDialog from "./SetAxisPositionDialog.svelte"; + import ShutdownDialog from "./ShutdownDialog.svelte"; const HomeMachineDialogProps = writable(); type HomeMachineDialogPropsType = { @@ -49,6 +50,11 @@ axis: string; }; + const ShutdownDialogProps = writable(); + type ShutdownDialogPropsType = { + open: boolean; + }; + export function showDialog( dialog: "HomeMachine", props: Omit @@ -84,6 +90,11 @@ props: Omit ); + export function showDialog( + dialog: "Shutdown", + props: Omit + ); + export function showDialog(dialog: string, props: any) { switch (dialog) { case "HomeMachine": @@ -114,8 +125,12 @@ SetAxisPositionDialogProps.set({ ...props, open: true }); break; + case "Shutdown": + ShutdownDialogProps.set({ ...props, open: true }); + break; + default: - throw new Error(`Unknown dialog '${dialog}`); + throw new Error(`Unknown dialog '${dialog}'`); } } @@ -127,3 +142,4 @@ + diff --git a/src/svelte-components/src/dialogs/ShutdownDialog.svelte b/src/svelte-components/src/dialogs/ShutdownDialog.svelte new file mode 100644 index 0000000..bf98e86 --- /dev/null +++ b/src/svelte-components/src/dialogs/ShutdownDialog.svelte @@ -0,0 +1,38 @@ + + + + Confirm Shutdown? + + + + + + + + + From 1bd096e55caf858ad7af59c97e6c855674995198 Mon Sep 17 00:00:00 2001 From: David Carley Date: Thu, 18 Aug 2022 08:01:00 +0000 Subject: [PATCH 05/17] Automatically adjust dialog position when the virtual keyboard is displayed, and allow input from the virtual keyboard to update value bindings in Svelte textfields. --- .../src/dialogs/ChangeHostnameDialog.svelte | 6 +- .../src/dialogs/DialogHost.svelte | 61 +++++++++++++++++++ .../src/dialogs/ManualHomeAxisDialog.svelte | 2 + .../src/dialogs/SetAxisPositionDialog.svelte | 2 + .../src/dialogs/SetTimeDialog.svelte | 4 ++ .../src/dialogs/WifiConnectionDialog.svelte | 2 + .../src/lib/customActions.ts | 4 ++ .../src/theme/_smui-theme.scss | 4 ++ 8 files changed, 81 insertions(+), 4 deletions(-) create mode 100644 src/svelte-components/src/lib/customActions.ts diff --git a/src/svelte-components/src/dialogs/ChangeHostnameDialog.svelte b/src/svelte-components/src/dialogs/ChangeHostnameDialog.svelte index 51bbdde..c8463a3 100644 --- a/src/svelte-components/src/dialogs/ChangeHostnameDialog.svelte +++ b/src/svelte-components/src/dialogs/ChangeHostnameDialog.svelte @@ -4,6 +4,7 @@ import TextField from "@smui/textfield"; import MessageDialog from "$dialogs/MessageDialog.svelte"; import * as api from "$lib/api"; + import { virtualKeyboardChangeHelper } from "$lib/customActions"; // https://man7.org/linux/man-pages/man7/hostname.7.html // @@ -72,15 +73,12 @@ (hostname = newValue)]]} label="New Hostname" spellcheck="false" variant="filled" style="width: 100%;" /> - -

- Clicking Confirm will reboot the controller to apply the change. -

diff --git a/src/svelte-components/src/dialogs/DialogHost.svelte b/src/svelte-components/src/dialogs/DialogHost.svelte index 129fd35..0f5b103 100644 --- a/src/svelte-components/src/dialogs/DialogHost.svelte +++ b/src/svelte-components/src/dialogs/DialogHost.svelte @@ -135,6 +135,67 @@ } + + + diff --git a/src/svelte-components/src/dialogs/ManualHomeAxisDialog.svelte b/src/svelte-components/src/dialogs/ManualHomeAxisDialog.svelte index eb08d36..14c4135 100644 --- a/src/svelte-components/src/dialogs/ManualHomeAxisDialog.svelte +++ b/src/svelte-components/src/dialogs/ManualHomeAxisDialog.svelte @@ -3,6 +3,7 @@ import TextField from "@smui/textfield"; import Button, { Label } from "@smui/button"; import { ControllerMethods } from "$lib/RegisterControllerMethods"; + import { virtualKeyboardChangeHelper } from "$lib/customActions"; export let open: boolean; export let axis = ""; @@ -30,6 +31,7 @@ label="Absolute" type="number" bind:value + use={[[virtualKeyboardChangeHelper, (newValue) => (value = newValue)]]} variant="filled" style="width: 100%;" /> diff --git a/src/svelte-components/src/dialogs/SetAxisPositionDialog.svelte b/src/svelte-components/src/dialogs/SetAxisPositionDialog.svelte index 8f49c26..19c3620 100644 --- a/src/svelte-components/src/dialogs/SetAxisPositionDialog.svelte +++ b/src/svelte-components/src/dialogs/SetAxisPositionDialog.svelte @@ -3,6 +3,7 @@ import TextField from "@smui/textfield"; import Button, { Label } from "@smui/button"; import { ControllerMethods } from "$lib/RegisterControllerMethods"; + import { virtualKeyboardChangeHelper } from "$lib/customActions"; export let open: boolean; export let axis = ""; @@ -42,6 +43,7 @@ label="Position" type="number" bind:value + use={[[virtualKeyboardChangeHelper, (newValue) => (value = newValue)]]} spellcheck="false" variant="filled" style="width: 100%;" diff --git a/src/svelte-components/src/dialogs/SetTimeDialog.svelte b/src/svelte-components/src/dialogs/SetTimeDialog.svelte index a294e61..2c39557 100644 --- a/src/svelte-components/src/dialogs/SetTimeDialog.svelte +++ b/src/svelte-components/src/dialogs/SetTimeDialog.svelte @@ -5,6 +5,7 @@ import CircularProgress from "@smui/circular-progress"; import VirtualList from "svelte-tiny-virtual-list"; import * as api from "$lib/api"; + import { virtualKeyboardChangeHelper } from "$lib/customActions"; const itemHeight = 35; @@ -153,6 +154,9 @@ (value = newValue)], + ]} label="Time" type="datetime-local" variant="filled" diff --git a/src/svelte-components/src/dialogs/WifiConnectionDialog.svelte b/src/svelte-components/src/dialogs/WifiConnectionDialog.svelte index 24feaf1..8d584b9 100644 --- a/src/svelte-components/src/dialogs/WifiConnectionDialog.svelte +++ b/src/svelte-components/src/dialogs/WifiConnectionDialog.svelte @@ -7,6 +7,7 @@ import MessageDialog from "$dialogs/MessageDialog.svelte"; import type { WifiNetwork } from "$lib/NetworkInfo"; import * as api from "$lib/api"; + import { virtualKeyboardChangeHelper } from "$lib/customActions"; export let open = false; export let network: WifiNetwork; @@ -56,6 +57,7 @@ {#if needPassword} (password = newValue)]]} label="Password" spellcheck="false" variant="filled" diff --git a/src/svelte-components/src/lib/customActions.ts b/src/svelte-components/src/lib/customActions.ts new file mode 100644 index 0000000..6241f7c --- /dev/null +++ b/src/svelte-components/src/lib/customActions.ts @@ -0,0 +1,4 @@ +export function virtualKeyboardChangeHelper(node: HTMLElement, cb: (value: any) => void) { + const input = node.querySelector("input"); + input.addEventListener("keyup", () => cb(input.value)); +} diff --git a/src/svelte-components/src/theme/_smui-theme.scss b/src/svelte-components/src/theme/_smui-theme.scss index c5e13b7..df1fdfe 100644 --- a/src/svelte-components/src/theme/_smui-theme.scss +++ b/src/svelte-components/src/theme/_smui-theme.scss @@ -20,6 +20,10 @@ :root { --mdc-theme-text-primary-on-background: #777; + .mdc-dialog .mdc-dialog__container { + transition: margin-bottom 0.5s; + } + .mdc-dialog .mdc-dialog__content { color: #777; } From c1b93270e79ad234f7832e8d27a47fd6c25fedc0 Mon Sep 17 00:00:00 2001 From: David Carley Date: Thu, 18 Aug 2022 20:30:53 +0000 Subject: [PATCH 06/17] New drop-menu for picking a standard bit size. --- .../src/components/DimensionInput.svelte | 91 ---------- .../components/TextFieldWithOptions.svelte | 90 ++++++++++ .../src/dialogs/ChangeHostnameDialog.svelte | 4 +- .../src/dialogs/ManualHomeAxisDialog.svelte | 4 +- .../src/dialogs/ProbeDialog.svelte | 160 +++++++++--------- .../src/dialogs/SetAxisPositionDialog.svelte | 4 +- .../src/dialogs/SetTimeDialog.svelte | 6 +- .../src/dialogs/WifiConnectionDialog.svelte | 4 +- .../src/lib/CustomActions.ts | 9 + src/svelte-components/src/lib/RegexHelpers.ts | 90 ++++++++++ .../src/lib/customActions.ts | 4 - src/svelte-components/vite.config.ts | 1 - 12 files changed, 278 insertions(+), 189 deletions(-) delete mode 100644 src/svelte-components/src/components/DimensionInput.svelte create mode 100644 src/svelte-components/src/components/TextFieldWithOptions.svelte create mode 100644 src/svelte-components/src/lib/CustomActions.ts create mode 100644 src/svelte-components/src/lib/RegexHelpers.ts delete mode 100644 src/svelte-components/src/lib/customActions.ts diff --git a/src/svelte-components/src/components/DimensionInput.svelte b/src/svelte-components/src/components/DimensionInput.svelte deleted file mode 100644 index bec8141..0000000 --- a/src/svelte-components/src/components/DimensionInput.svelte +++ /dev/null @@ -1,91 +0,0 @@ - - -
-
- menu.setOpen(true)} - /> - -
- - - {#each options as option} - onOptionSelected(option)}> - {option.label} - - {/each} - - -
- - \ No newline at end of file diff --git a/src/svelte-components/src/components/TextFieldWithOptions.svelte b/src/svelte-components/src/components/TextFieldWithOptions.svelte new file mode 100644 index 0000000..d1d487a --- /dev/null +++ b/src/svelte-components/src/components/TextFieldWithOptions.svelte @@ -0,0 +1,90 @@ + + +
+ showMenu(true)} + on:focusout={() => showMenu(false)} + use={[[virtualKeyboardChange, (newValue) => (value = newValue)]]} + {...$$restProps} + > +
+ {#if valid} + + {/if} +
+ {helperText} +
+ + +
+ {#each options as group} + + {#each group as option} + { + value = option; + showMenu(false); + + optionSelected = true; + }} + > + {option} + + {/each} + + {/each} +
+
+
+ + diff --git a/src/svelte-components/src/dialogs/ChangeHostnameDialog.svelte b/src/svelte-components/src/dialogs/ChangeHostnameDialog.svelte index c8463a3..c04a40c 100644 --- a/src/svelte-components/src/dialogs/ChangeHostnameDialog.svelte +++ b/src/svelte-components/src/dialogs/ChangeHostnameDialog.svelte @@ -4,7 +4,7 @@ import TextField from "@smui/textfield"; import MessageDialog from "$dialogs/MessageDialog.svelte"; import * as api from "$lib/api"; - import { virtualKeyboardChangeHelper } from "$lib/customActions"; + import { virtualKeyboardChange } from "$lib/CustomActions"; // https://man7.org/linux/man-pages/man7/hostname.7.html // @@ -73,7 +73,7 @@ (hostname = newValue)]]} + use={[[virtualKeyboardChange, (newValue) => (hostname = newValue)]]} label="New Hostname" spellcheck="false" variant="filled" diff --git a/src/svelte-components/src/dialogs/ManualHomeAxisDialog.svelte b/src/svelte-components/src/dialogs/ManualHomeAxisDialog.svelte index 14c4135..b008e83 100644 --- a/src/svelte-components/src/dialogs/ManualHomeAxisDialog.svelte +++ b/src/svelte-components/src/dialogs/ManualHomeAxisDialog.svelte @@ -3,7 +3,7 @@ import TextField from "@smui/textfield"; import Button, { Label } from "@smui/button"; import { ControllerMethods } from "$lib/RegisterControllerMethods"; - import { virtualKeyboardChangeHelper } from "$lib/customActions"; + import { virtualKeyboardChange } from "$lib/CustomActions"; export let open: boolean; export let axis = ""; @@ -31,7 +31,7 @@ label="Absolute" type="number" bind:value - use={[[virtualKeyboardChangeHelper, (newValue) => (value = newValue)]]} + use={[[virtualKeyboardChange, (newValue) => (value = newValue)]]} variant="filled" style="width: 100%;" /> diff --git a/src/svelte-components/src/dialogs/ProbeDialog.svelte b/src/svelte-components/src/dialogs/ProbeDialog.svelte index cc76844..6559b08 100644 --- a/src/svelte-components/src/dialogs/ProbeDialog.svelte +++ b/src/svelte-components/src/dialogs/ProbeDialog.svelte @@ -1,5 +1,4 @@ - @@ -203,4 +218,5 @@ + diff --git a/src/svelte-components/src/dialogs/MoveToZeroDialog.svelte b/src/svelte-components/src/dialogs/MoveToZeroDialog.svelte new file mode 100644 index 0000000..321d6be --- /dev/null +++ b/src/svelte-components/src/dialogs/MoveToZeroDialog.svelte @@ -0,0 +1,33 @@ + + + + + Move to ${(axes || "").toUpperCase()} origin? + + + + + + + + diff --git a/src/svelte-components/src/dialogs/ProbeDialog.svelte b/src/svelte-components/src/dialogs/ProbeDialog.svelte index 56dce8e..1fc9a3b 100644 --- a/src/svelte-components/src/dialogs/ProbeDialog.svelte +++ b/src/svelte-components/src/dialogs/ProbeDialog.svelte @@ -104,7 +104,7 @@ await stepCompleted("Done", userAcknowledged); if (probeType === "xyz") { - ControllerMethods.goto_zero(1, 1, 0, 0); + ControllerMethods.gotoZero("xy"); } } catch (err) { if (err.message !== "cancelled") { diff --git a/src/svelte-components/src/lib/RegisterControllerMethods.ts b/src/svelte-components/src/lib/RegisterControllerMethods.ts index f0b47d9..fe5388a 100644 --- a/src/svelte-components/src/lib/RegisterControllerMethods.ts +++ b/src/svelte-components/src/lib/RegisterControllerMethods.ts @@ -1,7 +1,6 @@ -type ControllerMethods = { +interface RegisterableControllerMethods { stop: () => void; send: (gcode: string) => void; - goto_zero: (x: number, y: number, z: number, a: number) => void; dispatch: (event: string, ...args: any[]) => void; isAxisHomed: (axis: string) => boolean; unhome: (axis: string) => void; @@ -9,11 +8,37 @@ type ControllerMethods = { set_home: (axis: string, value: number) => void; } +interface ControllerMethods extends RegisterableControllerMethods { + gotoZero: (axes: "xy" | "z") => void; +} + export let ControllerMethods: ControllerMethods; -export function registerControllerMethods(methods: Partial) { +export function registerControllerMethods(methods: Partial) { ControllerMethods = { ...ControllerMethods, - ...methods + ...methods, + gotoZero }; } + +function gotoZero(axes: "xy" | "z") { + let axesClause = ""; + switch (axes.toLowerCase()) { + case "xy": + axesClause = "X0Y0"; + break; + + case "z": + axesClause = "Z0"; + break; + + default: + throw new Error(`Invalid axes: ${axes}`); + } + + ControllerMethods.send(` + G90 + G0 ${axesClause} + `); +} \ No newline at end of file From dded59535fc58443caa6ec923935a004816905fe Mon Sep 17 00:00:00 2001 From: David Carley Date: Tue, 23 Aug 2022 07:42:45 +0000 Subject: [PATCH 15/17] Completed changes for the "Move to zero" dialog --- src/js/control-view.js | 4 ++++ src/svelte-components/src/dialogs/MoveToZeroDialog.svelte | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/js/control-view.js b/src/js/control-view.js index 3eb27ba..60e09b1 100644 --- a/src/js/control-view.js +++ b/src/js/control-view.js @@ -421,6 +421,10 @@ module.exports = { SvelteComponents.showDialog("SetAxisPosition", { axis }); }, + showMoveToZeroDialog: function (axes) { + SvelteComponents.showDialog("MoveToZero", { axes }); + }, + show_toolpath_msg: function (axis) { this.toolpath_msg[axis] = true; }, diff --git a/src/svelte-components/src/dialogs/MoveToZeroDialog.svelte b/src/svelte-components/src/dialogs/MoveToZeroDialog.svelte index 321d6be..29079fe 100644 --- a/src/svelte-components/src/dialogs/MoveToZeroDialog.svelte +++ b/src/svelte-components/src/dialogs/MoveToZeroDialog.svelte @@ -14,7 +14,7 @@ aria-describedby="move-to-zero-dialog-content" > - Move to ${(axes || "").toUpperCase()} origin? + Move to {(axes || "").toUpperCase()} origin? From ff7e99acf86731c0761252225b0f132ef0114c4c Mon Sep 17 00:00:00 2001 From: David Carley Date: Tue, 23 Aug 2022 09:11:57 +0000 Subject: [PATCH 16/17] Rebuild the "toolpath message" dialog in Svelte. --- src/js/control-view.js | 12 ++-------- src/pug/templates/control-view.pug | 14 ++---------- .../src/dialogs/DialogHost.svelte | 17 ++++++++++++++ .../src/dialogs/ToolpathMessageDialog.svelte | 22 +++++++++++++++++++ 4 files changed, 43 insertions(+), 22 deletions(-) create mode 100644 src/svelte-components/src/dialogs/ToolpathMessageDialog.svelte diff --git a/src/js/control-view.js b/src/js/control-view.js index 60e09b1..abf61e1 100644 --- a/src/js/control-view.js +++ b/src/js/control-view.js @@ -39,14 +39,6 @@ module.exports = { jog_adjust: parseInt(cookie.get('jog-adjust', 2)), deleteGCode: false, tab: 'auto', - toolpath_msg: { - x: false, - y: false, - z: false, - a: false, - b: false, - c: false - }, ask_home: true, showGcodeMessage: false } @@ -425,8 +417,8 @@ module.exports = { SvelteComponents.showDialog("MoveToZero", { axes }); }, - show_toolpath_msg: function (axis) { - this.toolpath_msg[axis] = true; + showToolpathMessageDialog: function (axis) { + SvelteComponents.showDialog("ToolpathMessage", { msg: this[axis].toolmsg }); }, set_position: function (axis, position) { diff --git a/src/pug/templates/control-view.pug b/src/pug/templates/control-view.pug index 6ca4ec7..6f5887d 100644 --- a/src/pug/templates/control-view.pug +++ b/src/pug/templates/control-view.pug @@ -107,20 +107,10 @@ script#control-view-template(type="text/x-template") td.state .fa(:class=`'fa-' + ${axis}.icon`) | {{#{axis}.state}} - td.tstate(:class=`${axis}.tklass`, :title=`${axis}.toolmsg`, @click=`show_toolpath_msg('${axis}')`) + td.tstate(:class=`${axis}.tklass`, :title=`${axis}.toolmsg`, @click=`showToolpathMessageDialog('${axis}')`) .fa(:class=`'fa-' + ${axis}.ticon`) | {{#{axis}.tstate}} - - message(:show.sync=`toolpath_msg['${axis}']`) - h3(slot="header") Tool path info {{'#{axis}' | upper}} axis - - div(slot="body") - p {{#{axis}.toolmsg}} - - div(slot="footer") - button.pure-button(@click=`toolpath_msg['${axis}'] = false`) - | OK - + th.actions button.pure-button(:disabled="!can_set_axis", title=`Set {{'${axis}' | upper}} axis position.`, diff --git a/src/svelte-components/src/dialogs/DialogHost.svelte b/src/svelte-components/src/dialogs/DialogHost.svelte index 377c5e2..b8275d3 100644 --- a/src/svelte-components/src/dialogs/DialogHost.svelte +++ b/src/svelte-components/src/dialogs/DialogHost.svelte @@ -9,6 +9,7 @@ import SetAxisPositionDialog from "./SetAxisPositionDialog.svelte"; import MoveToZeroDialog from "./MoveToZeroDialog.svelte"; import ShutdownDialog from "./ShutdownDialog.svelte"; + import ToolpathMessageDialog from "./ToolpathMessageDialog.svelte"; const HomeMachineDialogProps = writable(); type HomeMachineDialogPropsType = { @@ -62,6 +63,12 @@ open: boolean; }; + const ToolpathMessageDialogProps = writable(); + type ToolpathMessageDialogPropsType = { + open: boolean; + msg: string; + }; + export function showDialog( dialog: "HomeMachine", props: Omit @@ -107,6 +114,11 @@ props: Omit ); + export function showDialog( + dialog: "ToolpathMessage", + props: Omit + ); + export function showDialog(dialog: string, props: any) { switch (dialog) { case "HomeMachine": @@ -145,6 +157,10 @@ ShutdownDialogProps.set({ ...props, open: true }); break; + case "ToolpathMessage": + ToolpathMessageDialogProps.set({ ...props, open: true }); + break; + default: throw new Error(`Unknown dialog '${dialog}'`); } @@ -220,3 +236,4 @@ + diff --git a/src/svelte-components/src/dialogs/ToolpathMessageDialog.svelte b/src/svelte-components/src/dialogs/ToolpathMessageDialog.svelte new file mode 100644 index 0000000..6304698 --- /dev/null +++ b/src/svelte-components/src/dialogs/ToolpathMessageDialog.svelte @@ -0,0 +1,22 @@ + + + + {msg || ""} + + + + + From 7a20b49aeb32a269d4bb8b587630d890a45dfc0c Mon Sep 17 00:00:00 2001 From: David Carley Date: Tue, 23 Aug 2022 13:09:58 +0000 Subject: [PATCH 17/17] Rebuilt a couple more dialog boxes in Svelte. --- src/js/admin-general-view.js | 32 +++++++++---------- src/js/control-view.js | 2 +- src/pug/templates/admin-general-view.pug | 7 ---- .../src/dialogs/ChangeHostnameDialog.svelte | 2 +- .../src/dialogs/DialogHost.svelte | 20 ++++++------ .../src/dialogs/MessageDialog.svelte | 18 +++++++++-- .../src/dialogs/ScreenRotationDialog.svelte | 2 +- .../src/dialogs/ToolpathMessageDialog.svelte | 22 ------------- .../src/dialogs/WifiConnectionDialog.svelte | 9 +++--- 9 files changed, 50 insertions(+), 64 deletions(-) delete mode 100644 src/svelte-components/src/dialogs/ToolpathMessageDialog.svelte diff --git a/src/js/admin-general-view.js b/src/js/admin-general-view.js index 795bd1b..02aac51 100644 --- a/src/js/admin-general-view.js +++ b/src/js/admin-general-view.js @@ -46,9 +46,7 @@ module.exports = { data: function () { return { - configRestored: false, confirmReset: false, - configReset: false, autoCheckUpgrade: true, reset_variant: '' } @@ -71,29 +69,31 @@ module.exports = { }, restore: function (e) { - var files = e.target.files || e.dataTransfer.files; - if (!files.length) return; + const files = e.target.files || e.dataTransfer.files; + if (!files.length) { + return; + } - var fr = new FileReader(); - fr.onload = function (e) { - var config; + const fileReader = new FileReader(); + fileReader.onload = async ({ target }) => { + let config; try { - config = JSON.parse(e.target.result); + config = JSON.parse(target.result); } catch (ex) { api.alert("Invalid config file"); return; } - api.put('config/save', config).done(function (data) { + try { + await api.put('config/save', config); this.$dispatch('update'); - this.configRestored = true; - - }.bind(this)).fail(function (error) { + SvelteComponents.showDialog("Message", { title: "Success", message: "Configuration restored" }) + } catch (error) { api.alert('Restore failed', error); - }) - }.bind(this); + } + } - fr.readAsText(files[0]); + fileReader.readAsText(files[0]); }, reset: async function () { @@ -107,7 +107,7 @@ module.exports = { await api.put('config/save', config) this.confirmReset = false; this.$dispatch('update'); - this.configRestored = true; + SvelteComponents.showDialog("Message", { title: "Success", message: "Configuration restored" }) } catch (err) { api.alert('Restore failed'); console.error('Restore failed', err); diff --git a/src/js/control-view.js b/src/js/control-view.js index abf61e1..57f60ac 100644 --- a/src/js/control-view.js +++ b/src/js/control-view.js @@ -418,7 +418,7 @@ module.exports = { }, showToolpathMessageDialog: function (axis) { - SvelteComponents.showDialog("ToolpathMessage", { msg: this[axis].toolmsg }); + SvelteComponents.showDialog("Message", { title: this[axis].toolmsg }); }, set_position: function (axis, position) { diff --git a/src/pug/templates/admin-general-view.pug b/src/pug/templates/admin-general-view.pug index d90a20c..8eb358a 100644 --- a/src/pug/templates/admin-general-view.pug +++ b/src/pug/templates/admin-general-view.pug @@ -45,9 +45,6 @@ script#admin-general-view-template(type="text/x-template") label.pure-button.pure-button-primary(@click="restore_config") Restore form.restore-config.file-upload input(type="file", accept=".json", @change="restore") - message(:show.sync="configRestored") - h3(slot="header") Success - p(slot="body") Configuration restored. button.pure-button.pure-button-primary(@click="confirmReset = true") Reset message(:show.sync="confirmReset") @@ -70,10 +67,6 @@ script#admin-general-view-template(type="text/x-template") button.pure-button(@click="confirmReset = false") Cancel button.pure-button.pure-button-primary(@click="reset") Reset - message(:show.sync="configReset") - h3(slot="header") Success - p(slot="body") Configuration reset. - h2 Debugging a(href="/api/log", target="_blank") button.pure-button.pure-button-primary View Log diff --git a/src/svelte-components/src/dialogs/ChangeHostnameDialog.svelte b/src/svelte-components/src/dialogs/ChangeHostnameDialog.svelte index c04a40c..1cc79cb 100644 --- a/src/svelte-components/src/dialogs/ChangeHostnameDialog.svelte +++ b/src/svelte-components/src/dialogs/ChangeHostnameDialog.svelte @@ -58,7 +58,7 @@ } - + Rebooting to apply the hostname change... diff --git a/src/svelte-components/src/dialogs/DialogHost.svelte b/src/svelte-components/src/dialogs/DialogHost.svelte index b8275d3..0dadf2f 100644 --- a/src/svelte-components/src/dialogs/DialogHost.svelte +++ b/src/svelte-components/src/dialogs/DialogHost.svelte @@ -9,7 +9,7 @@ import SetAxisPositionDialog from "./SetAxisPositionDialog.svelte"; import MoveToZeroDialog from "./MoveToZeroDialog.svelte"; import ShutdownDialog from "./ShutdownDialog.svelte"; - import ToolpathMessageDialog from "./ToolpathMessageDialog.svelte"; + import MessageDialog from "./MessageDialog.svelte"; const HomeMachineDialogProps = writable(); type HomeMachineDialogPropsType = { @@ -63,10 +63,12 @@ open: boolean; }; - const ToolpathMessageDialogProps = writable(); - type ToolpathMessageDialogPropsType = { + const MessageDialogProps = writable(); + type MessageDialogPropsType = { open: boolean; - msg: string; + title: string; + message: string; + noaction: boolean; }; export function showDialog( @@ -115,8 +117,8 @@ ); export function showDialog( - dialog: "ToolpathMessage", - props: Omit + dialog: "Message", + props: Omit ); export function showDialog(dialog: string, props: any) { @@ -157,8 +159,8 @@ ShutdownDialogProps.set({ ...props, open: true }); break; - case "ToolpathMessage": - ToolpathMessageDialogProps.set({ ...props, open: true }); + case "Message": + MessageDialogProps.set({ ...props, open: true }); break; default: @@ -236,4 +238,4 @@ - + diff --git a/src/svelte-components/src/dialogs/MessageDialog.svelte b/src/svelte-components/src/dialogs/MessageDialog.svelte index 0cf3ea1..735341c 100644 --- a/src/svelte-components/src/dialogs/MessageDialog.svelte +++ b/src/svelte-components/src/dialogs/MessageDialog.svelte @@ -1,8 +1,11 @@ {title} + - + {message} + + {#if !noaction} + + + + {/if} diff --git a/src/svelte-components/src/dialogs/ScreenRotationDialog.svelte b/src/svelte-components/src/dialogs/ScreenRotationDialog.svelte index 4f02231..7cb7415 100644 --- a/src/svelte-components/src/dialogs/ScreenRotationDialog.svelte +++ b/src/svelte-components/src/dialogs/ScreenRotationDialog.svelte @@ -29,7 +29,7 @@ } - + Rebooting to apply the new screen rotation... diff --git a/src/svelte-components/src/dialogs/ToolpathMessageDialog.svelte b/src/svelte-components/src/dialogs/ToolpathMessageDialog.svelte deleted file mode 100644 index 6304698..0000000 --- a/src/svelte-components/src/dialogs/ToolpathMessageDialog.svelte +++ /dev/null @@ -1,22 +0,0 @@ - - - - {msg || ""} - - - - - diff --git a/src/svelte-components/src/dialogs/WifiConnectionDialog.svelte b/src/svelte-components/src/dialogs/WifiConnectionDialog.svelte index 644c1e5..0c167c1 100644 --- a/src/svelte-components/src/dialogs/WifiConnectionDialog.svelte +++ b/src/svelte-components/src/dialogs/WifiConnectionDialog.svelte @@ -39,7 +39,7 @@ } - + Rebooting to apply Wifi changes... @@ -49,9 +49,10 @@ aria-labelledby="wifi-connection-dialog-title" aria-describedby="wifi-connection-dialog-content" > - {connectToOrDisconnectFrom} {network.Name} + + {connectToOrDisconnectFrom} + {network.Name} + {#if needPassword}