Skip to content

Commit

Permalink
Ensure valid DeviceType when converting DeviceInfo_FFI -> DeviceInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
simon-wh committed Oct 29, 2024
1 parent c40f611 commit b61774b
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion wooting-analog-common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,15 @@ impl Drop for DeviceInfo_FFI {

impl DeviceInfo_FFI {
pub fn into_device_info(&self) -> DeviceInfo {
let raw = self.device_type.clone() as i32;
let device_type = DeviceType::from_i32(raw);
if device_type.is_none() {
log::error!(
"Invalid Device Type when converting DeviceInfo_FFI into DeviceInfo: {}",
raw
);
}

DeviceInfo {
vendor_id: self.vendor_id.clone(),
product_id: self.product_id.clone(),
Expand All @@ -102,7 +111,7 @@ impl DeviceInfo_FFI {
.to_owned()
},
device_id: self.device_id.clone(),
device_type: self.device_type.clone(),
device_type: device_type.unwrap_or(DeviceType::Other),
}
}
}
Expand Down

0 comments on commit b61774b

Please sign in to comment.