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 <junnan01.wu@samsung.com>
This commit is contained in:
Junnan Wu 2024-09-09 13:09:40 +08:00 committed by Manos Pitsidianakis
parent 67274cf5dd
commit fade33c618

View File

@ -453,8 +453,12 @@ impl IIOSensor {
fn read_axis(&self, axis: &Axis) -> Result<i64, ScmiDeviceError> {
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<i64, ScmiDeviceError> {
let offset: Option<i64> = self.read_axis_offset(&axis.path)?;
if let Some(offset_value) = offset {
match value.checked_add(offset_value) {