automatically connect and reconnect to otdipc

This commit is contained in:
2026-02-26 20:45:31 +01:00
parent 79a19a5748
commit c15c037771
4 changed files with 42 additions and 21 deletions

20
Cargo.lock generated
View File

@@ -203,7 +203,7 @@ version = "1.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "40c48f72fd53cd289104fc64099abca73db4166ad86ea0b4341abe65af83dadc"
dependencies = [
"windows-sys 0.61.2",
"windows-sys 0.60.2",
]
[[package]]
@@ -214,7 +214,7 @@ checksum = "291e6a250ff86cd4a820112fb8898808a366d8f9f58ce16d1f538353ad55747d"
dependencies = [
"anstyle",
"once_cell_polyfill",
"windows-sys 0.61.2",
"windows-sys 0.60.2",
]
[[package]]
@@ -2403,7 +2403,7 @@ dependencies = [
"libc",
"option-ext",
"redox_users",
"windows-sys 0.61.2",
"windows-sys 0.59.0",
]
[[package]]
@@ -2650,7 +2650,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb"
dependencies = [
"libc",
"windows-sys 0.61.2",
"windows-sys 0.52.0",
]
[[package]]
@@ -3924,7 +3924,7 @@ version = "0.50.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7957b9740744892f114936ab4a57b3f487491bbeafaf8083688b16841a4240e5"
dependencies = [
"windows-sys 0.61.2",
"windows-sys 0.59.0",
]
[[package]]
@@ -4365,7 +4365,7 @@ dependencies = [
[[package]]
name = "otd-ipc"
version = "0.1.0"
source = "git+https://git.avii.nl/Avii/otd-ipc-rs.git#ae15494e857ba93e63055e76da7105dd78b17610"
source = "git+https://git.avii.nl/Avii/otd-ipc-rs.git#bb3892a239412d95b954adb795407d6d0a244f07"
dependencies = [
"bytes",
"dirs",
@@ -4953,7 +4953,7 @@ dependencies = [
"errno",
"libc",
"linux-raw-sys 0.11.0",
"windows-sys 0.61.2",
"windows-sys 0.52.0",
]
[[package]]
@@ -5320,10 +5320,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0136791f7c95b1f6dd99f9cc786b91bb81c3800b639b3478e561ddb7be95e5f1"
dependencies = [
"fastrand",
"getrandom 0.4.1",
"getrandom 0.3.4",
"once_cell",
"rustix 1.1.3",
"windows-sys 0.61.2",
"windows-sys 0.52.0",
]
[[package]]
@@ -6183,7 +6183,7 @@ version = "0.1.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22"
dependencies = [
"windows-sys 0.61.2",
"windows-sys 0.52.0",
]
[[package]]

View File

@@ -1,13 +1,15 @@
use bevy::{
asset::{Asset, Handle},
asset::{Asset, Handle, uuid_handle},
image::Image,
pbr::{ExtendedMaterial, MaterialExtension, StandardMaterial},
reflect::TypePath,
render::render_resource::AsBindGroup,
shader::ShaderRef,
shader::{Shader, ShaderRef},
};
const SHADER_ASSET_PATH: &str = "shaders/shader.wgsl";
// const SHADER_ASSET_PATH: &str = "shaders/shader.wgsl";
pub const FRAGMENT_SHADER_HANDLE: Handle<Shader> =
uuid_handle!("b70d4f0f-8873-4b2a-bc6f-35b0e3e25e02");
#[derive(Asset, TypePath, AsBindGroup, Debug, Clone)]
pub struct CustomMaterial {
@@ -24,7 +26,7 @@ pub struct CustomMaterial {
/// You only need to implement functions for features that need non-default behavior. See the Material api docs for details!
impl MaterialExtension for CustomMaterial {
fn fragment_shader() -> ShaderRef {
SHADER_ASSET_PATH.into()
FRAGMENT_SHADER_HANDLE.into()
}
}

View File

@@ -6,7 +6,7 @@ use std::f32::consts::{FRAC_PI_2, PI};
use bevy::{
app::{App, Plugin, Startup, Update},
asset::{Assets, Handle},
asset::{Assets, Handle, load_internal_asset},
camera::{Camera, Camera3d, RenderTarget, visibility::RenderLayers},
color::{Color, palettes::css},
ecs::{
@@ -24,6 +24,7 @@ use bevy::{
pbr::{MaterialPlugin, MeshMaterial3d, StandardMaterial},
prelude::{Deref, DerefMut},
render::render_resource::{Extent3d, TextureUsages},
shader::Shader,
transform::components::Transform,
utils::default,
};
@@ -45,7 +46,7 @@ pub use crate::apad::otdipcplugin::TabletRotation;
use crate::{
MainCamera,
apad::{
custom_material::{CustomMaterial, MyCustomMaterial},
custom_material::{CustomMaterial, FRAGMENT_SHADER_HANDLE, MyCustomMaterial},
keyboard::VirtualKeyboard,
otdipcplugin::{OtdIpcPlugin, PenButtons, PenDelta, PenPosition},
},
@@ -119,7 +120,6 @@ impl Plugin for APadPlugin {
.init_persistent_resource::<KneeboardNotepad>();
app.insert_resource(TabletSize(Vec2::new(210.0, 279.0)));
// app.insert_resource(TabletResolutionScale(2.25));
app.insert_resource(TabletResolutionScale(2.5));
app.insert_resource(PointerImage(None));
app.insert_resource(Name("".to_string()));
@@ -141,6 +141,13 @@ impl Plugin for APadPlugin {
.add_systems(Update, update_pointer.in_set(EguiInputSet::WriteEguiEvents))
.add_systems(Update, render_pointer)
.add_systems(WorldspaceContextPass, update);
load_internal_asset!(
app,
FRAGMENT_SHADER_HANDLE,
"../../assets/shaders/shader.wgsl",
Shader::from_wgsl
);
}
}

View File

@@ -1,5 +1,7 @@
#![allow(unused)]
use std::{thread::sleep, time::Duration};
use bevy::{
app::{App, Plugin, PreUpdate},
ecs::{
@@ -69,10 +71,21 @@ impl Plugin for OtdIpcPlugin {
fn build(&self, app: &mut App) {
let (mut tx, rx) = triple_buffer(&None);
std::thread::spawn(move || {
let otd_ipc = OtdIpc::new("Kneeboard", "master").unwrap();
loop {
let Ok(otd_ipc) = OtdIpc::new("Kneeboard", "master") else {
sleep(Duration::from_secs(1));
continue;
};
for msg in otd_ipc {
tx.write(Some(msg));
for msg in otd_ipc {
let Ok(msg) = msg else {
break;
};
tx.write(Some(msg));
}
sleep(Duration::from_secs(1));
}
});
app.add_message::<PenDelta>();
@@ -88,7 +101,6 @@ impl Plugin for OtdIpcPlugin {
}
}
#[allow(clippy::too_many_arguments)]
fn reader(
rotation: Res<TabletRotation>,
mut last_position: ResMut<LastPosition>,