add new firmware settings

pull/1217/head
gabrielburnworth 2019-06-03 16:41:59 -07:00
parent 483675b2fe
commit 76fb80915b
12 changed files with 105 additions and 28 deletions

View File

@ -0,0 +1,11 @@
class AddCurrentAndSensitivityParamsXyzToFirmwareConfig < ActiveRecord::Migration[5.2]
safety_assured
def change
add_column :firmware_configs, :movement_motor_current_x, :integer, default: 600
add_column :firmware_configs, :movement_motor_current_y, :integer, default: 600
add_column :firmware_configs, :movement_motor_current_z, :integer, default: 600
add_column :firmware_configs, :movement_stall_sensitivity_x, :integer, default: 30
add_column :firmware_configs, :movement_stall_sensitivity_y, :integer, default: 30
add_column :firmware_configs, :movement_stall_sensitivity_z, :integer, default: 30
end
end

View File

@ -563,7 +563,13 @@ CREATE TABLE public.firmware_configs (
movement_invert_2_endpoints_z integer DEFAULT 0,
movement_microsteps_x integer DEFAULT 1,
movement_microsteps_y integer DEFAULT 1,
movement_microsteps_z integer DEFAULT 1
movement_microsteps_z integer DEFAULT 1,
movement_motor_current_x integer DEFAULT 600,
movement_motor_current_y integer DEFAULT 600,
movement_motor_current_z integer DEFAULT 600,
movement_stall_sensitivity_x integer DEFAULT 30,
movement_stall_sensitivity_y integer DEFAULT 30,
movement_stall_sensitivity_z integer DEFAULT 30
);
@ -2751,14 +2757,6 @@ ALTER TABLE ONLY public.points
ADD CONSTRAINT fk_rails_a62cbb8aca FOREIGN KEY (tool_id) REFERENCES public.tools(id);
--
-- Name: farmware_envs fk_rails_ab55c3a1d1; Type: FK CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.farmware_envs
ADD CONSTRAINT fk_rails_ab55c3a1d1 FOREIGN KEY (device_id) REFERENCES public.devices(id);
--
-- Name: primary_nodes fk_rails_bca7fee3b9; Type: FK CONSTRAINT; Schema: public; Owner: -
--
@ -2767,6 +2765,14 @@ ALTER TABLE ONLY public.primary_nodes
ADD CONSTRAINT fk_rails_bca7fee3b9 FOREIGN KEY (sequence_id) REFERENCES public.sequences(id);
--
-- Name: farmware_envs fk_rails_bdadc396eb; Type: FK CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.farmware_envs
ADD CONSTRAINT fk_rails_bdadc396eb FOREIGN KEY (device_id) REFERENCES public.devices(id);
--
-- Name: alerts fk_rails_c0132c78be; Type: FK CONSTRAINT; Schema: public; Owner: -
--
@ -2968,6 +2974,7 @@ INSERT INTO "schema_migrations" (version) VALUES
('20190512015442'),
('20190513221836'),
('20190515185612'),
('20190515205442');
('20190515205442'),
('20190603233157');

View File

@ -124,6 +124,12 @@ export namespace ToolTips {
export const INVERT_MOTORS =
trim(`Invert direction of motor during calibration. (default: disabled)`);
export const MOTOR_CURRENT =
trim(`Motor current in milliamps. (default: 600)`);
export const STALL_SENSITIVITY =
trim(`Motor stall sensitivity. (default: 30)`);
export const ENABLE_X2_MOTOR =
trim(`Enable use of a second x-axis motor. Connects to E0 on RAMPS.
(default: enabled)`);

View File

@ -11,6 +11,7 @@ import {
} from "../../__test_support__/resource_index_builder";
import { FarmbotOsSettings } from "../components/farmbot_os_settings";
import { fakeTimeSettings } from "../../__test_support__/fake_time_settings";
import { HardwareSettings } from "../components/hardware_settings";
describe("<Devices/>", () => {
const fakeProps = (): Props => ({
@ -23,7 +24,7 @@ describe("<Devices/>", () => {
images: [],
dispatch: jest.fn(),
resources: buildResourceIndex(FAKE_RESOURCES).index,
sourceFbosConfig: jest.fn(),
sourceFbosConfig: () => ({ value: undefined, consistent: true }),
sourceFwConfig: jest.fn(),
shouldDisplay: jest.fn(),
firmwareConfig: undefined,
@ -51,4 +52,12 @@ describe("<Devices/>", () => {
expect(wrapper.find(FarmbotOsSettings).props().botToMqttLastSeen)
.toEqual("123");
});
it("provides correct firmwareHardware value", () => {
const p = fakeProps();
p.sourceFbosConfig = () => ({ value: "arduino", consistent: true });
const wrapper = shallow(<Devices {...p} />);
expect(wrapper.find(HardwareSettings).props().firmwareHardware)
.toEqual("arduino");
});
});

View File

@ -20,6 +20,7 @@ describe("<HardwareSettings />", () => {
},
firmwareConfig: undefined,
shouldDisplay: jest.fn(),
firmwareHardware: undefined,
};
};

View File

@ -1,5 +1,4 @@
import * as React from "react";
import { MCUFactoryReset, bulkToggleControlPanel } from "../actions";
import { Widget, WidgetHeader, WidgetBody, SaveBtn } from "../../ui/index";
import { HardwareSettingsProps } from "../interfaces";
@ -24,7 +23,7 @@ export class HardwareSettings extends
render() {
const {
bot, dispatch, sourceFwConfig, controlPanelState, firmwareConfig,
botToMqttStatus
botToMqttStatus, firmwareHardware
} = this.props;
const { informational_settings } = this.props.bot.hardware;
const firmwareVersion = informational_settings.firmware_version;
@ -79,7 +78,8 @@ export class HardwareSettings extends
firmwareVersion={firmwareVersion}
controlPanelState={controlPanelState}
sourceFwConfig={sourceFwConfig}
isValidFwConfig={!!firmwareConfig} />
isValidFwConfig={!!firmwareConfig}
firmwareHardware={firmwareHardware} />
<EncodersAndEndStops
dispatch={dispatch}
shouldDisplay={this.props.shouldDisplay}

View File

@ -7,18 +7,25 @@ import { FBSelect } from "../../../../ui/index";
import { Encoder } from "farmbot";
describe("<EncoderType/>", () => {
const fakeProps = (): EncoderTypeProps => ({
hardware: {
encoder_type_x: 1,
encoder_type_y: 1,
encoder_type_z: 1
},
onChange: jest.fn(),
});
it("renders default content", () => {
const props: EncoderTypeProps = {
hardware: {
encoder_type_x: 1,
encoder_type_y: 1,
encoder_type_z: 1
},
onChange: jest.fn()
};
const el = shallow(<EncoderType {...props} />);
expect(el.find(FBSelect).length).toEqual(3);
// EncoderType
const wrapper = shallow(<EncoderType {...fakeProps()} />);
expect(wrapper.find(FBSelect).length).toEqual(3);
});
it("changes encoder type", () => {
const p = fakeProps();
const wrapper = shallow(<EncoderType {...p} />);
wrapper.find(FBSelect).first().simulate("change", { label: "", value: 1 });
expect(p.onChange).toHaveBeenCalledWith("encoder_type_x", 1);
});
});

View File

@ -32,6 +32,7 @@ describe("<Motors/>", () => {
controlPanelState,
sourceFwConfig: () => ({ value: 0, consistent: true }),
isValidFwConfig: true,
firmwareHardware: undefined,
};
};
@ -83,4 +84,12 @@ describe("<Motors/>", () => {
testParamToggle("toggles retries e-stop parameter", "param_e_stop_on_mov_err", 0);
testParamToggle("toggles enable X2", "movement_secondary_motor_x", 7);
testParamToggle("toggles invert X2", "movement_secondary_motor_invert_x", 8);
it("renders TMC params", () => {
const p = fakeProps();
p.firmwareHardware = "express_k10";
const wrapper = render(<Motors {...p} />);
expect(wrapper.text()).toContain("Motor Current");
expect(wrapper.text()).toContain("Stall Sensitivity");
});
});

View File

@ -15,6 +15,7 @@ import { t } from "../../../i18next_wrapper";
import { Xyz, McuParamName } from "farmbot";
import { SourceFwConfig } from "../../interfaces";
import { calcMicrostepsPerMm } from "../../../controls/move/direction_axes_props";
import { NumberConfigKey } from "farmbot/dist/resources/configs/firmware";
const SingleSettingRow =
({ label, tooltip, settingType, children }: {
@ -49,13 +50,14 @@ export const calculateScale =
export function Motors(props: MotorsProps) {
const {
dispatch, firmwareVersion, controlPanelState,
sourceFwConfig, isValidFwConfig
sourceFwConfig, isValidFwConfig, firmwareHardware
} = props;
const enable2ndXMotor = sourceFwConfig("movement_secondary_motor_x");
const invert2ndXMotor = sourceFwConfig("movement_secondary_motor_invert_x");
const eStopOnMoveError = sourceFwConfig("param_e_stop_on_mov_err");
const scale = calculateScale(sourceFwConfig);
const isFarmduinoExpress = firmwareHardware &&
firmwareHardware.includes("express");
return <section>
<Header
expanded={controlPanelState.motors}
@ -161,6 +163,24 @@ export function Motors(props: MotorsProps) {
z={"movement_invert_motor_z"}
dispatch={dispatch}
sourceFwConfig={sourceFwConfig} />
{isFarmduinoExpress &&
<NumericMCUInputGroup
name={t("Motor Current")}
tooltip={ToolTips.MOTOR_CURRENT}
x={"movement_motor_current_x" as NumberConfigKey}
y={"movement_motor_current_y" as NumberConfigKey}
z={"movement_motor_current_z" as NumberConfigKey}
dispatch={dispatch}
sourceFwConfig={sourceFwConfig} />}
{isFarmduinoExpress &&
<NumericMCUInputGroup
name={t("Stall Sensitivity")}
tooltip={ToolTips.STALL_SENSITIVITY}
x={"movement_stall_sensitivity_x" as NumberConfigKey}
y={"movement_stall_sensitivity_y" as NumberConfigKey}
z={"movement_stall_sensitivity_z" as NumberConfigKey}
dispatch={dispatch}
sourceFwConfig={sourceFwConfig} />}
<SingleSettingRow settingType="button"
label={t("Enable 2nd X Motor")}
tooltip={ToolTips.ENABLE_X2_MOTOR}>

View File

@ -2,7 +2,7 @@ import {
BotState, Xyz, SourceFwConfig,
ControlPanelState, ShouldDisplay
} from "../interfaces";
import { McuParamName, McuParams } from "farmbot/dist";
import { McuParamName, McuParams, FirmwareHardware } from "farmbot/dist";
import { IntegerSize } from "../../util";
import { FirmwareConfig } from "farmbot/dist/resources/configs/firmware";
@ -79,6 +79,7 @@ export interface MotorsProps {
controlPanelState: ControlPanelState;
sourceFwConfig: SourceFwConfig;
isValidFwConfig: boolean;
firmwareHardware: FirmwareHardware | undefined;
}
export interface EncodersProps {

View File

@ -8,6 +8,7 @@ import { Props } from "./interfaces";
import { PinBindings } from "./pin_bindings/pin_bindings";
import { selectAllDiagnosticDumps } from "../resources/selectors";
import { getStatus } from "../connectivity/reducer_support";
import { isFwHardwareValue } from "./components/fbos_settings/board_type";
@connect(mapStateToProps)
export class Devices extends React.Component<Props, {}> {
@ -18,6 +19,8 @@ export class Devices extends React.Component<Props, {}> {
const botToMqttLastSeen = (botToMqtt && botToMqttStatus === "up")
? botToMqtt.at
: "";
const { value } = this.props.sourceFbosConfig("firmware_hardware");
const firmwareHardware = isFwHardwareValue(value) ? value : undefined;
return <Page className="device-page">
<Row>
<Col xs={12} sm={6}>
@ -42,6 +45,7 @@ export class Devices extends React.Component<Props, {}> {
bot={this.props.bot}
botToMqttStatus={botToMqttStatus}
shouldDisplay={this.props.shouldDisplay}
firmwareHardware={firmwareHardware}
sourceFwConfig={this.props.sourceFwConfig}
firmwareConfig={this.props.firmwareConfig} />
<PinBindings

View File

@ -9,6 +9,7 @@ import {
TaggedDiagnosticDump,
TaggedFarmwareInstallation,
JobProgress,
FirmwareHardware,
} from "farmbot";
import { ResourceIndex } from "../resources/interfaces";
import { WD_ENV } from "../farmware/weed_detector/remote_env/interfaces";
@ -244,6 +245,7 @@ export interface HardwareSettingsProps {
shouldDisplay: ShouldDisplay;
sourceFwConfig: SourceFwConfig;
firmwareConfig: FirmwareConfig | undefined;
firmwareHardware: FirmwareHardware | undefined;
}
export interface ControlPanelState {