Have been trying to experiment with ALS but so far cannot get it to work. I have used the following snippet:
navigator.permissions.query({ name: 'ambient-light-sensor' }).then(result => {
if (result.state === 'denied') {
console.log('Permission to use ambient light sensor is denied.');
return;
}
const als = new AmbientLightSensor({frequency: 10});
als.addEventListener('activate', () => console.log('Ready to measure EV.'));
als.addEventListener('error', event => console.log(`Error: ${event.error.name}`));
als.addEventListener('reading', () => {
// Defaut ISO value.
const ISO = 100;
// Incident-light calibration constant.
const C = 250;
let EV = Math.round(Math.log2((als.illuminance * ISO) / C));
console.log(`Exposure Value (EV) is: ${EV}`);
});
als.start();
});
The error that I am getting is: Error: NotReadableError. No other errors or warning in the console.
Chrome Canary v97, MacOS 10.15.7