Class: Backlight::Settings

Inherits:
Object
  • Object
show all
Defined in:
lib/backlight.rb

Overview

Class to edit backlight settings on intel-based systems

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(output = '/sys/class/backlight/intel_backlight/brightness', max = '/sys/class/backlight/intel_backlight/max_brightness') ⇒ Settings

Initalizes a new Settings instance

Attributes

  • output - The file to write the backlight value to

  • max - The file (or numeric value) to use for the max brightness



18
19
20
21
22
23
24
25
# File 'lib/backlight.rb', line 18

def initialize(output = '/sys/class/backlight/intel_backlight/brightness',
               max = '/sys/class/backlight/intel_backlight/max_brightness')
  self.output = output
  self.max = max
  @value = IO.read(@output).to_i
  # NOTE: we don't call self.value= here, because this would make it
  # impossible to recover from a bad value being written in the file
end

Instance Attribute Details

#maxObject

Returns the value of attribute max.



7
8
9
# File 'lib/backlight.rb', line 7

def max
  @max
end

#outputObject

Returns the value of attribute output.



6
7
8
# File 'lib/backlight.rb', line 6

def output
  @output
end

#valueObject

Returns the value of attribute value.



8
9
10
# File 'lib/backlight.rb', line 8

def value
  @value
end

Instance Method Details

#getObject

Gets the backlight brightness as a percentage



83
84
85
# File 'lib/backlight.rb', line 83

def get
  100 * @value / @max
end

#set(percent) ⇒ Object

Sets the backlight brightness as a percentage



76
77
78
# File 'lib/backlight.rb', line 76

def set(percent)
  self.value = percent * @max / 100
end