class Backlight::Settings
Class to edit backlight settings on intel-based systems
Attributes
max[R]
output[R]
value[R]
Public Class Methods
new(output = '/sys/class/backlight/intel_backlight/brightness', max = '/sys/class/backlight/intel_backlight/max_brightness')
click to toggle source
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
# 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
Public Instance Methods
get()
click to toggle source
Gets the backlight brightness as a percentage.
# File lib/backlight.rb, line 85 def get (100.0 * @value / @max).round end
max=(max)
click to toggle source
Sets the maximum brightness value of the backlight.
Attributes¶ ↑
-
max
- This can either be the filename to read the max from, or anumeric maximum value.
# File lib/backlight.rb, line 47 def max=(max) if max.is_a? Numeric raise(ArgumentError, 'Max Brightness Cannot Be Less Than 0') if max < 0 @max = max.to_i elsif max.is_a? String raise(ArgumentError, 'Max File Does Not Exist') unless File.exist?(max) @max = IO.read(max).to_i else raise(ArgumentError, 'Unknown Parameter Type') end end
output=(file)
click to toggle source
set(percent)
click to toggle source
Sets the backlight brightness as a percentage.
# File lib/backlight.rb, line 78 def set(percent) self.value = (percent * @max / 100.0).round end
value=(value)
click to toggle source
Sets the value of the backlight, from zero to the set maximum. Should be given in integer form - Strings will be converted, floats will be truncated.
Attributes¶ ↑
-
value
- The value to set to the backlight output file
# File lib/backlight.rb, line 68 def value=(value) value = value.to_i raise(ArgumentError, 'Invalid Value') if value < 0 || value > @max IO.write(@output, value) @value = value end