Further adjustments to aura

This commit is contained in:
Luke D. Jones
2024-03-23 13:07:20 +13:00
parent 1c007b4216
commit 4b38e5daa6
3 changed files with 8 additions and 6 deletions

View File

@@ -26,18 +26,20 @@ use crate::{CtrlTask, Reloadable};
pub struct AuraManager { pub struct AuraManager {
_connection: Connection, _connection: Connection,
interfaces: Arc<Mutex<HashMap<String, OwnedObjectPath>>>, interfaces: Arc<Mutex<HashMap<AuraDevice, OwnedObjectPath>>>,
} }
impl AuraManager { impl AuraManager {
pub async fn new(mut connection: Connection) -> Result<Self, RogError> { pub async fn new(mut connection: Connection) -> Result<Self, RogError> {
let conn_copy = connection.clone(); let conn_copy = connection.clone();
let data = LaptopLedData::get_data(); let data = LaptopLedData::get_data();
let mut interfaces = HashMap::new();
// Do the initial keyboard detection: // Do the initial keyboard detection:
let all = CtrlKbdLed::find_all(&data)?; let all = CtrlKbdLed::find_all(&data)?;
for ctrl in all { for ctrl in all {
let path = ctrl.dbus_path.clone(); let path = ctrl.dbus_path.clone();
interfaces.insert(ctrl.led_prod, path.clone()); // ensure we record the initial stuff
let sig_ctx = CtrlAuraZbus::signal_context(&connection)?; let sig_ctx = CtrlAuraZbus::signal_context(&connection)?;
let sig_ctx2 = sig_ctx.clone(); let sig_ctx2 = sig_ctx.clone();
let zbus = CtrlAuraZbus::new(ctrl, sig_ctx); let zbus = CtrlAuraZbus::new(ctrl, sig_ctx);
@@ -49,7 +51,7 @@ impl AuraManager {
let manager = Self { let manager = Self {
_connection: connection, _connection: connection,
interfaces: Default::default(), interfaces: Arc::new(Mutex::new(interfaces)),
}; };
let interfaces_copy = manager.interfaces.clone(); let interfaces_copy = manager.interfaces.clone();
@@ -75,7 +77,7 @@ impl AuraManager {
if action == "remove" { if action == "remove" {
if let Some(id_product) = parent.attribute_value("idProduct") { if let Some(id_product) = parent.attribute_value("idProduct") {
let id_product = id_product.to_string_lossy().to_string(); let id_product = AuraDevice::from(id_product.to_str().unwrap());
let interfaces_copy = interfaces_copy.clone(); let interfaces_copy = interfaces_copy.clone();
let conn_copy = conn_copy.clone(); let conn_copy = conn_copy.clone();
tokio::spawn(async move { tokio::spawn(async move {
@@ -141,7 +143,7 @@ impl AuraManager {
// //
tokio::spawn(async move { tokio::spawn(async move {
let mut interfaces = interfaces_copy.lock().await; let mut interfaces = interfaces_copy.lock().await;
interfaces.insert(id_product, path.clone()); interfaces.insert(aura_device, path.clone());
let sig_ctx = CtrlAuraZbus::signal_context(&conn_copy)?; let sig_ctx = CtrlAuraZbus::signal_context(&conn_copy)?;
let zbus = CtrlAuraZbus::new(ctrl, sig_ctx); let zbus = CtrlAuraZbus::new(ctrl, sig_ctx);
// Now add it to device list // Now add it to device list

View File

@@ -31,7 +31,7 @@ pub const fn aura_brightness_bytes(brightness: u8) -> [u8; 17] {
derive(Type, Value, OwnedValue), derive(Type, Value, OwnedValue),
zvariant(signature = "s") zvariant(signature = "s")
)] )]
#[derive(Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Default)] #[derive(Copy, Clone, PartialEq, Eq, Hash, Serialize, Deserialize, Default)]
pub enum AuraDevice { pub enum AuraDevice {
Tuf = 0, Tuf = 0,
X1854 = 1, X1854 = 1,

View File

@@ -2,7 +2,7 @@
msgid "" msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PACKAGE VERSION\n" "Project-Id-Version: PACKAGE VERSION\n"
"POT-Creation-Date: 2024-03-22 22:27+0000\n" "POT-Creation-Date: 2024-03-22 22:45+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"