Factor down duplication

pull/692/head
Rick Carlino 2018-03-02 11:15:45 -06:00
parent e21ee8bac8
commit fcc7f214eb
2 changed files with 103 additions and 120 deletions

View File

@ -1,40 +1,29 @@
interface Props {
x_axis_inverted: boolean;
y_axis_inverted: boolean;
z_axis_inverted: boolean;
import { validBotLocationData } from "../util";
import { JogMovementControlsProps } from "./interfaces";
const _ = (nr_steps: number | undefined, steps_mm: number | undefined) => {
return (nr_steps || 0) / (steps_mm || 1);
};
function calculateAxialLengths(props: JogMovementControlsProps) {
const mp = props.bot.hardware.mcu_params;
return {
x: _(mp.movement_axis_nr_steps_x, mp.movement_step_per_mm_x),
y: _(mp.movement_axis_nr_steps_y, mp.movement_step_per_mm_y),
z: _(mp.movement_axis_nr_steps_z, mp.movement_step_per_mm_z),
};
}
interface NumericParams {
movement_axis_nr_steps_x: number;
movement_axis_nr_steps_y: number;
movement_axis_nr_steps_z: number;
movement_step_per_mm_x: number;
movement_step_per_mm_y: number;
movement_step_per_mm_z: number;
}
interface BooleanParams {
movement_home_up_x: boolean;
movement_home_up_y: boolean;
movement_home_up_z: boolean;
movement_stop_at_home_x: boolean;
movement_stop_at_home_y: boolean;
movement_stop_at_home_z: boolean;
movement_stop_at_max_x: boolean;
movement_stop_at_max_y: boolean;
movement_stop_at_max_z: boolean;
}
type McuParams = BooleanParams & NumericParams;
export const wow = (props: Props, mcu_params: McuParams, botLocationData: ) => {
const directionAxesProps = {
export function buildDirectionProps(props: JogMovementControlsProps) {
const { location_data, mcu_params } = props.bot.hardware;
const botLocationData = validBotLocationData(location_data);
const lengths = calculateAxialLengths(props);
return {
x: {
isInverted: props.x_axis_inverted,
stopAtHome: !!mcu_params.movement_stop_at_home_x,
stopAtMax: !!mcu_params.movement_stop_at_max_x,
axisLength: (mcu_params.movement_axis_nr_steps_x || 0)
/ (mcu_params.movement_step_per_mm_x || 1),
axisLength: lengths.x,
negativeOnly: !!mcu_params.movement_home_up_x,
position: botLocationData.position.x
},
@ -42,8 +31,7 @@ export const wow = (props: Props, mcu_params: McuParams, botLocationData: ) => {
isInverted: props.y_axis_inverted,
stopAtHome: !!mcu_params.movement_stop_at_home_y,
stopAtMax: !!mcu_params.movement_stop_at_max_y,
axisLength: (mcu_params.movement_axis_nr_steps_y || 0)
/ (mcu_params.movement_step_per_mm_y || 1),
axisLength: lengths.y,
negativeOnly: !!mcu_params.movement_home_up_y,
position: botLocationData.position.y
},
@ -51,8 +39,7 @@ export const wow = (props: Props, mcu_params: McuParams, botLocationData: ) => {
isInverted: props.z_axis_inverted,
stopAtHome: !!mcu_params.movement_stop_at_home_z,
stopAtMax: !!mcu_params.movement_stop_at_max_z,
axisLength: (mcu_params.movement_axis_nr_steps_z || 0)
/ (mcu_params.movement_step_per_mm_z || 1),
axisLength: lengths.z,
negativeOnly: !!mcu_params.movement_home_up_z,
position: botLocationData.position.z
},

View File

@ -1,90 +1,86 @@
import * as React from "react";
import { DirectionButton } from "./direction_button";
import { homeAll } from "../devices/actions";
import { JogMovementControlsProps, DirectionButtonProps } from "./interfaces";
import { JogMovementControlsProps } from "./interfaces";
import { getDevice } from "../device";
import { validBotLocationData } from "../util";
import { Axis } from "../devices/interfaces";
import { buildDirectionProps } from "./direction_axes_props";
export class JogButtons extends React.Component<JogMovementControlsProps, {}> {
render() {
const { location_data, mcu_params } = this.props.bot.hardware;
const botLocationData = validBotLocationData(location_data);
return <table className="jog-table" style={{ border: 0 }}>
<tbody>
<tr>
<td>
<button
className="i fa fa-camera arrow-button fb-button"
onClick={() => getDevice().takePhoto()} />
</td>
<td />
<td />
<td>
<DirectionButton
axis="y"
direction="up"
directionAxisProps={directionAxesProps.y}
steps={this.props.bot.stepSize || 1000}
disabled={this.props.disabled} />
</td>
<td />
<td />
<td>
<DirectionButton
axis="z"
direction="up"
directionAxisProps={directionAxesProps.z}
steps={this.props.bot.stepSize || 1000}
disabled={this.props.disabled} />
</td>
</tr>
<tr>
<td>
<button
className="i fa fa-home arrow-button fb-button"
onClick={() => homeAll(100)}
disabled={this.props.disabled || false} />
</td>
<td />
<td>
<DirectionButton
axis="x"
direction="left"
directionAxisProps={directionAxesProps.x}
steps={this.props.bot.stepSize || 1000}
disabled={this.props.disabled} />
</td>
<td>
<DirectionButton
axis="y"
direction="down"
directionAxisProps={directionAxesProps.y}
steps={this.props.bot.stepSize || 1000}
disabled={this.props.disabled} />
</td>
<td>
<DirectionButton
axis="x"
direction="right"
directionAxisProps={directionAxesProps.x}
steps={this.props.bot.stepSize || 1000}
disabled={this.props.disabled} />
</td>
<td />
<td>
<DirectionButton
axis="z"
direction="down"
directionAxisProps={directionAxesProps.z}
steps={this.props.bot.stepSize || 1000}
disabled={this.props.disabled} />
</td>
</tr>
<tr>
<td />
</tr>
</tbody>
</table>;
}
export function JogButtons(props: JogMovementControlsProps) {
const directionAxesProps = buildDirectionProps(props);
return <table className="jog-table" style={{ border: 0 }}>
<tbody>
<tr>
<td>
<button
className="i fa fa-camera arrow-button fb-button"
onClick={() => getDevice().takePhoto()} />
</td>
<td />
<td />
<td>
<DirectionButton
axis="y"
direction="up"
directionAxisProps={directionAxesProps.y}
steps={props.bot.stepSize || 1000}
disabled={props.disabled} />
</td>
<td />
<td />
<td>
<DirectionButton
axis="z"
direction="up"
directionAxisProps={directionAxesProps.z}
steps={props.bot.stepSize || 1000}
disabled={props.disabled} />
</td>
</tr>
<tr>
<td>
<button
className="i fa fa-home arrow-button fb-button"
onClick={() => homeAll(100)}
disabled={props.disabled || false} />
</td>
<td />
<td>
<DirectionButton
axis="x"
direction="left"
directionAxisProps={directionAxesProps.x}
steps={props.bot.stepSize || 1000}
disabled={props.disabled} />
</td>
<td>
<DirectionButton
axis="y"
direction="down"
directionAxisProps={directionAxesProps.y}
steps={props.bot.stepSize || 1000}
disabled={props.disabled} />
</td>
<td>
<DirectionButton
axis="x"
direction="right"
directionAxisProps={directionAxesProps.x}
steps={props.bot.stepSize || 1000}
disabled={props.disabled} />
</td>
<td />
<td>
<DirectionButton
axis="z"
direction="down"
directionAxisProps={directionAxesProps.z}
steps={props.bot.stepSize || 1000}
disabled={props.disabled} />
</td>
</tr>
<tr>
<td />
</tr>
</tbody>
</table>;
}