PebbleOS v4.48.0-75-g7416f78a1
Loading...
Searching...
No Matches
Ambient light sensor

Ambient light sensor (ALS) class. More...

Modules

 Ambient light sensor drivers
 Interface for ambient light sensor drivers.
 
 OPT3001
 TI OPT3001 Ambient light sensor driver.
 
 Simulator
 Simulated ambient light sensor, reading what pbl_als_sim_set() sets, complete darkness by default.
 
 W1160
 Sensortek W1160 Ambient light sensor driver.
 

Data Structures

struct  pbl_als_scale
 Raw count to lux calibration: lux = (raw - offset) * num / den. More...
 

Macros

#define PBL_ALS_LEVEL_MAX   0U
 Upper bound of the raw light level scale (CONFIG_ALS_BITS bits).
 

Functions

bool pbl_als_is_ready (const struct pbl_als *als)
 Check whether the sensor is ready.
 
int pbl_als_read (const struct pbl_als *als, uint32_t *level)
 Read the light level.
 
void pbl_als_prime (const struct pbl_als *als)
 Announce that readings will be wanted soon.
 
void pbl_als_release (const struct pbl_als *als)
 Drop a reference taken with pbl_als_prime().
 
void pbl_als_suspend (const struct pbl_als *als)
 Stop sampling until the matching pbl_als_resume().
 
void pbl_als_resume (const struct pbl_als *als)
 Drop a reference taken with pbl_als_suspend().
 
bool pbl_als_has_lux (const struct pbl_als *als)
 Check whether the sensor is calibrated to lux.
 
uint32_t pbl_als_to_lux (const struct pbl_als *als, uint32_t level)
 Convert a light level to lux.
 

Variables

const struct pbl_als *const ALS
 The board's ambient light sensor.
 

Detailed Description

Ambient light sensor (ALS) class.

An ambient light sensor is a struct pbl_als device. Readings are raw counts between 0 and PBL_ALS_LEVEL_MAX; a calibrated instance converts them to lux with pbl_als_to_lux().

Sampling is controlled by two reference counts kept by the class: a consumer that will read the sensor soon primes it, and code that would disturb the reading (e.g. backlight bleed-through) suspends it. The driver is told whenever the resulting state changes, and samples while primed and not suspended.

Every call into the driver runs with the device lock held, a recursive mutex.

uint32_t level;
...
if (pbl_als_read(ALS, &level) == 0) {
uint32_t lux = pbl_als_to_lux(ALS, level);
}
const struct pbl_als *const ALS
The board's ambient light sensor.
void pbl_als_prime(const struct pbl_als *als)
Announce that readings will be wanted soon.
int pbl_als_read(const struct pbl_als *als, uint32_t *level)
Read the light level.
void pbl_als_release(const struct pbl_als *als)
Drop a reference taken with pbl_als_prime().
uint32_t pbl_als_to_lux(const struct pbl_als *als, uint32_t level)
Convert a light level to lux.

Data Structure Documentation

◆ pbl_als_scale

struct pbl_als_scale

Raw count to lux calibration: lux = (raw - offset) * num / den.

Covers the sensor and the optical path in front of it, so it belongs to the board.

Data Fields
uint32_t den Denominator.
uint32_t num Numerator.
uint32_t offset Dark offset, in raw counts.

Macro Definition Documentation

◆ PBL_ALS_LEVEL_MAX

#define PBL_ALS_LEVEL_MAX   0U

Upper bound of the raw light level scale (CONFIG_ALS_BITS bits).

Function Documentation

◆ pbl_als_has_lux()

bool pbl_als_has_lux ( const struct pbl_als *  als)

Check whether the sensor is calibrated to lux.

Parameters
alsAmbient light sensor.
Returns
true if pbl_als_to_lux() converts to lux.

◆ pbl_als_is_ready()

bool pbl_als_is_ready ( const struct pbl_als *  als)

Check whether the sensor is ready.

Parameters
alsAmbient light sensor.
Returns
true if the sensor came up.

◆ pbl_als_prime()

void pbl_als_prime ( const struct pbl_als *  als)

Announce that readings will be wanted soon.

Reference counted; balance with pbl_als_release(). Lets drivers that sample continuously start ahead of the first read. Does nothing if the sensor is not ready.

Parameters
alsAmbient light sensor.

◆ pbl_als_read()

int pbl_als_read ( const struct pbl_als *  als,
uint32_t *  level 
)

Read the light level.

Parameters
alsAmbient light sensor.
[out]levelRaw light level between 0 and PBL_ALS_LEVEL_MAX.
Returns
0, -ENODEV if the sensor is not ready, or a negative errno.

◆ pbl_als_release()

void pbl_als_release ( const struct pbl_als *  als)

Drop a reference taken with pbl_als_prime().

Parameters
alsAmbient light sensor.

◆ pbl_als_resume()

void pbl_als_resume ( const struct pbl_als *  als)

Drop a reference taken with pbl_als_suspend().

Parameters
alsAmbient light sensor.

◆ pbl_als_suspend()

void pbl_als_suspend ( const struct pbl_als *  als)

Stop sampling until the matching pbl_als_resume().

Reference counted. Used while something disturbs the sensor, e.g. backlight bleed-through. Does nothing if the sensor is not ready.

Parameters
alsAmbient light sensor.

◆ pbl_als_to_lux()

uint32_t pbl_als_to_lux ( const struct pbl_als *  als,
uint32_t  level 
)

Convert a light level to lux.

On uncalibrated sensors the level is returned unchanged, so callers can use the result unconditionally.

Parameters
alsAmbient light sensor.
levelLight level, after screen compensation if any.
Returns
Light level in lux, or level if uncalibrated.

Variable Documentation

◆ ALS

const struct pbl_als* const ALS
extern

The board's ambient light sensor.