Parent

Namespace

Included Modules

Files

Class Index [+]

Quicksearch

BlinkenLights

Class that implements the functionality of the BlinkenLights library.

Attributes

delay[RW]

The standard delay of this BlinkenLights instance.

Public Class Methods

new(tty = DEF_TTY, delay = DEF_DELAY) click to toggle source

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
open(tty = DEF_TTY, delay = DEF_DELAY) click to toggle source

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

Public Instance Methods

cap() click to toggle source

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
cap=(toggle) click to toggle source

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
circle(delay = 0.0) click to toggle source

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() click to toggle source

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
closed?() click to toggle source

Return true if the constants tty has been closed.

# File lib/blinkenlights.rb, line 137
  def closed?
    @tty.closed?
  end
converge(delay = 0.0) click to toggle source

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
digital() click to toggle source

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
digital=(number) click to toggle source

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(delay = 0.0) click to toggle source

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
flash(delay = 0.0) click to toggle source

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
get() click to toggle source

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
inspect() click to toggle source

Alias for to_s

left() click to toggle source

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
left=(toggle) click to toggle source

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
left_to_right(delay = 0.0) click to toggle source

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
middle() click to toggle source

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
middle=(toggle) click to toggle source

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
num() click to toggle source

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
num=(toggle) click to toggle source

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
off() click to toggle source

Switch off all LEDs.

# File lib/blinkenlights.rb, line 149
  def off
    set LED_NONE
    self
  end
on() click to toggle source

Switch on all LEDs.

# File lib/blinkenlights.rb, line 155
  def on
    set LED_ALL
    self
  end
random(delay = 0.0) click to toggle source

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
reset() click to toggle source

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
reverse_circle(delay = 0.0) click to toggle source

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
right() click to toggle source

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
right=(toggle) click to toggle source

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
right_to_left(delay = 0.0) click to toggle source

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
scr() click to toggle source

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
scr=(toggle) click to toggle source

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(number) click to toggle source

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
to_s() click to toggle source

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
Also aliased as: inspect
toggle_cap(delay = 0.0) click to toggle source

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
toggle_left(delay = 0.0) click to toggle source

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
toggle_middle(delay = 0.0) click to toggle source

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
toggle_num(delay = 0.0) click to toggle source

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
toggle_right(delay = 0.0) click to toggle source

Switch the right LED on, if it was off before. Switch the right off, if it was on before.

# File lib/blinkenlights.rb, line 388
  def toggle_right(delay = 0.0)
    self.right = !right
    self
  end
toggle_scr(delay = 0.0) click to toggle source

Switch the Scroll Lock LED on, if it was off before. Switch the Scroll Lock LED off, if it was on before.

# File lib/blinkenlights.rb, line 273
  def toggle_scr(delay = 0.0)
    self.scr = !scr
    sleep delay
    self
  end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.