From a1d32b11302c8cce276bc921794c20f407ae560e Mon Sep 17 00:00:00 2001 From: aintercourse Date: Wed, 29 Mar 2023 08:12:57 +0300 Subject: [PATCH] many files, button test cycle --- Cargo.toml | 2 +- src/comport.rs | 117 ++++++++++ src/comport/oldprotocol.rs | 120 ++++++++++ src/lib.rs | 0 src/main.rs | 465 ++++++++++++++++--------------------- src/panelCalibration.rs | 29 +++ src/panelDiagnosis.rs | 16 ++ src/panelWorking.rs | 21 ++ 8 files changed, 504 insertions(+), 266 deletions(-) create mode 100644 src/comport.rs create mode 100644 src/comport/oldprotocol.rs create mode 100644 src/lib.rs create mode 100644 src/panelCalibration.rs create mode 100644 src/panelDiagnosis.rs create mode 100644 src/panelWorking.rs diff --git a/Cargo.toml b/Cargo.toml index e55a593..4aa53a4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,7 +6,7 @@ license = "MIT OR Apache-2.0" edition = "2021" rust-version = "1.61" publish = false - +feature = "dead_code" [dependencies] eframe = "0.21.3" diff --git a/src/comport.rs b/src/comport.rs new file mode 100644 index 0000000..dc15b53 --- /dev/null +++ b/src/comport.rs @@ -0,0 +1,117 @@ + +/******************************************************************************************************* + * ./src/comport.rs + * rustc v1.68.0 + * + *******************************************************************************************************/ + + #![allow(dead_code)] + +pub mod oldprotocol; +use std::sync::mpsc::{Receiver, Sender}; +use std::rc::Rc; +use std::sync::{mpsc, Arc, Mutex}; +use std::thread::ThreadId; +use std::{ + collections::btree_set::Union, + io::{self, ErrorKind}, + thread, + time::Duration, +}; +use serialport::{ClearBuffer, Error, Result, SerialPort}; + + +#[derive(PartialEq)] +#[repr(u8)] +enum PortMode { + Start, + Cycle, +} + +pub fn port_working_thread_init( + sender: Sender, + portname: String, + enabled: Receiver, +) -> ThreadId { + println!("{}", portname); + let res = thread::Builder::new() + .name("Connect to COM".to_string()) + .spawn(move || { + //тут ждать пока придёт сигнал от кнопки "подключиться" + println!("Попытка соединиться "); + let port_name = portname; + let port = serialport::new(&port_name, 9600) + .timeout(Duration::from_millis(100)) + .open(); + let mut port = match port { + Ok(port) => port, + Err(_) => { + eprintln!("Порт \"{}\" занят другой программой", port_name); + panic!() + } + }; + println!("Соединились"); + let limits = oldprotocol::get_mk_limits(&mut port); + println!("Limits: {limits:?}"); + loop { + let en = enabled.try_recv().ok(); + match en { + Some(en1) => { + println!("some {:?}", en1); + if en1 == false { + break; + } + } + None => (), + }; + + // if en == false { + // break;12 + // } + + // let data = get_mk_analog_data(&mut port); + // println!("Analog = {data:?}"); + // sender.send(data).ok(); + // let mode = get_mk_current_mode(&mut port); + // println!("Mode = {mode:?}"); + // for i in 0..=9 { + // let read_mode_data = get_mk_mode_data(&mut port, i); + // println!("Mode{i} = {read_mode_data:?}"); + // } + thread::sleep(Duration::from_millis(100)); + } + }) + .unwrap(); + let id = res.thread().id(); + id +} + +pub fn port_connection_thread_init(sender: Sender, portname: String) { + println!("{}", portname); + + let res = thread::Builder::new() + .name("Connect to COM".to_string()) + .spawn(move || { + //тут ждать пока придёт сигнал от кнопки "подключиться" + println!("Попытка соединиться "); + let port_name = portname; + let port = serialport::new(&port_name, 9600) + .timeout(Duration::from_millis(10)) + .open(); + let mut port = match port { + Ok(port) => port, + Err(_) => { + eprintln!("Порт \"{}\" занят другой программой", port_name); + panic!() + } + }; + println!("Соединились"); + let model = oldprotocol::get_mk_model(&mut port); + + println!("model = {:?}", model); + sender.send(model).ok(); + }) + .unwrap(); + res.join().ok(); + println!("Thread has stopped"); +} diff --git a/src/comport/oldprotocol.rs b/src/comport/oldprotocol.rs new file mode 100644 index 0000000..4cdd7c5 --- /dev/null +++ b/src/comport/oldprotocol.rs @@ -0,0 +1,120 @@ +/******************************************************************************************************* + * ./src/oldport.rs + * rustc v1.68.0 + *******************************************************************************************************/ + #![allow(dead_code)] + + use std::thread::ThreadId; + use std::{ + collections::btree_set::Union, + io::{self, ErrorKind}, + thread, + time::Duration, + }; + use serialport::{ClearBuffer, Error, Result, SerialPort}; + + +#[derive(Debug, Default, Clone, Copy)] +#[repr(C, packed)] +pub struct MK_AnalogData { + term: [f32; 4], + rrg: [f32; 6], + valve: [f32; 6], +} + +#[derive(Debug, Default, Clone, Copy)] +#[repr(C, packed)] +pub struct MK_Limits { + tmax: f32, + tmin: f32, + fmax: [f32; 6], + fmin: [f32; 6], +} + +#[derive(Debug, Clone, Copy, PartialEq)] +#[repr(u8)] +pub enum MKGazType { + Air, + Helium, + Nitrogen, +} + +impl Default for MKGazType { + fn default() -> Self { + MKGazType::Air + } +} + +#[derive(Debug, Default, Clone, Copy)] +#[repr(C, packed)] +pub struct MK_ModeData { + term: [f32; 4], + rrg: [f32; 6], + gaz_type: MKGazType, +} + +pub fn get_mk_data(port: &mut Box, cmd: &[u8]) -> [u8; 65] { + port.write_all(cmd).unwrap(); + thread::sleep(Duration::from_millis(100)); + let mut serial_buf = [0u8; 65]; + port.read(&mut serial_buf).ok(); + port.clear(ClearBuffer::Input).ok(); + serial_buf +} + +pub fn get_mk_model(port: &mut Box) -> u8 { + let data = get_mk_data(port, b"M"); + let res = 10 * data[0] as u8 + data[1] as u8; + res +} + +pub fn get_mk_analog_data(port: &mut Box) -> MK_AnalogData { + let data = get_mk_data(port, b"A"); + #[repr(C)] + union Union { + data: MK_AnalogData, + raw: [u8; 65], + } + let mut mk_data = unsafe { std::mem::zeroed::() }; + mk_data.raw = data; + let res = unsafe { mk_data.data }; + res +} + +pub fn get_mk_limits(port: &mut Box) -> MK_Limits { + let data = get_mk_data(port, b"B"); + #[repr(C)] + union Union { + data: MK_Limits, + raw: [u8; 65], + } + let mut mk_data = unsafe { std::mem::zeroed::() }; + mk_data.raw = data; + let res = unsafe { mk_data.data }; + res +} + +pub fn get_mk_current_mode(port: &mut Box) -> u8 { + let data = get_mk_data(port, b"R"); + let res = data[0]; + res +} + +pub fn get_mk_mode_data(port: &mut Box, mode: u8) -> MK_ModeData { + let mut cmd: [u8; 1] = [0u8; 1]; + if (mode >= 0) && (mode <= 9) { + cmd[0] = mode + 0x030; + } else { + cmd[0] = 0; + } + let data = get_mk_data(port, &cmd); + #[repr(C)] + union Union { + data: MK_ModeData, + raw: [u8; 65], + } + let mut mk_data = unsafe { std::mem::zeroed::() }; + mk_data.raw = data; + let res = unsafe { mk_data.data }; + res +} \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..e69de29 diff --git a/src/main.rs b/src/main.rs index 0f3fbc3..936766b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,18 @@ -//! Show a custom window frame instead of the default OS window chrome decorations. +/****************************************************************************************************** + * ./src/main.rs + * eframe v0.21.3 + * rustc v1.68.0 + * ! Show a custom window frame instead of the default OS window chrome decorations. + ******************************************************************************************************/ #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release +//#![allow(unused_variables)] +#![allow(unused)] +use eframe::{ + egui::{self, Button, RichText}, + epaint::Vec2, +}; use local_encoding::{Encoder, Encoding}; use std::rc::Rc; use std::sync::mpsc::{Receiver, Sender}; @@ -13,28 +24,54 @@ use std::{ thread, time::Duration, }; +mod comport; +use crate::comport::oldprotocol; +mod panelCalibration; +mod panelDiagnosis; +mod panelMode; +mod panelWorking; -use eframe::{ - egui::{self, Button, RichText}, - epaint::Vec2, -}; -use serialport::{ClearBuffer, Error, Result, SerialPort}; +//----------custom types------------------------------------------------------------------------// + +#[repr(u8)] +#[derive(Debug, Clone, Copy, PartialEq)] +enum ConnectionStatus { + Disconnected, + Connecting, + Connected, + ConnectionError, +} +impl Default for ConnectionStatus { + fn default() -> Self { + ConnectionStatus::Disconnected + } +} + +#[repr(u8)] +#[derive(Debug, Clone, Copy, PartialEq)] +enum WorkStatus { + Stop, + Run, + Cycle, +} +impl Default for WorkStatus { + fn default() -> Self { + WorkStatus::Stop + } +} -//custom types #[repr(u8)] #[derive(Debug, Clone, Copy, PartialEq)] enum ScreenCurrent { Config, - CheckStatus, + Working, Diagnosis, - WorkCycle, PortSelection, - CalibrationStend, + Calibration, } - impl Default for ScreenCurrent { fn default() -> Self { - ScreenCurrent::PortSelection + ScreenCurrent::Config } } #[derive(Debug)] @@ -45,7 +82,7 @@ struct Screen { #[derive(Debug)] struct ScreenSelector { - screen: [Screen; 6], + screen: [Screen; 5], } impl Default for ScreenSelector { @@ -54,26 +91,22 @@ impl Default for ScreenSelector { screen: [ Screen { id: (ScreenCurrent::Config), - name: ("Конфигурация работы".to_string()), + name: ("Конфигурация".to_string()), }, Screen { - id: (ScreenCurrent::CheckStatus), - name: ("Просмотр состояния".to_string()), + id: (ScreenCurrent::Working), + name: ("Работа".to_string()), }, Screen { id: (ScreenCurrent::Diagnosis), name: ("Диагностика".to_string()), }, - Screen { - id: (ScreenCurrent::WorkCycle), - name: ("Работа по циклу".to_string()), - }, Screen { id: (ScreenCurrent::PortSelection), name: ("Выбор порта".to_string()), }, Screen { - id: (ScreenCurrent::CalibrationStend), + id: (ScreenCurrent::Calibration), name: ("Калибровочный стенд".to_string()), }, ], @@ -81,50 +114,6 @@ impl Default for ScreenSelector { } } -#[derive(Debug, Default, Clone, Copy)] -#[repr(C, packed)] -struct MK_AnalogData { - term: [f32; 4], - rrg: [f32; 6], - valve: [f32; 6], -} - -#[derive(Debug, Default, Clone, Copy)] -#[repr(C, packed)] -struct MK_Limits { - tmax: f32, - tmin: f32, - fmax: [f32; 6], - fmin: [f32; 6], -} - -#[derive(Debug, Clone, Copy, PartialEq)] -#[repr(u8)] -enum MKGazType { - Air, - Helium, - Nitrogen, -} - -impl Default for MKGazType { - fn default() -> Self { - MKGazType::Air - } -} - -#[derive(Debug, Default, Clone, Copy)] -#[repr(C, packed)] -struct MK_ModeData { - term: [f32; 4], - rrg: [f32; 6], - gaz_type: MKGazType, -} -#[derive(PartialEq)] -#[repr(u8)] -enum PortMode { - Start, - Cycle, -} fn main() { let port = serialport::available_ports().unwrap(); @@ -134,7 +123,8 @@ fn main() { // To have rounded corners we need transparency: transparent: true, default_theme: eframe::Theme::Dark, - min_window_size: Some(egui::vec2(320.0, 100.0)), + //min_window_size: Some(egui::vec2(360.0, 60.0)), + initial_window_size: Some(egui::vec2(790.0, 400.0)), ..Default::default() }; eframe::run_native( @@ -146,13 +136,17 @@ fn main() { ..Default::default() }) }), - ).unwrap(); + ) + .unwrap(); } #[derive(Default)] + struct MyApp { + is_working: WorkStatus, + is_connected: ConnectionStatus, enabled: bool, - is_connected: bool, + // is_connected: bool, screen_current: ScreenCurrent, screens: ScreenSelector, ports: Vec, @@ -164,18 +158,20 @@ struct MyApp { impl eframe::App for MyApp { fn clear_color(&self, _visuals: &egui::Visuals) -> [f32; 4] { [0.0f32; 4] // Make sure we don't paint anything behind the rounded corners - // egui::Rgba::TRANSPARENT; + // egui::Rgba::TRANSPARENT; } fn update(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame) { let (tx, rx): (Sender, Receiver) = mpsc::channel(); - let (c_tx, c_rx): (Sender, Receiver) = mpsc::channel(); + let (c_tx, c_rx): ( + Sender, + Receiver, + ) = mpsc::channel(); let (en_tx, en_rx): (Sender, Receiver) = mpsc::channel(); let en = self.enabled.clone(); // println!("global={:?}",en); let en_mtx = Arc::new(Mutex::new(en)); - let mut mdl = "".to_string(); if self.model == 0 { @@ -183,32 +179,32 @@ impl eframe::App for MyApp { } else { mdl = self.model.to_string() } - if self.is_connected == true && self.enabled == false { - self.is_connected = false; - println!("Disable!"); - let a_mtx = Arc::clone(&en_mtx); - let en1_tx = en_tx.clone(); - thread::spawn(move||loop{ - let en = a_mtx.lock().unwrap(); - // println!("{:?}",en); - en1_tx.send(true).ok(); - thread::sleep(Duration::from_millis(100)); - }); - } - if self.is_connected == true && self.enabled { - self.is_connected = false; - let portname = self.ports[self.port_current_idx].port_name.as_str(); - let id = port_working_thread_init(c_tx, portname.to_string(), en_rx); - println!("{:?}", id); - // let a_mtx = Arc::clone(&en_mtx); - let en1_tx = en_tx.clone(); - // thread::spawn(move||loop{ - // // let en = a_mtx.lock().unwrap(); - - // en1_tx.send(true).ok(); - // thread::sleep(Duration::from_millis(100)); - // }); - } + // if self.is_connected == ConnectionStatus::Connected && self.enabled == false { + // self.is_connected = ConnectionStatus::Disconnected; + // println!("Disable!"); + // let a_mtx = Arc::clone(&en_mtx); + // let en1_tx = en_tx.clone(); + // thread::spawn(move || loop { + // let en = a_mtx.lock().unwrap(); + // // println!("{:?}",en); + // en1_tx.send(true).ok(); + // thread::sleep(Duration::from_millis(100)); + // }); + // } + // if self.is_connected == ConnectionStatus::Connected && self.enabled { + // self.is_connected = ConnectionStatus::Disconnected; + // let portname = self.ports[self.port_current_idx].port_name.as_str(); + // let id = comport::port_working_thread_init(c_tx, portname.to_string(), en_rx); + // println!("{:?}", id); + // // let a_mtx = Arc::clone(&en_mtx); + // let en1_tx = en_tx.clone(); + // // thread::spawn(move||loop{ + // // // let en = a_mtx.lock().unwrap(); + + // // en1_tx.send(true).ok(); + // // thread::sleep(Duration::from_millis(100)); + // // }); + // } let title = format!("Микрогаз-ФМ{}", mdl); custom_window_frame(ctx, frame, title.as_str(), |ui| { @@ -220,14 +216,12 @@ impl eframe::App for MyApp { // println!("Update"); self.connect_screen(ui, tx, rx) } - ScreenCurrent::CalibrationStend => { - - }, + ScreenCurrent::Config => panelMode::mode_screen(ctx, ui, tx, rx), + ScreenCurrent::Calibration => panelCalibration::calibration_screen(ctx, ui, tx, rx), _ => (), } }); } - } impl MyApp { @@ -236,11 +230,12 @@ impl MyApp { .default_width(200.0) .resizable(false) .show_inside(ui, |ui| { - ui.vertical_centered(|ui| { - ui.heading("Микрогаз"); - }); + //ui.vertical_centered(|ui| { + // ui.heading("Микрогаз"); + //}); ui.vertical(|ui| { + // buttons on left panel in cycle for screen in self.screens.screen.iter() { if ui .add_sized(Vec2::new(200.0, 24.0), Button::new(screen.name.as_str())) @@ -250,11 +245,106 @@ impl MyApp { println!("{:#?}", self.screen_current); }; } + // free space + + let mut enable_button: bool; + let mut lable_title = String::from("Сотояние ожидпния"); + let mut button_title = String::from("ПУСК"); + match self.is_working { + WorkStatus::Cycle => { + lable_title = String::from("Запущен цикл"); + button_title = String::from("СТОП"); + } + WorkStatus::Run => { + lable_title = String::from("Запущен режим"); + button_title = String::from("СТОП"); + } + WorkStatus::Stop => { + lable_title = String::from("Ожидание"); + button_title = String::from("ПУСК"); + } + _ => (), + } + // label WorkaStatus TODO:icon WorkaStatus + ui.add_sized( + [220.0, 40.0], + egui::Label::new( + egui::RichText::new(lable_title.clone()) + .font(egui::FontId::monospace(35.0)), + ) + .wrap(true), + ); + + // button start/stop + ui.add_enabled_ui(self.is_connected == ConnectionStatus::Connected, |ui| { + if ui + .add_sized(Vec2::new(200.0, 24.0), Button::new(button_title.clone())) + //.sized(Vec2::new(200.0, 24.0)) + .clicked() + { + println!("{:#?}", lable_title); + if self.is_working == WorkStatus::Stop { + self.is_working = WorkStatus::Run; + } else { + self.is_working = WorkStatus::Stop; + } + }; + }); + + match self.is_connected { + ConnectionStatus::Disconnected => { + lable_title = String::from("Отключено"); + button_title = String::from("Подключить"); + } + ConnectionStatus::Connecting => { + lable_title = String::from("Подключение..."); + button_title = String::from("Отмена"); + } + ConnectionStatus::Connected => { + lable_title = String::from("Подключено"); + button_title = String::from("Отключить"); + } + ConnectionStatus::ConnectionError => { + lable_title = String::from("Ошибка подключения"); + button_title = String::from("Подключить"); + } + _ => (), + } + // label ConnectionStatus TODO:icon ConnectionStatus + ui.add_sized( + [220.0, 40.0], + egui::Label::new( + egui::RichText::new(lable_title.clone()) + .font(egui::FontId::monospace(35.0)), + ) + .wrap(true), + ); + + // button connect/disconnect + if ui + .add_sized(Vec2::new(200.0, 24.0), Button::new(button_title.clone())) + // .enabled(self.is_connected != ConnectionStatus::Connected) + .clicked() + { + println!("{:#?}", lable_title); + if self.is_connected == ConnectionStatus::Connected // || + //self.is_connected == ConnectionStatus::Connecting + { + self.is_connected = ConnectionStatus::Disconnected; + self.is_working = WorkStatus::Stop; + } else { + if self.is_connected == ConnectionStatus::Disconnected { + self.is_connected = ConnectionStatus::Connecting; + } else { + if self.is_connected == ConnectionStatus::Connecting { + self.is_connected = ConnectionStatus::Connected; + }}} + }; }); }); } - fn connect_screen(&mut self, ui: &mut egui::Ui, snd: Sender, rx: Receiver) { + pub fn connect_screen(&mut self, ui: &mut egui::Ui, snd: Sender, rx: Receiver) { let tx = snd; egui::CentralPanel::default().show_inside(ui, |ui| { // CollapsingHeader::new("Соединение:").default_open(false).show(ui,|ui|{ @@ -289,11 +379,11 @@ impl MyApp { println!("Button {:?}", self.enabled); if self.enabled == true { self.enabled = false; - self.is_connected = true; + self.is_connected = ConnectionStatus::Connected; } else { let portname = self.ports[self.port_current_idx].port_name.as_str(); - port_connection_thread_init(tx, portname.to_string()); + comport::port_connection_thread_init(tx, portname.to_string()); let res = match rx.recv_timeout(Duration::from_millis(10)).ok() { Some(u) => u, @@ -305,7 +395,7 @@ impl MyApp { self.enabled = false; } else { self.enabled = true; - self.is_connected = true; + self.is_connected = ConnectionStatus::Connected; } } } @@ -337,7 +427,7 @@ fn custom_window_frame( CentralPanel::default() .frame(Frame::none()) .show(ctx, |ui| { - let rect = Rect::from_min_max(pos2(0.0, 0.0), pos2(640.0, 300.0)); + let rect = Rect::from_min_max(pos2(0.0, 0.0), pos2(790.0, 400.0)); // ui.clip_rect(); let painter = ui.painter(); @@ -380,11 +470,10 @@ fn custom_window_frame( frame.drag_window(); } - // Add the close button: let close_response = ui.put( Rect::from_min_size(rect.right_top() - vec2(height, 0.0), Vec2::splat(height)), - Button::new(RichText::new("❌").size(height-4.0)).frame(false), + Button::new(RichText::new("❌").size(height - 4.0)).frame(false), ); if close_response.clicked() { frame.close(); @@ -401,157 +490,3 @@ fn custom_window_frame( add_contents(&mut content_ui); }); } - -fn port_working_thread_init( - sender: Sender, - portname: String, - enabled: Receiver, -) -> ThreadId { - println!("{}", portname); - let res = thread::Builder::new() - .name("Connect to COM".to_string()) - .spawn(move || { - //тут ждать пока придёт сигнал от кнопки "подключиться" - println!("Попытка соединиться "); - let port_name = portname; - let port = serialport::new(&port_name, 9600) - .timeout(Duration::from_millis(100)) - .open(); - let mut port = match port { - Ok(port) => port, - Err(_) => { - eprintln!("Порт \"{}\" занят другой программой", port_name); - panic!() - } - }; - println!("Соединились"); - let limits = get_mk_limits(&mut port); - println!("Limits: {limits:?}"); - loop { - let en = enabled.try_recv().ok(); - match en { - Some(en1) => { - println!("some {:?}", en1); - if en1 == false { - break; - } - } - None => (), - }; - - // if en == false { - // break; - // } - - // let data = get_mk_analog_data(&mut port); - // println!("Analog = {data:?}"); - // sender.send(data).ok(); - // let mode = get_mk_current_mode(&mut port); - // println!("Mode = {mode:?}"); - // for i in 0..=9 { - // let read_mode_data = get_mk_mode_data(&mut port, i); - // println!("Mode{i} = {read_mode_data:?}"); - // } - thread::sleep(Duration::from_millis(100)); - } - }) - .unwrap(); - let id = res.thread().id(); - id -} - -fn port_connection_thread_init(sender: Sender, portname: String) { - println!("{}", portname); - - let res = thread::Builder::new() - .name("Connect to COM".to_string()) - .spawn(move || { - //тут ждать пока придёт сигнал от кнопки "подключиться" - println!("Попытка соединиться "); - let port_name = portname; - let port = serialport::new(&port_name, 9600) - .timeout(Duration::from_millis(10)) - .open(); - let mut port = match port { - Ok(port) => port, - Err(_) => { - eprintln!("Порт \"{}\" занят другой программой", port_name); - panic!() - } - }; - println!("Соединились"); - let model = get_mk_model(&mut port); - - println!("model = {:?}", model); - sender.send(model).ok(); - }) - .unwrap(); - res.join().ok(); - println!("Thread has stopped"); -} - -fn get_mk_data(port: &mut Box, cmd: &[u8]) -> [u8; 65] { - port.write_all(cmd).unwrap(); - thread::sleep(Duration::from_millis(100)); - let mut serial_buf = [0u8; 65]; - port.read(&mut serial_buf).ok(); - port.clear(ClearBuffer::Input).ok(); - serial_buf -} - -fn get_mk_model(port: &mut Box) -> u8 { - let data = get_mk_data(port, b"M"); - let res = 10 * data[0] as u8 + data[1] as u8; - res -} - -fn get_mk_analog_data(port: &mut Box) -> MK_AnalogData { - let data = get_mk_data(port, b"A"); - #[repr(C)] - union Union { - data: MK_AnalogData, - raw: [u8; 65], - } - let mut mk_data = unsafe { std::mem::zeroed::() }; - mk_data.raw = data; - let res = unsafe { mk_data.data }; - res -} - -fn get_mk_limits(port: &mut Box) -> MK_Limits { - let data = get_mk_data(port, b"B"); - #[repr(C)] - union Union { - data: MK_Limits, - raw: [u8; 65], - } - let mut mk_data = unsafe { std::mem::zeroed::() }; - mk_data.raw = data; - let res = unsafe { mk_data.data }; - res -} - -fn get_mk_current_mode(port: &mut Box) -> u8 { - let data = get_mk_data(port, b"R"); - let res = data[0]; - res -} - -fn get_mk_mode_data(port: &mut Box, mode: u8) -> MK_ModeData { - let mut cmd: [u8; 1] = [0u8; 1]; - if (mode >= 0) && (mode <= 9) { - cmd[0] = mode + 0x030; - } else { - cmd[0] = 0; - } - let data = get_mk_data(port, &cmd); - #[repr(C)] - union Union { - data: MK_ModeData, - raw: [u8; 65], - } - let mut mk_data = unsafe { std::mem::zeroed::() }; - mk_data.raw = data; - let res = unsafe { mk_data.data }; - res -} diff --git a/src/panelCalibration.rs b/src/panelCalibration.rs new file mode 100644 index 0000000..bad3af7 --- /dev/null +++ b/src/panelCalibration.rs @@ -0,0 +1,29 @@ + + +#![allow(dead_code)] + +use std::sync::mpsc::{Receiver, Sender}; +use std::{ + collections::btree_set::Union, + io::{self, ErrorKind}, +}; +use eframe::{ + egui::{self, Button, RichText}, + epaint::Vec2, +}; + +pub fn calibration_screen( ctx: &egui::Context, ui: &mut egui::Ui, snd: Sender, rx: Receiver) { + egui::CentralPanel::default().show_inside( ui, |ui| { + ui.add_sized( + [330.0, 70.0], + egui::Label::new( + egui::RichText::new("expression") + .font(egui::FontId::monospace(25.0)) + ).wrap(true), + ); + ui.add_sized( + [120.0, 30.0], + egui::Button::new("expression").small(), + ); + }); +} \ No newline at end of file diff --git a/src/panelDiagnosis.rs b/src/panelDiagnosis.rs new file mode 100644 index 0000000..0ab41c8 --- /dev/null +++ b/src/panelDiagnosis.rs @@ -0,0 +1,16 @@ + + +#![allow(dead_code)] + +use std::sync::mpsc::{Receiver, Sender}; +use std::{ + collections::btree_set::Union, + io::{self, ErrorKind}, +}; +use eframe::{ + egui::{self, Button, RichText}, + epaint::Vec2, +}; + +pub fn diagnosis_screen( ctx: &egui::Context, ui: &mut egui::Ui, snd: Sender, rx: Receiver) { +} \ No newline at end of file diff --git a/src/panelWorking.rs b/src/panelWorking.rs new file mode 100644 index 0000000..ba116cd --- /dev/null +++ b/src/panelWorking.rs @@ -0,0 +1,21 @@ + + +#![allow(dead_code)] + +use std::sync::mpsc::{Receiver, Sender}; +use std::rc::Rc; +use std::sync::{mpsc, Arc, Mutex}; +use std::thread::ThreadId; +use std::{ + collections::btree_set::Union, + io::{self, ErrorKind}, + thread, + time::Duration, +}; +use eframe::{ + egui::{self, Button, RichText}, + epaint::Vec2, +}; + +pub fn working_screen( ctx: &egui::Context, ui: &mut egui::Ui, snd: Sender, rx: Receiver) { +} \ No newline at end of file