fixing edgecase

This commit is contained in:
sanjayk03-dev
2024-12-05 16:07:17 +05:30
parent 5682f25d2b
commit a271360d1c
4 changed files with 12 additions and 7 deletions

View File

@@ -324,13 +324,13 @@ module.exports = new Vue({
showSwitchRotaryModeDialog: function(){ showSwitchRotaryModeDialog: function(){
SvelteComponents.showDialog("SwitchRotary", { SvelteComponents.showDialog("SwitchRotary", {
isActive: !this.is_rotary_active, 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 { try {
await api.put("rotary"); await api.put("rotary", {status: isActive});
} catch (error) { } catch (error) {
console.error(error); console.error(error);
alert("Error occured"); alert("Error occured");

View File

@@ -607,11 +607,14 @@ class RotaryHandler(bbctrl.APIHandler):
def put_ok(self): def put_ok(self):
try: try:
status = self.json.get('status', None)
ctrl = self.get_ctrl() ctrl = self.get_ctrl()
state = ctrl.state
config = ctrl.config config = ctrl.config
path = ctrl.get_path('config.json') path = ctrl.get_path('config.json')
if status is None:
raise Exception("No status provided")
try: try:
if os.path.exists(path): if os.path.exists(path):
with open(path, 'r') as f: config_data = json.load(f) with open(path, 'r') as f: config_data = json.load(f)
@@ -631,6 +634,8 @@ class RotaryHandler(bbctrl.APIHandler):
is_axis_A = motor_2.get("axis") == "A" 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_2["axis"] = "Y" if is_axis_A else "A"
motor_1["max-velocity"] *= 2 if is_axis_A else 0.5 motor_1["max-velocity"] *= 2 if is_axis_A else 0.5

View File

@@ -77,7 +77,7 @@
type SwitchRotaryDialogPropsType = { type SwitchRotaryDialogPropsType = {
open: boolean; open: boolean;
isActive: boolean; isActive: boolean;
switchMode: () => void; switchMode: (mode: boolean) => void;
}; };
export function showDialog( export function showDialog(

View File

@@ -9,7 +9,7 @@
export let open: boolean; export let open: boolean;
export let isActive: boolean; export let isActive: boolean;
export let switchMode: () => any; export let switchMode: (mode: boolean) => any;
</script> </script>
<Dialog <Dialog
@@ -29,7 +29,7 @@
<Label>No</Label> <Label>No</Label>
</Button> </Button>
<Button defaultAction use={[InitialFocus]} on:click={switchMode}> <Button defaultAction use={[InitialFocus]} on:click={() =>switchMode(isActive)}>
<Label>Yes</Label> <Label>Yes</Label>
</Button> </Button>
</Actions> </Actions>