Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mecademic hardware UI Integration #903

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions captain/routes/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ async def get_devices():
cameras=device_finder.get_cameras(),
serialDevices=device_finder.get_serial_devices(),
visaDevices=device_finder.get_visa_devices(),
mecademicDevices=device_finder.get_mecademic_devices(),
)
7 changes: 6 additions & 1 deletion captain/services/hardware.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import subprocess
from sys import platform

from captain.types.devices import CameraDevice, SerialDevice, VISADevice
from captain.types.devices import CameraDevice, SerialDevice, VISADevice, MecademicDevice

__all__ = ["get_device_finder"]

Expand Down Expand Up @@ -60,6 +60,11 @@ def get_visa_devices(self) -> list[VISADevice]:

return devices

def get_mecademic_devices(self) -> list[MecademicDevice]:
"""Returns a list of Mecademic devices connected to the system."""
devices = [MecademicDevice(name="Flojoy's Mecademic Meca500", ip="192.168.0.100")]
return devices


class LinuxDeviceFinder(DefaultDeviceFinder):
def get_cameras(self) -> list[CameraDevice]:
Expand Down
6 changes: 6 additions & 0 deletions captain/types/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@ class VISADevice(BaseModel):
description: str


class MecademicDevice(BaseModel):
name: str
ip: str


class DeviceInfo(BaseModel):
cameras: list[CameraDevice]
serialDevices: list[SerialDevice]
visaDevices: list[VISADevice]
mecademicDevices: list[MecademicDevice]
1 change: 1 addition & 0 deletions captain/utils/manifest/build_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
SerialDevice,
VisaDevice,
CameraConnection,
MecademicConnection,
SerialConnection,
VisaConnection,
]
Expand Down
1 change: 1 addition & 0 deletions src/feature/common/types/ParamValueType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ export type ParamValueType =
| "CameraConnection"
| "SerialConnection"
| "VisaConnection"
| "MecademicConnection"
| "unknown";
10 changes: 10 additions & 0 deletions src/feature/device_panel/components/HardwareInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ export const HardwareInfo = () => {
}))
: undefined;

const mecademicDevices: DeviceCardProps[] | undefined =
devices.mecademicDevices.length > 0
? devices.mecademicDevices.map((d) => ({
name: d.name,
port: d.ip,
}))
: undefined;

return (
<div>
<Button onClick={refetch}>Refresh</Button>
Expand All @@ -62,6 +70,8 @@ export const HardwareInfo = () => {
<DeviceSection title="Serial" devices={serialDevices} />
<div className="py-6" />
<DeviceSection title="VISA" devices={visaDevices} />
<div className="py-6" />
<DeviceSection title="Mecademic" devices={mecademicDevices} />
</div>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { useHardwareDevices } from "@src/hooks/useHardwareDevices";
import { DeviceSelect, SelectProps } from "./DeviceSelect";

export const MecademicDeviceSelect = (props: SelectProps) => {
const hardware = useHardwareDevices();
const mecas = hardware?.mecademicDevices;

return (
<DeviceSelect
{...props}
devices={mecas}
placeholder="No cameras found"
keySelector={(meca) => meca.ip.toString()}
valueSelector={(meca) => meca.ip.toString()}
nameSelector={(meca) => meca.name}
/>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import { useHasUnsavedChanges } from "@src/hooks/useHasUnsavedChanges";
import { CameraSelect } from "./CameraSelect";
import { SerialDeviceSelect } from "./SerialDeviceSelect";
import { VisaDeviceSelect } from "./VisaDeviceSelect";
import React from "react";
import { MecademicDeviceSelect } from "@feature/flow_chart_panel/components/node-edit-menu/MecademicDeviceSelect";

type ParamFieldProps = {
nodeId: string;
Expand Down Expand Up @@ -129,6 +131,8 @@ const ParamField = ({
case "VisaDevice":
case "VisaConnection":
return <VisaDeviceSelect onValueChange={handleChange} value={value} />;
case "MecademicConnection":
return <MecademicDeviceSelect onValueChange={handleChange} value={value} />;
case "str":
case "list[int]":
case "list[float]":
Expand Down
6 changes: 6 additions & 0 deletions src/hooks/useHardwareDevices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,18 @@ const VISADevice = z.object({
description: z.string(),
});

const MecademicDevice = z.object({
ip: z.string(),
name: z.string(),
});

type VISADevice = z.infer<typeof VISADevice>;

const DeviceInfo = z.object({
cameras: z.array(CameraDevice),
serialDevices: z.array(SerialDevice),
visaDevices: z.array(VISADevice),
mecademicDevices: z.array(MecademicDevice),
});

type DeviceInfo = z.infer<typeof DeviceInfo>;
Expand Down