mirror of
https://gitlab.steamos.cloud/holo/steamos-manager.git
synced 2025-07-05 14:10:34 -04:00
manager: Expand AmbientLightSensor1 to allow for querying systems with multiple sensors
This commit is contained in:
parent
064207ed76
commit
84a44a879f
3 changed files with 62 additions and 25 deletions
|
@ -25,7 +25,7 @@
|
||||||
|
|
||||||
Note: Will be -1.0 if ALS calibration is unavailable.
|
Note: Will be -1.0 if ALS calibration is unavailable.
|
||||||
-->
|
-->
|
||||||
<property name="AlsCalibrationGain" type="d" access="read"/>
|
<property name="AlsCalibrationGain" type="ad" access="read"/>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
GetAlsIntegrationTimeFileDescriptor:
|
GetAlsIntegrationTimeFileDescriptor:
|
||||||
|
@ -37,6 +37,7 @@
|
||||||
occurred.
|
occurred.
|
||||||
-->
|
-->
|
||||||
<method name="GetAlsIntegrationTimeFileDescriptor">
|
<method name="GetAlsIntegrationTimeFileDescriptor">
|
||||||
|
<arg type="u" name="index" direction="in"/>
|
||||||
<arg type="h" name="descriptor" direction="out"/>
|
<arg type="h" name="descriptor" direction="out"/>
|
||||||
</method>
|
</method>
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,7 @@ use crate::wifi::{
|
||||||
set_wifi_backend, set_wifi_debug_mode, set_wifi_power_management_state, WifiBackend,
|
set_wifi_backend, set_wifi_debug_mode, set_wifi_power_management_state, WifiBackend,
|
||||||
WifiDebugMode, WifiPowerManagement,
|
WifiDebugMode, WifiPowerManagement,
|
||||||
};
|
};
|
||||||
use crate::API_VERSION;
|
use crate::{path, API_VERSION};
|
||||||
|
|
||||||
macro_rules! with_platform_config {
|
macro_rules! with_platform_config {
|
||||||
($config:ident = $field:ident ($name:literal) => $eval:expr) => {
|
($config:ident = $field:ident ($name:literal) => $eval:expr) => {
|
||||||
|
@ -83,8 +83,6 @@ impl SteamOSManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const ALS_INTEGRATION_PATH: &str = "/sys/devices/platform/AMDI0010:00/i2c-0/i2c-PRP0001:01/iio:device0/in_illuminance_integration_time";
|
|
||||||
|
|
||||||
#[interface(name = "com.steampowered.SteamOSManager1.RootManager")]
|
#[interface(name = "com.steampowered.SteamOSManager1.RootManager")]
|
||||||
impl SteamOSManager {
|
impl SteamOSManager {
|
||||||
async fn prepare_factory_reset(&self) -> fdo::Result<u32> {
|
async fn prepare_factory_reset(&self) -> fdo::Result<u32> {
|
||||||
|
@ -133,25 +131,44 @@ impl SteamOSManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[zbus(property(emits_changed_signal = "false"))]
|
#[zbus(property(emits_changed_signal = "false"))]
|
||||||
async fn als_calibration_gain(&self) -> f64 {
|
async fn als_calibration_gain(&self) -> Vec<f64> {
|
||||||
// Run script to get calibration value
|
// Run script to get calibration value
|
||||||
let result = script_output(
|
let mut gains = Vec::new();
|
||||||
"/usr/bin/steamos-polkit-helpers/jupiter-get-als-gain",
|
let indices: &[&str] = match variant().await {
|
||||||
&[] as &[String; 0],
|
Ok(HardwareVariant::Jupiter) => &["2"],
|
||||||
)
|
Ok(HardwareVariant::Galileo) => &["2", "4"],
|
||||||
.await;
|
_ => return Vec::new(),
|
||||||
match result {
|
};
|
||||||
Ok(as_string) => as_string.trim().parse().unwrap_or(-1.0),
|
for index in indices {
|
||||||
Err(message) => {
|
let result = script_output(
|
||||||
error!("Unable to run als calibration script: {}", message);
|
"/usr/bin/steamos-polkit-helpers/jupiter-get-als-gain",
|
||||||
-1.0
|
&["-s", index],
|
||||||
}
|
)
|
||||||
|
.await;
|
||||||
|
gains.push(match result {
|
||||||
|
Ok(as_string) => as_string.trim().parse().unwrap_or(-1.0),
|
||||||
|
Err(message) => {
|
||||||
|
error!("Unable to run als calibration script: {}", message);
|
||||||
|
-1.0
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gains
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_als_integration_time_file_descriptor(&self) -> fdo::Result<Fd> {
|
async fn get_als_integration_time_file_descriptor(&self, index: u32) -> fdo::Result<Fd> {
|
||||||
// Get the file descriptor for the als integration time sysfs path
|
// Get the file descriptor for the als integration time sysfs path
|
||||||
let result = File::create(ALS_INTEGRATION_PATH).await;
|
let i0 = match variant().await.map_err(to_zbus_fdo_error)? {
|
||||||
|
HardwareVariant::Jupiter => 1,
|
||||||
|
HardwareVariant::Galileo => index,
|
||||||
|
HardwareVariant::Unknown => {
|
||||||
|
return Err(fdo::Error::Failed(String::from("Unknown model")))
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let als_path = path(format!("/sys/devices/platform/AMDI0010:00/i2c-0/i2c-PRP0001:0{i0}/iio:device{index}/in_illuminance_integration_time"));
|
||||||
|
let result = File::create(als_path).await;
|
||||||
|
|
||||||
match result {
|
match result {
|
||||||
Ok(f) => Ok(Fd::Owned(std::os::fd::OwnedFd::from(f.into_std().await))),
|
Ok(f) => Ok(Fd::Owned(std::os::fd::OwnedFd::from(f.into_std().await))),
|
||||||
Err(message) => {
|
Err(message) => {
|
||||||
|
@ -370,6 +387,7 @@ mod test {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::daemon::channel;
|
use crate::daemon::channel;
|
||||||
use crate::daemon::root::RootContext;
|
use crate::daemon::root::RootContext;
|
||||||
|
use crate::hardware::test::fake_model;
|
||||||
use crate::platform::{PlatformConfig, ScriptConfig};
|
use crate::platform::{PlatformConfig, ScriptConfig};
|
||||||
use crate::power::test::{format_clocks, read_clocks};
|
use crate::power::test::{format_clocks, read_clocks};
|
||||||
use crate::power::{self, get_gpu_performance_level};
|
use crate::power::{self, get_gpu_performance_level};
|
||||||
|
@ -461,7 +479,7 @@ mod test {
|
||||||
)]
|
)]
|
||||||
trait AlsCalibrationGain {
|
trait AlsCalibrationGain {
|
||||||
#[zbus(property(emits_changed_signal = "false"))]
|
#[zbus(property(emits_changed_signal = "false"))]
|
||||||
fn als_calibration_gain(&self) -> zbus::Result<f64>;
|
fn als_calibration_gain(&self) -> zbus::Result<Vec<f64>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
|
@ -476,19 +494,37 @@ mod test {
|
||||||
.test
|
.test
|
||||||
.process_cb
|
.process_cb
|
||||||
.set(|_, _| Ok((0, String::from("0.0\n"))));
|
.set(|_, _| Ok((0, String::from("0.0\n"))));
|
||||||
assert_eq!(proxy.als_calibration_gain().await.unwrap(), 0.0);
|
|
||||||
|
fake_model(HardwareVariant::Jupiter)
|
||||||
|
.await
|
||||||
|
.expect("fake_model");
|
||||||
|
assert_eq!(proxy.als_calibration_gain().await.unwrap(), &[0.0]);
|
||||||
|
|
||||||
|
fake_model(HardwareVariant::Galileo)
|
||||||
|
.await
|
||||||
|
.expect("fake_model");
|
||||||
|
assert_eq!(proxy.als_calibration_gain().await.unwrap(), &[0.0, 0.0]);
|
||||||
|
|
||||||
|
fake_model(HardwareVariant::Unknown)
|
||||||
|
.await
|
||||||
|
.expect("fake_model");
|
||||||
|
assert_eq!(proxy.als_calibration_gain().await.unwrap(), &[]);
|
||||||
|
|
||||||
|
fake_model(HardwareVariant::Jupiter)
|
||||||
|
.await
|
||||||
|
.expect("fake_model");
|
||||||
|
|
||||||
test.h
|
test.h
|
||||||
.test
|
.test
|
||||||
.process_cb
|
.process_cb
|
||||||
.set(|_, _| Ok((0, String::from("1.0\n"))));
|
.set(|_, _| Ok((0, String::from("1.0\n"))));
|
||||||
assert_eq!(proxy.als_calibration_gain().await.unwrap(), 1.0);
|
assert_eq!(proxy.als_calibration_gain().await.unwrap(), &[1.0]);
|
||||||
|
|
||||||
test.h
|
test.h
|
||||||
.test
|
.test
|
||||||
.process_cb
|
.process_cb
|
||||||
.set(|_, _| Ok((0, String::from("big\n"))));
|
.set(|_, _| Ok((0, String::from("big\n"))));
|
||||||
assert_eq!(proxy.als_calibration_gain().await.unwrap(), -1.0);
|
assert_eq!(proxy.als_calibration_gain().await.unwrap(), &[-1.0]);
|
||||||
|
|
||||||
test.connection.close().await.unwrap();
|
test.connection.close().await.unwrap();
|
||||||
}
|
}
|
||||||
|
|
|
@ -214,14 +214,14 @@ impl SteamOSManager {
|
||||||
#[interface(name = "com.steampowered.SteamOSManager1.AmbientLightSensor1")]
|
#[interface(name = "com.steampowered.SteamOSManager1.AmbientLightSensor1")]
|
||||||
impl AmbientLightSensor1 {
|
impl AmbientLightSensor1 {
|
||||||
#[zbus(property(emits_changed_signal = "false"))]
|
#[zbus(property(emits_changed_signal = "false"))]
|
||||||
async fn als_calibration_gain(&self) -> fdo::Result<f64> {
|
async fn als_calibration_gain(&self) -> fdo::Result<Vec<f64>> {
|
||||||
getter!(self, "AlsCalibrationGain")
|
getter!(self, "AlsCalibrationGain")
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_als_integration_time_file_descriptor(&self) -> fdo::Result<Fd> {
|
async fn get_als_integration_time_file_descriptor(&self, index: u32) -> fdo::Result<Fd> {
|
||||||
let m = self
|
let m = self
|
||||||
.proxy
|
.proxy
|
||||||
.call_method::<&str, ()>("GetAlsIntegrationTimeFileDescriptor", &())
|
.call_method("GetAlsIntegrationTimeFileDescriptor", &(index))
|
||||||
.await
|
.await
|
||||||
.map_err(zbus_to_zbus_fdo)?;
|
.map_err(zbus_to_zbus_fdo)?;
|
||||||
match m.body().deserialize::<Fd>() {
|
match m.body().deserialize::<Fd>() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue