diff --git a/settings.toml b/settings.toml index 237caf5..5cebaaa 100644 --- a/settings.toml +++ b/settings.toml @@ -1,2 +1,2 @@ -ip = "10.0.0.30" +ip = "localhost" port = 8765 diff --git a/src/coordinator.rs b/src/coordinator.rs index cc5d8e0..56c82b0 100644 --- a/src/coordinator.rs +++ b/src/coordinator.rs @@ -89,6 +89,11 @@ impl <'a> CoordState<'a> { if let Err(e) = self.to_gui.send(GuiUpdate::SocketState(false)).await { error!("Cannot send message to gui thread: {e}"); } + } else { + if let Err(e) = self.to_gui.send(GuiUpdate::SocketState(true)).await { + error!("Cannot send message to gui thread: {e}"); + self.close().await; + } } } diff --git a/src/joystick_loop.rs b/src/joystick_loop.rs index 842ffb8..f18a4f1 100644 --- a/src/joystick_loop.rs +++ b/src/joystick_loop.rs @@ -2,11 +2,14 @@ use crate::coordinator::{ApplicationEvent, MoveEvent}; use async_channel::Sender; use gilrs::{ev::filter::FilterFn, Axis, Button, Event, EventType, Filter, Gilrs, GilrsBuilder}; -use log::{warn, info}; +use log::{debug, info, warn}; use std::{ - panic::{self, AssertUnwindSafe}, sync::{atomic::AtomicBool, Arc}, time::Duration + panic::{self, AssertUnwindSafe}, + sync::{atomic::AtomicBool, Arc}, + time::Duration }; +static MAX_SENT_ZEROS: u32 = 10; struct UnknownSlayer; impl FilterFn for UnknownSlayer { @@ -44,6 +47,7 @@ pub async fn joystick_loop( let mut curr_y: i32 = 0; let mut past_x: i32 = 0; let mut past_y: i32 = 0; + let mut count_zeros: u32 = 0; loop { // catch unwind because some buttons on the joystick will panic the gilrs object @@ -74,10 +78,16 @@ pub async fn joystick_loop( } } - if curr_x != past_x || curr_y != past_y { + if (curr_x != past_x || curr_y != past_y) || (count_zeros < MAX_SENT_ZEROS) { past_x = curr_x; past_y = curr_y; + if curr_x == 0 && curr_y == 0 { + count_zeros += 1; + } else { + count_zeros = 0; + } + match tx.try_send(ApplicationEvent::MoveEvent(MoveEvent { x: curr_x, y: curr_y,