From a271360d1cfede45cf7b74033bdff36975d91015 Mon Sep 17 00:00:00 2001 From: sanjayk03-dev Date: Thu, 5 Dec 2024 16:07:17 +0530 Subject: [PATCH] fixing edgecase --- src/js/app.js | 6 +++--- src/py/bbctrl/Web.py | 7 ++++++- src/svelte-components/src/dialogs/DialogHost.svelte | 2 +- .../src/dialogs/SwitchRotaryDialog.svelte | 4 ++-- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/js/app.js b/src/js/app.js index 5700078..04d6cc8 100644 --- a/src/js/app.js +++ b/src/js/app.js @@ -324,13 +324,13 @@ module.exports = new Vue({ showSwitchRotaryModeDialog: function(){ SvelteComponents.showDialog("SwitchRotary", { isActive: !this.is_rotary_active, - switchMode: () => this.toggle_rotary() + switchMode: (isActive) => this.toggle_rotary(isActive) }); }, - toggle_rotary: async function() { + toggle_rotary: async function(isActive) { try { - await api.put("rotary"); + await api.put("rotary", {status: isActive}); } catch (error) { console.error(error); alert("Error occured"); diff --git a/src/py/bbctrl/Web.py b/src/py/bbctrl/Web.py index 7f36403..7b8e762 100644 --- a/src/py/bbctrl/Web.py +++ b/src/py/bbctrl/Web.py @@ -607,10 +607,13 @@ class RotaryHandler(bbctrl.APIHandler): def put_ok(self): try: + status = self.json.get('status', None) ctrl = self.get_ctrl() - state = ctrl.state config = ctrl.config path = ctrl.get_path('config.json') + + if status is None: + raise Exception("No status provided") try: if os.path.exists(path): @@ -631,6 +634,8 @@ class RotaryHandler(bbctrl.APIHandler): is_axis_A = motor_2.get("axis") == "A" + if is_axis_A == status: return + motor_2["axis"] = "Y" if is_axis_A else "A" motor_1["max-velocity"] *= 2 if is_axis_A else 0.5 diff --git a/src/svelte-components/src/dialogs/DialogHost.svelte b/src/svelte-components/src/dialogs/DialogHost.svelte index 405586b..f0bf798 100644 --- a/src/svelte-components/src/dialogs/DialogHost.svelte +++ b/src/svelte-components/src/dialogs/DialogHost.svelte @@ -77,7 +77,7 @@ type SwitchRotaryDialogPropsType = { open: boolean; isActive: boolean; - switchMode: () => void; + switchMode: (mode: boolean) => void; }; export function showDialog( diff --git a/src/svelte-components/src/dialogs/SwitchRotaryDialog.svelte b/src/svelte-components/src/dialogs/SwitchRotaryDialog.svelte index fdbf4be..093365d 100644 --- a/src/svelte-components/src/dialogs/SwitchRotaryDialog.svelte +++ b/src/svelte-components/src/dialogs/SwitchRotaryDialog.svelte @@ -9,7 +9,7 @@ export let open: boolean; export let isActive: boolean; - export let switchMode: () => any; + export let switchMode: (mode: boolean) => any; No -