Update config & dbus parts, cleanup deps, device power states

- Add extra config options and dbus methods
- Add power state signals for anime and led
- Refactor to use channels for dbus signal handler send/recv
- Split out profiles independant parts to a rog-profiles crate
- Cleanup dependencies
- Fix some dbus Supported issues
This commit is contained in:
Luke D. Jones
2021-05-22 13:00:11 +12:00
parent ba03e8feb8
commit 2b58e259de
69 changed files with 1241 additions and 1096 deletions

View File

@@ -14,7 +14,7 @@ exclude = ["data"]
[features]
default = ["dbus"]
dbus = ["zbus", "zvariant", "zvariant_derive"]
dbus = ["zvariant", "zvariant_derive"]
[dependencies]
png_pong = "^0.8.0"
@@ -26,6 +26,5 @@ serde_derive = "^1.0"
glam = { version = "0.14.0", features = ["serde"] }
zbus = { version = "^1.9.1", optional = true }
zvariant = { version = "^2.6", optional = true }
zvariant_derive = { version = "^2.6", optional = true }

View File

@@ -14,6 +14,14 @@ pub const ANIME_DATA_LEN: usize = PANE_LEN * 2;
const USB_PREFIX1: [u8; 7] = [0x5e, 0xc0, 0x02, 0x01, 0x00, 0x73, 0x02];
const USB_PREFIX2: [u8; 7] = [0x5e, 0xc0, 0x02, 0x74, 0x02, 0x73, 0x02];
#[cfg_attr(feature = "dbus", derive(Type))]
#[derive(Debug, PartialEq, Copy, Clone, Deserialize, Serialize)]
pub struct AnimePowerStates {
pub enabled: bool,
pub boot_anim_enabled: bool,
}
/// The minimal serializable data that can be transferred over wire types.
/// Other data structures in `rog_anime` will convert to this.
#[cfg_attr(feature = "dbus", derive(Type))]

View File

@@ -3,9 +3,6 @@ use png_pong::decode::Error as PngError;
use std::error::Error;
use std::fmt;
#[cfg(feature = "dbus")]
use zbus::fdo;
#[derive(Debug)]
pub enum AnimeError {
NoFrames,
@@ -15,8 +12,6 @@ pub enum AnimeError {
Format,
/// The input was incorrect size, expected size is `IncorrectSize(width, height)`
IncorrectSize(u32, u32),
#[cfg(feature = "dbus")]
Zbus(fdo::Error),
}
impl fmt::Display for AnimeError {
@@ -33,8 +28,6 @@ impl fmt::Display for AnimeError {
"The input image size is incorrect, expected {}x{}",
width, height
),
#[cfg(feature = "dbus")]
AnimeError::Zbus(e) => write!(f, "ZBUS error: {}", e),
}
}
}
@@ -61,11 +54,3 @@ impl From<DecodingError> for AnimeError {
AnimeError::Gif(err)
}
}
#[cfg(feature = "dbus")]
impl From<AnimeError> for fdo::Error {
#[inline]
fn from(err: AnimeError) -> Self {
fdo::Error::Failed(format!("{}", err))
}
}

View File

@@ -180,36 +180,34 @@ impl AnimeImage {
let du = led_from_px * Vec3::new(-0.5, 0.5, 0.0);
let dv = led_from_px * Vec3::new(0.5, 0.5, 0.0);
for led in self.led_pos.iter_mut() {
if let Some(led) = led {
let mut sum = 0.0;
let mut alpha = 0.0;
let mut count = 0;
for led in self.led_pos.iter_mut().flatten() {
let mut sum = 0.0;
let mut alpha = 0.0;
let mut count = 0;
let pos = Vec3::new(led.x(), led.y(), 1.0);
let x0 = led_from_px.mul_vec3(pos + Vec3::new(0.0, -0.5, 0.0));
let pos = Vec3::new(led.x(), led.y(), 1.0);
let x0 = led_from_px.mul_vec3(pos + Vec3::new(0.0, -0.5, 0.0));
const GROUP: [f32; 4] = [0.0, 0.5, 1.0, 1.5];
for u in GROUP.iter() {
for v in GROUP.iter() {
let sample = x0 + *u * du + *v * dv;
const GROUP: [f32; 4] = [0.0, 0.5, 1.0, 1.5];
for u in GROUP.iter() {
for v in GROUP.iter() {
let sample = x0 + *u * du + *v * dv;
let x = sample.x as i32;
let y = sample.y as i32;
if x > width - 1 || y > height - 1 || x < 0 || y < 0 {
continue;
}
let p = self.img_pixels[(x + (y * width)) as usize];
sum += p.color as f32;
alpha += p.alpha;
count += 1;
let x = sample.x as i32;
let y = sample.y as i32;
if x > width - 1 || y > height - 1 || x < 0 || y < 0 {
continue;
}
let p = self.img_pixels[(x + (y * width)) as usize];
sum += p.color as f32;
alpha += p.alpha;
count += 1;
}
alpha /= count as f32;
sum /= count as f32;
led.set_bright((sum * self.bright * alpha) as u8);
}
alpha /= count as f32;
sum /= count as f32;
led.set_bright((sum * self.bright * alpha) as u8);
}
}

View File

@@ -32,4 +32,4 @@ pub mod error;
/// Provides const methods to create the USB HID control packets
pub mod usb;
pub static VERSION: &str = env!("CARGO_PKG_VERSION");
pub static VERSION: &str = env!("CARGO_PKG_VERSION");