mirror of
https://gitlab.com/asus-linux/asusctl.git
synced 2026-02-06 00:15:04 +01:00
Use hashset in aura power config
This commit is contained in:
@@ -3,7 +3,7 @@ use log::{error, warn};
|
||||
use rog_aura::usb::AuraControl;
|
||||
use rog_aura::{AuraEffect, AuraModeNum, AuraZone, LedBrightness};
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use std::collections::BTreeMap;
|
||||
use std::collections::{BTreeMap, HashSet};
|
||||
use std::fs::{File, OpenOptions};
|
||||
use std::io::{Read, Write};
|
||||
|
||||
@@ -16,7 +16,7 @@ pub struct AuraConfig {
|
||||
pub current_mode: AuraModeNum,
|
||||
pub builtins: BTreeMap<AuraModeNum, AuraEffect>,
|
||||
pub multizone: Option<BTreeMap<AuraModeNum, Vec<AuraEffect>>>,
|
||||
pub enabled: Vec<AuraControl>,
|
||||
pub enabled: HashSet<AuraControl>,
|
||||
}
|
||||
|
||||
impl Default for AuraConfig {
|
||||
@@ -26,7 +26,7 @@ impl Default for AuraConfig {
|
||||
current_mode: AuraModeNum::Static,
|
||||
builtins: BTreeMap::new(),
|
||||
multizone: None,
|
||||
enabled: vec![
|
||||
enabled: HashSet::from([
|
||||
AuraControl::BootLogo,
|
||||
AuraControl::BootKeyb,
|
||||
AuraControl::SleepLogo,
|
||||
@@ -39,7 +39,7 @@ impl Default for AuraConfig {
|
||||
AuraControl::BootBar,
|
||||
AuraControl::SleepBar,
|
||||
AuraControl::ShutdownBar,
|
||||
],
|
||||
]),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -298,7 +298,8 @@ impl CtrlKbdLed {
|
||||
|
||||
/// Set combination state for boot animation/sleep animation/all leds/keys leds/side leds LED active
|
||||
pub(super) fn set_power_states(&self, config: &AuraConfig) -> Result<(), RogError> {
|
||||
let bytes = AuraControl::to_bytes(&config.enabled);
|
||||
let set: Vec<AuraControl> = config.enabled.iter().map(|v| *v).collect();
|
||||
let bytes = AuraControl::to_bytes(&set);
|
||||
|
||||
// Quite ugly, must be a more idiomatic way to do
|
||||
let message = [
|
||||
|
||||
@@ -35,9 +35,7 @@ impl CtrlKbdLedZbus {
|
||||
let mut states = None;
|
||||
if let Ok(mut ctrl) = self.0.try_lock() {
|
||||
for s in enabled {
|
||||
if !ctrl.config.enabled.contains(&s) {
|
||||
ctrl.config.enabled.push(s);
|
||||
}
|
||||
ctrl.config.enabled.insert(s);
|
||||
}
|
||||
ctrl.config.write();
|
||||
|
||||
@@ -45,7 +43,8 @@ impl CtrlKbdLedZbus {
|
||||
.map_err(|err| warn!("{}", err))
|
||||
.ok();
|
||||
|
||||
states = Some(ctrl.config.enabled.clone());
|
||||
let set: Vec<AuraControl> = ctrl.config.enabled.iter().map(|v| *v).collect();
|
||||
states = Some(set);
|
||||
}
|
||||
// Need to pull state out like this due to MutexGuard
|
||||
if let Some(states) = states {
|
||||
@@ -63,11 +62,7 @@ impl CtrlKbdLedZbus {
|
||||
let mut states = None;
|
||||
if let Ok(mut ctrl) = self.0.try_lock() {
|
||||
for s in disabled {
|
||||
if ctrl.config.enabled.contains(&s) {
|
||||
if let Ok(idx) = ctrl.config.enabled.binary_search(&s) {
|
||||
ctrl.config.enabled.remove(idx);
|
||||
}
|
||||
}
|
||||
ctrl.config.enabled.remove(&s);
|
||||
}
|
||||
ctrl.config.write();
|
||||
|
||||
@@ -75,7 +70,8 @@ impl CtrlKbdLedZbus {
|
||||
.map_err(|err| warn!("{}", err))
|
||||
.ok();
|
||||
|
||||
states = Some(ctrl.config.enabled.clone());
|
||||
let set: Vec<AuraControl> = ctrl.config.enabled.iter().map(|v| *v).collect();
|
||||
states = Some(set);
|
||||
}
|
||||
// Need to pull state out like this due to MutexGuard
|
||||
if let Some(states) = states {
|
||||
@@ -161,7 +157,8 @@ impl CtrlKbdLedZbus {
|
||||
#[dbus_interface(property)]
|
||||
async fn leds_enabled(&self) -> Vec<u8> {
|
||||
if let Ok(ctrl) = self.0.try_lock() {
|
||||
return AuraControl::to_bytes(&ctrl.config.enabled).to_vec();
|
||||
let set: Vec<AuraControl> = ctrl.config.enabled.iter().map(|v| *v).collect();
|
||||
return AuraControl::to_bytes(&set).to_vec();
|
||||
}
|
||||
vec![0, 0]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user