Skip to content

Commit

Permalink
feat: add getters for some field for device and led
Browse files Browse the repository at this point in the history
  • Loading branch information
meskill committed May 22, 2022
1 parent ccb1c15 commit 4a30763
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
9 changes: 9 additions & 0 deletions examples/disable_light_for_5_sec.rs
Expand Up @@ -17,8 +17,17 @@ fn main() -> Result<(), CommonError> {

let mut keyboard_leds = devices[2].leds()?;

println!("Second Device name is {}", devices[2].name());

println!("{:#?}", keyboard_leds);

println!(
"First led has name: {} with max_bright: {} and max_speed: {}",
keyboard_leds[0].name(),
keyboard_leds[0].max_bright(),
keyboard_leds[0].max_speed()
);

let state = keyboard_leds[0].get_state()?;

println!("Current device state: {:#?}", state);
Expand Down
4 changes: 4 additions & 0 deletions src/sdk/device.rs
Expand Up @@ -22,6 +22,10 @@ impl Debug for Device {
}

impl Device {
pub fn name(&self) -> &str {
&self.name
}

pub fn new(library: Rc<Library>, name: String, led_count: u32) -> Self {
Self {
library,
Expand Down
26 changes: 23 additions & 3 deletions src/sdk/led.rs
Expand Up @@ -32,9 +32,13 @@ pub struct DeviceLedState {
/// Represents single led of the device
pub struct DeviceLed {
library: Rc<Library>,

// internal field that required to make api calls
device_name: Bstr,
led_index: u32,
name: Bstr,

// public fields
name: String,
supported_styles: HashSet<String>,
max_bright: u32,
max_speed: u32,
Expand All @@ -43,7 +47,7 @@ pub struct DeviceLed {
impl Debug for DeviceLed {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("DeviceLed")
.field("name", &self.name.to_string())
.field("name", &self.name)
.field("supported_styles", &self.supported_styles)
.field("max_bright", &self.max_bright)
.field("max_speed", &self.max_speed)
Expand All @@ -52,6 +56,22 @@ impl Debug for DeviceLed {
}

impl DeviceLed {
pub fn name(&self) -> &str {
&self.name
}

pub fn supported_styles(&self) -> &HashSet<String> {
&self.supported_styles
}

pub fn max_bright(&self) -> u32 {
self.max_bright
}

pub fn max_speed(&self) -> u32 {
self.max_speed
}

pub fn new(library: Rc<Library>, device_name: &str, led_index: u32) -> Result<Self> {
let get_led_info: Symbol<
unsafe extern "C" fn(
Expand Down Expand Up @@ -111,7 +131,7 @@ impl DeviceLed {

let supported_styles = HashSet::from_safearray(led_styles);

let name = Bstr::from(led_name);
let name = Bstr::from(led_name).to_string();

Ok(Self {
library,
Expand Down

0 comments on commit 4a30763

Please sign in to comment.