How to use the farmbot/dist.Encoder.unknown function in farmbot

To help you get started, we’ve selected a few farmbot examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github FarmBot / Farmbot-Web-App / frontend / devices / components / hardware_settings / encoder_type.tsx View on Github external
import * as React from "react";
import { McuParams, Encoder, McuParamName } from "farmbot/dist";
import { FBSelect, DropDownItem } from "../../../ui/index";
import { t } from "../../../i18next_wrapper";

export interface EncoderTypeProps {
  hardware: McuParams;
  onChange(key: McuParamName, value: Encoder): void;
}

export const LOOKUP: { [name: string]: DropDownItem } = {
  [Encoder.differential]: { label: "Differential", value: Encoder.differential },
  [Encoder.quadrature]: { label: "Single-Ended", value: Encoder.quadrature },
  DEFAULT: { label: "---", value: Encoder.unknown }
};

const OPTIONS = [LOOKUP[Encoder.differential], LOOKUP[Encoder.quadrature]];

const KEYS: McuParamName[] = [
  "encoder_type_x",
  "encoder_type_y",
  "encoder_type_z"
];

export function isEncoderValue(x: unknown): x is Encoder {
  return !!Encoder[parseInt("" + x)];
}

export function findByType(input: number | string | undefined) {
  return LOOKUP[input || "DEFAULT"] || LOOKUP.DEFAULT;
github FarmBot / Farmbot-Web-App / webpack / devices / components / hardware_settings / encoder_type.tsx View on Github external
import * as React from "react";
import { McuParams, Encoder, McuParamName } from "farmbot/dist";
import { t } from "i18next";
import { FBSelect, DropDownItem } from "../../../ui/index";

export interface EncoderTypeProps {
  hardware: McuParams;
  onChange(key: McuParamName, value: Encoder): void;
}

export const LOOKUP: { [name: string]: DropDownItem } = {
  [Encoder.differential]: { label: "Differential", value: Encoder.differential },
  [Encoder.quadrature]: { label: "Single-Ended", value: Encoder.quadrature },
  DEFAULT: { label: "---", value: Encoder.unknown }
};

const OPTIONS = [LOOKUP[Encoder.differential], LOOKUP[Encoder.quadrature]];

const KEYS: McuParamName[] = [
  "encoder_type_x",
  "encoder_type_y",
  "encoder_type_z"
];

export function isEncoderValue(x: unknown): x is Encoder {
  return !!Encoder[parseInt("" + x)];
}

export function findByType(input: number | string | undefined) {
  return LOOKUP[input || "DEFAULT"] || LOOKUP.DEFAULT;