-
-
Notifications
You must be signed in to change notification settings - Fork 267
Feature/add yocto light sensor #1125
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
base: master
Are you sure you want to change the base?
Feature/add yocto light sensor #1125
Conversation
using an yocto light sensor to automatically set the screen brightness based off the ambient light level in lux it can be toggled per screen, as well light levels set per screen.
|
Very cool feature! Thanks for the PR! Light sensor support has come up many times over the years, but the sensor requested hasn't been consistent. If Twinkle Tray were to offer light sensor support, I would like for it to be as vendor agnostic as possible. For example, I would prefer the settings tab be called "Light Sensor", with an on-page option to select the type of sensor the user has (if supported). From there, users could input the settings relevant to their light sensor type. I don't have a light sensor myself, so I would love to hear what other users have to say about this. I'm not going to merge this PR as-is, but I have activated the workflow so that users can play around with the feature: |
|
Just to clarify, I don't expect you to add support for other light sensors. The idea is that if/when support for other light sensors are contributed, they can share the same settings tab/UI. |
|
Ok, thanks I'm going to go ahead and make those changes, hopefully before Christmas. I'll change it so it's more extendable, although of course it will be a bit of guess work as I don't know how other sensors will work. |
|
Hi, @xanderfrangos Were there any attempts to integrate laptops sensors? Many laptops have ambient light sensors, including mine. I was thinking that when a laptop has a built-in ambient light sensor and it's connected to an external monitor, it can control it's brightness automatically. |
|
Hi @psxvoid, So while revisiting the pr, I've looked in to the ambient sensors built in to a laptop, as i figured how hard can it be? What I have found is there is a simple windows UWP api for it. however that is an UWP api, and im not really sure how to consume that in to electron, I've tired edge-js, but that api isn't avabile that way (although i didn't spend much time on it) here was the code I quickly tired (just make a bare bones node project with edge-js installed and run this as a script) var edge = require('edge-js');
var getLight = edge.func({
source: function() {/*
using System.Threading.Tasks;
using Windows.Devices.Sensors;
public class Startup
{
public async Task<object> Invoke(dynamic input)
{
var sensor = LightSensor.GetDefault();
if (sensor == null)
{
return "No light sensor available";
}
var reading = sensor.GetCurrentReading();
return reading.IlluminanceInLux;
}
}
*/}
});
getLight(null, function (error, result) {
if (error) throw error;
console.log("Light sensor output (lux):", result);
});another option is nodeRT but I found that requires installing visual studio 2013, although there are many versions of the package built for different version of windows sdk here What I am going to do is add in a fake ui sensor, that lets you mimic having a sensor plugged in. This also lets me test what its like to extend the sensor page with multiple sensors. I will focus on the changes requested (more generic ui, support for multiple sensors in theory), then maybe look at how to add the ambient light sensor. |
|
Hi @ThomasMonkman, I've seen this UWP API as well, though I was planning to use an older Win32 Sensor API, seems like it can be consumed similarly to how it's already done in other native modules in this repo. But nodeRT might be a better option indeed, haven't tried it.
Yes, sure, don't want to put any pressure on you :) I was thinking that your feature might intersect a bit with what I want, but I'm not completely sure. Seems like your feature request is related to a remote light sensor - there is "yokto virtual hub" on your screenshots. And probably a UI for a built-in into a laptop ambient light sensor might be slightly different. |
|
@psxvoid Thanks, ohh yes that looks like it could work. So from what I've seen the ambient light sensor returns Lux, which is the same as the yocto sensor, so hopefully it should all just work "flawlessly" :D haha they even have an article talking through light aware ui I'm going to change the ui, so it should be simple to slot in another sensor. and yes it would be great if it worked with the ambient light sensor of a laptop, i went down the yocto route as I wanted it on my pc. |
|
@ThomasMonkman It's a real pain in the ass, but you can access the UWP APIs through C++. I had to write a few Node modules for Twinkle Tray that do this. For example: |
|
@xanderfrangos @psxvoid Ok I've got windows ambient light sensor working in the project using the old COM api you linked above, I need some time to wrap up the ui for it, but I think it shouldn't be much more work. Then hopefully this should work for a wide range of people :) I'm not sure if I should move this pr in to draft? But I need to push some in progress as I'm travelling and don't want it to disappear in to the ether. But it is not ready to review, I will ping when it is. |
…tor for multiple sensors
Hello! First off this has been a great library to use, thank you very much for making it.
I've added the ability to set the brightness levels based off the ambient light levels from an yocto light sensor
It works exactly like phones or laptops where it will just adjust the light levels based on how bright the room is.
You set a brightness mapping per screen, setting the 0% and 100% brightness at "X" Lux, it then linearly interpolates between that based on sensor readings.
I've been using it for the last few weeks, and it's like automagic :) as I found my self always having to adjust my screens, especially now its getting dark so fast in winter.
It can be toggled per screen, as well light levels set per screen.
Translations
I've completely left out translations as I wasn't sure how new translations are integrated, I do use a fair amount of information inside strings, so I'm not sure how that would work. But I'm happy to add that in.
I've tired my best to make minimal changes to the repo, and kept in the style you currently have everything.
Settings
I've also tried to make the settings ui as informative as possible, so hopefully someone can set it up without help
User Flow
Error handling
I've added error handling as much as I could, here are some screenshots show that off
Everything ok

No sensor found


No connection to virtual hub