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

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 {