Skip to content

Commit

Permalink
Feature/delay (#137)
Browse files Browse the repository at this point in the history
* Removed unneccessary delay and tested

* Readded linux delays just in case.

* Fix manual merge

---------

Co-authored-by: medzernik <1900179+medzernik@users.noreply.github.com>
  • Loading branch information
Aron-Kristofori and medzernik committed Jan 10, 2024
1 parent 81b3f57 commit b52eb63
Showing 1 changed file with 19 additions and 30 deletions.
49 changes: 19 additions & 30 deletions wooting-macro-backend/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,38 +1,27 @@
pub mod config;
mod hid_table;
pub mod plugin;

use rayon::prelude::*;

use log::*;

use itertools::Itertools;

use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
use std::{thread, time};
#[cfg(not(debug_assertions))]
use std::path::PathBuf;
use std::sync::Arc;
use std::sync::atomic::{AtomicBool, Ordering};

use anyhow::{Error, Result};
#[cfg(not(debug_assertions))]
use dirs;
use halfbrown::HashMap;
use itertools::Itertools;
use log::*;
use rayon::prelude::*;
use rdev::simulate;
use tokio::sync::mpsc::{UnboundedReceiver, UnboundedSender};
use tokio::sync::RwLock;
use tokio::task;

use halfbrown::HashMap;

use config::{ApplicationConfig, ConfigFile};
#[cfg(not(debug_assertions))]
use dirs;
#[cfg(not(debug_assertions))]
use std::path::PathBuf;

use rdev::simulate;

use anyhow::{Error, Result};

// This has to be imported for release build
#[allow(unused_imports)]
use crate::config::CONFIG_DIR;
use crate::hid_table::*;

//Plugin imports
use crate::plugin::delay;
#[allow(unused_imports)]
Expand All @@ -44,6 +33,10 @@ use crate::plugin::obs;
use crate::plugin::phillips_hue;
use crate::plugin::system_event;

pub mod config;
mod hid_table;
pub mod plugin;

#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
/// Type of a macro. Currently only Single is implemented. Others have been postponed for now.
///
Expand Down Expand Up @@ -300,7 +293,7 @@ async fn execute_macro(macros: Macro, channel: UnboundedSender<rdev::EventType>)
/// Puts a mandatory 0-20 ms delay between each macro execution (depending on the platform).
fn keypress_executor_sender(mut rchan_execute: UnboundedReceiver<rdev::EventType>) {
loop {
let received_event = match &rchan_execute.blocking_recv() {
let received_event = match &rchan_execute.blocking_recv() {
Some(event) => *event,
None => {
error!("Failed to receive an event!");
Expand All @@ -310,13 +303,9 @@ fn keypress_executor_sender(mut rchan_execute: UnboundedReceiver<rdev::EventType
plugin::util::direct_send_event(&received_event)
.unwrap_or_else(|err| error!("Error directly sending an event to keyboard: {}", err));

// MacOS and Linux require some delays.
//MacOS and Linux require a delay between each macro execution.
#[cfg(not(target_os = "windows"))]
thread::sleep(time::Duration::from_millis(10));

// Windows execution delay can be set lower.
#[cfg(target_os = "windows")]
thread::sleep(time::Duration::from_millis(1));
}
}

Expand Down Expand Up @@ -601,7 +590,7 @@ impl MacroBackend {
}
})
});
Err(anyhow::Error::msg("Error in grabbing thread!"))
Ok(())
}
}

Expand Down

0 comments on commit b52eb63

Please sign in to comment.