Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions src/components/config/ActuatorsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,14 @@ function gpioChannelField(entry: ActuatorEntry, setBinding: DetailProps["setBind
);
}

function relayTypeField(entry: ActuatorEntry, setActions: DetailProps["setActions"]) {
return (
<Field label="relay_type">
<SelectCell value={(entry.actions?.relay_type as string) ?? ""} options={RELAY_TYPES} onChange={(v) => setActions({ relay_type: v || null })} />
</Field>
);
}

function TypeDetail({ entry, setBinding, setActions, usedRelay, usedServo, usedGpio }: DetailProps) {
const act = entry.actions ?? {};
switch (entry.type) {
Expand All @@ -127,6 +135,7 @@ function TypeDetail({ entry, setBinding, setActions, usedRelay, usedServo, usedG
/>
</Field>
{relayChannelField(entry, setBinding, usedRelay)}
{relayTypeField(entry, setActions)}
{aliasesField(entry, setActions)}
<Field label="positions (µs)">
<CsvListCell
Expand All @@ -147,24 +156,21 @@ function TypeDetail({ entry, setBinding, setActions, usedRelay, usedServo, usedG
<Field label="solenoid_type">
<SelectCell value={(act.solenoid_type as string) ?? ""} options={SOLENOID_TYPES} onChange={(v) => setActions({ solenoid_type: v || null })} />
</Field>
{relayTypeField(entry, setActions)}
{relayChannelField(entry, setBinding, usedRelay)}
</Flex>
);
case "powered_device":
return (
<Flex gap={3} flexWrap="wrap">
<Field label="relay_type">
<SelectCell value={(act.relay_type as string) ?? ""} options={RELAY_TYPES} onChange={(v) => setActions({ relay_type: v || null })} />
</Field>
{relayTypeField(entry, setActions)}
{relayChannelField(entry, setBinding, usedRelay)}
</Flex>
);
case "powered_gpio_device":
return (
<Flex gap={3} flexWrap="wrap">
<Field label="relay_type">
<SelectCell value={(act.relay_type as string) ?? ""} options={RELAY_TYPES} onChange={(v) => setActions({ relay_type: v || null })} />
</Field>
{relayTypeField(entry, setActions)}
{relayChannelField(entry, setBinding, usedRelay)}
{gpioChannelField(entry, setBinding, usedGpio)}
{gpioField(entry, setActions, "arm, disarm")}
Expand Down
18 changes: 16 additions & 2 deletions src/components/config/SensorsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { CalibrationModal } from "./CalibrationModal";

const SENSOR_TYPES: SensorType[] = ["PT", "LC", "TC"];
const SOURCES = ["GCS", "TCS", "FAS"] as const;
const CONVERT_METHODS: ConvertMethod[] = ["none", "linear", "polynomial"];
const CONVERT_METHODS: ConvertMethod[] = ["none", "zero_offset", "linear", "polynomial"];

export interface SensorsTableProps {
sensors: SensorEntry[];
Expand All @@ -41,6 +41,10 @@ export function SensorsTable({ sensors, onChange }: SensorsTableProps) {
: { source: source as "GCS" | "TCS", hat_id: 0, channel_id: 0 };
update(i, { binding });
}
function setRange(i: number, index: 0 | 1, v: number | undefined) {
const [lo, hi] = sensors[i].range ?? [0, 0];
update(i, { range: index === 0 ? [v ?? 0, hi] : [lo, v ?? 0] });
}
function remove(i: number) {
onChange(sensors.filter((_, idx) => idx !== i));
}
Expand All @@ -63,6 +67,7 @@ export function SensorsTable({ sensors, onChange }: SensorsTableProps) {
<Table.ColumnHeader>Source</Table.ColumnHeader>
<Table.ColumnHeader>Hat / Node</Table.ColumnHeader>
<Table.ColumnHeader>Channel</Table.ColumnHeader>
<Table.ColumnHeader>Range</Table.ColumnHeader>
<Table.ColumnHeader>Convert</Table.ColumnHeader>
<Table.ColumnHeader>Calibration</Table.ColumnHeader>
<Table.ColumnHeader />
Expand All @@ -71,7 +76,7 @@ export function SensorsTable({ sensors, onChange }: SensorsTableProps) {
<Table.Body>
{sensors.length === 0 ? (
<Table.Row>
<Table.Cell colSpan={9}>
<Table.Cell colSpan={10}>
<Box color="text.muted" fontSize="sm" py={2}>No sensors. Add one below.</Box>
</Table.Cell>
</Table.Row>
Expand Down Expand Up @@ -104,6 +109,15 @@ export function SensorsTable({ sensors, onChange }: SensorsTableProps) {
)}
</Cell>
</Table.Cell>
<Table.Cell>
<Cell>
<Flex gap={1} align="center">
<NumberCell value={s.range?.[0]} onChange={(v) => setRange(i, 0, v)} placeholder="min" />
<NumberCell value={s.range?.[1]} onChange={(v) => setRange(i, 1, v)} placeholder="max" />
{s.range && <IconButton icon="close" label="Clear range" onClick={() => update(i, { range: undefined })} />}
</Flex>
</Cell>
</Table.Cell>
<Table.Cell><Cell><SelectCell value={s.convert?.method ?? "none"} options={CONVERT_METHODS} onChange={(v) => update(i, { convert: { ...s.convert, method: v as ConvertMethod } })} /></Cell></Table.Cell>
<Table.Cell>
<Cell>
Expand Down
2 changes: 1 addition & 1 deletion src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export type ActuatorType =
| "powered_gpio_device"
| "gpio_device"
| "motor";
export type ConvertMethod = "none" | "linear" | "polynomial";
export type ConvertMethod = "none" | "zero_offset" | "linear" | "polynomial";
export type ClientRole = "viewer" | "pad" | "operator" | "admin";

export type SensorBinding =
Expand Down
Loading