Skip to content

Commit

Permalink
Fix brightness not turnning on with Numpad after change it's volume(t…
Browse files Browse the repository at this point in the history
…ries2)
  • Loading branch information
vazw committed May 9, 2024
1 parent a4a3b42 commit ae88e25
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
5 changes: 3 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ impl Numpad {
self.touchpad_i2c.set_brightness(self.state.brightness)?;
// don't grab touchpad - allow moving pointer even if active
} else {
self.touchpad_i2c.set_brightness(Brightness::Zero)?;
self.touchpad_i2c.set_brightness(Brightness::Off)?;
// we might still be grabbing the touchpad. release it.
self.ungrab();
}
Expand All @@ -201,10 +201,11 @@ impl Numpad {
self.state.numlock = false;
// we might still be grabbing the touchpad. release it.
self.ungrab();
self.touchpad_i2c.set_brightness(Brightness::Zero)
self.touchpad_i2c.set_brightness(Brightness::Off)
} else {
debug!("setting on {}", self.state.brightness);
self.state.numlock = true;
self.touchpad_i2c.set_brightness(Brightness::On)?;
self.touchpad_i2c.set_brightness(self.state.brightness)
}
// The numlock has already been toggled on the system- no need to press
Expand Down
17 changes: 10 additions & 7 deletions src/touchpad_i2c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,25 @@ use i2cdev::linux::{LinuxI2CDevice, LinuxI2CError};

#[derive(Debug, Clone, Copy)]
pub enum Brightness {
Zero = 0,
Low = 31,
Half = 24,
Full = 1,
Off = 0,
On = 1,
Low = 0x41,
Half = 0x44,
Full = 0x48,
}

impl Default for Brightness {
fn default() -> Self {
Brightness::Full
Brightness::On
}
}

impl std::fmt::Display for Brightness {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
use Brightness::*;
let level = match self {
Zero => "Zero",
Off => "Off",
On => "On",
Low => "Low",
Half => "Half",
Full => "Full",
Expand All @@ -36,7 +38,8 @@ impl Brightness {
fn next(&self) -> Self {
use Brightness::*;
match self {
Zero => Default::default(), // Jump to default
Off => Default::default(), // Jump to default
On => Low,
Low => Half,
Half => Full,
Full => Low,
Expand Down

0 comments on commit ae88e25

Please sign in to comment.