Skip to content

Commit

Permalink
update express firmware conditionals
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielburnworth committed May 18, 2022
1 parent 7ee0280 commit 0b2cac8
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 38 deletions.
8 changes: 8 additions & 0 deletions frontend/settings/firmware/firmware_hardware_support.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ const EXPRESS_BOARDS = ["express_k10", "express_k11"];
const NO_SENSORS = [...EXPRESS_BOARDS];
const NO_ENCODERS = [...EXPRESS_BOARDS];
const NO_TOOLS = [...EXPRESS_BOARDS];
const NO_ETHERNET = ["express_k10"];
const NO_EXTRA_BUTTONS = [...EXPRESS_BOARDS];
const NO_TMC = ["arduino", "farmduino", "farmduino_k14"];

export const isTMCBoard = (firmwareHardware: FirmwareHardware | undefined) =>
Expand All @@ -36,6 +38,9 @@ export const isExpress = (firmwareHardware: FirmwareHardware | undefined) =>
export const hasButtons = (firmwareHardware: FirmwareHardware | undefined) =>
!firmwareHardware || !NO_BUTTONS.includes(firmwareHardware);

export const hasExtraButtons = (firmwareHardware: FirmwareHardware | undefined) =>
!firmwareHardware || !NO_EXTRA_BUTTONS.includes(firmwareHardware);

export const hasEncoders = (firmwareHardware: FirmwareHardware | undefined) =>
!firmwareHardware || !NO_ENCODERS.includes(firmwareHardware);

Expand All @@ -45,6 +50,9 @@ export const hasSensors = (firmwareHardware: FirmwareHardware | undefined) =>
export const hasUTM = (firmwareHardware: FirmwareHardware | undefined) =>
!firmwareHardware || !NO_TOOLS.includes(firmwareHardware);

export const hasEthernet = (firmwareHardware: FirmwareHardware | undefined) =>
!firmwareHardware || !NO_ETHERNET.includes(firmwareHardware);

export const getBoardIdentifier =
(firmwareVersion: string | undefined): string =>
firmwareVersion ? firmwareVersion.split(".")[3] : "undefined";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ describe("<BoxTopGpioDiagram />", () => {
const fakeProps = (): BoxTopGpioDiagramProps => ({
boundPins: [16],
setSelectedPin: jest.fn(),
selectedPin: undefined
selectedPin: undefined,
firmwareHardware: undefined,
});

it("renders", () => {
Expand All @@ -16,6 +17,13 @@ describe("<BoxTopGpioDiagram />", () => {
expect(wrapper.find("circle").length).toEqual(18);
});

it("renders: express", () => {
const p = fakeProps();
p.firmwareHardware = "express_k10";
const wrapper = mount(<BoxTopGpioDiagram {...p} />);
expect(wrapper.find("circle").length).toEqual(8);
});

it("pin hover", () => {
const wrapper = mount<BoxTopGpioDiagram>(<BoxTopGpioDiagram
{...fakeProps()} />);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
PinNumberInputGroup,
BindingTargetDropdown,
BindingTargetDropdownProps,
PinNumberInputGroupProps,
} from "../pin_binding_input_group";
import {
PinBindingType, PinBindingSpecialAction,
Expand All @@ -46,6 +47,7 @@ describe("<PinBindingInputGroup/>", () => {
],
dispatch: jest.fn(),
resources: resources,
firmwareHardware: undefined,
};
};

Expand Down Expand Up @@ -185,16 +187,20 @@ describe("<PinBindingInputGroup/>", () => {
});

describe("<PinNumberInputGroup />", () => {
const fakeProps = (): PinNumberInputGroupProps => ({
pinNumberInput: undefined,
boundPins: [],
setSelectedPin: jest.fn(),
firmwareHardware: undefined,
});

it("sets pin", () => {
const setSelectedPin = jest.fn();
const wrapper = shallow(<PinNumberInputGroup
pinNumberInput={undefined}
boundPins={[]}
setSelectedPin={setSelectedPin} />);
const p = fakeProps();
const wrapper = shallow(<PinNumberInputGroup {...p} />);
wrapper.find("FBSelect").simulate("change", {
label: "", value: AVAILABLE_PIN
});
expect(setSelectedPin).toHaveBeenCalledWith(AVAILABLE_PIN);
expect(p.setSelectedPin).toHaveBeenCalledWith(AVAILABLE_PIN);
});
});

Expand Down
27 changes: 20 additions & 7 deletions frontend/settings/pin_bindings/box_top_gpio_diagram.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,38 @@
import React from "react";
import { t } from "../../i18next_wrapper";
import { Color } from "../../ui/colors";
import { FirmwareHardware } from "farmbot";
import { hasExtraButtons } from "../firmware/firmware_hardware_support";

export interface BoxTopGpioDiagramProps {
boundPins: number[] | undefined;
setSelectedPin(pin: number | undefined): void;
selectedPin: number | undefined;
firmwareHardware: FirmwareHardware | undefined;
}

interface BoxTopGpioDiagramState {
hoveredPin: number | undefined;
}

export const CIRCLES = () => [
{ cx: 20, cy: 20, r: 7, pin: 20, label: t("Button 5"), color: Color.white },
{ cx: 40, cy: 20, r: 7, pin: 5, label: t("Button 4"), color: Color.white },
{ cx: 60, cy: 20, r: 7, pin: 26, label: t("Button 3"), color: Color.white },
export const CIRCLES = (firmwareHardware: FirmwareHardware | undefined) => [
...(hasExtraButtons(firmwareHardware)
? [{ cx: 20, cy: 20, r: 7, pin: 20, label: t("Button 5"), color: Color.white }]
: []),
...(hasExtraButtons(firmwareHardware)
? [{ cx: 40, cy: 20, r: 7, pin: 5, label: t("Button 4"), color: Color.white }]
: []),
...(hasExtraButtons(firmwareHardware)
? [{ cx: 60, cy: 20, r: 7, pin: 26, label: t("Button 3"), color: Color.white }]
: []),
{ cx: 80, cy: 20, r: 7, pin: 22, label: t("Button 2"), color: Color.yellow },
{ cx: 100, cy: 20, r: 7, pin: 16, label: t("Button 1"), color: Color.red },
{ cx: 30, cy: 38, r: 4, pin: 0, label: t("LED 4"), color: Color.white },
{ cx: 50, cy: 38, r: 4, pin: 0, label: t("LED 3"), color: Color.white },
...(hasExtraButtons(firmwareHardware)
? [{ cx: 30, cy: 38, r: 4, pin: 0, label: t("LED 4"), color: Color.white }]
: []),
...(hasExtraButtons(firmwareHardware)
? [{ cx: 50, cy: 38, r: 4, pin: 0, label: t("LED 3"), color: Color.white }]
: []),
{ cx: 70, cy: 38, r: 4, pin: 0, label: t("Connection"), color: Color.blue },
{ cx: 90, cy: 38, r: 4, pin: 0, label: t("Sync LED"), color: Color.green },
];
Expand Down Expand Up @@ -76,7 +89,7 @@ export class BoxTopGpioDiagram
return <svg id={"box-top-gpio"}
width={"100%"} height={"100%"} viewBox={"0 0 120 52"}
style={{ maxHeight: "300px", maxWidth: "500px" }}>
{CIRCLES().map(circle =>
{CIRCLES(this.props.firmwareHardware).map(circle =>
<Button key={circle.cx}
cx={circle.cx} cy={circle.cy} r={circle.r} color={circle.color}
hover={this.hover} hovered={(this.state.hoveredPin == circle.pin)
Expand Down
1 change: 1 addition & 0 deletions frontend/settings/pin_bindings/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export interface PinBindingInputGroupProps {
dispatch: Function;
resources: ResourceIndex;
pinBindings: PinBindingListItems[];
firmwareHardware: FirmwareHardware | undefined;
}

export interface PinBindingInputGroupState {
Expand Down
16 changes: 11 additions & 5 deletions frontend/settings/pin_bindings/pin_binding_input_group.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { DeviceSetting } from "../../constants";
import { BoxTopGpioDiagram } from "./box_top_gpio_diagram";
import { findSequenceById, selectAllSequences } from "../../resources/selectors";
import { ResourceIndex } from "../../resources/interfaces";
import { FirmwareHardware } from "farmbot";

export class PinBindingInputGroup
extends React.Component<PinBindingInputGroupProps, PinBindingInputGroupState> {
Expand Down Expand Up @@ -92,6 +93,7 @@ export class PinBindingInputGroup

Number = () =>
<PinNumberInputGroup
firmwareHardware={this.props.firmwareHardware}
pinNumberInput={this.state.pinNumberInput}
boundPins={this.boundPins}
setSelectedPin={this.setSelectedPin} />;
Expand Down Expand Up @@ -135,12 +137,15 @@ export class PinBindingInputGroup
}
}

export interface PinNumberInputGroupProps {
pinNumberInput: number | undefined;
boundPins: number[];
setSelectedPin: (pin: number | undefined) => void;
firmwareHardware: FirmwareHardware | undefined;
}

/** pin number selection */
export const PinNumberInputGroup = (props: {
pinNumberInput: number | undefined,
boundPins: number[],
setSelectedPin: (pin: number | undefined) => void
}) => {
export const PinNumberInputGroup = (props: PinNumberInputGroupProps) => {
const { pinNumberInput, boundPins, setSelectedPin } = props;
const selectedPinNumber = isNumber(pinNumberInput)
? {
Expand All @@ -153,6 +158,7 @@ export const PinNumberInputGroup = (props: {
<Popover position={Position.TOP}
target={<i className="fa fa-circle-o-notch" />}
content={<BoxTopGpioDiagram
firmwareHardware={props.firmwareHardware}
boundPins={boundPins}
setSelectedPin={setSelectedPin}
selectedPin={pinNumberInput} />} />
Expand Down
1 change: 1 addition & 0 deletions frontend/settings/pin_bindings/pin_bindings_content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export const PinBindingsContent = (props: PinBindingsContentProps) => {
</Highlight>
<Highlight settingName={DeviceSetting.addNewPinBinding}>
<PinBindingInputGroup
firmwareHardware={firmwareHardware}
pinBindings={pinBindings}
dispatch={dispatch}
resources={resources} />
Expand Down
2 changes: 2 additions & 0 deletions frontend/wizard/checks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,9 @@ export const PeripheralsCheck = (props: WizardStepComponentProps) => {

export const PinBinding = (props: WizardStepComponentProps) => {
const pinBindings = apiPinBindings(props.resources);
const firmwareHardware = getFwHardwareValue(getFbosConfig(props.resources));
return <PinBindingInputGroup
firmwareHardware={firmwareHardware}
pinBindings={pinBindings}
dispatch={props.dispatch}
resources={props.resources} />;
Expand Down
42 changes: 23 additions & 19 deletions frontend/wizard/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ import {
BootSequence,
} from "./checks";
import { FirmwareHardware, TaggedWizardStepResult } from "farmbot";
import { hasUTM } from "../settings/firmware/firmware_hardware_support";
import {
hasEthernet, hasExtraButtons, hasUTM,
} from "../settings/firmware/firmware_hardware_support";
import { GetWebAppConfigValue } from "../config_storage/actions";
import { BooleanSetting } from "../session_keys";
import { ExternalUrl } from "../external_urls";
Expand Down Expand Up @@ -255,7 +257,7 @@ export const WIZARD_STEPS = (
question: t(SetupWizardContent.NETWORK_PORTS_QUESTION),
outcomes: [],
},
...(hasUTM(firmwareHardware)
...(hasEthernet(firmwareHardware)
? [{
section: WizardSectionSlug.connectivity,
slug: WizardStepSlug.ethernetOption,
Expand Down Expand Up @@ -902,23 +904,25 @@ export const WIZARD_STEPS = (
},
],
},
{
section: WizardSectionSlug.peripherals,
slug: WizardStepSlug.findHomeButton,
title: t("Find Home Button"),
prerequisites: [botOnlineReq],
content: t(SetupWizardContent.FIND_HOME_BUTTON),
component: PinBinding,
componentOptions: { fullWidth: true },
question: t("Did FarmBot find home?"),
outcomes: [
{
slug: "noFindHomeSequence",
description: t("There is no 'Find Home' sequence"),
tips: t("Create a new sequence and add the FIND HOME command."),
},
],
},
...(hasExtraButtons(firmwareHardware)
? [{
section: WizardSectionSlug.peripherals,
slug: WizardStepSlug.findHomeButton,
title: t("Find Home Button"),
prerequisites: [botOnlineReq],
content: t(SetupWizardContent.FIND_HOME_BUTTON),
component: PinBinding,
componentOptions: { fullWidth: true },
question: t("Did FarmBot find home?"),
outcomes: [
{
slug: "noFindHomeSequence",
description: t("There is no 'Find Home' sequence"),
tips: t("Create a new sequence and add the FIND HOME command."),
},
],
}]
: []),
{
section: WizardSectionSlug.camera,
slug: WizardStepSlug.photo,
Expand Down

0 comments on commit 0b2cac8

Please sign in to comment.