Object
Class that implements the functionality of the BlinkenLights library.
Creates a BlinkenLights instance for tty, a full pathname like ‘/dev/tty8’ to control the LEDs. This parameter is ignored under the Windows operating system.
delay is the standard delay in seconds, that is slept everytime the LED state is changed. If delay is too small your keyboard may become confused about its LEDs’ status.
# File lib/blinkenlights.rb, line 103 def initialize(tty = DEF_TTY, delay = DEF_DELAY) @tty = File.new(tty, File::RDWR) @delay = delay @old_leds = get end
Creates a BlinkenLights instance and yields to it. After the block returns the BlinkenLights#close method is called.
# File lib/blinkenlights.rb, line 116 def self.open(tty = DEF_TTY, delay = DEF_DELAY) obj = new(tty, delay) if block_given? begin yield obj ensure obj.close if obj end else obj end end
Return the state of the Caps Lock LED: true for switched on, false for off.
# File lib/blinkenlights.rb, line 280 def cap (get & LED_CAP) != LED_NONE end
Switch the Caps Lock LED on, if toggle is true, off, otherwise.
# File lib/blinkenlights.rb, line 285 def cap=(toggle) old = get if toggle set old | LED_CAP else set old & ~LED_CAP end end
Blink all the LEDs from the left to the right, and then from the right to the left. Sleep for delay seconds in between.
# File lib/blinkenlights.rb, line 214 def circle(delay = 0.0) left_to_right(delay) right_to_left(delay) self end
Close the open console tty after resetting LEDs to the original state.
# File lib/blinkenlights.rb, line 130 def close reset @tty.close self end
Return true if the constants tty has been closed.
# File lib/blinkenlights.rb, line 137 def closed? @tty.closed? end
Converge, that is, first blink the outer LEDs, then blink the inner LED. Sleep for delay seconds in between.
# File lib/blinkenlights.rb, line 237 def converge(delay = 0.0) for i in [ LED_LEFT|LED_RIGHT, LED_MIDDLE ] self.digital = i sleep delay end self end
Return the state of the LEDs expressed in binary digital mode.
# File lib/blinkenlights.rb, line 181 def digital setting = get result = 0 2.downto(0) do |i| if setting[i] == 1 result |= 1 << (2 - LEDS_VALUES.index(1 << i)) end end result end
Set LEDs to number in binary digital mode.
# File lib/blinkenlights.rb, line 169 def digital=(number) number %= 8 setting = 0 0.upto(2) do |i| if number[i] == 1 setting |= 1 << DIGITAL.index(LEDS[2 - i]) end end set setting end
Diverge, that is, first blink the inner LED, then blink the outer LEDs. Sleep for delay seconds in between.
# File lib/blinkenlights.rb, line 247 def diverge(delay = 0.0) for i in [ LED_MIDDLE, LED_LEFT|LED_RIGHT ] self.digital = i sleep delay end self end
First switches all LEDs on, then off. Sleep for delay seconds after switching them on.
# File lib/blinkenlights.rb, line 162 def flash(delay = 0.0) on sleep delay off end
Return the state of the LEDs as an integer number. (Quite low level)
# File lib/blinkenlights.rb, line 421 def get char = [0].pack('C') @tty.ioctl(KDGETLED, char) char.unpack('C')[0] end
Return the state of the left LED: true for switched on, false for off.
# File lib/blinkenlights.rb, line 326 def left (digital & LED_LEFT) != LED_NONE end
Switch the left LED on, if toggle is true, off, otherwise.
# File lib/blinkenlights.rb, line 331 def left=(toggle) old = digital if toggle self.digital = old | LED_LEFT else self.digital = old & ~LED_LEFT end end
Blink all the LEDs from the left to the right. Sleep for delay seconds in between.
# File lib/blinkenlights.rb, line 194 def left_to_right(delay = 0.0) for i in [ LED_LEFT, LED_MIDDLE, LED_RIGHT ] self.digital = i sleep delay end self end
Return the state of the middle LED: true for switched on, false for off.
# File lib/blinkenlights.rb, line 349 def middle (digital & LED_MIDDLE) != LED_NONE end
Switch the middle LED on, if toggle is true, off, otherwise.
# File lib/blinkenlights.rb, line 354 def middle=(toggle) old = digital if toggle self.digital = old | LED_MIDDLE else self.digital = old & ~LED_MIDDLE end end
Return the state of the Num Lock LED: true for switched on, false for off.
# File lib/blinkenlights.rb, line 303 def num (get & LED_NUM) != LED_NONE end
Switch the Num Lock LED on, if toggle is true, off, otherwise.
# File lib/blinkenlights.rb, line 308 def num=(toggle) old = get if toggle set old | LED_NUM else set old & ~LED_NUM end end
Switch off all LEDs.
# File lib/blinkenlights.rb, line 149 def off set LED_NONE self end
Switch on all LEDs.
# File lib/blinkenlights.rb, line 155 def on set LED_ALL self end
Switch some of the LEDs on by random. Then sleep for delay seconds.
# File lib/blinkenlights.rb, line 229 def random(delay = 0.0) self.digital = rand(LED_ALL + 1) sleep delay self end
Resets the LED state to the starting state (when the BlinkenLights object was created).
# File lib/blinkenlights.rb, line 143 def reset set @old_leds self end
Blink all the LEDs from the right to the left, and then from the left to the right. Sleep for delay seconds in between.
# File lib/blinkenlights.rb, line 222 def reverse_circle(delay = 0.0) right_to_left(delay) left_to_right(delay) self end
Return the state of the right LED: true for switched on, false for off.
# File lib/blinkenlights.rb, line 372 def right (digital & LED_RIGHT) != LED_NONE end
Switch the right LED on, if toggle is true, off, otherwise.
# File lib/blinkenlights.rb, line 377 def right=(toggle) old = digital if toggle self.digital = old | LED_RIGHT else self.digital = old & ~LED_RIGHT end end
Blink all the LEDs from the right to the left. Sleep for delay seconds in between.
# File lib/blinkenlights.rb, line 204 def right_to_left(delay = 0.0) for i in [ LED_RIGHT, LED_MIDDLE, LED_LEFT ] self.digital = i sleep delay end self end
Return the state of the Scroll Lock LED: true for switched on, false for off.
# File lib/blinkenlights.rb, line 257 def scr (get & LED_SCR) != LED_NONE end
Switch the Scroll Lock LED on, if toggle is true, off, otherwise.
# File lib/blinkenlights.rb, line 262 def scr=(toggle) old = get if toggle set old | LED_SCR else set old & ~LED_SCR end end
Set the state of the LEDs to integer number. (Quite low level)
# File lib/blinkenlights.rb, line 414 def set(number) @tty.ioctl(KDSETLED, number) sleep @delay number end
Return a string representation of this BlinkenLights instance, showing some interesting data.
# File lib/blinkenlights.rb, line 430 def to_s if @tty.closed? "#<#{self.class}: closed>" else "#<#{self.class}: delay=#{@delay}s, tty=#{@tty.path}," + " LEDs=#{'%03b' % self.digital}>" end end
Switch the Caps Lock LED on, if it was off before. Switch the Caps Lock LED off, if it was on before.
# File lib/blinkenlights.rb, line 296 def toggle_cap(delay = 0.0) self.cap = !cap sleep delay self end
Switch the left LED on, if it was off before. Switch the left LED off, if it was on before.
# File lib/blinkenlights.rb, line 342 def toggle_left(delay = 0.0) self.left = !left sleep delay self end
Switch the middle LED on, if it was off before. Switch the middle LED off, if it was on before.
# File lib/blinkenlights.rb, line 365 def toggle_middle(delay = 0.0) self.middle = !middle sleep delay self end
Switch the Num Lock LED on, if it was off before. Switch the Num Lock LED off, if it was on before.
# File lib/blinkenlights.rb, line 319 def toggle_num(delay = 0.0) self.num = !num self end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.