This repository has been archived on 2026-08-31. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
donglora/vendor/ssd1306/src/brightness.rs
T
swaitsandClaude Opus 4.6 3102fc747a feat: add display UI with splash screen, dashboard, and RSSI sparkline
Implement full SSD1306 OLED display support:
- Splash screen on boot (1.5s) with project name, version, board
- Dashboard showing radio state, config, counters, RSSI/SNR
- RSSI history sparkline (64-sample ring buffer, 2px-wide bars)
- DisplayOn/DisplayOff host commands routed via dedicated channel
- Pure render functions against generic DrawTarget (no hardware coupling)
- Display on/off control bypasses radio task entirely

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-29 20:42:54 -06:00

54 lines
1.8 KiB
Rust

//! Display brightness
/// Struct that holds display brightness
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub struct Brightness {
pub(crate) precharge: u8,
pub(crate) contrast: u8,
}
impl Default for Brightness {
fn default() -> Self {
Brightness::NORMAL
}
}
impl Brightness {
/// The dimmest predefined brightness level
pub const DIMMEST: Brightness = Brightness::custom(0x1, 0x00);
/// A dim predefined brightness level
pub const DIM: Brightness = Brightness::custom(0x2, 0x2F);
/// A medium predefined brightness level
pub const NORMAL: Brightness = Brightness::custom(0x2, 0x5F);
/// A bright predefined brightness level
pub const BRIGHT: Brightness = Brightness::custom(0x2, 0x9F);
/// The brightest predefined brightness level
pub const BRIGHTEST: Brightness = Brightness::custom(0x2, 0xFF);
/// Create a Brightness object from a precharge period and contrast pair.
///
/// `precharge` sets the `phase 2` argument of the `0xD9 Set Pre-Charge Period` command and must
/// be must be between 1 and 15.
/// The effects of this parameter are hardware dependent. For the common 128x64 displays, values
/// 1 and 2 result in different brightness levels, values above 2 behave the same was as 2.
/// See section 10.1.17 of the SSD1306 datasheet for more information.
///
/// `contrast` sets the value used in the `0x81 Set Contrast Control` command and must be
/// between 0 and 255. See section 10.1.7 of the SSD1306 datasheet for more information.
pub const fn custom(precharge: u8, contrast: u8) -> Self {
debug_assert!(
0 < precharge && precharge <= 15,
"Precharge value must be between 1 and 15"
);
Self {
precharge,
contrast,
}
}
}