Resolve linter warnings

This commit is contained in:
ninjadev64 committed 2025-01-08 19:59:52 +00:00
1 parent be51e0786e
commit 891de15d21
3 files changed
+28 -47

No files matched your search

+2 -5
View File
@@ -43,7 +43,7 @@ pub const PID_AJAZZ_AKP153E: u16 = 0x1010;
/// Product ID of Ajazz AKP153R Desk Controller
pub const PID_AJAZZ_AKP153R: u16 = 0x1020;
const RECOGNIZED_VENDORS: &'static [u16] = &[ELGATO_VENDOR_ID, AJAZZ_VENDOR_ID_1, AJAZZ_VENDOR_ID_2];
const RECOGNIZED_VENDORS: [u16; 3] = [ELGATO_VENDOR_ID, AJAZZ_VENDOR_ID_1, AJAZZ_VENDOR_ID_2];
/// Returns true for vendors IDs that are recognized by the library
pub fn is_vendor_familiar(vendor: &u16) -> bool {
@@ -226,10 +226,7 @@ impl Kind {
/// Tells if the Stream Deck kind has a screen
pub fn is_visual(&self) -> bool {
match self {
Kind::Pedal => false,
_ => true,
}
!matches!(self, Kind::Pedal)
}
/// Key layout of the Stream Deck kind as (rows, columns)
+15 -19
View File
@@ -104,11 +104,7 @@ pub enum StreamDeckInput {
impl StreamDeckInput {
/// Checks if there's data received or not
pub fn is_empty(&self) -> bool {
if let StreamDeckInput::NoData = self {
true
} else {
false
}
matches!(self, StreamDeckInput::NoData)
}
}
@@ -261,9 +257,7 @@ impl StreamDeck {
}
Kind::Akp153 | Kind::Akp153E | Kind::Akp153R | Kind::Akp815 | Kind::MiraBoxHSV293S => {
let data = match self.kind {
_ => read_data(&self.device, 512, timeout),
}?;
let data = read_data(&self.device, 512, timeout)?;
if data[0] == 0 {
return Ok(StreamDeckInput::NoData);
@@ -312,10 +306,11 @@ impl StreamDeck {
Ok(send_feature_report(&self.device, buf.as_slice())?)
}
Kind::Akp153 | Kind::Akp153E | Kind::Akp153R | Kind::Akp815 | Kind::MiraBoxHSV293S => Ok({
Kind::Akp153 | Kind::Akp153E | Kind::Akp153R | Kind::Akp815 | Kind::MiraBoxHSV293S => {
self.set_brightness(100)?;
self.clear_button_image(0xff)?;
}),
Ok(())
},
_ => {
let mut buf = vec![0x03, 0x02];
@@ -330,7 +325,7 @@ impl StreamDeck {
/// Sets brightness of the device, value range is 0 - 100
pub fn set_brightness(&self, percent: u8) -> Result<(), StreamDeckError> {
self.initialize()?;
let percent = percent.max(0).min(100);
let percent = percent.clamp(0, 100);
match self.kind {
Kind::Original | Kind::Mini | Kind::MiniMk2 => {
@@ -594,7 +589,8 @@ impl StreamDeck {
pub fn set_button_image(&self, key: u8, image: DynamicImage) -> Result<(), StreamDeckError> {
self.initialize()?;
let image_data = convert_image(self.kind, image)?;
Ok(self.write_image(key, &image_data)?)
self.write_image(key, &image_data)?;
Ok(())
}
/// Set logo image
@@ -815,6 +811,7 @@ impl StreamDeck {
/// Returns button state reader for this device
pub fn get_reader(self: &Arc<Self>) -> Arc<DeviceStateReader> {
#[allow(clippy::arc_with_non_send_sync)]
Arc::new(DeviceStateReader {
device: self.clone(),
states: Mutex::new(DeviceState {
@@ -1032,19 +1029,18 @@ impl DeviceStateReader {
}
}
_ => {
if *their != *mine {
if index < self.device.kind.key_count() as usize {
if their != mine {
let key_count = self.device.kind.key_count();
if index < key_count as usize {
if *their {
updates.push(DeviceStateUpdate::ButtonDown(index as u8));
} else {
updates.push(DeviceStateUpdate::ButtonUp(index as u8));
}
} else if *their {
updates.push(DeviceStateUpdate::TouchPointDown(index as u8 - key_count));
} else {
if *their {
updates.push(DeviceStateUpdate::TouchPointDown(index as u8 - self.device.kind.key_count()));
} else {
updates.push(DeviceStateUpdate::TouchPointUp(index as u8 - self.device.kind.key_count()));
}
updates.push(DeviceStateUpdate::TouchPointUp(index as u8 - key_count));
}
}
}
+11 -23
View File
@@ -18,7 +18,7 @@ pub fn get_feature_report(device: &HidDevice, report_id: u8, length: usize) -> R
/// Performs send_feature_report on [HidDevice]
pub fn send_feature_report(device: &HidDevice, payload: &[u8]) -> Result<(), HidError> {
Ok(device.send_feature_report(payload)?)
device.send_feature_report(payload)
}
/// Reads data from [HidDevice]. Blocking mode is used if timeout is specified
@@ -37,25 +37,13 @@ pub fn read_data(device: &HidDevice, length: usize, timeout: Option<Duration>) -
/// Writes data to [HidDevice]
pub fn write_data(device: &HidDevice, payload: &[u8]) -> Result<usize, HidError> {
#[cfg(target_os = "windows")]
let platform = "windows";
#[cfg(target_os = "macos")]
let platform = "mac";
#[cfg(target_os = "linux")]
let platform = "linux";
match platform {
"windows" => Ok(device.write(payload)?),
_ => {
if payload[0] == 0 {
let mut buf = vec![0u8; payload.len() + 1];
buf[0] = 0;
buf[1..].copy_from_slice(payload);
return Ok(device.write(buf.as_slice())?);
} else {
Ok(device.write(payload)?)
}
}
if cfg!(windows) || payload[0] != 0 {
device.write(payload)
} else {
let mut buf = vec![0u8; payload.len() + 1];
buf[0] = 0;
buf[1..].copy_from_slice(payload);
device.write(buf.as_slice())
}
}
@@ -132,7 +120,7 @@ pub fn flip_key_index(kind: &Kind, key: u8) -> u8 {
}
/// Reads button states, empty vector if no data
pub fn read_button_states(kind: &Kind, states: &Vec<u8>) -> Vec<bool> {
pub fn read_button_states(kind: &Kind, states: &[u8]) -> Vec<bool> {
if states[0] == 0 {
return vec![];
}
@@ -167,7 +155,7 @@ pub fn read_button_states(kind: &Kind, states: &Vec<u8>) -> Vec<bool> {
}
/// Reads lcd screen input
pub fn read_lcd_input(data: &Vec<u8>) -> Result<StreamDeckInput, StreamDeckError> {
pub fn read_lcd_input(data: &[u8]) -> Result<StreamDeckInput, StreamDeckError> {
let start_x = u16::from_le_bytes([data[6], data[7]]);
let start_y = u16::from_le_bytes([data[8], data[9]]);
@@ -187,7 +175,7 @@ pub fn read_lcd_input(data: &Vec<u8>) -> Result<StreamDeckInput, StreamDeckError
}
/// Reads encoder input
pub fn read_encoder_input(kind: &Kind, data: &Vec<u8>) -> Result<StreamDeckInput, StreamDeckError> {
pub fn read_encoder_input(kind: &Kind, data: &[u8]) -> Result<StreamDeckInput, StreamDeckError> {
match &data[4] {
0x0 => Ok(StreamDeckInput::EncoderStateChange(data[5..5 + kind.encoder_count() as usize].iter().map(|s| *s != 0).collect())),