Initial draft of write_peripheral step + write_pin updates
parent
c66703033d
commit
6545ead803
|
@ -24,6 +24,7 @@ import { t } from "i18next";
|
|||
import { Session } from "../../session";
|
||||
import { BooleanSetting } from "../../session_keys";
|
||||
import { TileReadPeripheral } from "./tile_read_peripheral";
|
||||
import { TileWritePeripheral } from "./tile_write_peripheral";
|
||||
|
||||
interface MoveParams {
|
||||
step: Step;
|
||||
|
@ -125,18 +126,19 @@ function numericNonsense(val: string, copy: CeleryNode, field: LegalArgString) {
|
|||
|
||||
export function renderCeleryNode(kind: LegalSequenceKind, props: StepParams) {
|
||||
switch (props.currentStep.kind) {
|
||||
case "execute": return <ExecuteBlock {...props} />;
|
||||
case "_if": return <TileIf {...props} />;
|
||||
case "move_relative": return <TileMoveRelative {...props} />;
|
||||
case "move_absolute": return <TileMoveAbsolute {...props} />;
|
||||
case "write_pin": return <TileWritePin {...props} />;
|
||||
case "wait": return <TileWait {...props} />;
|
||||
case "send_message": return <TileSendMessage {...props} />;
|
||||
case "read_pin": return <TileReadPin {...props} />;
|
||||
case "execute_script": return <TileExecuteScript {...props} />;
|
||||
case "take_photo": return <TileTakePhoto {...props} />;
|
||||
case "execute": return <ExecuteBlock {...props} />;
|
||||
case "find_home": return <TileFindHome {...props} />;
|
||||
case "move_absolute": return <TileMoveAbsolute {...props} />;
|
||||
case "move_relative": return <TileMoveRelative {...props} />;
|
||||
case "read_peripheral": return <TileReadPeripheral {...props} />;
|
||||
case "read_pin": return <TileReadPin {...props} />;
|
||||
case "send_message": return <TileSendMessage {...props} />;
|
||||
case "take_photo": return <TileTakePhoto {...props} />;
|
||||
case "wait": return <TileWait {...props} />;
|
||||
case "write_pin": return <TileWritePin {...props} />;
|
||||
case "write_peripheral": return <TileWritePeripheral {...props} />;
|
||||
default: return <div><hr /> ? Unknown step ? <hr /></div>;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import * as React from "react";
|
||||
import { ReadPeripheral, SequenceBodyItem, ReadPin } from "farmbot";
|
||||
import { ReadPeripheral, SequenceBodyItem, ReadPin, WritePin } from "farmbot";
|
||||
import { TaggedSequence } from "../../resources/tagged_resources";
|
||||
import { editStep } from "../../api/crud";
|
||||
import { StepParams } from "../interfaces";
|
||||
|
@ -21,6 +21,16 @@ export const EMPTY_READ_PERIPHERAL: ReadPeripheral = {
|
|||
args: { peripheral_id: 0, pin_mode: 0 }
|
||||
};
|
||||
|
||||
export const EMPTY_WRITE_PERIPHERAL: WritePeripheral = {
|
||||
kind: "write_peripheral",
|
||||
args: { peripheral_id: 0, pin_value: 0, pin_mode: 0 }
|
||||
};
|
||||
|
||||
export const EMPTY_WRITE_PIN: WritePin = {
|
||||
kind: "write_pin",
|
||||
args: { pin_number: 13, pin_value: 0, pin_mode: 0 }
|
||||
};
|
||||
|
||||
/** Generates a function that returns a redux action. */
|
||||
export const changeStep =
|
||||
/** When put inside a call to `dispatch()`, transforms the provided step from
|
||||
|
@ -49,6 +59,16 @@ const selectedItem = (id: number, resources: ResourceIndex) => {
|
|||
}
|
||||
};
|
||||
|
||||
const getPeripheralId = (step: SequenceBodyItem) => {
|
||||
switch (step.kind) { // Cute tricks to keep typechecker happy. Sorry.
|
||||
case "write_peripheral":
|
||||
case "read_peripheral":
|
||||
return step.args.peripheral_id;
|
||||
default:
|
||||
throw new Error("No");
|
||||
}
|
||||
};
|
||||
|
||||
export function PeripheralSelector(props: StepParams) {
|
||||
const { currentStep, currentSequence, index, dispatch } = props;
|
||||
const peripherals: DropDownItem[] = selectAllPeripherals(props.resources)
|
||||
|
@ -58,9 +78,7 @@ export function PeripheralSelector(props: StepParams) {
|
|||
return { label, value };
|
||||
})
|
||||
.filter(x => x.value);
|
||||
if (currentStep.kind !== "read_peripheral") {
|
||||
throw new Error("Expected `read_peripheral`");
|
||||
}
|
||||
|
||||
return <>
|
||||
<label>{t("Peripheral")} </label>
|
||||
<FBSelect
|
||||
|
@ -82,7 +100,7 @@ export function PeripheralSelector(props: StepParams) {
|
|||
}));
|
||||
}
|
||||
}
|
||||
selectedItem={selectedItem(currentStep.args.peripheral_id, props.resources)} />
|
||||
selectedItem={selectedItem(getPeripheralId(currentStep), props.resources)} />
|
||||
</>;
|
||||
}
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ export function TileReadPeripheral(props: StepParams) {
|
|||
<Col xs={6} md={3}>
|
||||
<StepCheckBox
|
||||
onClick={() => dispatch(action)}
|
||||
checked={false}>
|
||||
checked={true}>
|
||||
{t("Peripheral")}
|
||||
</StepCheckBox>
|
||||
</Col>
|
||||
|
|
|
@ -56,7 +56,7 @@ export function TileReadPin(props: StepParams) {
|
|||
<Col xs={6} md={3}>
|
||||
<StepCheckBox
|
||||
onClick={() => dispatch(action)}
|
||||
checked={true}>
|
||||
checked={false}>
|
||||
{t("Peripheral")}
|
||||
</StepCheckBox>
|
||||
</Col>
|
||||
|
|
|
@ -9,10 +9,16 @@ import {
|
|||
} from "./tile_pin_support";
|
||||
import { StepWrapper, StepHeader, StepContent } from "../step_ui/index";
|
||||
import { Row, Col, FBSelect } from "../../ui/index";
|
||||
import { PeripheralSelector } from "./pin_and_peripheral_support";
|
||||
import {
|
||||
PeripheralSelector,
|
||||
StepCheckBox,
|
||||
changeStep,
|
||||
EMPTY_WRITE_PIN
|
||||
} from "./pin_and_peripheral_support";
|
||||
|
||||
const pinValueField = (props: StepParams) => {
|
||||
const { currentSequence, currentStep, dispatch, index } = props;
|
||||
const { currentSequence,
|
||||
currentStep, dispatch, index } = props;
|
||||
if (currentStep.kind !== "write_peripheral") { throw new Error("NO"); }
|
||||
if (!(currentStep.args.pin_mode === 0) || currentStep.args.pin_value > 1) {
|
||||
return <StepInputBox dispatch={dispatch}
|
||||
|
@ -28,10 +34,13 @@ const pinValueField = (props: StepParams) => {
|
|||
}
|
||||
};
|
||||
|
||||
const convertToWritePin = changeStep(EMPTY_WRITE_PIN);
|
||||
|
||||
export function TileWritePeripheral(props: StepParams) {
|
||||
const { dispatch, currentStep, index, currentSequence } = props;
|
||||
const className = "write-pin-step";
|
||||
if (props.currentStep.kind === "write_peripheral") {
|
||||
const action = convertToWritePin(currentStep, currentSequence, index);
|
||||
return <StepWrapper>
|
||||
<StepHeader
|
||||
className={className}
|
||||
|
@ -56,6 +65,13 @@ export function TileWritePeripheral(props: StepParams) {
|
|||
selectedItem={currentModeSelection(currentStep)}
|
||||
list={PIN_MODES} />
|
||||
</Col>
|
||||
<Col xs={6} md={3}>
|
||||
<StepCheckBox
|
||||
onClick={() => dispatch(action)}
|
||||
checked={true}>
|
||||
{t("Peripheral")}
|
||||
</StepCheckBox>
|
||||
</Col>
|
||||
</Row>
|
||||
</StepContent>
|
||||
</StepWrapper>;
|
||||
|
|
|
@ -9,6 +9,13 @@ import {
|
|||
} from "./tile_pin_support";
|
||||
import { StepWrapper, StepHeader, StepContent } from "../step_ui/index";
|
||||
import { Row, Col, FBSelect } from "../../ui/index";
|
||||
import {
|
||||
StepCheckBox,
|
||||
changeStep,
|
||||
EMPTY_WRITE_PERIPHERAL
|
||||
} from "./pin_and_peripheral_support";
|
||||
|
||||
const convertToWritePeripheral = changeStep(EMPTY_WRITE_PERIPHERAL);
|
||||
|
||||
export function TileWritePin(props: StepParams) {
|
||||
const { dispatch, currentStep, index, currentSequence } = props;
|
||||
|
@ -29,6 +36,8 @@ export function TileWritePin(props: StepParams) {
|
|||
}
|
||||
};
|
||||
const className = "write-pin-step";
|
||||
const action = convertToWritePeripheral(currentStep, currentSequence, index);
|
||||
|
||||
return <StepWrapper>
|
||||
<StepHeader
|
||||
className={className}
|
||||
|
@ -58,6 +67,13 @@ export function TileWritePin(props: StepParams) {
|
|||
selectedItem={currentModeSelection(currentStep)}
|
||||
list={PIN_MODES} />
|
||||
</Col>
|
||||
<Col xs={6} md={3}>
|
||||
<StepCheckBox
|
||||
onClick={() => dispatch(action)}
|
||||
checked={false}>
|
||||
{t("Peripheral")}
|
||||
</StepCheckBox>
|
||||
</Col>
|
||||
</Row>
|
||||
</StepContent>
|
||||
</StepWrapper>;
|
||||
|
|
Loading…
Reference in New Issue