OpenThread_app
Loading...
Searching...
No Matches
Button Device Brightness Control

Brightness control and dimming logic for button device. More...

Topics

 Brightness Constants

Functions

uint8_t ad_btn_dim_GetNewValue (uint32_t dimLevel)
 Calculate new brightness value based on current dim level.

Detailed Description

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:

  1. Determines current brightness range using threshTab
  2. Selects appropriate step size from stepsTab
  3. Increments/decrements brightness by that step

Customizing Brightness Behavior

Modifying Brightness Thresholds

Edit the threshTab[] array to change brightness range boundaries:

// Default configuration (5 ranges)
static const uint8_t threshTab[OT_BTN_LEVELS_COUNT] = {30, 80, 160, 220, OT_BTN_MAX_BRIGHTNESS};
// Custom configuration - more ranges for finer control
#define OT_BTN_LEVELS_COUNT 7
static const uint8_t threshTab[OT_BTN_LEVELS_COUNT] = {20, 50, 100, 150, 200, 230, OT_BTN_MAX_BRIGHTNESS};
#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:

// Default configuration
static const uint8_t stepsTab[OT_BTN_LEVELS_COUNT] = {1, 4, 6, 8, 16};
// Custom - slower dimming for more precise control
static const uint8_t stepsTab[OT_BTN_LEVELS_COUNT] = {1, 2, 3, 4, 8};
// Custom - faster dimming for quick adjustment
static const uint8_t stepsTab[OT_BTN_LEVELS_COUNT] = {2, 8, 12, 16, 32};

Modifying Brightness Limits

Adjust minimum and maximum brightness values:

#define OT_BTN_MAX_BRIGHTNESS 200 // Reduce maximum brightness to 78%
#define OT_BTN_MIN_BRIGHTNESS 10 // Increase minimum visible brightness

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)

Function Documentation

◆ ad_btn_dim_GetNewValue()

uint8_t ad_btn_dim_GetNewValue ( uint32_t dimLevel)

Calculate new brightness value based on current dim level.

Parameters
[in]dimLevelCurrent brightness level (0-255) or direction indicator
Returns
New brightness value after applying appropriate step adjustment
Return values
0if brightness drops below OT_BTN_MIN_BRIGHTNESS (turns off)
OT_BTN_MAX_BRIGHTNESSif brightness exceeds maximum

This function implements the adaptive brightness algorithm:

  1. Identifies current brightness range using threshTab[]
  2. Selects step size from stepsTab[]
  3. Applies adjustment in dimming or brightening direction
  4. Ensures result stays within valid range
Note
Function handles both dimming (decreasing) and brightening (increasing) operations