|
PebbleOS
|
Ambient light sensor (ALS) driver interface. More...
Macros | |
| #define | AMBIENT_LIGHT_LEVEL_ENUM_COUNT (AmbientLightLevelVeryLight + 1) |
| Number of AmbientLightLevel values. | |
Enumerations | |
| enum | AmbientLightLevel { AmbientLightLevelUnknown = 0 , AmbientLightLevelVeryDark , AmbientLightLevelDark , AmbientLightLevelLight , AmbientLightLevelVeryLight } |
| Light level enum. More... | |
Functions | |
| void | ambient_light_init (void) |
| Initialize the ambient light sensor. | |
| uint32_t | ambient_light_get_light_level (void) |
| Read the light level. | |
| void | ambient_light_prime (void) |
| Announce that readings will be wanted soon. | |
| void | ambient_light_release (void) |
| Drop a reference taken with ambient_light_prime(). | |
| void | ambient_light_suspend (void) |
| Stop sampling until the matching ambient_light_resume(). | |
| void | ambient_light_resume (void) |
| Drop a reference taken with ambient_light_suspend(). | |
| void | ambient_light_common_init (void) |
| Initialize the reference counting common to all drivers. | |
| void | ambient_light_driver_set_state (bool active, bool sampling) |
| Apply the sampling state computed by the common code. | |
| uint32_t | ambient_light_get_dark_threshold (void) |
| Get the threshold between light and dark. | |
| void | ambient_light_set_dark_threshold (uint32_t new_threshold) |
| Set the threshold between light and dark. | |
| bool | ambient_light_is_light () |
| Check whether it is light. | |
| AmbientLightLevel | ambient_light_level_to_enum (uint32_t light_level) |
| Classify a light level against the dark threshold. | |
| bool | ambient_light_lux_available (void) |
| Check whether the board has raw-count to lux coefficients. | |
| uint32_t | ambient_light_level_to_lux (uint32_t light_level) |
| Convert a light level to lux using the board coefficients. | |
Variables | |
| static const uint32_t | AMBIENT_LIGHT_LEVEL_MAX = (1U << CONFIG_AMBIENT_LIGHT_BITS) |
Upper bound of the raw light level scale (CONFIG_AMBIENT_LIGHT_BITS bits). | |
Ambient light sensor (ALS) driver interface.
Readings are raw counts between 0 and AMBIENT_LIGHT_LEVEL_MAX. Boards with calibration coefficients can convert them to lux with ambient_light_level_to_lux().
Sampling is controlled by two reference counts kept by the common code: a client that will read the sensor soon primes it, and code that would disturb the reading (e.g. backlight bleed-through) suspends it. The sensor samples while primed and not suspended.
| #define AMBIENT_LIGHT_LEVEL_ENUM_COUNT (AmbientLightLevelVeryLight + 1) |
Number of AmbientLightLevel values.
| enum AmbientLightLevel |
Light level enum.
| void ambient_light_common_init | ( | void | ) |
Initialize the reference counting common to all drivers.
Called by the driver's ambient_light_init(); prime and suspend requests made earlier are ignored.
| void ambient_light_driver_set_state | ( | bool | active, |
| bool | sampling | ||
| ) |
Apply the sampling state computed by the common code.
Implemented by the driver and called with the common lock held whenever a reference count changes. A no-op for drivers without a sampling gate.
| active | True while primed. |
| sampling | True while primed and not suspended. |
| uint32_t ambient_light_get_dark_threshold | ( | void | ) |
Get the threshold between light and dark.
| uint32_t ambient_light_get_light_level | ( | void | ) |
Read the light level.
| void ambient_light_init | ( | void | ) |
Initialize the ambient light sensor.
| bool ambient_light_is_light | ( | ) |
Check whether it is light.
| AmbientLightLevel ambient_light_level_to_enum | ( | uint32_t | light_level | ) |
Classify a light level against the dark threshold.
| light_level | Light level, in the units of the dark threshold. |
| uint32_t ambient_light_level_to_lux | ( | uint32_t | light_level | ) |
Convert a light level to lux using the board coefficients.
On boards without coefficients the level is returned unchanged, so callers can use the result unconditionally.
| light_level | Light level, after screen compensation if any. |
light_level if uncalibrated. | bool ambient_light_lux_available | ( | void | ) |
Check whether the board has raw-count to lux coefficients.
| void ambient_light_prime | ( | void | ) |
Announce that readings will be wanted soon.
Reference counted; balance with ambient_light_release(). Lets drivers that sample continuously start ahead of the first read.
| void ambient_light_release | ( | void | ) |
Drop a reference taken with ambient_light_prime().
| void ambient_light_resume | ( | void | ) |
Drop a reference taken with ambient_light_suspend().
| void ambient_light_set_dark_threshold | ( | uint32_t | new_threshold | ) |
Set the threshold between light and dark.
| new_threshold | Threshold, in the units returned by ambient_light_level_to_lux(), at most AMBIENT_LIGHT_LEVEL_MAX. |
| void ambient_light_suspend | ( | void | ) |
Stop sampling until the matching ambient_light_resume().
Reference counted. Used while something disturbs the sensor, e.g. backlight bleed-through.
|
static |
Upper bound of the raw light level scale (CONFIG_AMBIENT_LIGHT_BITS bits).