Derive machines from macro again

This time we also add get_machine_identification_unique.

Also fix import warnings
This commit is contained in:
Oshgnacknak committed 2025-10-02 13:58:54 +02:00
1 parent ffe0f09061
commit 0be18aaed0
14 files changed
+77 -97

No files matched your search

+6 -1
View File
@@ -40,10 +40,15 @@ fn machine_derive2(item: TokenStream2) -> Result<TokenStream2, Error> {
let ast: DeriveInput = syn::parse2(item)?;
let ident = &ast.ident;
let (impl_generics, ty_generics, where_clause) = ast.generics.split_for_impl();
let expanded = quote! {
impl #impl_generics control_core::machines::Machine for #ident #ty_generics #where_clause {}
impl #impl_generics control_core::machines::Machine for #ident #ty_generics #where_clause {
fn get_machine_identification_unique(&self) -> control_core::machines::identification::MachineIdentificationUnique {
self.machine_identification_unique.clone()
}
}
impl #impl_generics control_core::machines::AnyGetters for #ident #ty_generics #where_clause {
fn as_any(&self) -> &dyn std::any::Any {
+5
View File
@@ -16,3 +16,8 @@ pub mod registry;
pub trait Machine: MachineAct + MachineNewTrait + MachineApi + Any + Debug + Send + Sync {
fn get_machine_identification_unique(&self) -> MachineIdentificationUnique;
}
pub trait AnyGetters: Any {
fn as_any(&self) -> &dyn Any;
fn as_any_mut(&mut self) -> &mut dyn Any;
}
+4 -11
View File
@@ -1,11 +1,9 @@
use control_core::{
machines::{
Machine,
identification::{MachineIdentification, MachineIdentificationUnique},
},
machines::identification::{MachineIdentification, MachineIdentificationUnique},
socketio::namespace::NamespaceCacheingLogic,
};
use control_core_derive::Machine;
use serde::{Deserialize, Serialize};
use std::time::Instant;
use uom::si::{
@@ -80,7 +78,7 @@ impl Default for Flow {
}
}
#[derive(Debug)]
#[derive(Debug, Machine)]
pub struct AquaPathV1 {
machine_identification_unique: MachineIdentificationUnique,
namespace: AquaPathV1Namespace,
@@ -89,6 +87,7 @@ pub struct AquaPathV1 {
front_controller: Controller,
back_controller: Controller,
}
impl AquaPathV1 {
pub const MACHINE_IDENTIFICATION: MachineIdentification = MachineIdentification {
vendor: VENDOR_QITECH,
@@ -96,12 +95,6 @@ impl AquaPathV1 {
};
}
impl Machine for AquaPathV1 {
fn get_machine_identification_unique(&self) -> MachineIdentificationUnique {
self.machine_identification_unique.clone()
}
}
impl std::fmt::Display for AquaPathV1 {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "Aquapath")
+2 -8
View File
@@ -8,19 +8,19 @@ use buffer_tower_controller::BufferTowerController;
use control_core::machines::connection::{CrossConnectableMachine, MachineCrossConnection};
use control_core::{
machines::{
Machine,
identification::{MachineIdentification, MachineIdentificationUnique},
manager::MachineManager,
},
socketio::namespace::NamespaceCacheingLogic,
};
use control_core_derive::Machine;
use serde::{Deserialize, Serialize};
use smol::lock::RwLock;
use std::{sync::Weak, time::Instant};
use crate::machines::{MACHINE_BUFFER_V1, VENDOR_QITECH, winder2::Winder2};
#[derive(Debug)]
#[derive(Debug, Machine)]
pub struct BufferV1 {
// controllers
pub buffer_tower_controller: BufferTowerController,
@@ -40,12 +40,6 @@ pub struct BufferV1 {
mode: BufferV1Mode,
}
impl Machine for BufferV1 {
fn get_machine_identification_unique(&self) -> MachineIdentificationUnique {
self.machine_identification_unique.clone()
}
}
impl CrossConnectableMachine<BufferV1, Winder2> for BufferV1 {
fn get_cross_connection(&mut self) -> &mut MachineCrossConnection<BufferV1, Winder2> {
&mut self.connected_winder
+1
View File
@@ -3,6 +3,7 @@ use super::{ExtruderV2Mode, mitsubishi_cs80::MotorStatus};
#[cfg(not(feature = "mock-machine"))]
use super::ExtruderV2;
#[cfg(not(feature = "mock-machine"))]
use </