Implement GetAlsIntegrationTimeFileDescriptor.

And this attempt works now. I guess this is adequate to release
as a throw away implementation to replace later with something better.
Also add strip="symbols" for release builds to get it down to a lean
3.2M size.
This commit is contained in:
Jeremy Whiting 2023-10-20 09:37:07 -06:00 committed by Jeremy Whiting
parent b73ae9ebd1
commit bf3cca29ac
4 changed files with 34 additions and 24 deletions

20
Cargo.lock generated
View file

@ -296,12 +296,6 @@ dependencies = [
"crypto-common",
]
[[package]]
name = "dyn"
version = "0.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dd5d33be9d461be19ff7168302689ed4ca466300600546c93795e845d5fa3faf"
[[package]]
name = "enumflags2"
version = "0.7.8"
@ -778,18 +772,18 @@ dependencies = [
[[package]]
name = "serde"
version = "1.0.188"
version = "1.0.192"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf9e0fcba69a370eed61bcf2b728575f726b50b55cba78064753d708ddc7549e"
checksum = "bca2a08484b285dcb282d0f67b26cadc0df8b19f8c12502c13d966bf9482f001"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.188"
version = "1.0.192"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4eca7ac642d82aa35b60049a6eccb4be6be75e599bd2e9adb5f875a737654af2"
checksum = "d6c7207fbec9faa48073f3e3074cbe553af6ea512d7c21ba46e434e70ea9fbc1"
dependencies = [
"proc-macro2",
"quote",
@ -798,9 +792,9 @@ dependencies = [
[[package]]
name = "serde_repr"
version = "0.1.16"
version = "0.1.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8725e1dfadb3a50f7e5ce0b1a540466f6ed3fe7a0fca2ac2b8b831d31316bd00"
checksum = "3081f5ffbb02284dda55132aa26daecedd7372a42417bbbab6f14ab7d6bb9145"
dependencies = [
"proc-macro2",
"quote",
@ -876,8 +870,6 @@ checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
name = "steamos-manager"
version = "0.9.0"
dependencies = [
"dyn",
"serde",
"tokio",
"zbus",
"zbus_macros",

View file

@ -5,9 +5,10 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[profile.release]
strip="symbols"
[dependencies]
dyn = "0.0.0"
serde = { version = "1.0.188", features = ["derive"] }
tokio = { version = "1.33.0", features = ["fs", "process", "io-std", "rt-multi-thread", "macros"] }
zbus = { version = "3.14.1", features = ["tokio"] }
zbus_macros = "3.14.1"

View file

@ -172,15 +172,14 @@
</method>
<!--
SetALSIntegrationTime:
@seconds: The number of seconds to use for ALS integration.
@success: True on success. False otherwise.
GetAlsIntegrationTimeFileDescriptor:
@descriptor: A unix file descriptor that can be written to to set ALS integration time.
Will be null if unable to open file or other error occurred.
Set the ALS integration time to the given value.
Get the ALS integration time file descriptor.
-->
<method name="SetALSIntegrationTime">
<arg type="i" name="seconds" direction="in"/>
<arg type="b" name="success" direction="out"/>
<method name="GetAlsIntegrationTimeFileDescriptor">
<arg type="h" name="descriptor" direction="out"/>
</method>
</interface>

View file

@ -23,8 +23,9 @@
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
use std::{ffi::OsStr};
use std::{ffi::OsStr, os::fd::{FromRawFd, IntoRawFd}};
use tokio::{process::Command, fs::File, io::AsyncWriteExt};
use zbus::zvariant::OwnedFd;
use zbus_macros::dbus_interface;
pub struct SMManager {
}
@ -237,6 +238,23 @@ impl SMManager {
}
}
async fn get_als_integration_time_file_descriptor(&self) -> Result<zbus::zvariant::OwnedFd, zbus::fdo::Error> {
// Get the file descriptor for the als integration time sysfs path
// /sys/devices/platform/AMDI0010:00/i2c-0/i2c-PRP0001:01/iio:device0/in_illuminance_integration_time
// Return -1 on error
let result = File::create("/sys/devices/platform/AMDI0010:00/i2c-0/i2c-PRP0001:01/iio:device0/in_illuminance_integration_time").await;
match result {
Ok(f) => {
let raw = f.into_std().await.into_raw_fd();
unsafe {
let fd: OwnedFd = OwnedFd::from_raw_fd(raw);
Ok(fd)
}
},
Err(message) => { println!("Error opening sysfs file for giving file descriptor {message}"); Err(zbus::fdo::Error::IOError(message.to_string())) }
}
}
/// A version property.
#[dbus_interface(property)]
async fn version(&self) -> u32 {