mirror of https://github.com/4yn/slidershim
basic logging
parent
06707302d1
commit
8570091df8
|
@ -126,6 +126,17 @@ dependencies = [
|
||||||
"wildmatch",
|
"wildmatch",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "atty"
|
||||||
|
version = "0.2.14"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
|
||||||
|
dependencies = [
|
||||||
|
"hermit-abi",
|
||||||
|
"libc",
|
||||||
|
"winapi",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "autocfg"
|
name = "autocfg"
|
||||||
version = "1.0.1"
|
version = "1.0.1"
|
||||||
|
@ -788,6 +799,19 @@ dependencies = [
|
||||||
"syn",
|
"syn",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "env_logger"
|
||||||
|
version = "0.9.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0b2cf0344971ee6c64c31be0d530793fba457d322dfec2810c453d0ef228f9c3"
|
||||||
|
dependencies = [
|
||||||
|
"atty",
|
||||||
|
"humantime",
|
||||||
|
"log",
|
||||||
|
"regex",
|
||||||
|
"termcolor",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "fastrand"
|
name = "fastrand"
|
||||||
version = "1.7.0"
|
version = "1.7.0"
|
||||||
|
@ -1334,6 +1358,12 @@ version = "0.1.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "eee9694f83d9b7c09682fdb32213682939507884e5bcf227be9aff5d644b90dc"
|
checksum = "eee9694f83d9b7c09682fdb32213682939507884e5bcf227be9aff5d644b90dc"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "humantime"
|
||||||
|
version = "2.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ico"
|
name = "ico"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
@ -2764,6 +2794,8 @@ name = "slidershim"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"directories",
|
"directories",
|
||||||
|
"env_logger",
|
||||||
|
"log",
|
||||||
"palette",
|
"palette",
|
||||||
"rusb",
|
"rusb",
|
||||||
"serde",
|
"serde",
|
||||||
|
@ -3210,6 +3242,15 @@ dependencies = [
|
||||||
"utf-8",
|
"utf-8",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "termcolor"
|
||||||
|
version = "1.1.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2dfed899f0eb03f32ee8c6a0aabdb8a7949659e3466561fc0adf54e26d88c5f4"
|
||||||
|
dependencies = [
|
||||||
|
"winapi-util",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "thin-slice"
|
name = "thin-slice"
|
||||||
version = "0.1.1"
|
version = "0.1.1"
|
||||||
|
|
|
@ -22,6 +22,8 @@ rusb = "0.9.0"
|
||||||
palette = "0.6.0"
|
palette = "0.6.0"
|
||||||
winapi = "0.3.9"
|
winapi = "0.3.9"
|
||||||
directories = "4.0.1"
|
directories = "4.0.1"
|
||||||
|
log = "0.4.14"
|
||||||
|
env_logger = "0.9.0"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = [ "custom-protocol" ]
|
default = [ "custom-protocol" ]
|
||||||
|
|
|
@ -5,6 +5,10 @@ use std::io;
|
||||||
use slidershim::slider_io::{Config, Manager};
|
use slidershim::slider_io::{Config, Manager};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
env_logger::Builder::new()
|
||||||
|
.filter_level(log::LevelFilter::Debug)
|
||||||
|
.init();
|
||||||
|
|
||||||
// let config = Config::from_str(
|
// let config = Config::from_str(
|
||||||
// r#"{
|
// r#"{
|
||||||
// "deviceMode": "yuancon",
|
// "deviceMode": "yuancon",
|
||||||
|
@ -17,7 +21,7 @@ fn main() {
|
||||||
|
|
||||||
let config = Config::from_str(
|
let config = Config::from_str(
|
||||||
r#"{
|
r#"{
|
||||||
"deviceMode": "yuancon",
|
"deviceMode": "tasoller-two",
|
||||||
"outputMode": "kb-32-tasoller",
|
"outputMode": "kb-32-tasoller",
|
||||||
"keyboardSensitivity": 50,
|
"keyboardSensitivity": 50,
|
||||||
"ledMode": "reactive-8",
|
"ledMode": "reactive-8",
|
||||||
|
|
|
@ -9,6 +9,9 @@ mod slider_io;
|
||||||
|
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
|
|
||||||
|
use env_logger;
|
||||||
|
use log::info;
|
||||||
|
|
||||||
use tauri::{
|
use tauri::{
|
||||||
AppHandle, CustomMenuItem, Event, Manager, Runtime, SystemTray, SystemTrayEvent, SystemTrayMenu,
|
AppHandle, CustomMenuItem, Event, Manager, Runtime, SystemTray, SystemTrayEvent, SystemTrayMenu,
|
||||||
};
|
};
|
||||||
|
@ -26,9 +29,10 @@ fn quit_app() {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
env_logger::init();
|
||||||
|
|
||||||
let config = Arc::new(Mutex::new(Some(slider_io::Config::default())));
|
let config = Arc::new(Mutex::new(Some(slider_io::Config::default())));
|
||||||
{
|
{
|
||||||
println!("Saving");
|
|
||||||
config.lock().unwrap().as_ref().unwrap().save();
|
config.lock().unwrap().as_ref().unwrap().save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,7 +71,7 @@ fn main() {
|
||||||
let config_clone = Arc::clone(&config);
|
let config_clone = Arc::clone(&config);
|
||||||
app.listen_global("heartbeat", move |e| {
|
app.listen_global("heartbeat", move |e| {
|
||||||
let config_handle = config_clone.lock().unwrap();
|
let config_handle = config_clone.lock().unwrap();
|
||||||
println!("Heartbeat {}", config_handle.as_ref().unwrap().raw.as_str());
|
info!("Heartbeat received");
|
||||||
app_handle
|
app_handle
|
||||||
.emit_all(
|
.emit_all(
|
||||||
"showConfig",
|
"showConfig",
|
||||||
|
@ -79,7 +83,7 @@ fn main() {
|
||||||
let config_clone = Arc::clone(&config);
|
let config_clone = Arc::clone(&config);
|
||||||
app.listen_global("setConfig", move |event| {
|
app.listen_global("setConfig", move |event| {
|
||||||
let payload = event.payload().unwrap();
|
let payload = event.payload().unwrap();
|
||||||
println!("Setting config to {}", payload);
|
info!("Config applied {}", payload);
|
||||||
if let Some(new_config) = slider_io::Config::from_str(payload) {
|
if let Some(new_config) = slider_io::Config::from_str(payload) {
|
||||||
let mut config_handle = config_clone.lock().unwrap();
|
let mut config_handle = config_clone.lock().unwrap();
|
||||||
config_handle.replace(new_config);
|
config_handle.replace(new_config);
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
use directories::ProjectDirs;
|
|
||||||
use std::{convert::TryFrom, fs, path::PathBuf};
|
use std::{convert::TryFrom, fs, path::PathBuf};
|
||||||
|
|
||||||
|
use log::info;
|
||||||
|
|
||||||
|
use directories::ProjectDirs;
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
|
@ -148,9 +150,8 @@ impl Config {
|
||||||
if !config_path.exists() {
|
if !config_path.exists() {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
println!("Found saved");
|
info!("Config file found at {:?}", config_path);
|
||||||
let mut saved_data = fs::read_to_string(config_path.as_path()).ok()?;
|
let mut saved_data = fs::read_to_string(config_path.as_path()).ok()?;
|
||||||
println!("Loaded saved {}", saved_data);
|
|
||||||
return Self::from_str(saved_data.as_str());
|
return Self::from_str(saved_data.as_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -161,10 +162,12 @@ impl Config {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn save(&self) -> Option<()> {
|
pub fn save(&self) -> Option<()> {
|
||||||
|
info!("Config saving...");
|
||||||
let config_path = Self::get_saved_path()?;
|
let config_path = Self::get_saved_path()?;
|
||||||
println!("Saving to {:?}", config_path);
|
info!("Config saving to {:?}", config_path);
|
||||||
fs::write(config_path.as_path(), self.raw.as_str()).unwrap();
|
fs::write(config_path.as_path(), self.raw.as_str()).unwrap();
|
||||||
|
|
||||||
|
info!("Config saved");
|
||||||
Some(())
|
Some(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,12 @@
|
||||||
use std::{
|
use std::{
|
||||||
error,
|
error,
|
||||||
ops::{Deref, DerefMut},
|
ops::{Deref, DerefMut},
|
||||||
|
thread,
|
||||||
time::Duration,
|
time::Duration,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use log::{error, info};
|
||||||
|
|
||||||
use rusb::{self, DeviceHandle, GlobalContext};
|
use rusb::{self, DeviceHandle, GlobalContext};
|
||||||
|
|
||||||
use crate::slider_io::{
|
use crate::slider_io::{
|
||||||
|
@ -182,11 +185,21 @@ impl HidDeviceJob {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn setup_impl(&mut self) -> Result<(), Box<dyn error::Error>> {
|
fn setup_impl(&mut self) -> Result<(), Box<dyn error::Error>> {
|
||||||
let mut handle = rusb::open_device_with_vid_pid(self.vid, self.pid).unwrap();
|
info!("Device finding vid {} pid {}", self.vid, self.pid);
|
||||||
|
let handle = rusb::open_device_with_vid_pid(self.vid, self.pid);
|
||||||
|
if handle.is_none() {
|
||||||
|
error!("Could not find device");
|
||||||
|
}
|
||||||
|
let mut handle = handle.unwrap();
|
||||||
|
info!("Device found {:?}", handle);
|
||||||
|
|
||||||
if handle.kernel_driver_active(0).unwrap_or(false) {
|
if handle.kernel_driver_active(0).unwrap_or(false) {
|
||||||
|
info!("Device detaching kernel driver");
|
||||||
handle.detach_kernel_driver(0)?;
|
handle.detach_kernel_driver(0)?;
|
||||||
}
|
}
|
||||||
|
info!("Device setting configuration");
|
||||||
handle.set_active_configuration(1)?;
|
handle.set_active_configuration(1)?;
|
||||||
|
info!("Device claiming interface");
|
||||||
handle.claim_interface(0)?;
|
handle.claim_interface(0)?;
|
||||||
self.handle = Some(handle);
|
self.handle = Some(handle);
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -216,11 +229,15 @@ impl Job for HidDeviceJob {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Led loop
|
// Led loop
|
||||||
|
{
|
||||||
{
|
{
|
||||||
let mut led_state_handle = self.state.led_state.lock().unwrap();
|
let mut led_state_handle = self.state.led_state.lock().unwrap();
|
||||||
if led_state_handle.dirty {
|
if led_state_handle.dirty {
|
||||||
(self.led_callback)(&mut self.led_buf, led_state_handle.deref());
|
(self.led_callback)(&mut self.led_buf, led_state_handle.deref());
|
||||||
led_state_handle.dirty = false;
|
led_state_handle.dirty = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if self.led_buf.len != 0 {
|
if self.led_buf.len != 0 {
|
||||||
let res = (match self.led_write_type {
|
let res = (match self.led_write_type {
|
||||||
WriteType::Bulk => handle.write_bulk(self.led_endpoint, &self.led_buf.data, TIMEOUT),
|
WriteType::Bulk => handle.write_bulk(self.led_endpoint, &self.led_buf.data, TIMEOUT),
|
||||||
|
@ -234,7 +251,8 @@ impl Job for HidDeviceJob {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
// thread::sleep(Duration::from_millis(10));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn teardown(&mut self) {
|
fn teardown(&mut self) {
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
use log::info;
|
||||||
|
|
||||||
use crate::slider_io::{
|
use crate::slider_io::{
|
||||||
config::Config, controller_state::FullState, device::HidDeviceJob, led::LedJob,
|
config::Config, controller_state::FullState, device::HidDeviceJob, led::LedJob,
|
||||||
output::KeyboardOutputJob, worker::Worker,
|
output::KeyboardOutputJob, worker::Worker,
|
||||||
|
@ -18,7 +20,7 @@ impl Manager {
|
||||||
let output_worker = Worker::new(KeyboardOutputJob::new(&state, &config.output_mode));
|
let output_worker = Worker::new(KeyboardOutputJob::new(&state, &config.output_mode));
|
||||||
let led_worker = Worker::new(LedJob::new(&state, &config.led_mode));
|
let led_worker = Worker::new(LedJob::new(&state, &config.led_mode));
|
||||||
|
|
||||||
println!("Starting manager with config: {:?}", config);
|
info!("Starting manager with config: {:?}", config);
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
state,
|
state,
|
||||||
|
|
Loading…
Reference in New Issue