mirror of
https://gitlab.com/asus-linux/asusctl.git
synced 2026-02-06 00:15:04 +01:00
Merge branch 'fluke/anime-cli' into 'main'
anime: tweak gif animation time types See merge request asus-linux/asus-nb-ctrl!48
This commit is contained in:
@@ -15,7 +15,7 @@ fn main() {
|
|||||||
let path = Path::new(&args[1]);
|
let path = Path::new(&args[1]);
|
||||||
let brightness = args[2].parse::<f32>().unwrap();
|
let brightness = args[2].parse::<f32>().unwrap();
|
||||||
let mut seq = Sequences::new();
|
let mut seq = Sequences::new();
|
||||||
seq.add_asus_gif(path, None, brightness).unwrap();
|
seq.add_asus_gif(path, rog_anime::AnimTime::Infinite, brightness).unwrap();
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
for action in seq.iter() {
|
for action in seq.iter() {
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ use std::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use glam::Vec2;
|
use glam::Vec2;
|
||||||
use rog_anime::{Action, Sequences};
|
use rog_anime::{Action, AnimTime, Sequences};
|
||||||
use rog_dbus::AuraDbusClient;
|
use rog_dbus::AuraDbusClient;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
@@ -32,12 +32,12 @@ fn main() {
|
|||||||
),
|
),
|
||||||
if let Ok(time) = args[7].parse::<u64>() {
|
if let Ok(time) = args[7].parse::<u64>() {
|
||||||
if time != 0 {
|
if time != 0 {
|
||||||
Some(Duration::from_secs(time))
|
AnimTime::Time(Duration::from_secs(time))
|
||||||
} else {
|
} else {
|
||||||
None
|
AnimTime::Infinite
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
None
|
AnimTime::Infinite
|
||||||
},
|
},
|
||||||
args[6].parse::<f32>().unwrap(),
|
args[6].parse::<f32>().unwrap(),
|
||||||
)
|
)
|
||||||
@@ -54,12 +54,12 @@ fn main() {
|
|||||||
),
|
),
|
||||||
if let Ok(time) = args[7].parse::<u64>() {
|
if let Ok(time) = args[7].parse::<u64>() {
|
||||||
if time != 0 {
|
if time != 0 {
|
||||||
Some(Duration::from_secs(time))
|
AnimTime::Time(Duration::from_secs(time))
|
||||||
} else {
|
} else {
|
||||||
None
|
AnimTime::Infinite
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
None
|
AnimTime::Infinite
|
||||||
},
|
},
|
||||||
args[6].parse::<f32>().unwrap(),
|
args[6].parse::<f32>().unwrap(),
|
||||||
)
|
)
|
||||||
@@ -69,6 +69,7 @@ fn main() {
|
|||||||
loop {
|
loop {
|
||||||
for action in seq.iter() {
|
for action in seq.iter() {
|
||||||
if let Action::Animation(frames) = action {
|
if let Action::Animation(frames) = action {
|
||||||
|
let mut count = 0;
|
||||||
let start = Instant::now();
|
let start = Instant::now();
|
||||||
'outer: loop {
|
'outer: loop {
|
||||||
for frame in frames.frames() {
|
for frame in frames.frames() {
|
||||||
@@ -77,13 +78,18 @@ fn main() {
|
|||||||
.anime()
|
.anime()
|
||||||
.write(frame.frame().clone())
|
.write(frame.frame().clone())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
if let Some(time) = frames.duration() {
|
if let AnimTime::Time(time) = frames.duration() {
|
||||||
if Instant::now().duration_since(start) > time {
|
if Instant::now().duration_since(start) > time {
|
||||||
break 'outer;
|
break 'outer;
|
||||||
}
|
}
|
||||||
|
} else if let AnimTime::Cycles(times) = frames.duration() {
|
||||||
|
if count == times {
|
||||||
|
break 'outer;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
sleep(frame.delay());
|
sleep(frame.delay());
|
||||||
}
|
}
|
||||||
|
count +=1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use rog_anime::Action;
|
use rog_anime::{Action, AnimTime};
|
||||||
use rog_dbus::AuraDbusClient;
|
use rog_dbus::AuraDbusClient;
|
||||||
use rog_user::user_config::*;
|
use rog_user::user_config::*;
|
||||||
|
|
||||||
@@ -27,20 +27,26 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
let start = Instant::now();
|
let start = Instant::now();
|
||||||
|
|
||||||
match action {
|
match action {
|
||||||
Action::Animation(frames) => 'animation: loop {
|
Action::Animation(frames) => {
|
||||||
for frame in frames.frames() {
|
let mut count = 0;
|
||||||
client.proxies().anime().write(frame.frame().clone())?;
|
'animation: loop {
|
||||||
if let Some(time) = frames.duration() {
|
for frame in frames.frames() {
|
||||||
if Instant::now().duration_since(start) > time {
|
client.proxies().anime().write(frame.frame().clone())?;
|
||||||
|
if let AnimTime::Time(time) = frames.duration() {
|
||||||
|
if Instant::now().duration_since(start) > time {
|
||||||
|
break 'animation;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sleep(frame.delay());
|
||||||
|
}
|
||||||
|
if let AnimTime::Cycles(times) = frames.duration() {
|
||||||
|
count += 1;
|
||||||
|
if count >= times {
|
||||||
break 'animation;
|
break 'animation;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sleep(frame.delay());
|
|
||||||
}
|
}
|
||||||
if frames.duration().is_none() {
|
}
|
||||||
break 'animation;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
Action::Image(image) => {
|
Action::Image(image) => {
|
||||||
client.proxies().anime().write(image.as_ref().clone())?;
|
client.proxies().anime().write(image.as_ref().clone())?;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ use std::{
|
|||||||
time::Duration,
|
time::Duration,
|
||||||
};
|
};
|
||||||
|
|
||||||
use rog_anime::{Sequences, Vec2};
|
use rog_anime::{AnimTime, Sequences, Vec2};
|
||||||
use serde_derive::{Deserialize, Serialize};
|
use serde_derive::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::error::Error;
|
use crate::error::Error;
|
||||||
@@ -20,7 +20,7 @@ pub enum AnimeAction {
|
|||||||
/// Full gif sequence. Immutable.
|
/// Full gif sequence. Immutable.
|
||||||
AsusAnimation {
|
AsusAnimation {
|
||||||
file: PathBuf,
|
file: PathBuf,
|
||||||
duration: Option<Duration>,
|
time: AnimTime,
|
||||||
brightness: f32,
|
brightness: f32,
|
||||||
},
|
},
|
||||||
/// Basic image, can have properties changed
|
/// Basic image, can have properties changed
|
||||||
@@ -29,7 +29,7 @@ pub enum AnimeAction {
|
|||||||
scale: f32,
|
scale: f32,
|
||||||
angle: f32,
|
angle: f32,
|
||||||
translation: Vec2,
|
translation: Vec2,
|
||||||
duration: Option<Duration>,
|
time: AnimTime,
|
||||||
brightness: f32,
|
brightness: f32,
|
||||||
},
|
},
|
||||||
Image {
|
Image {
|
||||||
@@ -45,12 +45,12 @@ pub enum AnimeAction {
|
|||||||
|
|
||||||
impl UserConfig {
|
impl UserConfig {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
let x = Self {
|
||||||
anime: vec![
|
anime: vec![
|
||||||
AnimeAction::AsusAnimation {
|
AnimeAction::AsusAnimation {
|
||||||
file: "/usr/share/asusd/anime/asus/rog/Sunset.gif".into(),
|
file: "/usr/share/asusd/anime/asus/rog/Sunset.gif".into(),
|
||||||
brightness: 0.5,
|
brightness: 0.5,
|
||||||
duration: None,
|
time: AnimTime::Cycles(1),
|
||||||
},
|
},
|
||||||
AnimeAction::ImageAnimation {
|
AnimeAction::ImageAnimation {
|
||||||
file: "/usr/share/asusd/anime/custom/sonic-run.gif".into(),
|
file: "/usr/share/asusd/anime/custom/sonic-run.gif".into(),
|
||||||
@@ -58,7 +58,7 @@ impl UserConfig {
|
|||||||
angle: 0.65,
|
angle: 0.65,
|
||||||
translation: Vec2::default(),
|
translation: Vec2::default(),
|
||||||
brightness: 0.5,
|
brightness: 0.5,
|
||||||
duration: Some(Duration::from_secs(5)),
|
time: AnimTime::Time(Duration::from_secs(5)),
|
||||||
},
|
},
|
||||||
AnimeAction::Image {
|
AnimeAction::Image {
|
||||||
file: "/usr/share/asusd/anime/custom/rust.png".into(),
|
file: "/usr/share/asusd/anime/custom/rust.png".into(),
|
||||||
@@ -74,10 +74,12 @@ impl UserConfig {
|
|||||||
angle: 0.0,
|
angle: 0.0,
|
||||||
translation: Vec2::new(3.0, 2.0),
|
translation: Vec2::new(3.0, 2.0),
|
||||||
brightness: 0.5,
|
brightness: 0.5,
|
||||||
duration: None,
|
time: AnimTime::Cycles(2),
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
}
|
};
|
||||||
|
println!("{}", serde_json::to_string_pretty(&x).unwrap());
|
||||||
|
x
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn load_config(&mut self) -> Result<(), Error> {
|
pub fn load_config(&mut self) -> Result<(), Error> {
|
||||||
@@ -122,7 +124,7 @@ impl UserConfig {
|
|||||||
match anime {
|
match anime {
|
||||||
AnimeAction::AsusAnimation {
|
AnimeAction::AsusAnimation {
|
||||||
file,
|
file,
|
||||||
duration,
|
time: duration,
|
||||||
brightness,
|
brightness,
|
||||||
} => seq.add_asus_gif(&file, *duration, *brightness)?,
|
} => seq.add_asus_gif(&file, *duration, *brightness)?,
|
||||||
AnimeAction::ImageAnimation {
|
AnimeAction::ImageAnimation {
|
||||||
@@ -130,7 +132,7 @@ impl UserConfig {
|
|||||||
scale,
|
scale,
|
||||||
angle,
|
angle,
|
||||||
translation,
|
translation,
|
||||||
duration,
|
time: duration,
|
||||||
brightness,
|
brightness,
|
||||||
} => {
|
} => {
|
||||||
seq.add_image_gif(&file, *scale, *angle, *translation, *duration, *brightness)?
|
seq.add_image_gif(&file, *scale, *angle, *translation, *duration, *brightness)?
|
||||||
|
|||||||
@@ -1,45 +1,64 @@
|
|||||||
{
|
{
|
||||||
"anime": [
|
"anime": [
|
||||||
{
|
{
|
||||||
"AsusAnimation": {
|
"AsusAnimation": {
|
||||||
"file": "/usr/share/asusd/anime/asus/Controller.gif",
|
"file": "/usr/share/asusd/anime/asus/rog/Sunset.gif",
|
||||||
"duration": {
|
"time": {
|
||||||
|
"Cycles": 1
|
||||||
|
},
|
||||||
|
"brightness": 0.5
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"ImageAnimation": {
|
||||||
|
"file": "/usr/share/asusd/anime/custom/sonic-run.gif",
|
||||||
|
"scale": 0.9,
|
||||||
|
"angle": 0.65,
|
||||||
|
"translation": [
|
||||||
|
0.0,
|
||||||
|
0.0
|
||||||
|
],
|
||||||
|
"time": {
|
||||||
|
"Time": {
|
||||||
"secs": 5,
|
"secs": 5,
|
||||||
"nanos": 0
|
"nanos": 0
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
},
|
"brightness": 0.5
|
||||||
{
|
|
||||||
"ImageAnimation": {
|
|
||||||
"file": "/usr/share/asusd/anime/sonic.gif",
|
|
||||||
"scale": 0.9,
|
|
||||||
"angle": 0.65,
|
|
||||||
"translation": [
|
|
||||||
0.0,
|
|
||||||
0.0
|
|
||||||
],
|
|
||||||
"duration": {
|
|
||||||
"secs": 5,
|
|
||||||
"nanos": 0
|
|
||||||
},
|
|
||||||
"brightness": 0.5
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"Image": {
|
|
||||||
"file_path": "/usr/share/asusd/anime/doom.png",
|
|
||||||
"scale": 0.7,
|
|
||||||
"angle": 0.0,
|
|
||||||
"translation": [
|
|
||||||
0.0,
|
|
||||||
0.0
|
|
||||||
],
|
|
||||||
"duration": {
|
|
||||||
"secs": 5,
|
|
||||||
"nanos": 0
|
|
||||||
},
|
|
||||||
"brightness": 0.6
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
]
|
},
|
||||||
}
|
{
|
||||||
|
"Image": {
|
||||||
|
"file": "/usr/share/asusd/anime/custom/rust.png",
|
||||||
|
"scale": 1.0,
|
||||||
|
"angle": 0.0,
|
||||||
|
"translation": [
|
||||||
|
0.0,
|
||||||
|
0.0
|
||||||
|
],
|
||||||
|
"brightness": 0.6
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Pause": {
|
||||||
|
"secs": 6,
|
||||||
|
"nanos": 0
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"ImageAnimation": {
|
||||||
|
"file": "/usr/share/asusd/anime/custom/sonic-wait.gif",
|
||||||
|
"scale": 0.9,
|
||||||
|
"angle": 0.0,
|
||||||
|
"translation": [
|
||||||
|
3.0,
|
||||||
|
2.0
|
||||||
|
],
|
||||||
|
"time": {
|
||||||
|
"Cycles": 2
|
||||||
|
},
|
||||||
|
"brightness": 0.5
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|||||||
@@ -22,16 +22,30 @@ impl AniMeFrame {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Copy, Clone, Deserialize, Serialize)]
|
||||||
|
pub enum AnimTime {
|
||||||
|
Time(Duration),
|
||||||
|
Cycles(u32),
|
||||||
|
Infinite,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for AnimTime {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::Infinite
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// A gif animation. This is a collection of frames from the gif, and a duration
|
/// A gif animation. This is a collection of frames from the gif, and a duration
|
||||||
/// that the animation should be shown for.
|
/// that the animation should be shown for.
|
||||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||||
pub struct AniMeGif(Vec<AniMeFrame>, Option<Duration>);
|
pub struct AniMeGif(Vec<AniMeFrame>, AnimTime);
|
||||||
|
|
||||||
impl AniMeGif {
|
impl AniMeGif {
|
||||||
/// Create an animation using the 74x36 ASUS gif format
|
/// Create an animation using the 74x36 ASUS gif format
|
||||||
pub fn create_diagonal_gif(
|
pub fn create_diagonal_gif(
|
||||||
file_name: &Path,
|
file_name: &Path,
|
||||||
duration: Option<Duration>,
|
duration: AnimTime,
|
||||||
brightness: f32,
|
brightness: f32,
|
||||||
) -> Result<Self, AnimeError> {
|
) -> Result<Self, AnimeError> {
|
||||||
let mut matrix = AniMeDiagonal::new(None);
|
let mut matrix = AniMeDiagonal::new(None);
|
||||||
@@ -75,7 +89,7 @@ impl AniMeGif {
|
|||||||
scale: f32,
|
scale: f32,
|
||||||
angle: f32,
|
angle: f32,
|
||||||
translation: Vec2,
|
translation: Vec2,
|
||||||
duration: Option<Duration>,
|
duration: AnimTime,
|
||||||
brightness: f32,
|
brightness: f32,
|
||||||
) -> Result<Self, AnimeError> {
|
) -> Result<Self, AnimeError> {
|
||||||
let mut frames = Vec::new();
|
let mut frames = Vec::new();
|
||||||
@@ -142,7 +156,7 @@ impl AniMeGif {
|
|||||||
&self.0
|
&self.0
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn duration(&self) -> Option<Duration> {
|
pub fn duration(&self) -> AnimTime {
|
||||||
self.1
|
self.1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ use std::{path::Path, time::Duration};
|
|||||||
use glam::Vec2;
|
use glam::Vec2;
|
||||||
use serde_derive::{Deserialize, Serialize};
|
use serde_derive::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::{error::AnimeError, AniMeDataBuffer, AniMeGif, AniMeImage};
|
use crate::{AniMeDataBuffer, AniMeGif, AniMeImage, AnimTime, error::AnimeError};
|
||||||
|
|
||||||
///
|
///
|
||||||
#[derive(Debug, Deserialize, Serialize)]
|
#[derive(Debug, Deserialize, Serialize)]
|
||||||
@@ -36,7 +36,7 @@ impl Sequences {
|
|||||||
pub fn add_asus_gif(
|
pub fn add_asus_gif(
|
||||||
&mut self,
|
&mut self,
|
||||||
file: &Path,
|
file: &Path,
|
||||||
duration: Option<Duration>,
|
duration: AnimTime,
|
||||||
brightness: f32,
|
brightness: f32,
|
||||||
) -> Result<(), AnimeError> {
|
) -> Result<(), AnimeError> {
|
||||||
let frames = AniMeGif::create_diagonal_gif(file, duration, brightness)?;
|
let frames = AniMeGif::create_diagonal_gif(file, duration, brightness)?;
|
||||||
@@ -64,7 +64,7 @@ impl Sequences {
|
|||||||
scale: f32,
|
scale: f32,
|
||||||
angle: f32,
|
angle: f32,
|
||||||
translation: Vec2,
|
translation: Vec2,
|
||||||
duration: Option<Duration>,
|
duration: AnimTime,
|
||||||
brightness: f32,
|
brightness: f32,
|
||||||
) -> Result<(), AnimeError> {
|
) -> Result<(), AnimeError> {
|
||||||
let frames =
|
let frames =
|
||||||
|
|||||||
Reference in New Issue
Block a user