Fluke/dbus refactor

This commit is contained in:
Luke Jones
2023-12-03 20:44:01 +00:00
parent f6e4cc0626
commit 0a69c23288
143 changed files with 5421 additions and 10343 deletions

View File

@@ -2,7 +2,7 @@ use dmi_id::DMIID;
use log::{error, info, warn};
use serde_derive::{Deserialize, Serialize};
use typeshare::typeshare;
use zbus::zvariant::Type;
use zbus::zvariant::{OwnedValue, Type, Value};
use crate::usb::AuraDevice;
use crate::{AdvancedAuraType, AuraModeNum, AuraZone};
@@ -25,20 +25,24 @@ pub struct LedSupportFile(Vec<LaptopLedData>);
/// The powerr zones this laptop supports
#[typeshare]
#[cfg_attr(feature = "dbus", derive(Type), zvariant(signature = "s"))]
#[cfg_attr(
feature = "dbus",
derive(Type, Value, OwnedValue),
zvariant(signature = "s")
)]
#[derive(Serialize, Deserialize, PartialEq, Eq, Debug, Default, Copy, Clone)]
pub enum PowerZones {
/// The logo on some laptop lids
#[default]
Logo,
Logo = 0,
/// The full keyboard (not zones)
Keyboard,
Keyboard = 1,
/// The lightbar, typically on the front of the laptop
Lightbar,
Lightbar = 2,
/// The leds that may be placed around the edge of the laptop lid
Lid,
Lid = 3,
/// The led strip on the rear of some laptops
RearGlow,
RearGlow = 4,
}
#[derive(Debug, Clone, Default, PartialEq, Eq, Deserialize, Serialize)]

View File

@@ -10,24 +10,48 @@ use std::str::FromStr;
use serde_derive::{Deserialize, Serialize};
use typeshare::typeshare;
#[cfg(feature = "dbus")]
use zbus::zvariant::Type;
use zbus::zvariant::{OwnedValue, Type, Value};
use crate::error::Error;
use crate::LED_MSG_LEN;
#[typeshare]
#[cfg_attr(feature = "dbus", derive(Type), zvariant(signature = "s"))]
#[derive(Debug, Default, Copy, Clone, PartialEq, Eq, Deserialize, Serialize)]
#[cfg_attr(
feature = "dbus",
derive(Type, Value, OwnedValue),
zvariant(signature = "u")
)]
pub enum LedBrightness {
Off,
Low,
Off = 0,
Low = 1,
#[default]
Med,
High,
Med = 2,
High = 3,
}
impl From<u32> for LedBrightness {
fn from(bright: u32) -> Self {
impl LedBrightness {
pub const fn next(&self) -> Self {
match self {
Self::Off => Self::Low,
Self::Low => Self::Med,
Self::Med => Self::High,
Self::High => Self::Off,
}
}
pub const fn prev(&self) -> Self {
match self {
Self::Off => Self::High,
Self::Low => Self::Off,
Self::Med => Self::Low,
Self::High => Self::Med,
}
}
}
impl From<u8> for LedBrightness {
fn from(bright: u8) -> Self {
match bright {
0 => LedBrightness::Off,
1 => LedBrightness::Low,
@@ -37,8 +61,14 @@ impl From<u32> for LedBrightness {
}
}
impl From<LedBrightness> for u8 {
fn from(l: LedBrightness) -> Self {
l as u8
}
}
#[typeshare]
#[cfg_attr(feature = "dbus", derive(Type))]
#[cfg_attr(feature = "dbus", derive(Type, Value, OwnedValue))]
#[derive(Debug, Clone, PartialEq, Eq, Copy, Deserialize, Serialize)]
pub struct Colour {
pub r: u8,
@@ -99,7 +129,11 @@ impl From<Colour> for [u8; 3] {
}
#[typeshare]
#[cfg_attr(feature = "dbus", derive(Type), zvariant(signature = "s"))]
#[cfg_attr(
feature = "dbus",
derive(Type, Value, OwnedValue),
zvariant(signature = "s")
)]
#[derive(Debug, Default, Copy, Clone, PartialEq, Eq, Deserialize, Serialize)]
pub enum Speed {
Low = 0xe1,
@@ -135,14 +169,18 @@ impl From<Speed> for u8 {
///
/// Enum corresponds to the required integer value
#[typeshare]
#[cfg_attr(feature = "dbus", derive(Type), zvariant(signature = "s"))]
#[cfg_attr(
feature = "dbus",
derive(Type, Value, OwnedValue),
zvariant(signature = "s")
)]
#[derive(Debug, Default, Copy, Clone, PartialEq, Eq, Deserialize, Serialize)]
pub enum Direction {
#[default]
Right,
Left,
Up,
Down,
Right = 0,
Left = 1,
Up = 2,
Down = 3,
}
impl FromStr for Direction {
@@ -162,7 +200,11 @@ impl FromStr for Direction {
/// Enum of modes that convert to the actual number required by a USB HID packet
#[typeshare]
#[cfg_attr(feature = "dbus", derive(Type), zvariant(signature = "s"))]
#[cfg_attr(
feature = "dbus",
derive(Type, Value, OwnedValue),
zvariant(signature = "u")
)]
#[derive(
Debug, Default, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Copy, Deserialize, Serialize,
)]
@@ -250,28 +292,38 @@ impl From<u8> for AuraModeNum {
}
}
impl From<AuraEffect> for AuraModeNum {
fn from(value: AuraEffect) -> Self {
value.mode
}
}
/// Base effects have no zoning, while multizone is 1-4
#[typeshare]
#[cfg_attr(feature = "dbus", derive(Type), zvariant(signature = "s"))]
#[cfg_attr(
feature = "dbus",
derive(Type, Value, OwnedValue),
zvariant(signature = "s")
)]
#[derive(Debug, Default, Copy, Clone, PartialEq, Eq, Deserialize, Serialize)]
pub enum AuraZone {
/// Used if keyboard has no zones, or if setting all
#[default]
None,
None = 0,
/// Leftmost zone
Key1,
Key1 = 1,
/// Zone after leftmost
Key2,
Key2 = 2,
/// Zone second from right
Key3,
Key3 = 3,
/// Rightmost zone
Key4,
Key4 = 4,
/// Logo on the lid (or elsewhere?)
Logo,
Logo = 5,
/// The left part of a lightbar (typically on the front of laptop)
BarLeft,
BarLeft = 6,
/// The right part of a lightbar
BarRight,
BarRight = 7,
}
impl FromStr for AuraZone {
@@ -299,7 +351,7 @@ impl FromStr for AuraZone {
/// // let bytes: [u8; LED_MSG_LEN] = mode.into();
/// ```
#[typeshare]
#[cfg_attr(feature = "dbus", derive(Type))]
#[cfg_attr(feature = "dbus", derive(Type, Value, OwnedValue))]
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct AuraEffect {
/// The effect type
@@ -354,6 +406,12 @@ impl Default for AuraEffect {
}
}
impl Display for AuraEffect {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{:?}", self)
}
}
pub struct AuraParameters {
pub zone: bool,
pub colour1: bool,

View File

@@ -3,12 +3,12 @@ use std::fmt::Debug;
use serde::{Deserialize, Serialize};
use typeshare::typeshare;
#[cfg(feature = "dbus")]
use zbus::zvariant::Type;
use zbus::zvariant::{OwnedValue, Type, Value};
use crate::aura_detection::PowerZones;
#[typeshare]
#[cfg_attr(feature = "dbus", derive(Type))]
#[cfg_attr(feature = "dbus", derive(Type, Value, OwnedValue))]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct KbAuraPowerState {
pub zone: PowerZones,
@@ -95,7 +95,7 @@ impl KbAuraPowerState {
/// |00000000| 00000000| 00000000| 00000100|sleep_rear|
/// |00000000| 00000000| 00000000| 00001000|shut_rear_|
#[typeshare]
#[cfg_attr(feature = "dbus", derive(Type))]
#[cfg_attr(feature = "dbus", derive(Type, Value, OwnedValue))]
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
pub struct AuraPower {
pub keyboard: KbAuraPowerState,

View File

@@ -4,7 +4,7 @@ use std::ops::{BitAnd, BitOr};
use serde::{Deserialize, Serialize};
use typeshare::typeshare;
#[cfg(feature = "dbus")]
use zbus::zvariant::Type;
use zbus::zvariant::{OwnedValue, Type, Value};
use crate::power::AuraPower;
@@ -26,19 +26,23 @@ pub const fn aura_brightness_bytes(brightness: u8) -> [u8; 17] {
}
#[typeshare]
#[cfg_attr(feature = "dbus", derive(Type), zvariant(signature = "s"))]
#[cfg_attr(
feature = "dbus",
derive(Type, Value, OwnedValue),
zvariant(signature = "s")
)]
#[derive(Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Default)]
pub enum AuraDevice {
Tuf,
X1854,
X1869,
X1866,
X18c6,
Tuf = 0,
X1854 = 1,
X1869 = 2,
X1866 = 3,
X18c6 = 4,
#[default]
X19b6,
X1a30,
X1abe,
Unknown,
X19b6 = 5,
X1a30 = 6,
X1abe = 7,
Unknown = 99,
}
impl AuraDevice {
@@ -116,7 +120,7 @@ impl Debug for AuraDevice {
/// This struct is intended as a helper to pass args to generic dbus interface
#[typeshare]
#[cfg_attr(feature = "dbus", derive(Type))]
#[cfg_attr(feature = "dbus", derive(Type, Value, OwnedValue))]
#[derive(Clone, Default, Debug, Serialize, Deserialize)]
pub struct AuraPowerDev {
/// TUF laptops use a similar style of control to the older ROG devices but
@@ -130,14 +134,18 @@ pub struct AuraPowerDev {
}
#[typeshare]
#[cfg_attr(feature = "dbus", derive(Type), zvariant(signature = "s"))]
#[cfg_attr(
feature = "dbus",
derive(Type, Value, OwnedValue),
zvariant(signature = "s")
)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[repr(u32)]
pub enum AuraDevTuf {
Boot,
Awake,
Sleep,
Keyboard,
Boot = 0,
Awake = 1,
Sleep = 2,
Keyboard = 3,
}
impl AuraDevTuf {
@@ -161,7 +169,11 @@ impl AuraDevTuf {
/// | 0011, 0000 | 0000, 1000 | 0000, 0100 | Sleep | 30,08,04 |
/// | 1111, 1111 | 0001, 1111 | 0000, 1111 | all on | |
#[typeshare]
#[cfg_attr(feature = "dbus", derive(Type), zvariant(signature = "s"))]
#[cfg_attr(
feature = "dbus",
derive(Type, Value, OwnedValue),
zvariant(signature = "s")
)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[repr(u32)]
pub enum AuraDevRog1 {