Farmbot-Web-App/frontend/devices/components/hardware_settings/motors.tsx

161 lines
6.0 KiB
TypeScript
Raw Normal View History

2017-06-29 12:54:02 -06:00
import * as React from "react";
import { BooleanMCUInputGroup } from "../boolean_mcu_input_group";
2020-02-18 12:21:09 -07:00
import { ToolTips, DeviceSetting } from "../../../constants";
2017-06-29 12:54:02 -06:00
import { ToggleButton } from "../../../controls/toggle_button";
import { settingToggle } from "../../actions";
import { NumericMCUInputGroup } from "../numeric_mcu_input_group";
import { MotorsProps } from "../interfaces";
import { Header } from "./header";
2020-02-15 11:29:09 -07:00
import { Collapse } from "@blueprintjs/core";
2019-04-16 11:01:27 -06:00
import { Xyz, McuParamName } from "farmbot";
import { SourceFwConfig } from "../../interfaces";
import { calcMicrostepsPerMm } from "../../../controls/move/direction_axes_props";
2020-02-15 11:29:09 -07:00
import { isTMCBoard } from "../firmware_hardware_support";
import { SingleSettingRow } from "./single_setting_row";
2020-02-18 12:21:09 -07:00
import { Highlight } from "../maybe_highlight";
2020-02-28 09:50:14 -07:00
import { SpacePanelHeader } from "./space_panel_header";
2018-08-01 19:27:19 -06:00
2019-04-16 11:01:27 -06:00
export const calculateScale =
(sourceFwConfig: SourceFwConfig): Record<Xyz, number | undefined> => {
2020-02-28 09:34:28 -07:00
const getV = (key: McuParamName) => sourceFwConfig(key).value;
2019-04-16 11:01:27 -06:00
return {
x: calcMicrostepsPerMm(getV("movement_step_per_mm_x"),
getV("movement_microsteps_x")),
y: calcMicrostepsPerMm(getV("movement_step_per_mm_y"),
getV("movement_microsteps_y")),
z: calcMicrostepsPerMm(getV("movement_step_per_mm_z"),
getV("movement_microsteps_z")),
};
};
2018-01-27 02:29:13 -07:00
export function Motors(props: MotorsProps) {
2018-03-09 02:34:24 -07:00
const {
2020-02-07 16:06:40 -07:00
dispatch, controlPanelState, sourceFwConfig, firmwareHardware
2018-03-09 02:34:24 -07:00
} = props;
const enable2ndXMotor = sourceFwConfig("movement_secondary_motor_x");
const invert2ndXMotor = sourceFwConfig("movement_secondary_motor_invert_x");
2019-04-16 11:01:27 -06:00
const scale = calculateScale(sourceFwConfig);
2020-02-15 11:29:09 -07:00
2020-02-18 12:21:09 -07:00
return <Highlight className={"section"}
settingName={DeviceSetting.motors}>
2017-06-29 12:54:02 -06:00
<Header
expanded={controlPanelState.motors}
2020-02-18 12:21:09 -07:00
title={DeviceSetting.motors}
panel={"motors"}
2017-08-23 16:26:09 -06:00
dispatch={dispatch} />
2018-03-09 02:34:24 -07:00
<Collapse isOpen={!!controlPanelState.motors}>
2020-03-13 15:06:40 -06:00
<SpacePanelHeader />
2017-06-29 12:54:02 -06:00
<NumericMCUInputGroup
2020-02-18 12:21:09 -07:00
label={DeviceSetting.maxSpeed}
tooltip={ToolTips.MAX_SPEED}
2017-06-29 12:54:02 -06:00
x={"movement_max_spd_x"}
y={"movement_max_spd_y"}
z={"movement_max_spd_z"}
2019-04-16 11:01:27 -06:00
xScale={scale.x}
yScale={scale.y}
zScale={scale.z}
2018-03-09 02:34:24 -07:00
sourceFwConfig={sourceFwConfig}
2017-08-23 16:26:09 -06:00
dispatch={dispatch} />
2020-02-07 16:06:40 -07:00
<NumericMCUInputGroup
2020-02-18 12:21:09 -07:00
label={DeviceSetting.homingSpeed}
2020-02-07 16:06:40 -07:00
tooltip={ToolTips.HOME_SPEED}
x={"movement_home_spd_x"}
y={"movement_home_spd_y"}
z={"movement_home_spd_z"}
xScale={scale.x}
yScale={scale.y}
zScale={scale.z}
sourceFwConfig={sourceFwConfig}
dispatch={dispatch} />
2017-06-29 12:54:02 -06:00
<NumericMCUInputGroup
2020-02-18 12:21:09 -07:00
label={DeviceSetting.minimumSpeed}
tooltip={ToolTips.MIN_SPEED}
2017-06-29 12:54:02 -06:00
x={"movement_min_spd_x"}
y={"movement_min_spd_y"}
z={"movement_min_spd_z"}
2019-04-16 11:01:27 -06:00
xScale={scale.x}
yScale={scale.y}
zScale={scale.z}
2018-03-09 02:34:24 -07:00
sourceFwConfig={sourceFwConfig}
2017-08-23 16:26:09 -06:00
dispatch={dispatch} />
2017-06-29 12:54:02 -06:00
<NumericMCUInputGroup
2020-02-18 12:21:09 -07:00
label={DeviceSetting.accelerateFor}
tooltip={ToolTips.ACCELERATE_FOR}
2017-06-29 12:54:02 -06:00
x={"movement_steps_acc_dec_x"}
y={"movement_steps_acc_dec_y"}
z={"movement_steps_acc_dec_z"}
2019-04-16 11:01:27 -06:00
xScale={scale.x}
yScale={scale.y}
zScale={scale.z}
2018-03-09 02:34:24 -07:00
sourceFwConfig={sourceFwConfig}
2017-08-23 16:26:09 -06:00
dispatch={dispatch} />
2019-01-28 17:04:42 -07:00
<NumericMCUInputGroup
2020-02-18 12:21:09 -07:00
label={DeviceSetting.stepsPerMm}
2019-01-28 17:04:42 -07:00
tooltip={ToolTips.STEPS_PER_MM}
x={"movement_step_per_mm_x"}
y={"movement_step_per_mm_y"}
z={"movement_step_per_mm_z"}
2019-04-16 11:01:27 -06:00
xScale={sourceFwConfig("movement_microsteps_x").value}
yScale={sourceFwConfig("movement_microsteps_y").value}
zScale={sourceFwConfig("movement_microsteps_z").value}
2019-01-28 17:04:42 -07:00
float={false}
sourceFwConfig={props.sourceFwConfig}
dispatch={props.dispatch} />
2019-04-16 11:01:27 -06:00
<NumericMCUInputGroup
2020-02-18 12:21:09 -07:00
label={DeviceSetting.microstepsPerStep}
2019-04-16 11:01:27 -06:00
tooltip={ToolTips.MICROSTEPS_PER_STEP}
x={"movement_microsteps_x"}
y={"movement_microsteps_y"}
z={"movement_microsteps_z"}
sourceFwConfig={props.sourceFwConfig}
dispatch={props.dispatch} />
2017-06-29 12:54:02 -06:00
<BooleanMCUInputGroup
2020-02-18 12:21:09 -07:00
label={DeviceSetting.alwaysPowerMotors}
tooltip={ToolTips.ALWAYS_POWER_MOTORS}
2017-06-29 12:54:02 -06:00
x={"movement_keep_active_x"}
y={"movement_keep_active_y"}
z={"movement_keep_active_z"}
dispatch={dispatch}
2018-03-09 02:34:24 -07:00
sourceFwConfig={sourceFwConfig} />
2017-06-29 12:54:02 -06:00
<BooleanMCUInputGroup
2020-02-18 12:21:09 -07:00
label={DeviceSetting.invertMotors}
tooltip={ToolTips.INVERT_MOTORS}
2017-06-29 12:54:02 -06:00
x={"movement_invert_motor_x"}
y={"movement_invert_motor_y"}
z={"movement_invert_motor_z"}
dispatch={dispatch}
2018-03-09 02:34:24 -07:00
sourceFwConfig={sourceFwConfig} />
2020-02-07 16:06:40 -07:00
{isTMCBoard(firmwareHardware) &&
2019-06-03 17:41:59 -06:00
<NumericMCUInputGroup
2020-02-18 12:21:09 -07:00
label={DeviceSetting.motorCurrent}
2019-06-03 17:41:59 -06:00
tooltip={ToolTips.MOTOR_CURRENT}
2019-06-03 18:32:09 -06:00
x={"movement_motor_current_x"}
y={"movement_motor_current_y"}
z={"movement_motor_current_z"}
2019-06-03 17:41:59 -06:00
dispatch={dispatch}
sourceFwConfig={sourceFwConfig} />}
2018-08-01 19:27:19 -06:00
<SingleSettingRow settingType="button"
2020-02-18 12:21:09 -07:00
label={DeviceSetting.enable2ndXMotor}
2018-08-01 19:27:19 -06:00
tooltip={ToolTips.ENABLE_X2_MOTOR}>
<ToggleButton
2020-03-13 15:06:40 -06:00
className={"no-float"}
2018-08-01 19:27:19 -06:00
toggleValue={enable2ndXMotor.value}
dim={!enable2ndXMotor.consistent}
toggleAction={() => dispatch(
settingToggle("movement_secondary_motor_x", sourceFwConfig))} />
</SingleSettingRow>
<SingleSettingRow settingType="button"
2020-02-18 12:21:09 -07:00
label={DeviceSetting.invert2ndXMotor}
2018-08-01 19:27:19 -06:00
tooltip={ToolTips.INVERT_MOTORS}>
<ToggleButton
2020-03-13 15:06:40 -06:00
className={"no-float"}
2018-08-01 19:27:19 -06:00
grayscale={!enable2ndXMotor.value}
toggleValue={invert2ndXMotor.value}
dim={!invert2ndXMotor.consistent}
toggleAction={() => dispatch(
settingToggle("movement_secondary_motor_invert_x", sourceFwConfig))} />
</SingleSettingRow>
2017-06-29 12:54:02 -06:00
</Collapse>
2020-02-18 12:21:09 -07:00
</Highlight>;
2017-06-29 12:54:02 -06:00
}