mirror of
https://codeberg.org/Fl1tzi/microdeck.git
synced 2024-05-19 19:20:20 +00:00
fmt
This commit is contained in:
parent
7edb88192c
commit
df8b668a0a
|
@ -1,15 +1,10 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
modules::{retrieve_module_from_name, start_module, HostEvent},
|
modules::{retrieve_module_from_name, start_module, HostEvent},
|
||||||
Button, ConfigError, DeviceConfig,
|
skip_if_none, unwrap_or_error, Button, ConfigError, DeviceConfig,
|
||||||
skip_if_none, unwrap_or_error
|
|
||||||
};
|
};
|
||||||
use deck_driver as streamdeck;
|
use deck_driver as streamdeck;
|
||||||
use hidapi::HidApi;
|
use hidapi::HidApi;
|
||||||
use std::{
|
use std::{collections::HashMap, fmt::Display, sync::Arc};
|
||||||
collections::HashMap,
|
|
||||||
fmt::Display,
|
|
||||||
sync::Arc,
|
|
||||||
};
|
|
||||||
use streamdeck::{
|
use streamdeck::{
|
||||||
asynchronous::{AsyncStreamDeck, ButtonStateUpdate},
|
asynchronous::{AsyncStreamDeck, ButtonStateUpdate},
|
||||||
info::Kind,
|
info::Kind,
|
||||||
|
@ -17,8 +12,8 @@ use streamdeck::{
|
||||||
};
|
};
|
||||||
use tokio::{
|
use tokio::{
|
||||||
process::Command,
|
process::Command,
|
||||||
sync::mpsc::{self, error::TrySendError},
|
|
||||||
runtime::Runtime,
|
runtime::Runtime,
|
||||||
|
sync::mpsc::{self, error::TrySendError},
|
||||||
};
|
};
|
||||||
use tracing::{debug, error, info_span, trace};
|
use tracing::{debug, error, info_span, trace};
|
||||||
|
|
||||||
|
@ -93,11 +88,13 @@ impl Device {
|
||||||
let button = self.config.buttons.get(i).unwrap().to_owned();
|
let button = self.config.buttons.get(i).unwrap().to_owned();
|
||||||
unwrap_or_error!(self._create_module(button).await);
|
unwrap_or_error!(self._create_module(button).await);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn _create_module(&mut self, btn: Arc<Button>) -> Result<(), DeviceError> {
|
async fn _create_module(&mut self, btn: Arc<Button>) -> Result<(), DeviceError> {
|
||||||
let runtime = self.modules_runtime.as_ref().expect("Runtime has to be created before module can be spawned");
|
let runtime = self
|
||||||
|
.modules_runtime
|
||||||
|
.as_ref()
|
||||||
|
.expect("Runtime has to be created before module can be spawned");
|
||||||
let (button_sender, button_receiver) = mpsc::channel(4);
|
let (button_sender, button_receiver) = mpsc::channel(4);
|
||||||
if let Some(module) = retrieve_module_from_name(&btn.module) {
|
if let Some(module) = retrieve_module_from_name(&btn.module) {
|
||||||
{
|
{
|
||||||
|
@ -109,8 +106,7 @@ impl Device {
|
||||||
start_module(ser, b, module, dev, Box::new(button_receiver)).await
|
start_module(ser, b, module, dev, Box::new(button_receiver)).await
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
self.modules
|
self.modules.insert(btn.index, (btn.clone(), button_sender));
|
||||||
.insert(btn.index, (btn.clone(), button_sender));
|
|
||||||
return Ok(());
|
return Ok(());
|
||||||
} else {
|
} else {
|
||||||
return Err(DeviceError::Config(ConfigError::ModuleDoesNotExist(
|
return Err(DeviceError::Config(ConfigError::ModuleDoesNotExist(
|
||||||
|
|
|
@ -10,8 +10,8 @@ use std::{
|
||||||
io::ErrorKind,
|
io::ErrorKind,
|
||||||
path::PathBuf,
|
path::PathBuf,
|
||||||
process::exit,
|
process::exit,
|
||||||
|
sync::Arc,
|
||||||
time::Duration,
|
time::Duration,
|
||||||
sync::Arc
|
|
||||||
};
|
};
|
||||||
use tracing::{debug, error, info, warn};
|
use tracing::{debug, error, info, warn};
|
||||||
use tracing_subscriber::{
|
use tracing_subscriber::{
|
||||||
|
@ -41,7 +41,7 @@ macro_rules! unwrap_or_error {
|
||||||
($res:expr) => {
|
($res:expr) => {
|
||||||
match $res {
|
match $res {
|
||||||
Ok(v) => v,
|
Ok(v) => v,
|
||||||
Err(e) => error!("{}", e)
|
Err(e) => error!("{}", e),
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -143,7 +143,8 @@ pub async fn start(config: Config, mut hid: HidApi) {
|
||||||
config.device.iter().find(|d| d.serial == hw_device.1)
|
config.device.iter().find(|d| d.serial == hw_device.1)
|
||||||
{
|
{
|
||||||
// start the device and its listener
|
// start the device and its listener
|
||||||
if let Some(device) = start_device(hw_device, &hid, device_config.clone()).await
|
if let Some(device) =
|
||||||
|
start_device(hw_device, &hid, device_config.clone()).await
|
||||||
{
|
{
|
||||||
devices.insert(device.serial(), device);
|
devices.insert(device.serial(), device);
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,7 +50,7 @@ pub async fn start_module(
|
||||||
button: Arc<Button>,
|
button: Arc<Button>,
|
||||||
module_function: ModuleFunction,
|
module_function: ModuleFunction,
|
||||||
device: Arc<AsyncStreamDeck>,
|
device: Arc<AsyncStreamDeck>,
|
||||||
br: ChannelReceiver
|
br: ChannelReceiver,
|
||||||
) {
|
) {
|
||||||
debug!("STARTED");
|
debug!("STARTED");
|
||||||
let da = DeviceAccess::new(device, button.index).await;
|
let da = DeviceAccess::new(device, button.index).await;
|
||||||
|
|
Loading…
Reference in a new issue