Files
qitech-control/docs/developer-docs/adding-a-machine.md
T

3.9 KiB
Raw Blame History

How can I add a new Machine?

Adding a new machine follows a common structure in server/machines/.

TLDR

Summary

When adding a new machine:

  • Create Folder server/machines/YOUR_MACHINE_NAME/.
  • Add the 4 files (mod.rs, new.rs, act.rs, api.rs).
  • Register it in machines/mod.rs with a unique constant.
  • mod.rs: define the struct + emit functions.
  • new.rs: assemble devices/controllers into the machine.
  • act.rs: implement the machine loop (MachineAct).
  • api.rs: define request (mutations) and response (events) types.

Tip: Start simple (copy MockMachine) and grow complexity as needed (add EtherCAT devices, controllers, etc.).


1. Create the folder

Create a new directory: server/machines/YOUR_MACHINE_NAME

At a minimum, this folder needs the following files:

  • mod.rs
  • new.rs
  • act.rs
  • api.rs

2. Register the module

Add your machine to server/machines/mod.rs:

// mod.rs
pub mod buffer1;
pub mod extruder1;
pub mod laser;
pub mod mock;
pub mod registry;
pub mod winder2;
pub mod YOUR_MACHINE;

pub const VENDOR_QITECH: u16 = 0x0001;
pub const MACHINE_WINDER_V1: u16 = 0x0002;
pub const MACHINE_EXTRUDER_V1: u16 = 0x0004;
pub const MACHINE_LASER_V1: u16 = 0x0006;
pub const MACHINE_MOCK: u16 = 0x0007;
pub const MACHINE_BUFFER_V1: u16 = 0x0008;
pub const YOUR_MACHINE_V1: u16 = 0xffff; // pick a unique ID to avoid collisions also DO NOT touch any already defined ids!!

3. mod.rs

This file defines your machine struct and the required event emitters.

Look at MockMachine’s mod.rs for the simplest possible version.

At a min