async fn read_sensor_input_report(
    device: &AmbientLightInputReportReaderProxy,
) -> Result<Option<AmbientLightInputRpt>, Error> {
    let r = device.proxy.read_input_reports().await;

    match r {
        Ok(Ok(reports)) => {
            for report in reports {
                if report.report_id.unwrap_or(0) != device.illuminance.as_ref().unwrap().report_id {
                    continue;
                }

                if let Some(sensor) = report.sensor {
                    if let Some(values) = sensor.values {
                        let f = |component: &Option<AmbientLightComponent>| match component {
                            Some(val) => match val.exponent {
                                0 => values[val.report_index] as f32,
                                _ => {
                                    values[val.report_index] as f32
                                        * f32::powf(10.0, val.exponent as f32)
                                }
                            },
                            None => 0.0,
                        };

                        let illuminance = f(&device.illuminance);
                        let red = f(&device.red);
                        let green = f(&device.green);
                        let blue = f(&device.blue);

                        return Ok(Some(AmbientLightInputRpt { illuminance, red, blue, green }));
                    }
                }
            }
            Ok(None)
        }
        Ok(Err(e)) => Err(format_err!("ReadInputReports error: {}", e)),
        Err(e) => Err(format_err!("FIDL call failed: {}", e)),
    }
}
/// Reads the sensor's input report and decodes it.
Reads the sensor's input report and decodes it.
Reads the sensor ' s input report and decodes it .
async fn read_sensor_input_report(
    device: &AmbientLightInputReportReaderProxy,
) -> Result<Option<AmbientLightInputRpt>, Error> {
    let r = device.proxy.read_input_reports().await;
    match r {
        Ok(Ok(reports)) => {
            for report in reports {
                if report.report_id.unwrap_or(0) != device.illuminance.as_ref().unwrap().report_id {
                    continue;
                }
                if let Some(sensor) = report.sensor {
                    if let Some(values) = sensor.values {
                        let f = |component: &Option<AmbientLightComponent>| match component {
                            Some(val) => match val.exponent {
                                0 => values[val.report_index] as f32,
                                _ => {
                                    values[val.report_index] as f32
                                        * f32::powf(10.0, val.exponent as f32)
                                }
                            },
                            None => 0.0,
                        };
                        let illuminance = f(&device.illuminance);
                        let red = f(&device.red);
                        let green = f(&device.green);
                        let blue = f(&device.blue);
                        return Ok(Some(AmbientLightInputRpt { illuminance, red, blue, green }));
                    }
                }
            }
            Ok(None)
        }
        Ok(Err(e)) => Err(format_err!("ReadInputReports error: {}", e)),
        Err(e) => Err(format_err!("FIDL call failed: {}", e)),
    }
}
async fn read_sensor_input_report ( device : & AmbientLightInputReportReaderProxy , ) -> Result < Option < AmbientLightInputRpt > , Error > { let r = device . proxy . read_input_reports ( ) . await ; match r { Ok ( Ok ( reports ) ) => { for report in reports { if report . report_id . unwrap_or ( 0 ) != device . illuminance . as_ref ( ) . unwrap ( ) . report_id { continue ; } if let Some ( sensor ) = report . sensor { if let Some ( values ) = sensor . values { let f = | component : & Option < AmbientLightComponent > | match component { Some ( val ) => match val . exponent { 0 => values [ val . report_index ] as f32 , _ => { values [ val . report_index ] as f32 * f32 :: powf ( 10.0 , val . exponent as f32 ) } } , None => 0.0 , } ; let illuminance = f ( & device . illuminance ) ; let red = f ( & device . red ) ; let green = f ( & device . green ) ; let blue = f ( & device . blue ) ; return Ok ( Some ( AmbientLightInputRpt { illuminance , red , blue , green } ) ) ; } } } Ok ( None ) } Ok ( Err ( e ) ) => Err ( format_err ! ( " " e ) ) , Err ( e ) => Err ( format_err ! ( " " e ) ) , } }
Reads the sensor's input report and decodes it.
Reads the sensor ' s input report and decodes it .
device
&AmbientLightInputReportReaderProxy
device
&AmbientLightInputReportReaderProxy