mirror of
https://gitlab.com/asus-linux/asusctl.git
synced 2026-02-06 00:15:04 +01:00
ROGCC: effect visual test
This commit is contained in:
@@ -1,10 +1,11 @@
|
|||||||
use std::{
|
use std::{
|
||||||
|
f64::consts::PI,
|
||||||
io::Write,
|
io::Write,
|
||||||
sync::{
|
sync::{
|
||||||
atomic::{AtomicBool, Ordering},
|
atomic::{AtomicBool, AtomicU8, Ordering},
|
||||||
Arc,
|
Arc,
|
||||||
},
|
},
|
||||||
time::Duration,
|
time::{Duration, Instant},
|
||||||
};
|
};
|
||||||
|
|
||||||
use egui::{Button, RichText};
|
use egui::{Button, RichText};
|
||||||
@@ -26,6 +27,12 @@ pub struct RogApp<'a> {
|
|||||||
// TODO: can probably just open and read whenever
|
// TODO: can probably just open and read whenever
|
||||||
pub config: Config,
|
pub config: Config,
|
||||||
pub asus_dbus: RogDbusClientBlocking<'a>,
|
pub asus_dbus: RogDbusClientBlocking<'a>,
|
||||||
|
/// Oscillator in percentage
|
||||||
|
pub oscillator: Arc<AtomicU8>,
|
||||||
|
/// Frequency of oscillation
|
||||||
|
pub oscillator_freq: Arc<AtomicU8>,
|
||||||
|
/// A toggle that toggles true/false when the oscillator reaches 0
|
||||||
|
pub oscillator_toggle: Arc<AtomicBool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> RogApp<'a> {
|
impl<'a> RogApp<'a> {
|
||||||
@@ -40,6 +47,38 @@ impl<'a> RogApp<'a> {
|
|||||||
let (dbus, _) = RogDbusClientBlocking::new()?;
|
let (dbus, _) = RogDbusClientBlocking::new()?;
|
||||||
let supported = dbus.proxies().supported().supported_functions()?;
|
let supported = dbus.proxies().supported().supported_functions()?;
|
||||||
|
|
||||||
|
// Set up an oscillator to run on a thread.
|
||||||
|
// Helpful for visual effects like colour pulse.
|
||||||
|
let oscillator = Arc::new(AtomicU8::new(0));
|
||||||
|
let oscillator1 = oscillator.clone();
|
||||||
|
let oscillator_freq = Arc::new(AtomicU8::new(5));
|
||||||
|
let oscillator_freq1 = oscillator_freq.clone();
|
||||||
|
let oscillator_toggle = Arc::new(AtomicBool::new(false));
|
||||||
|
let oscillator_toggle1 = oscillator_toggle.clone();
|
||||||
|
std::thread::spawn(move || {
|
||||||
|
let started = Instant::now();
|
||||||
|
let mut toggled = false;
|
||||||
|
loop {
|
||||||
|
let time = started.elapsed();
|
||||||
|
// 32 = slow, 16 = med, 8 = fast
|
||||||
|
let scale = oscillator_freq1.load(Ordering::SeqCst) as f64;
|
||||||
|
let elapsed = time.as_millis() as f64 / 10000.0;
|
||||||
|
let tmp = ((scale * elapsed * PI).cos()).abs();
|
||||||
|
if tmp <= 0.1 && !toggled {
|
||||||
|
let s = oscillator_toggle1.load(Ordering::SeqCst);
|
||||||
|
oscillator_toggle1.store(!s, Ordering::SeqCst);
|
||||||
|
toggled = true;
|
||||||
|
} else if tmp > 0.9 {
|
||||||
|
toggled = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
let tmp = (255.0 * tmp * 100.0 / 255.0) as u8;
|
||||||
|
|
||||||
|
oscillator1.store(tmp, Ordering::SeqCst);
|
||||||
|
std::thread::sleep(Duration::from_millis(33));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
supported,
|
supported,
|
||||||
states,
|
states,
|
||||||
@@ -48,6 +87,9 @@ impl<'a> RogApp<'a> {
|
|||||||
running_in_bg: start_closed,
|
running_in_bg: start_closed,
|
||||||
config,
|
config,
|
||||||
asus_dbus: dbus,
|
asus_dbus: dbus,
|
||||||
|
oscillator,
|
||||||
|
oscillator_toggle,
|
||||||
|
oscillator_freq,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -159,6 +159,9 @@ pub struct AuraState {
|
|||||||
pub enabled: AuraPowerDev,
|
pub enabled: AuraPowerDev,
|
||||||
/// Brightness from 0-3
|
/// Brightness from 0-3
|
||||||
pub bright: i16,
|
pub bright: i16,
|
||||||
|
pub wave_red: [u8; 22],
|
||||||
|
pub wave_green: [u8; 22],
|
||||||
|
pub wave_blue: [u8; 22],
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AuraState {
|
impl AuraState {
|
||||||
@@ -186,8 +189,34 @@ impl AuraState {
|
|||||||
} else {
|
} else {
|
||||||
2
|
2
|
||||||
},
|
},
|
||||||
|
wave_red: [0u8; 22],
|
||||||
|
wave_green: [0u8; 22],
|
||||||
|
wave_blue: [0u8; 22],
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Bump value in to the wave and surf all along.
|
||||||
|
pub fn nudge_wave(&mut self, value: u8) {
|
||||||
|
for i in (0..self.wave_red.len()).rev() {
|
||||||
|
if i > 0 {
|
||||||
|
self.wave_red[i] = self.wave_red[i - 1];
|
||||||
|
self.wave_green[i] = self.wave_green[i - 1];
|
||||||
|
self.wave_blue[i] = self.wave_blue[i - 1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let mut g = value + 33;
|
||||||
|
if g > 100 {
|
||||||
|
g -= 100;
|
||||||
|
}
|
||||||
|
let mut b = value + 66;
|
||||||
|
if b > 100 {
|
||||||
|
b -= 100;
|
||||||
|
}
|
||||||
|
self.wave_red[0] = value;
|
||||||
|
self.wave_green[0] = g;
|
||||||
|
self.wave_blue[0] = b;
|
||||||
|
dbg!(self.wave_blue);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
@@ -331,6 +360,9 @@ impl Default for PageDataStates {
|
|||||||
x19b6: vec![],
|
x19b6: vec![],
|
||||||
},
|
},
|
||||||
bright: Default::default(),
|
bright: Default::default(),
|
||||||
|
wave_red: Default::default(),
|
||||||
|
wave_green: Default::default(),
|
||||||
|
wave_blue: Default::default(),
|
||||||
},
|
},
|
||||||
anime: AnimeState {
|
anime: AnimeState {
|
||||||
was_notified: Default::default(),
|
was_notified: Default::default(),
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
|
use std::{sync::atomic::Ordering, time::Duration};
|
||||||
|
|
||||||
use egui::Color32;
|
use egui::Color32;
|
||||||
|
use rog_aura::AuraModeNum;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
widgets::{aura_modes_group, keyboard},
|
widgets::{aura_modes_group, keyboard},
|
||||||
@@ -11,21 +14,59 @@ impl<'a> RogApp<'a> {
|
|||||||
supported,
|
supported,
|
||||||
states,
|
states,
|
||||||
asus_dbus: dbus,
|
asus_dbus: dbus,
|
||||||
|
oscillator,
|
||||||
..
|
..
|
||||||
} = self;
|
} = self;
|
||||||
|
|
||||||
let c = states
|
let osc = oscillator.load(Ordering::SeqCst) as u32;
|
||||||
|
states.aura.nudge_wave(osc as u8);
|
||||||
|
// let osc = c.0 * 255 / osc;
|
||||||
|
// dbg!(osc);
|
||||||
|
let c1 = states
|
||||||
.aura
|
.aura
|
||||||
.modes
|
.modes
|
||||||
.get(&states.aura.current_mode)
|
.get(&states.aura.current_mode)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.colour1;
|
.colour1;
|
||||||
let colour = Color32::from_rgb(c.0, c.1, c.2);
|
|
||||||
|
let c2 = states
|
||||||
|
.aura
|
||||||
|
.modes
|
||||||
|
.get(&states.aura.current_mode)
|
||||||
|
.unwrap()
|
||||||
|
.colour2;
|
||||||
|
|
||||||
|
let mut colour = Color32::from_rgb(c1.0, c1.1, c1.2);
|
||||||
|
if states.aura.current_mode == AuraModeNum::Pulse {
|
||||||
|
colour = Color32::from_rgb(
|
||||||
|
(osc * c1.0 as u32 / 100) as u8,
|
||||||
|
(osc * c1.1 as u32 / 100) as u8,
|
||||||
|
(osc * c1.2 as u32 / 100) as u8,
|
||||||
|
);
|
||||||
|
} else if states.aura.current_mode == AuraModeNum::Breathe {
|
||||||
|
if self.oscillator_toggle.load(Ordering::SeqCst) {
|
||||||
|
colour = Color32::from_rgb(
|
||||||
|
(osc * c2.0 as u32 / 100) as u8,
|
||||||
|
(osc * c2.1 as u32 / 100) as u8,
|
||||||
|
(osc * c2.2 as u32 / 100) as u8,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
colour = Color32::from_rgb(
|
||||||
|
(osc * c1.0 as u32 / 100) as u8,
|
||||||
|
(osc * c1.1 as u32 / 100) as u8,
|
||||||
|
(osc * c1.2 as u32 / 100) as u8,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: animation of colour changes/periods/blending
|
// TODO: animation of colour changes/periods/blending
|
||||||
egui::CentralPanel::default().show(ctx, |ui| {
|
egui::CentralPanel::default().show(ctx, |ui| {
|
||||||
aura_modes_group(supported, states, dbus, ui);
|
aura_modes_group(supported, states, dbus, ui);
|
||||||
|
|
||||||
keyboard(ui, &states.keyboard_layout, colour);
|
keyboard(ui, &states.keyboard_layout, &mut states.aura, colour);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Only do repaint request if on this page
|
||||||
|
ctx.request_repaint_after(Duration::from_millis(33));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,22 @@
|
|||||||
use egui::{Align, Color32, Vec2};
|
use egui::{Align, Color32, Vec2};
|
||||||
use rog_aura::{keys::KeyShape, layouts::KeyLayout};
|
use rog_aura::{keys::KeyShape, layouts::KeyLayout, AuraModeNum};
|
||||||
|
|
||||||
pub fn keyboard(ui: &mut egui::Ui, keyboard_layout: &KeyLayout, colour: Color32) {
|
use crate::page_states::AuraState;
|
||||||
|
|
||||||
|
pub fn keyboard(ui: &mut egui::Ui, keyboard_layout: &KeyLayout, states: &mut AuraState, mut colour: Color32) {
|
||||||
ui.spacing_mut().item_spacing = egui::vec2(0.0, 0.0);
|
ui.spacing_mut().item_spacing = egui::vec2(0.0, 0.0);
|
||||||
let mut arrows_done = false;
|
let mut arrows_done = false;
|
||||||
let mut rog_done = false;
|
let mut rog_done = false;
|
||||||
for row in keyboard_layout.rows() {
|
for row in keyboard_layout.rows() {
|
||||||
ui.horizontal_top(|ui| {
|
ui.horizontal_top(|ui| {
|
||||||
for key in row.row() {
|
for (i, key) in row.row().enumerate() {
|
||||||
|
if states.current_mode == AuraModeNum::Rainbow {
|
||||||
|
colour = Color32::from_rgb(
|
||||||
|
(states.wave_red[i] as u32 * 255 / 100) as u8,
|
||||||
|
(states.wave_green[i]as u32 * 255 / 100) as u8,
|
||||||
|
(states.wave_blue[i]as u32 * 255 / 100) as u8,
|
||||||
|
);
|
||||||
|
}
|
||||||
// your boat
|
// your boat
|
||||||
let height = if rog_done {
|
let height = if rog_done {
|
||||||
row.height()
|
row.height()
|
||||||
|
|||||||
Reference in New Issue
Block a user