diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 00000000..e7e9d11d
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,2 @@
+# Default ignored files
+/workspace.xml
diff --git a/.idea/dictionaries/luke.xml b/.idea/dictionaries/luke.xml
new file mode 100644
index 00000000..8d06eb22
--- /dev/null
+++ b/.idea/dictionaries/luke.xml
@@ -0,0 +1,7 @@
+
+
+
+ hotkey
+
+
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 00000000..66234fcc
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/rog-core.iml b/.idea/rog-core.iml
new file mode 100644
index 00000000..d40838f0
--- /dev/null
+++ b/.idea/rog-core.iml
@@ -0,0 +1,24 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 00000000..94a25f7f
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/rog-core/src/daemon.rs b/rog-core/src/daemon.rs
index 89ce97ef..59177868 100644
--- a/rog-core/src/daemon.rs
+++ b/rog-core/src/daemon.rs
@@ -4,21 +4,18 @@ use dbus::{
tree::{Factory, MethodErr},
};
use rog_lib::core::RogCore;
-use rog_lib::hotkeys::*;
use std::error::Error;
use std::time::Duration;
use std::{cell::RefCell, rc::Rc};
pub struct Daemon {
rogcore: RogCore,
- hotkeys: Box,
}
impl Daemon {
pub fn new() -> Self {
Daemon {
rogcore: RogCore::new().expect("Could not start RogCore"),
- hotkeys: Box::new(LaptopGX502GW::new()),
}
}
@@ -46,10 +43,8 @@ impl Daemon {
let bytes: Vec = m.msg.read1()?;
let s = format!("Wrote {:x?}", bytes);
- let supported =
- unsafe { (*daemon.as_ptr()).hotkeys.supported_modes() };
- let mut daemon = daemon.borrow_mut();
- match daemon.rogcore.aura_set_and_save(&bytes[..], supported) {
+ match daemon.borrow_mut().rogcore.aura_set_and_save(&bytes[..])
+ {
Ok(_) => {
let mret = m.msg.method_return().append1(s);
Ok(vec![mret])
@@ -73,14 +68,17 @@ impl Daemon {
connection.process(Duration::from_millis(1))?;
// READ KEYBOARD
// TODO: this needs to move to a thread, but there is unsafety
- match daemon.borrow_mut().rogcore.poll_keyboard(&mut key_buf) {
+ let borrowed_daemon = daemon.borrow();
+ match borrowed_daemon.rogcore.poll_keyboard(&mut key_buf) {
Ok(read) => {
- let hotkeys = unsafe { &mut (*daemon.as_ptr()).hotkeys };
+ // Doing this because the Laptop trait takes RogCore, but RogCore contains laptop
+ // and this makes the borrow checker unhappy, but it's safe for this
let mut rogcore = unsafe { &mut (*daemon.as_ptr()).rogcore };
+ let laptop = borrowed_daemon.rogcore.laptop();
if let Some(_count) = read {
- if key_buf[0] == hotkeys.hotkey_group_byte() {
- hotkeys.do_hotkey_action(&mut rogcore, key_buf[1]);
+ if key_buf[0] == laptop.hotkey_group_byte() {
+ laptop.do_hotkey_action(&mut rogcore, key_buf[1]);
}
}
}
diff --git a/rog-core/src/main.rs b/rog-core/src/main.rs
index 7adb303c..4f68fbf1 100644
--- a/rog-core/src/main.rs
+++ b/rog-core/src/main.rs
@@ -1,4 +1,3 @@
-// TODO: use /sys/class/dmi/id/board_name to detect model
mod daemon;
use crate::daemon::*;
diff --git a/rog-lib/src/core.rs b/rog-lib/src/core.rs
index b28009f2..93906dd7 100644
--- a/rog-lib/src/core.rs
+++ b/rog-lib/src/core.rs
@@ -1,8 +1,7 @@
-use crate::aura::BuiltInModeByte;
-use crate::config::Config;
-use crate::error::AuraError;
+use crate::{aura::BuiltInModeByte, config::Config, error::AuraError, laptops::*};
use gumdrop::Options;
use rusb::{DeviceHandle, Error};
+use std::cell::{Ref, RefCell};
use std::str::FromStr;
use std::time::Duration;
@@ -57,19 +56,22 @@ pub struct RogCore {
handle: DeviceHandle,
initialised: bool,
led_interface_num: u8,
- pub config: Config,
+ config: Config,
+ laptop: RefCell>,
}
impl RogCore {
pub fn new() -> Result {
- // TODO: make this more configurable
- let mut handle = RogCore::get_device(0x0B05, 0x1866)?;
- handle.set_active_configuration(0).unwrap_or(());
+ // TODO: use /sys/class/dmi/id/board_name to detect model
+ let laptop = LaptopGX502GW::new();
- let config = handle.device().config_descriptor(0).unwrap();
+ let mut dev_handle = RogCore::get_device(laptop.usb_vendor(), laptop.usb_product())?;
+ dev_handle.set_active_configuration(0).unwrap_or(());
+
+ let dev_config = dev_handle.device().config_descriptor(0).unwrap();
// Interface with outputs
let mut led_interface_num = 0;
- for iface in config.interfaces() {
+ for iface in dev_config.interfaces() {
for desc in iface.descriptors() {
for endpoint in desc.endpoint_descriptors() {
if endpoint.address() == 0x81 {
@@ -80,16 +82,29 @@ impl RogCore {
}
}
- handle.set_auto_detach_kernel_driver(true).unwrap();
+ dev_handle.set_auto_detach_kernel_driver(true).unwrap();
Ok(RogCore {
- handle,
+ handle: dev_handle,
initialised: false,
led_interface_num,
config: Config::default().read(),
+ laptop: RefCell::new(Box::new(laptop)),
})
}
+ pub fn laptop(&self) -> Ref> {
+ self.laptop.borrow()
+ }
+
+ pub fn config(&self) -> &Config {
+ &self.config
+ }
+
+ pub fn config_mut(&mut self) -> &mut Config {
+ &mut self.config
+ }
+
fn get_device(vendor: u16, product: u16) -> Result, Error> {
for device in rusb::devices().unwrap().iter() {
let device_desc = device.device_descriptor().unwrap();
@@ -138,13 +153,9 @@ impl RogCore {
Ok(bright)
}
- pub fn aura_set_and_save(
- &mut self,
- bytes: &[u8],
- supported: &[BuiltInModeByte],
- ) -> Result<(), Error> {
+ pub fn aura_set_and_save(&mut self, bytes: &[u8]) -> Result<(), Error> {
let mode = BuiltInModeByte::from(bytes[3]);
- if supported.contains(&mode) || bytes[1] == 0xba {
+ if self.laptop().supported_modes().contains(&mode) || bytes[1] == 0xba {
let messages = [bytes];
self.aura_write_messages(&messages)?;
self.config.set_field_from(bytes);
@@ -163,7 +174,7 @@ impl RogCore {
// Ok(())
// }
- pub fn poll_keyboard(&mut self, buf: &mut [u8; 32]) -> Result