From fade33c618a6a1ff9cfcc5dcf1b4d55bd216b34e Mon Sep 17 00:00:00 2001 From: Junnan Wu Date: Mon, 9 Sep 2024 13:09:40 +0800 Subject: [PATCH] scmi: refactor function read_axis In function read_axis, there are two steps. The first is reading number for sysfs file. The second is reading offset and scales. And the second step can be reused in notification, therefore we separate it into two functions. Signed-off-by: Junnan Wu --- vhost-device-scmi/src/devices/iio.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/vhost-device-scmi/src/devices/iio.rs b/vhost-device-scmi/src/devices/iio.rs index 3c56f58..4ce817e 100644 --- a/vhost-device-scmi/src/devices/iio.rs +++ b/vhost-device-scmi/src/devices/iio.rs @@ -453,8 +453,12 @@ impl IIOSensor { fn read_axis(&self, axis: &Axis) -> Result { let path_result = axis.path.clone().into_string(); - let mut value: i64 = + let value: i64 = read_number_from_file(Path::new(&(path_result.unwrap() + "_raw")))?.unwrap(); + self.deal_axis_raw_data(value, axis) + } + + fn deal_axis_raw_data(&self, mut value: i64, axis: &Axis) -> Result { let offset: Option = self.read_axis_offset(&axis.path)?; if let Some(offset_value) = offset { match value.checked_add(offset_value) {