Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature request]: Support applesmc ALS sensor type #74

Open
podbyte opened this issue May 12, 2023 · 5 comments
Open

[Feature request]: Support applesmc ALS sensor type #74

podbyte opened this issue May 12, 2023 · 5 comments

Comments

@podbyte
Copy link

podbyte commented May 12, 2023

Please describe your feature request

Trying to use wluma on a MacBook Pro 11,x on Arch. The ALS output is at
/sys/devices/platform/applesmc.768/light

Error shown is thread 'als' panicked at 'Unable to initialize ALS IIO sensor: "No iio device found"', src/main.rs:112:26

wluma will not launch.

@maximbaz
Copy link
Owner

Hello! Exciting to get it it working on MacBook!

To clarify, you changed this config line, and you get the crash, is that right?

path = "/sys/bus/iio/devices"

Could you show me the contents of the folder?

ls -al /sys/devices/platform/applesmc.768/light

Thanks

@podbyte
Copy link
Author

podbyte commented May 15, 2023

Hello! Exciting to get it it working on MacBook!

To clarify, you changed this config line, and you get the crash, is that right?

path = "/sys/bus/iio/devices"

Could you show me the contents of the folder?

ls -al /sys/devices/platform/applesmc.768/light

Thanks

Hi, only just realised there was a config.toml, I pulled it from the AUR and didn't manually build it.
/sys/devices/platform/applesmc.768/light is a file, it reads (x,0) (x is the light level).
I don't know rust but I made a fork and I'm trying to see if I can get it to work.

@maximbaz
Copy link
Owner

maximbaz commented May 16, 2023

Lovely! Allow me to give you some general pointers, and feel free to ask for clarification 🙂

In this project, the architecture is already prepared to be plug-and-play for different hardware. iio is just one of many light sensors, and you are the first person to desire to have applesmc type.

First, create a file next to iio.rs and call it applesmc.rs. Inside you will implement the logic that is responsible for letting the rest of the app know about this particular driver.

At the very minimum, your file must contain the implementation for this trait:

wluma/src/als/mod.rs

Lines 11 to 13 in 191e984

pub trait Als {
fn get(&self) -> Result<String, Box<dyn Error>>;
}

In iio.rs, this looks like so:

wluma/src/als/iio.rs

Lines 72 to 80 in 191e984

impl super::Als for Als {
fn get(&self) -> Result<String, Box<dyn Error>> {
let raw = self.get_raw()?;
let profile = super::find_profile(raw, &self.thresholds);
log::trace!("ALS (iio): {} ({})", profile, raw);
Ok(profile)
}
}

and in time.rs, it looks like so:

wluma/src/als/time.rs

Lines 15 to 23 in 191e984

impl super::Als for Als {
fn get(&self) -> Result<String, Box<dyn Error>> {
let raw = Local::now().hour() as u64;
let profile = super::find_profile(raw, &self.thresholds);
log::trace!("ALS (time): {} ({})", profile, raw);
Ok(profile)
}
}

Most likely, you can have exactly the same function, with substituted "raw" value read from your sensor.

What are those "thresholds": your sensor will give some integer values, and we need to convert them to some logical groups. I recommend trying to have the same groups as here ("night", "dark", "dim", etc) - and the numbers are the values from your /sys/devices/platform/applesmc.768/light file under these conditions:

thresholds = { 0 = "night", 20 = "dark", 80 = "dim", 250 = "normal", 500 = "bright", 800 = "outdoors" }

Don't worry too much about getting the perfect values, it's just a default config. But it would be nice for them to be reasonable for most people 😉 How you find them is an art... Go in a dark room, see what value your sensor shows, go in a sunny day outside and see the values, etc...

Once you do this, just fill out the rest of the glue code, like defining config like so:

wluma/src/config/app.rs

Lines 10 to 14 in 191e984

pub enum Als {
Iio {
path: String,
thresholds: HashMap<u64, String>,
},

Extending config.toml with your example commented out, etc, whatever is needed to make the app run 🙂

And good luck, enjoy this exploration!

@maximbaz maximbaz changed the title [Feature request]: ALS IIO sensor not found. Change path to sensor? [Feature request]: Support applesmc ALS sensor type May 16, 2023
@nullptr-deref
Copy link

Have kind of the same issue as well.
I'm using MacBook Pro (early 2011) and trying to get wluma working properly but it halts with error:

thread 'als' panicked at 'Unable to initialize ALS IIO sensor: "No iio device found"', src/main.rs:112:26

I have

iio:device0
trigger0

under /sys/bus/iio/devices directory which are symlinks somewhere into the Linux deeps.

I tried to set [als.iio] path both to /sys/bus/iio/devices/ and /sys/bus/iio/devices/iio:device0 but had no success.

@maximbaz
Copy link
Owner

maximbaz commented Jun 9, 2023

Judging by what you shared, your laptop might not have iio type of ambient light sensor - you could check inside the iio:device0 folder, there will be a file called name, and it will tell you what this sensor is - wluma will only use sensors whose name is als (and it gets the sensor values from another file in the same directory called in_illuminance_raw.

This thread is about a different kind of sensor that wluma currently doesn't support, called applesmc, you can check if you have this folder on your laptop /sys/devices/platform/applesmc.768/, if yes - implementing this new sensor type this issue will indeed solve the issue for you; if you don't have it, it might be better to open another issue if you would like to continue this investigation 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants