Brightness control and dimming logic for button device.
More...
Brightness control and dimming logic for button device.
Overview
This module implements adaptive brightness control with configurable thresholds and step sizes. The dimming behavior changes based on current brightness level - brighter levels use larger steps for faster adjustment, while darker levels use smaller steps for fine control.
Algorithm Description
The brightness adjustment uses two lookup tables:
- threshTab: Defines brightness range boundaries (thresholds)
- stepsTab: Defines adjustment step size for each range
When adjusting brightness, the algorithm:
- Determines current brightness range using threshTab
- Selects appropriate step size from stepsTab
- Increments/decrements brightness by that step
Customizing Brightness Behavior
Modifying Brightness Thresholds
Edit the threshTab[] array to change brightness range boundaries:
#define OT_BTN_LEVELS_COUNT 7
#define OT_BTN_MAX_BRIGHTNESS
Maximum brightness value (full brightness).
Definition ad_btn_dimControl.h:105
#define OT_BTN_LEVELS_COUNT
Number of brightness threshold levels.
Definition ad_btn_dimControl.h:107
Modifying Brightness Steps
Edit the stepsTab[] array to change adjustment speed for each range:
Modifying Brightness Limits
Adjust minimum and maximum brightness values:
#define OT_BTN_MAX_BRIGHTNESS 200
#define OT_BTN_MIN_BRIGHTNESS 10
Configuration Examples
Smooth Fine Control
#define OT_BTN_LEVELS_COUNT 8
static const uint8_t threshTab[] = {15, 30, 60, 90, 120, 160, 200, 255};
static const uint8_t stepsTab[] = {1, 1, 2, 3, 4, 6, 8, 12};
Fast Adjustment
#define OT_BTN_LEVELS_COUNT 3
static const uint8_t threshTab[] = {85, 170, 255};
static const uint8_t stepsTab[] = {10, 20, 40};
- Note
- Both arrays must have exactly OT_BTN_LEVELS_COUNT elements
-
Last element of threshTab must equal OT_BTN_MAX_BRIGHTNESS
-
Array elements must be in ascending order
- Warning
- After modifying tables, recompile the entire project to ensure consistency
- Version
- 0.1
- Date
- 06-11-2025
- Author
- Jan Łukaszewicz (plhar.nosp@m.eo@g.nosp@m.mail..nosp@m.com)
- Copyright
- © 2025 MIT LICENCE
◆ ad_btn_dim_GetNewValue()
| uint8_t ad_btn_dim_GetNewValue |
( |
uint32_t | dimLevel | ) |
|
Calculate new brightness value based on current dim level.
- Parameters
-
| [in] | dimLevel | Current brightness level (0-255) or direction indicator |
- Returns
- New brightness value after applying appropriate step adjustment
- Return values
-
| 0 | if brightness drops below OT_BTN_MIN_BRIGHTNESS (turns off) |
| OT_BTN_MAX_BRIGHTNESS | if brightness exceeds maximum |
This function implements the adaptive brightness algorithm:
- Identifies current brightness range using threshTab[]
- Selects step size from stepsTab[]
- Applies adjustment in dimming or brightening direction
- Ensures result stays within valid range
- Note
- Function handles both dimming (decreasing) and brightening (increasing) operations