From f0bb9079d41f3f3df44d56b4b5117f9ae9da79fd Mon Sep 17 00:00:00 2001 From: David Carley Date: Sat, 16 Jul 2022 19:02:38 -0700 Subject: [PATCH 01/12] Screen rotation dialog --- package-lock.json | 4 +- package.json | 2 +- src/js/settings-view.js | 6 ++ src/pug/templates/settings-view.pug | 10 +-- src/py/bbctrl/Web.py | 42 ++++++++++ .../src/dialogs/ChangeHostnameDialog.svelte | 2 +- .../src/dialogs/DialogHost.svelte | 42 +++++++--- .../src/dialogs/DialogProps.ts | 13 ---- .../src/dialogs/ScreenRotationDialog.svelte | 76 +++++++++++++++++++ .../src/dialogs/WifiConnectionDialog.svelte | 2 +- 10 files changed, 163 insertions(+), 36 deletions(-) delete mode 100644 src/svelte-components/src/dialogs/DialogProps.ts create mode 100644 src/svelte-components/src/dialogs/ScreenRotationDialog.svelte diff --git a/package-lock.json b/package-lock.json index 8b6a115..3dd092c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "bbctrl", - "version": "1.0.10b2", + "version": "1.0.10b4", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "bbctrl", - "version": "1.0.10b2", + "version": "1.0.10b4", "license": "GPL-3.0+", "dependencies": { "browserify": "^17.0.0", diff --git a/package.json b/package.json index e7e8200..0610ea7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bbctrl", - "version": "1.0.10b2", + "version": "1.0.10b4", "homepage": "https://onefinitycnc.com/", "repository": "https://github.com/OneFinityCNC/onefinity", "license": "GPL-3.0+", diff --git a/src/js/settings-view.js b/src/js/settings-view.js index 2df783c..6d26b98 100644 --- a/src/js/settings-view.js +++ b/src/js/settings-view.js @@ -21,5 +21,11 @@ module.exports = { this.$dispatch('config-changed'); return false; } + }, + + methods: { + showScreenRotationDialog: function () { + SvelteComponents.showDialog("ScreenRotation"); + } } } diff --git a/src/pug/templates/settings-view.pug b/src/pug/templates/settings-view.pug index afeaa52..15ec257 100644 --- a/src/pug/templates/settings-view.pug +++ b/src/pug/templates/settings-view.pug @@ -4,16 +4,14 @@ script#settings-view-template(type="text/x-template") .pure-form.pure-form-aligned fieldset - h2 Units + h2 Screen .pure-control-group - label(for="units") units - select(name="units", v-model="display_units") - option(value="METRIC") METRIC - option(value="IMPERIAL") IMPERIAL + label(for="screen-rotation") + button.pure-button(name="screen-rotation", @click="showScreenRotationDialog") Change Screen Rotation fieldset h2 Probe Dimensions - templated-input(v-for="templ in template.probe", :name="$key", + templated-input(v-for="templ in template.probe", v-if="$key !== 'probe-diameter'", :name="$key" :model.sync="config.probe[$key]", :template="templ") fieldset diff --git a/src/py/bbctrl/Web.py b/src/py/bbctrl/Web.py index 1a96146..15892c8 100644 --- a/src/py/bbctrl/Web.py +++ b/src/py/bbctrl/Web.py @@ -1,4 +1,5 @@ import os +import re import json import tornado import sockjs.tornado @@ -349,6 +350,46 @@ class JogHandler(bbctrl.APIHandler): self.get_ctrl().mach.jog(self.json) +displayRotatePattern = re.compile(r'display_rotate\s*=\s*(\d)') +transformationMatrixPattern = re.compile( + r'(\n)(\s+)(MatchIsTouchscreen.*?\n)(\s+Option\s+\"TransformationMatrix\".*?\n)(.*?EndSection)', re.DOTALL) +matchIsTouchscreenPattern = re.compile( + r'(\n)(\s+)(MatchIsTouchscreen.*?\n)(.*?EndSection)', re.DOTALL) + + +class ScreenRotationHandler(bbctrl.APIHandler): + @gen.coroutine + def get(self): + with open("/boot/config.txt", 'rt') as config: + lines = config.readlines() + for line in lines: + if line.startswith('display_rotate'): + self.write_json({ + 'rotated': int(displayRotatePattern.search(line).group(1)) != 0 + }) + return + + self.write_json({'rotated': False}) + return + + @gen.coroutine + def put_ok(self): + rotated = self.json['rotated'] + + subprocess.Popen( + ['/usr/local/bin/edit-boot-config', 'display_rotate={}'.format(2 if rotated else 0)]) + + with open("/usr/share/X11/xorg.conf.d/40-libinput.conf", 'rt') as config: + text = config.read() + text = transformationMatrixPattern.sub(r'\1\2\3\5', text) + if rotated: + text = matchIsTouchscreenPattern.sub(r'\1\2\3\2Option "TransformationMatrix" "-1 0 1 0 -1 1 0 0 1"\1\4', text) + with open("/usr/share/X11/xorg.conf.d/40-libinput.conf", 'wt') as config: + config.write(text) + + subprocess.run('reboot') + + # Base class for Web Socket connections class ClientConnection(object): def __init__(self, app): @@ -484,6 +525,7 @@ class Web(tornado.web.Application): (r'/api/modbus/write', ModbusWriteHandler), (r'/api/jog', JogHandler), (r'/api/video', bbctrl.VideoHandler), + (r'/api/screen-rotation', ScreenRotationHandler), (r'/(.*)', StaticFileHandler, {'path': bbctrl.get_resource('http/'), 'default_filename': 'index.html'}), diff --git a/src/svelte-components/src/dialogs/ChangeHostnameDialog.svelte b/src/svelte-components/src/dialogs/ChangeHostnameDialog.svelte index de8930b..77e472e 100644 --- a/src/svelte-components/src/dialogs/ChangeHostnameDialog.svelte +++ b/src/svelte-components/src/dialogs/ChangeHostnameDialog.svelte @@ -88,7 +88,7 @@ diff --git a/src/svelte-components/src/dialogs/DialogHost.svelte b/src/svelte-components/src/dialogs/DialogHost.svelte index c6319dd..1a03f68 100644 --- a/src/svelte-components/src/dialogs/DialogHost.svelte +++ b/src/svelte-components/src/dialogs/DialogHost.svelte @@ -1,31 +1,48 @@ - - + + + diff --git a/src/svelte-components/src/dialogs/DialogProps.ts b/src/svelte-components/src/dialogs/DialogProps.ts deleted file mode 100644 index 338c722..0000000 --- a/src/svelte-components/src/dialogs/DialogProps.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { writable } from "svelte/store"; - -export const HomeMachineProps = writable(); -export type HomeMachinePropsType = { - open: boolean, - home: () => void -} - -export const ProbeProps = writable(); -export type ProbePropsType = { - open: boolean, - probeType: "xyz" | "z" -}; diff --git a/src/svelte-components/src/dialogs/ScreenRotationDialog.svelte b/src/svelte-components/src/dialogs/ScreenRotationDialog.svelte new file mode 100644 index 0000000..0fd78a0 --- /dev/null +++ b/src/svelte-components/src/dialogs/ScreenRotationDialog.svelte @@ -0,0 +1,76 @@ + + + + Rebooting to apply the new screen rotation... + + + + Screen Rotation + + + {#each options as option} + + + + {option.label} + + + {/each} + + + + + + + + + diff --git a/src/svelte-components/src/dialogs/WifiConnectionDialog.svelte b/src/svelte-components/src/dialogs/WifiConnectionDialog.svelte index b213330..447783a 100644 --- a/src/svelte-components/src/dialogs/WifiConnectionDialog.svelte +++ b/src/svelte-components/src/dialogs/WifiConnectionDialog.svelte @@ -92,7 +92,7 @@ on:click={onConfirm} disabled={needPassword && (password.length < 8 || password.length > 128)} > - + From f34e1413b764dc62d24d2054079b711ca21adbad Mon Sep 17 00:00:00 2001 From: David Carley Date: Sat, 16 Jul 2022 19:07:28 -0700 Subject: [PATCH 02/12] Brought back the metric and imperial state variables. --- src/py/bbctrl/Ctrl.py | 1 + src/py/bbctrl/State.py | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/src/py/bbctrl/Ctrl.py b/src/py/bbctrl/Ctrl.py index fae382c..f66f39d 100644 --- a/src/py/bbctrl/Ctrl.py +++ b/src/py/bbctrl/Ctrl.py @@ -71,6 +71,7 @@ class Ctrl(object): def configure(self): # Indirectly configures state via calls to config() and the AVR self.config.reload() + self.state.init() def ready(self): # This is used to synchronize the start of the preplanner diff --git a/src/py/bbctrl/State.py b/src/py/bbctrl/State.py index 61b163b..d60de7b 100644 --- a/src/py/bbctrl/State.py +++ b/src/py/bbctrl/State.py @@ -419,3 +419,12 @@ class State(object): if switch[1:] == '-max': return self.get_axis_switch(switch[0], 'max') raise Exception('Unsupported switch "%s"' % switch) + + def init(self): + # Init machine units + metric = self.ctrl.config.get('units', 'METRIC').upper() == 'METRIC' + self.log.info('INIT Metric %d' % metric) + if not 'metric' in self.vars: + self.set('metric', metric) + if not 'imperial' in self.vars: + self.set('imperial', not metric) From 8a904da3f69e1cf5226b81df433e42e86dfec90a Mon Sep 17 00:00:00 2001 From: David Carley Date: Sat, 16 Jul 2022 19:09:16 -0700 Subject: [PATCH 03/12] Fixed wifi display when quality = 0 --- src/svelte-components/src/components/AdminNetworkView.svelte | 1 + 1 file changed, 1 insertion(+) diff --git a/src/svelte-components/src/components/AdminNetworkView.svelte b/src/svelte-components/src/components/AdminNetworkView.svelte index 8efe39e..453c59e 100644 --- a/src/svelte-components/src/components/AdminNetworkView.svelte +++ b/src/svelte-components/src/components/AdminNetworkView.svelte @@ -19,6 +19,7 @@ const strength = Math.ceil((Number(network.Quality) / 100) * 4); switch (strength) { + case 0: case 1: return ""; From 9fa83d30c09db5a0acd3c7c32e877ed468400fb4 Mon Sep 17 00:00:00 2001 From: David Carley Date: Sat, 16 Jul 2022 19:12:56 -0700 Subject: [PATCH 04/12] When in devmode, clip to 1280x720 --- src/svelte-components/src/components/Devmode.svelte | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/svelte-components/src/components/Devmode.svelte b/src/svelte-components/src/components/Devmode.svelte index 43adbd5..36cdb51 100644 --- a/src/svelte-components/src/components/Devmode.svelte +++ b/src/svelte-components/src/components/Devmode.svelte @@ -1,5 +1,15 @@
From f6e17c656fe50e807e60fad52e126442f1f48de7 Mon Sep 17 00:00:00 2001 From: David Carley Date: Sat, 16 Jul 2022 19:18:58 -0700 Subject: [PATCH 05/12] Fixed dimension labels in the probe dialog --- .../src/components/DimensionInput.svelte | 28 +++++++++---------- .../src/dialogs/ProbeDialog.svelte | 28 +++++++++---------- 2 files changed, 27 insertions(+), 29 deletions(-) diff --git a/src/svelte-components/src/components/DimensionInput.svelte b/src/svelte-components/src/components/DimensionInput.svelte index e700e73..bec8141 100644 --- a/src/svelte-components/src/components/DimensionInput.svelte +++ b/src/svelte-components/src/components/DimensionInput.svelte @@ -11,6 +11,7 @@ type Option = { value: number; + label: string; metric: boolean; }; @@ -65,10 +66,7 @@ {#each options as option} onOptionSelected(option)}> - - {option.value} - {option.metric ? "mm" : "in"} - + {option.label} {/each} @@ -76,18 +74,18 @@
+ \ No newline at end of file diff --git a/src/svelte-components/src/dialogs/ProbeDialog.svelte b/src/svelte-components/src/dialogs/ProbeDialog.svelte index 618bcd2..74de934 100644 --- a/src/svelte-components/src/dialogs/ProbeDialog.svelte +++ b/src/svelte-components/src/dialogs/ProbeDialog.svelte @@ -63,21 +63,21 @@ import { Config } from "$lib/ConfigStore"; const cutterDiameterOptions = [ - { value: 0.5, metric: false }, - { value: 10, metric: true }, - { value: 0.25, metric: false }, - { value: 6, metric: true }, - { value: 0.125, metric: false }, - { value: 3, metric: true }, + { value: 0.5, label: '1/2 "', metric: false }, + { value: 0.25, label: '1/4 "', metric: false }, + { value: 0.125, label: '1/8 "', metric: false }, + { value: 10, label: "10 mm", metric: true }, + { value: 6, label: "6 mm", metric: true }, + { value: 3, label: "10 mm", metric: true }, ]; const cutterLengthOptions = [ - { value: 1, metric: false }, - { value: 20, metric: true }, - { value: 0.5, metric: false }, - { value: 10, metric: true }, - { value: 0.25, metric: false }, - { value: 6, metric: true }, + { value: 1, label: '1 "', metric: false }, + { value: 0.5, label: '1/2 "', metric: false }, + { value: 0.25, label: '1/4 "', metric: false }, + { value: 20, label: "20 mm", metric: true }, + { value: 10, label: "10 mm", metric: true }, + { value: 6, label: "6 mm", metric: true }, ]; export let open; @@ -132,8 +132,8 @@ if (probeType === "xyz") { await stepCompleted("BitDimensions", userAcknowledged); - localStorage.setItem("cutterDiameter", cutterDiameter); - localStorage.setItem("cutterLength", cutterLength); + localStorage.setItem("cutterDiameter", cutterDiameter.toString()); + localStorage.setItem("cutterLength", cutterLength.toString()); } await stepCompleted("PlaceProbeBlock", userAcknowledged); From 735064ca5e3698e864bb41db97b20642dbe40e4e Mon Sep 17 00:00:00 2001 From: David Carley Date: Sat, 16 Jul 2022 19:36:52 -0700 Subject: [PATCH 06/12] Fixed some ui alignment issues. --- .../src/dialogs/ChangeHostnameDialog.svelte | 8 ++++---- .../src/dialogs/HomeMachineDialog.svelte | 8 ++++---- src/svelte-components/src/dialogs/MessageDialog.svelte | 8 ++++---- src/svelte-components/src/dialogs/ProbeDialog.svelte | 10 +++++----- .../src/dialogs/ScreenRotationDialog.svelte | 10 +++++----- .../src/dialogs/WifiConnectionDialog.svelte | 8 ++++---- 6 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/svelte-components/src/dialogs/ChangeHostnameDialog.svelte b/src/svelte-components/src/dialogs/ChangeHostnameDialog.svelte index 77e472e..51bbdde 100644 --- a/src/svelte-components/src/dialogs/ChangeHostnameDialog.svelte +++ b/src/svelte-components/src/dialogs/ChangeHostnameDialog.svelte @@ -64,12 +64,12 @@ - Change Hostname + Change Hostname - + - Home Machine + Home Machine - Home the machine? + Home the machine? diff --git a/src/svelte-components/src/dialogs/ProbeDialog.svelte b/src/svelte-components/src/dialogs/ProbeDialog.svelte index 74de934..3a36ac2 100644 --- a/src/svelte-components/src/dialogs/ProbeDialog.svelte +++ b/src/svelte-components/src/dialogs/ProbeDialog.svelte @@ -310,13 +310,13 @@ bind:open class="probe-dialog" scrimClickAction="" - aria-labelledby="simple-title" - aria-describedby="simple-content" + aria-labelledby="probe-dialog-title" + aria-describedby="probe-dialog-content" surface$style="width: 700px; height: 400px; max-width: calc(100vw - 32px); overflow: visible;" > - Probing {probeType?.toUpperCase()} + Probing {probeType?.toUpperCase()} - +

Step {steps.indexOf(currentStep) + 1} of {steps.length}

    @@ -402,7 +402,7 @@ $light: #ddd; :global { - .mdc-dialog__content { + #probe-dialog-content { display: flex; flex-direction: row; } diff --git a/src/svelte-components/src/dialogs/ScreenRotationDialog.svelte b/src/svelte-components/src/dialogs/ScreenRotationDialog.svelte index 0fd78a0..4f02231 100644 --- a/src/svelte-components/src/dialogs/ScreenRotationDialog.svelte +++ b/src/svelte-components/src/dialogs/ScreenRotationDialog.svelte @@ -36,12 +36,12 @@ - Screen Rotation + Screen Rotation - + {#each options as option} @@ -68,7 +68,7 @@