Farmbot-Web-App/frontend/sequences/step_button_cluster.tsx

213 lines
5.4 KiB
TypeScript
Raw Normal View History

2017-06-29 12:54:02 -06:00
import * as React from "react";
2019-12-05 13:52:16 -07:00
import { StepButton } from "./step_buttons";
import { scrollToBottom } from "../util";
2018-06-14 12:48:30 -06:00
import { Row } from "../ui/index";
2018-08-01 07:33:39 -06:00
import { TaggedSequence } from "farmbot";
import { CONFIG_DEFAULTS } from "farmbot/dist/config";
2018-09-11 17:17:30 -06:00
import { ShouldDisplay, Feature } from "../devices/interfaces";
2019-02-26 20:12:02 -07:00
import { MessageType } from "./interfaces";
2019-04-02 13:59:37 -06:00
import { t } from "../i18next_wrapper";
2019-04-09 22:11:26 -06:00
import { NOTHING_SELECTED } from "./locals_list/handle_select";
2017-06-29 12:54:02 -06:00
2018-09-11 17:17:30 -06:00
export interface StepButtonProps {
2017-06-29 12:54:02 -06:00
dispatch: Function;
current: TaggedSequence | undefined;
2018-09-11 17:17:30 -06:00
shouldDisplay: ShouldDisplay;
2019-04-09 19:45:59 -06:00
stepIndex: number | undefined;
2017-06-29 12:54:02 -06:00
}
2018-09-11 17:17:30 -06:00
export function StepButtonCluster(props: StepButtonProps) {
2019-04-09 19:45:59 -06:00
const { dispatch, current, shouldDisplay, stepIndex } = props;
const commonStepProps = { dispatch, current, index: stepIndex };
2017-06-29 12:54:02 -06:00
const ALL_THE_BUTTONS = [
2019-04-09 19:45:59 -06:00
<StepButton {...commonStepProps}
2017-06-29 12:54:02 -06:00
step={{
kind: "move_absolute",
args: {
2019-04-09 22:11:26 -06:00
location: NOTHING_SELECTED,
2019-04-09 19:45:59 -06:00
offset: { kind: "coordinate", args: { x: 0, y: 0, z: 0 } },
speed: CONFIG_DEFAULTS.speed
2017-06-29 12:54:02 -06:00
}
}}
color="blue">
2019-04-09 22:00:03 -06:00
{t("MOVE TO")}
2017-06-29 12:54:02 -06:00
</StepButton>,
2019-04-09 19:45:59 -06:00
<StepButton {...commonStepProps}
2017-06-29 12:54:02 -06:00
step={{
kind: "move_relative",
args: { x: 0, y: 0, z: 0, speed: CONFIG_DEFAULTS.speed }
2017-06-29 12:54:02 -06:00
}}
color="green">
{t("MOVE RELATIVE")}
</StepButton>,
2019-04-09 19:45:59 -06:00
<StepButton {...commonStepProps}
2017-06-29 12:54:02 -06:00
step={{
kind: "write_pin",
2019-04-09 22:11:26 -06:00
args: { pin_number: NOTHING_SELECTED, pin_value: 0, pin_mode: 0 }
2017-06-29 12:54:02 -06:00
}}
color="orange">
2019-04-09 22:11:26 -06:00
{t("CONTROL PERIPHERAL")}
2017-06-29 12:54:02 -06:00
</StepButton>,
2019-04-09 19:45:59 -06:00
<StepButton {...commonStepProps}
2017-06-29 12:54:02 -06:00
step={{
kind: "read_pin",
args: {
2019-04-09 22:11:26 -06:00
pin_number: NOTHING_SELECTED,
2017-06-29 12:54:02 -06:00
pin_mode: 0,
label: "---"
}
}}
color="yellow">
2019-04-09 22:11:26 -06:00
{t("READ SENSOR")}
2017-06-29 12:54:02 -06:00
</StepButton>,
<StepButton {...commonStepProps}
step={{
kind: "set_servo_angle",
args: {
pin_number: 4,
pin_value: 90
}
}}
color="blue">
{t("CONTROL SERVO")}
</StepButton>,
2019-04-09 19:45:59 -06:00
<StepButton {...commonStepProps}
2017-06-29 12:54:02 -06:00
step={{
kind: "wait",
args: { milliseconds: 0 }
}}
color="brown">
{t("WAIT")}
</StepButton>,
2019-04-09 19:45:59 -06:00
<StepButton {...commonStepProps}
2017-06-29 12:54:02 -06:00
step={{
kind: "send_message",
args: {
2018-02-27 10:49:37 -07:00
message: t("FarmBot is at position ") + "{{ x }}, {{ y }}, {{ z }}.",
2019-02-26 20:12:02 -07:00
message_type: MessageType.success
2017-06-29 12:54:02 -06:00
}
}}
color="brown">
2020-01-07 14:00:25 -07:00
{t("SEND MESSAGE")}
</StepButton>,
2019-12-26 09:25:03 -07:00
<StepButton {...commonStepProps}
step={{ kind: "reboot", args: { package: "farmbot_os" } }}
color="brown">
{t("REBOOT")}
</StepButton>,
2020-04-28 08:18:04 -06:00
<StepButton {...commonStepProps}
step={{ kind: "power_off", args: {} }}
color="brown">
{t("SHUTDOWN")}
</StepButton>,
2020-01-07 14:00:25 -07:00
<StepButton {...commonStepProps}
step={{ kind: "emergency_lock", args: {} }}
color="red">
{t("E-STOP")}
</StepButton>,
2019-04-09 19:45:59 -06:00
<StepButton{...commonStepProps}
2017-06-29 12:54:02 -06:00
step={{
kind: "find_home",
args: {
axis: "all",
speed: 100
2017-06-29 12:54:02 -06:00
}
}}
color="blue">
{t("Find Home")}
</StepButton>,
2019-12-02 13:53:19 -07:00
<StepButton{...commonStepProps}
step={{
kind: "zero",
args: { axis: "all" }
}}
color="blue">
{t("Set Zero")}
</StepButton>,
<StepButton{...commonStepProps}
step={{
kind: "calibrate",
args: { axis: "all" }
}}
color="blue">
{t("Calibrate")}
</StepButton>,
2019-04-09 19:45:59 -06:00
<StepButton {...commonStepProps}
2017-06-29 12:54:02 -06:00
step={{
kind: "_if",
args: {
lhs: "x",
op: "is",
rhs: 0,
_then: { kind: "nothing", args: {} },
_else: { kind: "nothing", args: {} }
}
}}
color="purple">
{t("IF STATEMENT")}
</StepButton>,
2019-04-09 19:45:59 -06:00
<StepButton {...commonStepProps}
2017-06-29 12:54:02 -06:00
step={{
kind: "execute",
args: { sequence_id: 0 }
}}
color="gray">
{t("EXECUTE SEQUENCE")}
</StepButton>,
2019-04-09 19:45:59 -06:00
<StepButton {...commonStepProps}
2017-06-29 12:54:02 -06:00
step={{
kind: "execute_script",
args: { label: "plant-detection" }
}}
color="pink">
{t("Run Farmware")}
</StepButton>,
<StepButton
2019-04-09 19:45:59 -06:00
{...commonStepProps}
color="brown"
2019-09-23 12:56:35 -06:00
step={{ kind: "take_photo", args: {} }}>
2017-06-29 12:54:02 -06:00
{t("TAKE PHOTO")}
</StepButton>,
2020-04-23 13:11:25 -06:00
<StepButton
{...commonStepProps}
step={{
kind: "assertion",
args: {
lua: "return 2 + 2 == 4",
_then: { kind: "nothing", args: {} },
assertion_type: "abort_recover",
}
}}
color="purple">
{t("ASSERTION")}
</StepButton>,
2017-06-29 12:54:02 -06:00
];
shouldDisplay(Feature.update_resource) && ALL_THE_BUTTONS.push(<StepButton
2019-04-09 19:45:59 -06:00
{...commonStepProps}
2018-09-11 17:17:30 -06:00
step={{
kind: "update_resource",
2018-09-11 17:17:30 -06:00
args: {
resource: {
kind: "resource",
args: { resource_id: 0, resource_type: "Device" }
}
},
body: [
{ kind: "pair", args: { label: "mounted_tool_id", value: 0 } },
],
2018-09-11 17:17:30 -06:00
}}
color="brown">
{t("Mark As...")}
2020-02-28 09:35:32 -07:00
</StepButton>);
2020-04-23 13:11:25 -06:00
2020-02-28 09:34:28 -07:00
return <Row>
<div className="step-button-cluster">
{ALL_THE_BUTTONS.map((stepButton, inx) =>
<div key={inx} onClick={() => scrollToBottom("sequenceDiv")}>
{stepButton}
</div>)}
</div>
</Row>;
2017-06-29 12:54:02 -06:00
}