fading-tail #2
126
Cargo.lock
generated
126
Cargo.lock
generated
@@ -1,6 +1,6 @@
|
|||||||
# This file is automatically @generated by Cargo.
|
# This file is automatically @generated by Cargo.
|
||||||
# It is not intended for manual editing.
|
# It is not intended for manual editing.
|
||||||
version = 3
|
version = 4
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "adler2"
|
name = "adler2"
|
||||||
@@ -32,6 +32,12 @@ version = "1.3.2"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
|
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bitflags"
|
||||||
|
version = "2.6.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bytemuck"
|
name = "bytemuck"
|
||||||
version = "1.18.0"
|
version = "1.18.0"
|
||||||
@@ -56,6 +62,12 @@ version = "1.1.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b"
|
checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "core-foundation-sys"
|
||||||
|
version = "0.8.7"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "crc32fast"
|
name = "crc32fast"
|
||||||
version = "1.4.2"
|
version = "1.4.2"
|
||||||
@@ -122,12 +134,51 @@ dependencies = [
|
|||||||
"png",
|
"png",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "io-kit-sys"
|
||||||
|
version = "0.4.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "617ee6cf8e3f66f3b4ea67a4058564628cde41901316e19f559e14c7c72c5e7b"
|
||||||
|
dependencies = [
|
||||||
|
"core-foundation-sys",
|
||||||
|
"mach2",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libc"
|
name = "libc"
|
||||||
version = "0.2.159"
|
version = "0.2.159"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "561d97a539a36e26a9a5fad1ea11a3039a67714694aaa379433e580854bc3dc5"
|
checksum = "561d97a539a36e26a9a5fad1ea11a3039a67714694aaa379433e580854bc3dc5"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "libudev"
|
||||||
|
version = "0.3.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "78b324152da65df7bb95acfcaab55e3097ceaab02fb19b228a9eb74d55f135e0"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
"libudev-sys",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "libudev-sys"
|
||||||
|
version = "0.1.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3c8469b4a23b962c1396b9b451dda50ef5b283e8dd309d69033475fa9b334324"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
"pkg-config",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "mach2"
|
||||||
|
version = "0.4.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "19b955cdeb2a02b9117f121ce63aa52d08ade45de53e48fe6a38b39c10f6f709"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "macroquad"
|
name = "macroquad"
|
||||||
version = "0.4.13"
|
version = "0.4.13"
|
||||||
@@ -186,6 +237,17 @@ version = "0.2.2"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "e1bcdd74c20ad5d95aacd60ef9ba40fdf77f767051040541df557b7a9b2a2121"
|
checksum = "e1bcdd74c20ad5d95aacd60ef9ba40fdf77f767051040541df557b7a9b2a2121"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "nix"
|
||||||
|
version = "0.26.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "598beaf3cc6fdd9a5dfb1630c2800c7acd31df7aaf0f565796fba2b53ca1af1b"
|
||||||
|
dependencies = [
|
||||||
|
"bitflags 1.3.2",
|
||||||
|
"cfg-if",
|
||||||
|
"libc",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "num-traits"
|
name = "num-traits"
|
||||||
version = "0.2.19"
|
version = "0.2.19"
|
||||||
@@ -213,13 +275,19 @@ dependencies = [
|
|||||||
"portable-atomic",
|
"portable-atomic",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "pkg-config"
|
||||||
|
version = "0.3.31"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "png"
|
name = "png"
|
||||||
version = "0.17.14"
|
version = "0.17.14"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "52f9d46a34a05a6a57566bc2bfae066ef07585a6e3fa30fbbdff5936380623f0"
|
checksum = "52f9d46a34a05a6a57566bc2bfae066ef07585a6e3fa30fbbdff5936380623f0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags",
|
"bitflags 1.3.2",
|
||||||
"crc32fast",
|
"crc32fast",
|
||||||
"fdeflate",
|
"fdeflate",
|
||||||
"flate2",
|
"flate2",
|
||||||
@@ -246,6 +314,7 @@ name = "quad"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"macroquad",
|
"macroquad",
|
||||||
|
"serialport",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -263,6 +332,30 @@ dependencies = [
|
|||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "scopeguard"
|
||||||
|
version = "1.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "serialport"
|
||||||
|
version = "4.5.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3ba776acc8c373b9175829206229366273225436845c04f9c20aab8099960e2e"
|
||||||
|
dependencies = [
|
||||||
|
"bitflags 2.6.0",
|
||||||
|
"cfg-if",
|
||||||
|
"core-foundation-sys",
|
||||||
|
"io-kit-sys",
|
||||||
|
"libudev",
|
||||||
|
"mach2",
|
||||||
|
"nix",
|
||||||
|
"scopeguard",
|
||||||
|
"unescaper",
|
||||||
|
"winapi",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "simd-adler32"
|
name = "simd-adler32"
|
||||||
version = "0.3.7"
|
version = "0.3.7"
|
||||||
@@ -289,12 +382,41 @@ dependencies = [
|
|||||||
"unicode-ident",
|
"unicode-ident",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "thiserror"
|
||||||
|
version = "1.0.64"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d50af8abc119fb8bb6dbabcfa89656f46f84aa0ac7688088608076ad2b459a84"
|
||||||
|
dependencies = [
|
||||||
|
"thiserror-impl",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "thiserror-impl"
|
||||||
|
version = "1.0.64"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "08904e7672f5eb876eaaf87e0ce17857500934f4981c4a0ab2b4aa98baac7fc3"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ttf-parser"
|
name = "ttf-parser"
|
||||||
version = "0.15.2"
|
version = "0.15.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "7b3e06c9b9d80ed6b745c7159c40b311ad2916abb34a49e9be2653b90db0d8dd"
|
checksum = "7b3e06c9b9d80ed6b745c7159c40b311ad2916abb34a49e9be2653b90db0d8dd"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "unescaper"
|
||||||
|
version = "0.1.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c878a167baa8afd137494101a688ef8c67125089ff2249284bd2b5f9bfedb815"
|
||||||
|
dependencies = [
|
||||||
|
"thiserror",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "unicode-ident"
|
name = "unicode-ident"
|
||||||
version = "1.0.13"
|
version = "1.0.13"
|
||||||
|
|||||||
@@ -5,3 +5,4 @@ edition = "2021"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
macroquad = "0.4.13"
|
macroquad = "0.4.13"
|
||||||
|
serialport = "4.5.1"
|
||||||
|
|||||||
77
src/main.rs
77
src/main.rs
@@ -1,10 +1,10 @@
|
|||||||
use core::f32;
|
use core::f32;
|
||||||
use std::io::stdin;
|
use std::{io::stdin, time::Duration};
|
||||||
|
|
||||||
use macroquad::prelude::*;
|
use macroquad::prelude::*;
|
||||||
|
|
||||||
const THICKNESS: f32 = 2.0;
|
const THICKNESS: f32 = 2.0;
|
||||||
const TAIL_LEN: usize = 250;
|
const TAIL_LEN: usize = 500;
|
||||||
|
|
||||||
#[derive(Clone,Copy, PartialEq)]
|
#[derive(Clone,Copy, PartialEq)]
|
||||||
struct Point {
|
struct Point {
|
||||||
@@ -61,10 +61,10 @@ struct Tail {
|
|||||||
px_per_s: f32,
|
px_per_s: f32,
|
||||||
}
|
}
|
||||||
impl Tail {
|
impl Tail {
|
||||||
fn new(axis: Axis) -> Self {
|
fn new(axis: Axis, y_axis_offset: f32) -> Self {
|
||||||
let (x_offset, y_offset) = match axis {
|
let (x_offset, y_offset) = match axis {
|
||||||
Axis::One => (0., screen_height() /2.),
|
Axis::One => (0., y_axis_offset),
|
||||||
Axis::Two => (screen_width() /2., screen_height() /2.),
|
Axis::Two => (screen_width() /2., y_axis_offset),
|
||||||
};
|
};
|
||||||
Self {
|
Self {
|
||||||
// start all the dots off screen
|
// start all the dots off screen
|
||||||
@@ -73,7 +73,7 @@ impl Tail {
|
|||||||
axis,
|
axis,
|
||||||
x_offset,
|
x_offset,
|
||||||
y_offset,
|
y_offset,
|
||||||
px_per_s: 1000.,
|
px_per_s: 750.,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn place_next(&mut self, delta_time: f32, x_displace: f32, y_displace: f32) {
|
fn place_next(&mut self, delta_time: f32, x_displace: f32, y_displace: f32) {
|
||||||
@@ -147,9 +147,10 @@ impl Tail {
|
|||||||
#[macroquad::main("Graph")]
|
#[macroquad::main("Graph")]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
// Dot params
|
// Dot params
|
||||||
let mut y_displacement = 0.;
|
let realtive_y_origin =screen_height()*0.75;
|
||||||
let mut x_displacement = 0.;
|
// FIXME realtive_x_origin doesn't work yet
|
||||||
let mut tail = Tail::new(Axis::One);
|
let realtive_x_origin =0.;
|
||||||
|
let mut tail = Tail::new(Axis::One, realtive_y_origin);
|
||||||
|
|
||||||
// Selection box
|
// Selection box
|
||||||
let mut inital_x_pos = 0.;
|
let mut inital_x_pos = 0.;
|
||||||
@@ -158,17 +159,60 @@ async fn main() {
|
|||||||
// Tooling
|
// Tooling
|
||||||
let mut show_debug = true;
|
let mut show_debug = true;
|
||||||
|
|
||||||
let stdin = stdin();
|
// Serial
|
||||||
let handle= stdin.lock();
|
let port = serialport::available_ports()
|
||||||
|
.expect("No ports found!")
|
||||||
|
.iter()
|
||||||
|
.filter(|x| x.port_name.contains("ACM"))
|
||||||
|
.fold(None, |_, x| {
|
||||||
|
let x = serialport::new(x.port_name.clone(), 57600)
|
||||||
|
.timeout(Duration::from_millis(10))
|
||||||
|
.open().expect("Failed to open port");
|
||||||
|
Some(x)
|
||||||
|
});
|
||||||
|
let mut port = port.expect("Failed to find valid serial port");
|
||||||
|
let mut serial_buf: Vec<u8> = vec![0; 8];
|
||||||
|
let mut plot_delta_time = 0.;
|
||||||
loop {
|
loop {
|
||||||
clear_background(BLACK);
|
clear_background(BLACK);
|
||||||
|
match tail.axis {
|
||||||
|
Axis::One => {
|
||||||
|
draw_line(realtive_x_origin,realtive_y_origin,screen_width(),realtive_y_origin,1.,DARKGRAY);
|
||||||
|
},
|
||||||
|
Axis::Two => {
|
||||||
|
// horizontal (x)
|
||||||
|
draw_line(0.,realtive_y_origin,screen_width(),realtive_y_origin,1.,DARKGRAY);
|
||||||
|
// vertical (y)
|
||||||
|
draw_line(realtive_x_origin,realtive_y_origin, realtive_x_origin,screen_height(),1.,DARKGRAY);
|
||||||
|
},
|
||||||
|
}
|
||||||
|
let frame_delta_time = get_frame_time();
|
||||||
|
let mut y_displacement = 0.;
|
||||||
|
let mut x_displacement = 0.;
|
||||||
|
// keep track of the delta time since last plot
|
||||||
|
plot_delta_time += frame_delta_time;
|
||||||
|
|
||||||
let delta_time = get_frame_time();
|
if let Ok(x) = port.read(serial_buf.as_mut_slice()) {
|
||||||
|
let s: String = serial_buf.iter().take(x-1).map(|x| *x as char).collect();
|
||||||
|
if let Ok(parse) = s.parse::<f32>() {
|
||||||
|
y_displacement = parse;
|
||||||
|
|
||||||
|
// only draw when requied
|
||||||
|
tail.place_next(plot_delta_time, x_displacement, -y_displacement);
|
||||||
|
plot_delta_time = 0.;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
tail.place_next(delta_time, x_displacement, y_displacement);
|
|
||||||
tail.draw();
|
tail.draw();
|
||||||
|
|
||||||
|
// Info about the cursor locaiton
|
||||||
|
let (mouse_x, mouse_y) = mouse_position();
|
||||||
|
|
||||||
|
let size = measure_text(&format!("x{mouse_x}, y{}",-1.*(mouse_y-realtive_y_origin)), None, 30,1.);
|
||||||
|
draw_rectangle(mouse_x, mouse_y, size.width, -(size.height+5.), WHITE);
|
||||||
|
draw_text(&format!("x{}, y{}", mouse_x+realtive_x_origin,-1.*(mouse_y-realtive_y_origin)), mouse_x, mouse_y-5., 30., BLACK);
|
||||||
|
|
||||||
|
|
||||||
if is_key_down(KeyCode::S) {
|
if is_key_down(KeyCode::S) {
|
||||||
if y_displacement < screen_height()/2. {
|
if y_displacement < screen_height()/2. {
|
||||||
y_displacement += 10.;
|
y_displacement += 10.;
|
||||||
@@ -207,9 +251,10 @@ async fn main() {
|
|||||||
// toggle debug box
|
// toggle debug box
|
||||||
if show_debug {
|
if show_debug {
|
||||||
let mut debug = DebugWindow::new();
|
let mut debug = DebugWindow::new();
|
||||||
debug.add_line(format!("FPS {}, Latency {:.2}ms", get_fps(), delta_time * 1000.0));
|
debug.add_line(format!("FPS {:03}, Latency {:.2}ms", get_fps(), frame_delta_time * 1000.0));
|
||||||
debug.add_line(format!("Points {}", tail.points()));
|
debug.add_line(format!("Tail Length {TAIL_LEN}, px/s {:.2}", tail.px_per_s));
|
||||||
debug.add_line(format!("Cursor Pos {:?}", mouse_position()));
|
debug.add_line(format!("Cursor Pos {:?}", mouse_position()));
|
||||||
|
debug.add_line(format!("Serial Port {}, Baud Rate {}", port.name().unwrap_or("Unknown".to_string()), port.baud_rate().unwrap_or(0)));
|
||||||
debug.draw();
|
debug.draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user