Better anime options & gumdrop error Display

This commit is contained in:
Asere
2020-10-27 13:50:10 +01:00
parent 5c8d138cef
commit 3bdc11c994
5 changed files with 99 additions and 38 deletions

View File

@@ -46,6 +46,10 @@ impl AniMeDbusWriter {
)
}
fn thread_sleep(&self) {
thread::sleep(Duration::from_millis(self.block_time));
}
pub fn write_image_to_buf(_buf: &mut AniMePacketType, _image_data: &[u8]) {
unimplemented!("Image format is in progress of being worked out")
}
@@ -74,7 +78,7 @@ impl AniMeDbusWriter {
image[1][..7].copy_from_slice(&ANIME_PANE2_PREFIX);
proxy.set_anime(vec![image[0].to_vec(), image[1].to_vec()])?;
thread::sleep(Duration::from_millis(self.block_time));
self.thread_sleep();
Ok(())
}
@@ -90,24 +94,24 @@ impl AniMeDbusWriter {
Ok(())
}
fn turn_on_off(&self, status : bool) -> Result<(), Box<dyn Error>> {
#[inline]
pub fn turn_on_off(&self, status: bool) -> Result<(), Box<dyn Error>> {
let proxy = self.new_proxy();
proxy.set_on_off(status)?;
thread::sleep(Duration::from_millis(self.block_time));
self.thread_sleep();
Ok(())
}
#[inline]
pub fn turn_on(&self) -> Result<(), Box<dyn Error>> {
self.turn_on_off(true)?;
Ok(())
}
pub fn turn_boot_on_off(&self, status: bool)
-> Result<(), Box<dyn Error>> {
let proxy = self.new_proxy();
proxy.set_boot_on_off(status)?;
self.thread_sleep();
#[inline]
pub fn turn_off(&self) -> Result<(), Box<dyn Error>> {
self.turn_on_off(false)?;
Ok(())
}
}

View File

@@ -231,6 +231,37 @@ impl Default for SetAuraBuiltin {
}
}
#[derive(Copy, Clone, Debug)]
pub enum AniMeStatusValue {
On,
Off,
}
impl FromStr for AniMeStatusValue {
type Err = AuraError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
let s = s.to_lowercase();
match s.as_str() {
"on" => Ok(AniMeStatusValue::On),
"off" => Ok(AniMeStatusValue::Off),
_ => {
print!("{}\n{}\n",
"Invalid argument, must be one of:",
"on, off");
Err(AuraError::ParseAnime)
}
}
}
}
impl From<AniMeStatusValue> for bool {
fn from(value: AniMeStatusValue) -> Self {
match value {
AniMeStatusValue::On => true,
AniMeStatusValue::Off => false,
}
}
}
#[derive(Options)]
pub struct AniMeLeds {
#[options(help = "print help message")]
@@ -240,7 +271,6 @@ pub struct AniMeLeds {
help = "set all leds brightness value")]
led_brightness: u8,
}
impl AniMeLeds {
pub fn led_brightness(&self) -> u8 {
self.led_brightness

View File

@@ -7,6 +7,7 @@ use dbus::blocking;
pub trait OrgAsuslinuxDaemon {
fn set_anime(&self, input: Vec<Vec<u8>>) -> Result<(), dbus::Error>;
fn set_on_off(&self, status: bool) -> Result<(), dbus::Error>;
fn set_boot_on_off(&self, status: bool) -> Result<(), dbus::Error>;
}
impl<'a, T: blocking::BlockingSender, C: ::std::ops::Deref<Target=T>> OrgAsuslinuxDaemon for blocking::Proxy<'a, C> {
@@ -18,4 +19,8 @@ impl<'a, T: blocking::BlockingSender, C: ::std::ops::Deref<Target=T>> OrgAsuslin
fn set_on_off(&self, status: bool) -> Result<(), dbus::Error> {
self.method_call("org.asuslinux.Daemon", "SetOnOff", (status, ))
}
fn set_boot_on_off(&self, status: bool) -> Result<(), dbus::Error> {
self.method_call("org.asuslinux.Daemon", "SetBootOnOff", (status, ))
}
}